Pages: [1]   Go Down
 Author Topic: [Solved]using robs dht11 library c to f conversion is this the best way?  (Read 576 times) 0 Members and 1 Guest are viewing this topic.
Offline
Full Member
Karma: 2
Posts: 148
 « on: January 17, 2013, 02:27:50 pm » Bigger Smaller Reset

is this the easiest/best way to do C to Farenheit conversions?

Code:
Serial.print(DHT.humidity, 1);
Serial.print(",\t");
Serial.println(DHT.temperature*1.8+32, 1);

also, storing each in eeprom, will one byte hold the data? say 76.1? best way to do that would be appreciated thanks!

solution. changed
Code:
Serial.print(DHT.humidity,1);
to
Code:
Serial.print(DHT.humidity,0);
for the whole number. the first one gives a one place decimal point. moral of story, i learned a bit more by reading around. thank you all. kudos to rob for library, i couldnt use the dht22 library couldnt figure out conversion for life of me. this is small and compact, keep up good work you arduino folks.
 « Last Edit: January 17, 2013, 08:15:33 pm by grendle » Logged

Global Moderator
Netherlands
Offline
Shannon Member
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
 « Reply #1 on: January 17, 2013, 02:42:12 pm » Bigger Smaller Reset

Hi Grendle,

This is an easy way to convert an Celsius to a Fahrenheit temperature.
It is slow as it uses floating points math, it is relative fast as it does not use division.
Because it uses floating point is is quite accurate.
The formula works for integer and float values of Celsius. Note the DHT11 only produces integer values for temp.

A far more elaborate C2F discussion can be found here - http://arduino.cc/forum/index.php/topic,139006.0.html -

 Logged

Rob Tillaart

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

Offline
Full Member
Karma: 2
Posts: 148
 « Reply #2 on: January 17, 2013, 03:04:50 pm » Bigger Smaller Reset

 Logged

Seattle, WA USA
Offline
Brattain Member
Karma: 601
Posts: 48543
Seattle, WA USA
 « Reply #3 on: January 17, 2013, 03:05:22 pm » Bigger Smaller Reset

Quote
will one byte hold the data? say 76.1?
Will one byte, that holds an integral value in the range 0 to 255, hold 76.1? What do you think?
 Logged

Offline
Full Member
Karma: 2
Posts: 148
 « Reply #4 on: January 17, 2013, 03:50:53 pm » Bigger Smaller Reset

sigh, well put it that way, no. maybe i asked wrong, how can i store 76.1 in eeprom, doable? no? then how to round up and down in code?
 Logged

Seattle, WA USA
Offline
Brattain Member
Karma: 601
Posts: 48543
Seattle, WA USA
 « Reply #5 on: January 17, 2013, 03:58:17 pm » Bigger Smaller Reset

Given that the sensor only returns integer values, why would you want to store a 4 byte float in EEPROM instead of a 2 byte int? Storing a 2 byte int is easy - use highByte() and lowByte() to get the bytes.
 Logged

Offline
Full Member
Karma: 2
Posts: 148
 « Reply #6 on: January 17, 2013, 04:00:13 pm » Bigger Smaller Reset

ok thank you, that makes sense. i appreciate the response. i think i am confusing myself and making it more difficult than it is. i will take your advice and experiment with this. thanks again for helping, Rob and Paul.
 Logged

 Pages: [1]   Go Up