Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support for non 16mhz devices

Added constructor parameter to allow for different timing needs. It has
the a default value of 6 which is the original value, so it should be
backwards compatible
  • Loading branch information...
commit ad73fab6233853daa6835212d5a6eb5791e16a3d 1 parent 71ee113
Lars Sørup soerup authored
Showing with 5 additions and 4 deletions.
  1. +3 −2 DHT.cpp
  2. +2 −2 DHT.h
5 DHT.cpp
View
@@ -6,9 +6,10 @@ written by Adafruit Industries
#include "DHT.h"
-DHT::DHT(uint8_t pin, uint8_t type) {
+DHT::DHT(uint8_t pin, uint8_t type, uint8_t count) {
_pin = pin;
_type = type;
+ _count = count;
firstreading = true;
}
@@ -129,7 +130,7 @@ boolean DHT::read(void) {
if ((i >= 4) && (i%2 == 0)) {
// shove each bit into the storage bytes
data[j/8] <<= 1;
- if (counter > 6)
+ if (counter > _count)
Simon John
sej7278 added a note

how is this to be used, e.g. for an 8mhz atmega328p? do we halve or double count perhaps?

Lars Sørup
soerup added a note

I would expect to halve when you slow down the processor to half speed.

Simon John
sej7278 added a note

yup, 3 works but its pretty erratic - sometimes i get 0,2,18 when the actual temperature is 26 (which it correctly reports sometimes).

maybe because i'm putting the mcu to sleep to reduce power usage?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
data[j/8] |= 1;
j++;
}
4 DHT.h
View
@@ -23,13 +23,13 @@ written by Adafruit Industries
class DHT {
private:
uint8_t data[6];
- uint8_t _pin, _type;
+ uint8_t _pin, _type, _count;
boolean read(void);
unsigned long _lastreadtime;
boolean firstreading;
public:
- DHT(uint8_t pin, uint8_t type);
+ DHT(uint8_t pin, uint8_t type, uint8_t count=6);
void begin(void);
float readTemperature(bool S=false);
float convertCtoF(float);
Simon John

how is this to be used, e.g. for an 8mhz atmega328p? do we halve or double count perhaps?

Lars Sørup

I would expect to halve when you slow down the processor to half speed.

Simon John

yup, 3 works but its pretty erratic - sometimes i get 0,2,18 when the actual temperature is 26 (which it correctly reports sometimes).

maybe because i'm putting the mcu to sleep to reduce power usage?

Please sign in to comment.
Something went wrong with that request. Please try again.