Hi there,
I want to try to use the joystick demo from the article about nRF24L01+ wireless module using the ReliableDatagram from RadioHead. Instead of the joystick i want to use a DHT11 temperature and humidity sensor and send the data to the server (receiver).
The problem I face is that values from the joystick are integers but im reading floats from the DHT sensor.
What should I use instead of the 8-bit unsigned integer array (uint8_t) to send the values correctly?
Hi duddimobile,
got the same problem, there are a two solutions: one simple, just to get it work (that may not satisfy you at all) just leave the decimals. In my project I used three DHT11-sensors (stacked near beside in a beadboard for testing purposes) ...the values differed by 2°C and up to 4% huminity, so I think they are not that precise. That may be a good reason to forget the decimals. Next, not that simple is to split the DHT11-values into two parts integer and decimal, TX them and put them together in the RX-unit for display. (! Keep in mind that temperature can be minus! - that's another problem that has to be solved.)
Hope it will be fun to puzzle that out yourself! Hope this will be helpful.
Hi again, forgot to say something important... the transmission can be done (usualy) by (ASCII-)caracters... therfore the uint8_t-value-space (0-255), of cause you can convert each number of the value into a char (including the negative-sign) and send them seperately... i.e. for the temperature value of -24,25 send: '-', '2', '4', '.', '2', '5' if you just want to display them on RX that's OK. Of cause you have to convert the chars to a float to do calculations like a trend or the average
There is an easier way 😉
void setup() { Serial.begin(9600); float sensorValue = -1.0912345; byte decimalPlaces = 3; // IIRC... Max dp == 6 // First, convert to string... String data = String(sensorValue, decimalPlaces); // At the recieving end of the nRF24L01... // Convert it back to a float and perform calculations if necessary. float floatReceieved = data.toFloat(); }
Cheers!
Hi frogandtoad, this is a nice hint. I will try that, next time when I do any serial communication with floats. Thanks!
Hi frogandtoad, this is a nice hint. I will try that, next time when I do any serial communication with floats. Thanks!
You're welcome!
Let us know how you go 🙂