I am working with two Arduino Uno boards with one acting as a 16x2 LCD using the Sainsmart LCD shield. I wanting to take a sensor value from arduino A to arduino B ising the I2C bus, where it will be displayed on the LCD. I am able to do this using integer numbers however when I try to send a floating point number to be displayed it simply displays 0.
Thanks very much. This code compiled and using the serial monitor it appears to be transmitting the correct values. However, I am still only seeing the value 0.00 on my LCD screen. So i am assuming something is still not right in the receiver code
That's the second part of the puzzle.
You should now be sending a four byte float one byte at a time.
You did this by persuading the compiler that the float was, in fact a buffer of four consecutive bytes.
The next part is to read those four bytes, and reassemble them into a float.
I already explained that “Wire.read” returns a byte, and that a float is actually four bytes.
You need to read four bytes, one after the other, and assemble them into a float.
Wire.onReceive(receiveEvent);
float receiveEvent(y)
I’m a little (ok, ok, a lot) surprised that that compiled.
“receiveEvent” should not return anything, and the parameter should be of type “int”.