Jump to content
43oh

SOLVED! DHT22 Temp & RH% One-Wire Sensor on Energia


Recommended Posts

  • Replies 57
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

...and a picture!     The DHT22 sensor is at the bottom-right part of the proto-board. The LCD is a Nokia 5110 compatible. Temperature and humidity are displayed with a double-sized font.

Conclusion is that the original sketch depends on delays caused by digitalRead(). On MSP430 a digitalRead takes about 2.5 us and on AVR about 3.8 us. This difference + more efficient code on MSP430 c

Finally, it works! Thank you for your help!   I think it's time to consider buying an oscilloscope. :eh:   Please find the library with a basic example attached: DHT22_430_main.zip

Posted Images

I happen to have that sensor and am playing with that board. Will read the tutorial and try to reconstruct the experiment with what i have here (about an hour away from home for the weekend).

 

***EDIT (continually)***

I don't think i have a 10K resistor to play with. It is really interesting that you are getting what seem to be 16 bit results with errors (the 65535). When you used the pull up resistor, you either got high or low, so that didn't help. It seems like the sampling isn't being done correctly. BTW, did you try removing the atmega stuff from the h file?

Link to post
Share on other sites

Please find a LaunchPad-only version of the sketch (attached).

 

I've cleaned the code as much as I could, swiped out the float and added extra prints for debugging.

 

I tried changing the value of the resistor. 10 k? is for 5 V, so I tried 4.7 for k? is for 3.3 V, to no avail.

 

I suspect the sampling, and the millis() and micros() used.

 

Any idea to make it work?

 

Good luck!

DHT22_430_main.zip

Link to post
Share on other sites

That is sometimes true. I used asm to do Dallas/Maxim one wire @ 1 MHz+, 115200 bps serial @ 1 MHz and 2400 bps serial at 32 kHz. The timing of those was very demanding.

 

The DHT11/DHT22 protocol can be written in C and run at 1 MHz - I have done that. It requires careful coding to get the necessary efficiency. Each bit has to be processed in 70 clock cycles or less.

Link to post
Share on other sites

I have compared the delayMicroseconds() for Arduino uno and LaunchPad using the following snippet of code. Both boards yield the same result. I have attached the scope shots. It will be hard to get to the bottom of this without having the actually sensor. Will order one from Adafruit. To be continued...

 

void setup() {
 pinMode(GREEN_LED, OUTPUT);
}

void loop() {
 noInterrupts();
 delayMicroseconds(1);
 digitalWrite(GREEN_LED, HIGH);
 delayMicroseconds(1);
 digitalWrite(GREEN_LED, LOW);
}

post-28238-135135553129_thumb.jpg

post-28238-135135553136_thumb.jpg

Link to post
Share on other sites

Conclusion is that the original sketch depends on delays caused by digitalRead().

On MSP430 a digitalRead takes about 2.5 us and on AVR about 3.8 us. This difference + more efficient code on MSP430 caused the below counting loop to be about 3 us shorter on MSP430 vs AVR resulting in more counts than the code anticipates. Replacing the delayMicroseconds(1) with delayMicroseconds(3) compensates for the difference in timing and makes it all work.

 

while (digitalRead(_pin) == laststate) {
 counter++;
 delayMicroseconds(1);
 if (counter == 255) {
   break;
 }
}

 

An alternative work-around would be to compare counter to a higher number in the if-statement below.

 

if ((i >= 4) && (i%2 == 0)) {
 // shove each bit into the storage bytes
 data[j/8] <<= 1;
 if (counter > 6)
   data[j/8] |= 1;
   j++;
 }
}

 

Robert

post-28238-135135554293_thumb.png

post-28238-1351355543_thumb.png

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...