Jump to content
Rei Vilo

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

Recommended Posts

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?

Share this post


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

Share this post


Link to post
Share on other sites

Looking at your code the problem probably is the delayMicroseconds() not being accurate. I thought I hooked it up to a scope and confirmed that it was indeed close to 1us. Will hook it up again and run some tests on the delayMicroseconds().

 

Robert

Share this post


Link to post
Share on other sites

Thank you for your help and for the precise measures!

 

Problem is, I don't have an oscilloscope :roll:

 

The LaunchPad has a place for the optional crystal. Does the quartz provide a better accuracy?

Share this post


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.

Share this post


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

Share this post


Link to post
Share on other sites

I have the DHT22 and it runs fine with the Arduino but I lack an oscilloscope.

 

My logic analyser doesn't feature adjustable trigger value, so I can't use it for 3.3V signals.

 

Sorry, I can't help!

Share this post


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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×