Go Down

Topic: Class for DHT11, DHT21 and DHT22 (temperature & humidity) (Read 183700 times) previous topic - next topic

robtillaart

#60
Nov 25, 2013, 09:50 pm Last Edit: Nov 26, 2013, 07:03 pm by robtillaart Reason: 1

You are welcome, I added an offset -2º in temperature data
Thanks!


Do you (or others)  think the library should support for a corrective offset?

e.g.  
Code: [Select]
void setTempOffset(float delta);
float getTempOffset();
void setHumOffset(float delta);
float getHumOffset();

or in the constructor...

will work better if the library uses an object per sensor iso one object for all sensors. need a rewrite... something like  
DHT22 sensor1(pin, offset);
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robtillaart

#61
Nov 26, 2013, 07:04 pm Last Edit: Jun 01, 2014, 10:17 am by robtillaart Reason: 1
Updated the playground to version 0.1.08
major change - support for DUE (adaptive TIMEOUT).
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

derrick345

     Greetings,
Thanks for the work. I am having problems with compiling the code. I have an UDOO and I am attempting to execute the code on the DUE side. I get the following error though. Any help would be greatly appreciated.

V/r

Derrick

Quote

DHT/dht.cpp.o: In function `dht::read(unsigned char)':
/home/ubuntu/Arduino/libraries/DHT/dht.cpp:116: multiple definition of `dht::read(unsigned char)'
dht.cpp.o:dht.cpp:116: first defined here
DHT/dht.cpp.o: In function `dht::read22(unsigned char)':
/home/ubuntu/Arduino/libraries/DHT/dht.cpp:78: multiple definition of `dht::read22(unsigned char)'
dht.cpp.o:dht.cpp:78: first defined here
DHT/dht.cpp.o: In function `dht::read21(unsigned char)':
/home/ubuntu/Arduino/libraries/DHT/dht.cpp:70: multiple definition of `dht::read21(unsigned char)'
dht.cpp.o:dht.cpp:70: first defined here
DHT/dht.cpp.o: In function `dht::read11(unsigned char)':
/home/ubuntu/Arduino/libraries/DHT/dht.cpp:42: multiple definition of `dht::read11(unsigned char)'
dht.cpp.o:dht.cpp:42: first defined here
/opt/arduino-1.5.4/hardware/tools/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/thumb/libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
sbrkr.c:(.text._sbrk_r+0xc): warning: undefined reference to `_sbrk'
collect2: ld returned 1 exit status


robtillaart

do you have the lib included twice?
copied it to 2 locations?  (sketch folder , library folder, arduino lib folder?)
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

derrick345

    Thanks for the reply,
Apparently, it  was Arduino IDE issue. Initially, I placed the sketch in the same place as I did the libs. Once I changed that the sketched worked.  I tried the latetst lib and code for the DHT22, and I noticed that it did not execute at all. Is it suppose to work with the DUE? IT compiled fine however, there is no output from the Arduino serial monitor even though there are serial print functions listed. Even if something was wrong with the libs, those statements should print.  Not sure if it is a UDOO, DUE, or library thing.
V/r
Derrick

robtillaart

Can you post the code you used?

Do you check the return values the library gives for read?

If you use DHT11 in your code and sample a DHT22 (HW) you should get some values back.
Can you try that?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

perrociego

#66
Dec 15, 2013, 08:22 pm Last Edit: Dec 15, 2013, 08:39 pm by perrociego Reason: 1
Hi Rob:

Thank you for your easy and great code. I´m learning a lot.

By the way:  
Doesnt if ((micros() - t) > 40) {} require something like else return DHTLIB_ERROR_TIMEOUT; ?

Also, isnt bits() a Byte?

Regards:
Marcelo from Buenos Aires




robtillaart


By the way: 
Doesnt if ((micros() - t) > 40) {} require something like else return DHTLIB_ERROR_TIMEOUT; ?


HI Marcello,

This line of code sets a 1 bit on a specific bit position (the cnt'th bit).

As the bits are preset to 0 on all bit positions they do not need to be explicitly cleared, e.g. like the code below would do.
Code: [Select]

if ((micros() - t) > 40) bitset(bits[idx], cnt);
else bitclear(bits[idx], cnt)


The timeout is guarded by the loops above this line with the variable loopCnt.

I have thought about a version of the DHT lib where timing and timeout is replaced by a proper call to micros(); That way the protocol would work on faster or slower CPU's. Problem with micros() however is that for a 16Mhz Arduino it has a granularity of 4 uSec. An 8MHZ version would have a micros() granularity of 8 or maybe even more. That would make it hard to do the short timing. (Imagine a tiny85 working on 1 MHz => would not work)
For the faster processors like the DUE, the lib would work probably better with micros() for timekeeping.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

perrociego

HI Rob:

Of course.

I was looking at the code again. Get that. Going to change my question.

But you go too fast.  :smiley-eek:


robtillaart

you will pick up speed as long as you keep asking questions! (no there ain't no bad questions, only bad answers)
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robtillaart

Updated the playground to version 0.1.09
+ reduced the foot print with 30 bytes.
  - predecrement in timeoutloops
  - use of mask to build up bytes.

+ added time measurement in the DHT22 example sketch.
   On average a reading takes 24- 25 milliseconds, most of this time is the wake up call.
   Should be investigated as this is now 80% of the blocking time.

- http://playground.arduino.cc//Main/DHTLib -
- https://github.com/RobTillaart/Arduino/tree/master/libraries/DHTlib - (code only)

Recently confirmed to work on:  Digistump Digix   84 MHz Clock Speed too.
- http://forum.arduino.cc/index.php?topic=215336 -


Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Burn-In

I've copy+paste the code for the dht.h and dht.cpp from github. But if i use it for my scetch i have this strange "\stray" errors.

.../dht.h:1: error: stray '\357' in program
.../dht.h:1: error: stray '\273' in program
.../dht.h:1: error: stray '\277' in program

I think it means there is an error in the dht.h file. Isn't it?
With the older revision of the library everything was fine.

robtillaart

cannot replicate your error.

Can you zip the dht.h that fails and attach it in a post here  ?
Are you on windows mac unix?
What editor (settings) are you using?  ==> is the file changed to UTF-8 format instead of ASCII?


link to the previous version 1.0.8 - https://github.com/RobTillaart/Arduino/blob/4126dfc63a3dc645bfc518e0cefe3cda653903cf/libraries/DHTlib/dht.h -
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Burn-In

Hi Rob,
thanks for reply.
You had the right instinct. :)
There was the same 3 characters in both files too much. The files was changed to UTF-8 and everything seems ok.

Many thanks .
Joerg

robtillaart

You're welcome.

please let me know if any other issues pop up.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up