Jump to content
Rei Vilo

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

Recommended Posts

I tried DHT11 with this library (post #19), and Stellaris launchpad LM4F120XL.  It works fine with some changes already suggested in this thread. I tried with both 4.7K and 10K resistor both works.   But I get only 8BIT resolution data from DHT11 (Byte0 and 2) .  It might be something wrong with the sensor itself as someone reported in another forum. Energia version is 0101E0011.

 

here is the summary

 

I had to change DHT22_430.h

 

from

-----

#if defined(__MSP430G2452__) || defined(__MSP430G2553__) || defined(__MSP430G2231__) // LaunchPad specific
#include "Energia.h"
#else // error
#error Platform not supported
#endif
 
to
---
#include "Energia.h"
 
 
 
on  DHT22_430.cpp
 
from
------
 
      if (counter > 8)
 
to
---
 
      if (counter > 13)
 
For me 15 also worked here.
In the same file I had to comment out
 
///    _temperature *= 256;
///    _humidity *= 256;
 
 
on the main sketch
 
    Serial.print("RH% \t");
    Serial.print(h);   // no divide by 10 and following two lines commented out
//    Serial.print(".");
//    Serial.print(h%10);
    Serial.println(" %\t");
    
    Serial.print("oC \t");
    Serial.print(t);            // no divide by 10 and following two lines commented out
//    Serial.print(".");  
//    Serial.print(t%10);
    Serial.println(" *C");    

Share this post


Link to post
Share on other sites

Hello

 

once again I have problem with Stellaris LM4F120 Launchpad and DHT22 (connected on PB_7).

I'm using LCD 5110(3,3v) + DHT22(tested on 5v+ resistor 10kOhm & 3,3v + resistor 10kOhm )  + on I2C BMP085(3,3v), TinyRTC (5v), HD44780 20x4(5v) (all on PD_0 & PD_1)

 

When I'm using only LCD5110 + DHT22 without <Wire.h> liblary included, both are working well:

post-37176-0-28559500-1403472457_thumb.jpg
 
When I'm using LCD5110, DHT22 + all I2C devices with <Wire.h> I get on HD44780:
post-37176-0-26519300-1403472638_thumb.jpg

Also TinyRTC gives me a strange dates for example 2050/07/21

 

When I'm disconnecting DHT22 and running the same code as in case above, I get:

post-37176-0-90055100-1403472758_thumb.jpg
 
So it looks like a problem with running I2C and DHT22 at the same time.
 
 
->  Fixed changed connection of the I2C devices to module 1.
 
Thanks
mic

post-37176-0-28559500-1403472457_thumb.jpg

post-37176-0-26519300-1403472638_thumb.jpg

post-37176-0-90055100-1403472758_thumb.jpg

Edited by mic

Share this post


Link to post
Share on other sites

Hello all,

 

I just tried the example code in Energia 13 and get the following error when compiling. I deleted my energia preferences to not avail. The library resides in its own directory inside my ~/sketchbook/libraries/ and shows up in the Energia menu.

[/home/laga/download/energia-0101E0013/hardware/tools/msp430/bin/msp430-g++, -c, -Os, -w, -ffunction-sections, -fdata-sections, -mmcu=msp430g2553, -DF_CPU=16000000L, -MMD, -DARDUINO=101, -DENERGIA=13, -I/home/laga/download/energia-0101E0013/hardware/msp430/cores/msp430, -I/home/laga/download/energia-0101E0013/hardware/msp430/variants/launchpad, -I/home/laga/sketchbook/libraries/DHT22_430_main, /tmp/build3433782599202339748.tmp/DHT22_430.cpp, -o, /tmp/build3433782599202339748.tmp/DHT22_430.cpp.o]
[/home/laga/download/energia-0101E0013/hardware/tools/msp430/bin/msp430-g++, -c, -Os, -w, -ffunction-sections, -fdata-sections, -mmcu=msp430g2553, -DF_CPU=16000000L, -MMD, -DARDUINO=101, -DENERGIA=13, -I/home/laga/download/energia-0101E0013/hardware/msp430/cores/msp430, -I/home/laga/download/energia-0101E0013/hardware/msp430/variants/launchpad, -I/home/laga/sketchbook/libraries/DHT22_430_main, /tmp/build3433782599202339748.tmp/DHT22_430_main.cpp, -o, /tmp/build3433782599202339748.tmp/DHT22_430_main.cpp.o]
[/home/laga/download/energia-0101E0013/hardware/tools/msp430/bin/msp430-ar, rcs, /tmp/build3433782599202339748.tmp/core.a, /tmp/build3433782599202339748.tmp/twi.c.o]
[/home/laga/download/energia-0101E0013/hardware/tools/msp430/bin/msp430-ar, rcs, /tmp/build3433782599202339748.tmp/core.a, /tmp/build3433782599202339748.tmp/WInterrupts.c.o]
[/home/laga/download/energia-0101E0013/hardware/tools/msp430/bin/msp430-ar, rcs, /tmp/build3433782599202339748.tmp/core.a, /tmp/build3433782599202339748.tmp/random.c.o]
[/home/laga/download/energia-0101E0013/hardware/tools/msp430/bin/msp430-ar, rcs, /tmp/build3433782599202339748.tmp/core.a, /tmp/build3433782599202339748.tmp/wiring.c.o]
[/home/laga/download/energia-0101E0013/hardware/tools/msp430/bin/msp430-ar, rcs, /tmp/build3433782599202339748.tmp/core.a, /tmp/build3433782599202339748.tmp/wiring_analog.c.o]
[/home/laga/download/energia-0101E0013/hardware/tools/msp430/bin/msp430-ar, rcs, /tmp/build3433782599202339748.tmp/core.a, /tmp/build3433782599202339748.tmp/wiring_shift.c.o]
[/home/laga/download/energia-0101E0013/hardware/tools/msp430/bin/msp430-ar, rcs, /tmp/build3433782599202339748.tmp/core.a, /tmp/build3433782599202339748.tmp/wiring_pulse.c.o]
[/home/laga/download/energia-0101E0013/hardware/tools/msp430/bin/msp430-ar, rcs, /tmp/build3433782599202339748.tmp/core.a, /tmp/build3433782599202339748.tmp/wiring_digital.c.o]
[/home/laga/download/energia-0101E0013/hardware/tools/msp430/bin/msp430-ar, rcs, /tmp/build3433782599202339748.tmp/core.a, /tmp/build3433782599202339748.tmp/usci_isr_handler.c.o]
[/home/laga/download/energia-0101E0013/hardware/tools/msp430/bin/msp430-ar, rcs, /tmp/build3433782599202339748.tmp/core.a, /tmp/build3433782599202339748.tmp/Tone.cpp.o]
[/home/laga/download/energia-0101E0013/hardware/tools/msp430/bin/msp430-ar, rcs, /tmp/build3433782599202339748.tmp/core.a, /tmp/build3433782599202339748.tmp/WMath.cpp.o]
[/home/laga/download/energia-0101E0013/hardware/tools/msp430/bin/msp430-ar, rcs, /tmp/build3433782599202339748.tmp/core.a, /tmp/build3433782599202339748.tmp/Stream.cpp.o]
[/home/laga/download/energia-0101E0013/hardware/tools/msp430/bin/msp430-ar, rcs, /tmp/build3433782599202339748.tmp/core.a, /tmp/build3433782599202339748.tmp/IPAddress.cpp.o]
[/home/laga/download/energia-0101E0013/hardware/tools/msp430/bin/msp430-ar, rcs, /tmp/build3433782599202339748.tmp/core.a, /tmp/build3433782599202339748.tmp/Wire.cpp.o]
[/home/laga/download/energia-0101E0013/hardware/tools/msp430/bin/msp430-ar, rcs, /tmp/build3433782599202339748.tmp/core.a, /tmp/build3433782599202339748.tmp/main.cpp.o]
[/home/laga/download/energia-0101E0013/hardware/tools/msp430/bin/msp430-ar, rcs, /tmp/build3433782599202339748.tmp/core.a, /tmp/build3433782599202339748.tmp/new.cpp.o]
[/home/laga/download/energia-0101E0013/hardware/tools/msp430/bin/msp430-ar, rcs, /tmp/build3433782599202339748.tmp/core.a, /tmp/build3433782599202339748.tmp/HardwareSerial.cpp.o]
[/home/laga/download/energia-0101E0013/hardware/tools/msp430/bin/msp430-ar, rcs, /tmp/build3433782599202339748.tmp/core.a, /tmp/build3433782599202339748.tmp/Print.cpp.o]
[/home/laga/download/energia-0101E0013/hardware/tools/msp430/bin/msp430-ar, rcs, /tmp/build3433782599202339748.tmp/core.a, /tmp/build3433782599202339748.tmp/WString.cpp.o]
[/home/laga/download/energia-0101E0013/hardware/tools/msp430/bin/msp430-ar, rcs, /tmp/build3433782599202339748.tmp/core.a, /tmp/build3433782599202339748.tmp/TimerSerial.cpp.o]
[/home/laga/download/energia-0101E0013/hardware/tools/msp430/bin/msp430-gcc, -Os, -Wl,-gc-sections,-u,main, -mmcu=msp430g2553, -o, /tmp/build3433782599202339748.tmp/DHT22_430_main.cpp.elf, /tmp/build3433782599202339748.tmp/DHT22_430.cpp.o, /tmp/build3433782599202339748.tmp/DHT22_430_main.cpp.o, /tmp/build3433782599202339748.tmp/DHT22_430_main/DHT22_430.cpp.o, /tmp/build3433782599202339748.tmp/core.a, -L/tmp/build3433782599202339748.tmp, -lm]
DHT22_430_main/DHT22_430.cpp.o: In function `DHT22::DHT22(unsigned char)':
DHT22_430.cpp:(.text._ZN5DHT22C2Eh+0x0): multiple definition of `DHT22::DHT22(unsigned char)'
DHT22_430.cpp.o:DHT22_430.cpp:(.text._ZN5DHT22C2Eh+0x0): first defined here
DHT22_430_main/DHT22_430.cpp.o: In function `DHT22::begin()':
DHT22_430.cpp:(.text._ZN5DHT225beginEv+0x0): multiple definition of `DHT22::begin()'
DHT22_430.cpp.o:DHT22_430.cpp:(.text._ZN5DHT225beginEv+0x0): first defined here
DHT22_430_main/DHT22_430.cpp.o: In function `DHT22::temperatureX10()':
DHT22_430.cpp:(.text._ZN5DHT2214temperatureX10Ev+0x0): multiple definition of `DHT22::temperatureX10()'
DHT22_430.cpp.o:DHT22_430.cpp:(.text._ZN5DHT2214temperatureX10Ev+0x0): first defined here
DHT22_430_main/DHT22_430.cpp.o: In function `DHT22::humidityX10()':
DHT22_430.cpp:(.text._ZN5DHT2211humidityX10Ev+0x0): multiple definition of `DHT22::humidityX10()'
DHT22_430.cpp.o:DHT22_430.cpp:(.text._ZN5DHT2211humidityX10Ev+0x0): first defined here
DHT22_430_main/DHT22_430.cpp.o: In function `DHT22::get()':
DHT22_430.cpp:(.text._ZN5DHT223getEv+0x0): multiple definition of `DHT22::get()'
DHT22_430.cpp.o:DHT22_430.cpp:(.text._ZN5DHT223getEv+0x0): first defined here
DHT22_430_main/DHT22_430.cpp.o: In function `DHT22::DHT22(unsigned char)':
DHT22_430.cpp:(.text._ZN5DHT22C2Eh+0x0): multiple definition of `DHT22::DHT22(unsigned char)'
DHT22_430.cpp.o:DHT22_430.cpp:(.text._ZN5DHT22C2Eh+0x0): first defined here
collect2: ld returned 1 exit status

Share this post


Link to post
Share on other sites

Dear all,

 

I found out why the example won't compile for me. DHT22_430.cpp.o is included twice in the linking step, hence the errors about 'multiple definitions'.

 

If I copy the example sketch into a new sketch, it compiles just fine. Before, I would just select the example from the examples menu and get the error I pasted above.

 

Working line:

[/home/laga/download/energia-0101E0013/hardware/tools/msp430/bin/msp430-gcc, -Os, -Wl,-gc-sections,-u,main, -mmcu=msp430g2553, -o, /tmp/build1383130571671707338.tmp/sketch_oct25b.cpp.elf, /tmp/build1383130571671707338.tmp/sketch_oct25b.cpp.o, /tmp/build1383130571671707338.tmp/DHT22_430_main/DHT22_430.cpp.o, /tmp/build1383130571671707338.tmp/core.a, -L/tmp/build1383130571671707338.tmp, -lm]

Broken line:

[/home/laga/download/energia-0101E0013/hardware/tools/msp430/bin/msp430-gcc, -Os, -Wl,-gc-sections,-u,main, -mmcu=msp430g2553, -o, /tmp/build1383130571671707338.tmp/DHT22_430_main.cpp.elf, /tmp/build1383130571671707338.tmp/DHT22_430.cpp.o, /tmp/build1383130571671707338.tmp/DHT22_430_main.cpp.o, /tmp/build1383130571671707338.tmp/DHT22_430_main/DHT22_430.cpp.o, /tmp/build1383130571671707338.tmp/core.a, -L/tmp/build1383130571671707338.tmp, -lm]

Best,

 

Michael

Share this post


Link to post
Share on other sites

Am about to use a DHT22 in a TIVA that's running wire.h (plus using Energia 14)

Mic, a few posts ago, said this configuration fails when I2C is in the mix.

 

Is this the case.

 

Or to put it simply has anyone got a DHT22 TIVA lib, that works when I2C is also used.

Share this post


Link to post
Share on other sites

DHT22 now works on the Tiva and can now get on with where I was 3 days ago with the F5529, but now have the freedom of rom space.

 

I must commend Rei VILO on his smart use of #define DEBUG, this made lib fault-finding a breeze. Be nice if all libs have this sort of feature, so that later lib iterations (to cater for new devices)  can be checked.

 

One bug I had (not sure if you can call a hardware bug a bug- never mind) was R9 & R10. They are zero link resistors that connect pins 14 & 23 together, as well as linking pins 15 & 24 together. Was getting all sorts of strange results until I unsoldered them.

Grant

Share this post


Link to post
Share on other sites

One bug I had (not sure if you can call a hardware bug a bug- never mind) was R9 & R10. They are zero link resistors that connect pins 14 & 23 together, as well as linking pins 15 & 24 together. Was getting all sorts of strange results until I unsoldered them.

 

I'm glad it works now. Thank you for the accolade.

 

R9 and R10 on the Stellaris / Tiva C LaunchPad redirect an I

post-12238-0-65674500-1425846015_thumb.png

Share this post


Link to post
Share on other sites

I think I'm looking at the latest version, and line 82 of the .cpp file says:

#if defined(__MSP430G2452__) || defined(__MSP430G2553__) || defined(__MSP430G2231__) // LaunchPad specific

Can I just add the MSP430F5529 to this list?

Share this post


Link to post
Share on other sites

Idk why but I've run this with my Tiva C TM4C123G without actually modding anything ( except the part that require exactly device, i've erased it ). So why'd you guy so confuse about the Sysclk. I choose my Tiva C (80Mhz) and this code is working fine

But can I ask you a question please :( ?

how is those debug code work, i mean those

 

debug bits received 40

debug 2, F8, 1, 4A, 45 =? 45
debug checksum NO
debug RH% 760
debug oC 330
 
and i am trying to connect this to a 16x2 LCD. hope it gonna work

Share this post


Link to post
Share on other sites

 I finally connect the DHT22 with my Tiva C TM4C123G and the code have been work, but when I try to mod the code so it can show info on my LCD. the code is as following:

 

#include "Energia.h"
// Include application, user and local libraries
#include "DHT22_430.h"
#include "LiquidCrystal.h"
#define DHTPIN PD_0 //Stellaris
//#define DHTPIN P1_4 //MSP430
DHT22 mySensor(DHTPIN);

boolean flag;

LiquidCrystal lcd(PD1, PD2, PD3, PE1, PE2, PE3);


void setup() {
Serial.begin(9600);
Serial.println("\n\n\n*** DHT22 test starts");
Serial.println("PUSH2 to end");
pinMode(PUSH2, INPUT_PULLUP);
mySensor.begin();
lcd.begin(16, 2);
}

void loop() {
delay(2000); // for Stellaris a lower value has a greater deviation
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
flag = mySensor.get();
int32_t h = mySensor.humidityX10();
int32_t t = mySensor.temperatureX10();

// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (!flag) {
Serial.println("Failed to read from DHT");
}
else {
Serial.print("RH% \t");
Serial.print(h/10);
Serial.print(".");
Serial.print(h%10);
Serial.println(" %\t");

Serial.print("oC \t");
Serial.print(t/10);
Serial.print(".");
Serial.print(t%10);
Serial.println(" *C");

lcd.setCusor(0, 1);
lcd.print("RH% \t");
lcd.print(h/10);
lcd.print(".");
lcd.print(h%10);
lcd.println(" %\t");

lcd.setCusor (0, 2);
lcd.print("oC \t");
lcd.print(t/10);
lcd.print(".");
lcd.print(t%10);
lcd.println(" *C");
}

if (digitalRead(PUSH2)==LOW) {
Serial.println("\n\n*** End");
Serial.end();
while(true); // endless loop
}

}

but unfortunately it show the bug that:

core.a(main.cpp.o): In function `main':main.cpp:(.text.startup.main+0x2): undefined reference to `setup'
main.cpp:(.text.startup.main+0x6): undefined reference to `loop'
collect2.exe: error: ld returned 1 exit status

i don't really know what happen

 

and for the code in the .cpp file, I don't understand the DEBUG section of it, really confused

Share this post


Link to post
Share on other sites

Hello! I am new to msp430 and Energia Compiler and I found this library for DHT22 that you posted several years ago and I really need some help: I need to send the data from the sensor to a GSM module SIM 808 (works with AT commands) through serial port. When I run the example I get in the serial monitor the debug info lines and then the values. My big question is:Are the debug lines affecting my commands sent to the GSM Module and if so...how can i remove them? Please help:) Thank you in advance!

 

 

debug bits received 40

debug 2, F8, 1, 4A, 45 =? 45
debug checksum OK
debug RH% 690
debug oC 290

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

×