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

Finally, it works!

debug bits received 40

debug 1, 75, 1, 6, 7D =? 7D

debug checksum ok

debug RH% 373

debug oC 262

RH% 37.3 %

oC 26.2 *C

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

Link to post
Share on other sites
  • 2 months later...

Is there a potential to modify this library for the DS18b20? I am way new to the microcontroller scene. I'm not asking anyone to simply solve this for me, a point in the direction to start would be good enough. I plan on looking at the arduino library to get things moving, but my knowledge of programming is limted so I will be pestering yall for help.

Link to post
Share on other sites
  • 2 weeks later...

Hi!

 

I am back playing with Energia and the LaunchPad.

I just ordered a DTH11 for around 1$ shipped from a Hong Kong seller on eBay. Planning to play with it later (also ordered a UHF transmitter, and a LCD, a remote temp/humidity sensor could be a nice toy).

I haven't dig around this chip yet but I was crawling in the Energia forums and read your topic so I am jumping in.

Thanks for the code examples!

 

Regards,

Yan.

 

EDIT : Missed page 2 of the discussion and first writing the message did not see all the participants...

Link to post
Share on other sites
  • 6 months later...

I guess so. The one-wire connection is the same but data sent by the DHT11 is different.

 

As I don't have any DHT11, I can't help much more, sorry :-(

 

No problem  :thumbup:

Just got to adapt some stuff. Maybe will even use the DHT22 since it's more acurate

Thanks

Link to post
Share on other sites

Here is a late addendum to the original problem:

 

As it was pointed out by Robert (in message #15), the discrimination of '1'-s from '0'-s is based on a simple comparison:

if (counter > 6)

The constant value of 6 is the "discrimination level". This value is good for the AVR chips, but is too small for other cards like MSP430 Launchpad, ChipKit UNO32, or GR-Sakura. The latest version of the Adafruit's DHT library therefore allows us to use an optional parameter to specify the preferred value of the "discrimination level".

 

But how can you determine the optimal value? Especially, if you don't have an oscilloscope at home...

Here comes the idea: let's print the observed counter values, then we can see some statistical distribution of these values.

I added some debug features (which compile conditionally when the DEBUG symbol is defined.

 

1. Declare an array bytes having 40 elements.

    uint8_t res[40];

2. Store the counter values for each of the 40 bits (just before the above mentioned comparison)

#ifdef DEBUG
            res[j] = counter;
#endif

3. At the end of DHT::read(void) function, print out the results:

#ifdef DEBUG
    for(i=0; i<j; i++) {
        Serial.print(res[i],DEC);
        Serial.print(" ");
        if(i%8 == 7) {
            Serial.println();
        }
    }
  Serial.println(j, DEC);
  Serial.print(data[0], HEX); Serial.print(", ");
  Serial.print(data[1], HEX); Serial.print(", ");
  Serial.print(data[2], HEX); Serial.print(", ");
  Serial.print(data[3], HEX); Serial.print(", ");
  Serial.print(data[4], HEX); Serial.print(" =? ");
  Serial.println(data[0] + data[1] + data[2] + data[3], HEX);
#endif

The result of a typical run on an MSP430G2553 can be seen here:

66 7 7 6 6 7 7 21
6 21 6 7 7 21 21 7
6 6 7 7 6 6 7 21
7 6 6 7 21 7 21 6
6 21 6 22 6 7 21 7
40
1, 46, 1, A, 52 =? 52
Humidity: 32.6 %    Temperature: 26.6 *C
7 7 7 6 6 7 7 21
6 22 6 7 7 21 21 6
6 6 7 7 6 6 7 21
7 6 7 7 21 7 21 21
7 21 7 21 7 6 22 20
40
1, 46, 1, B, 53 =? 53
Humidity: 32.6 %    Temperature: 26.7 *C
7 7 7 6 6 7 7 21
6 22 6 7 7 21 21 6
6 7 7 7 6 7 7 21
6 6 7 7 21 7 21 21
7 21 6 21 6 6 21 21
40
1, 46, 1, B, 53 =? 53
Humidity: 32.6 %    Temperature: 26.7 *C

 

You see, that the results can be divided in two groups: low values are 6 or 7 which means '0' and higher values of 20-21-22, which means '1'. In this case 15 is a good value for the discrimination level.

 

So this is how the poor man's tool can substitute oscilloscope.  :thumbup: 

 

Best regards,

Istvan Cserny

 

Link to post
Share on other sites
  • 6 months later...

Trying to figure out what, if any, changes would have to be made to support the F5529 version of the MSP430. I know it has some different default pin assignments than other versions. 

 

(This is from the .cpp file:

  _pin = pin;
Where does this pin value get defined?) 

 

Thoughts? 

Link to post
Share on other sites

The pin value is defined in the constructor. See the example provided DHT22_430_main.ino at lines 68-70:

#define DHTPIN P1_4

DHT22 mySensor(DHTPIN);

Trying to figure out what, if any, changes would have to be made to support the F5529 version of the MSP430. I know it has some different default pin assignments than other versions. 

 

(This is from the .cpp file:

  _pin = pin;
Where does this pin value get defined?) 

 

Thoughts? 

Link to post
Share on other sites

Thanks, found the pin definition. 

 

Also found this in the file: 

// Core library - MCU-based
#if defined(__MSP430G2452__) || defined(__MSP430G2553__) || defined(__MSP430G2231__) // LaunchPad specific
#include "Energia.h"
#else // error
#error Platform not supported
#endif

since my LaunchPad is a different model (F5529), is this going to fail? What would be needed to add support for it? 

Also, where do these variables get set? My guess: in the Energia app when you select the Board in the Tools menu. 

(Sigh. I have so much to learn and I'm not finding much in the way of documentation.) 

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...