Tarahi
March 21, 2020, 3:20pm
1
Hi every one.
I faced a problem and search too mach,but not find the solution for this case.
The problem is :
I need the output of a DHT11 sensor
float temp = dht.readTemperature();
to a char format like this :
char radiopacket[8] = "28.44";
So how can I convert ?
or tell me if there is a way to get sensor data in char format ...
Thanks
or sprintf
sprintf(radiopacket,"%.2f",temp);
hope that helps...
EDIT: not applicable if using ARDUINO IDE. see post#3
The Arduino IDE by default does not support floating point (%f) with sprintf().
Most people use dtostf() instead.
jremington:
The Arduino IDE by default does not support floating point (%f) with sprintf().
you learn something everyday....
It is possible to include the %f feature in sprintf() by linking the appropriate libraries, but most people don't take the trouble.
A search will reveal the required steps.
Tarahi
March 21, 2020, 8:40pm
7
[Solved]
As friends say, I found that sprintf library is not complete in arduino and for float just gives "?" !!!
finally I found the answer with dtostrf
That is :
float temp = dht.readTemperature();
char radiopacket[8];
dtostrf(temp,2,2,radiopacket);
Thanks all for help