I have a float variable on my Arduino slave and I want to send it to my Raspberry Pi 3 Model B master. What I know is that I probably need to send an array of bytes from Arduino and then read it properly on my Raspberry Pi. I had no luck using this so far.
What I don't know is how should I read it, since WiringPi libraries offer only int values in return (sending 0-255 works like a charm, though).
It has been done here, but for Python, and here. C has a different set of libraries for I2C and doesn't offer such thing as struct.
Is it possible to read an array of bytes from I2C using WiringPi and convert it to float in C?
Multiplying the number on Arduino (to get rid of comma) and dividing it on Raspberry Pi is okay as well, but the problem of sending more than 255 via WiringPi remains.
Here's how I send the data on Arduino:
void sendData(){
Wire.write((byte*) &floatNumber, 4);
}
And here's how I can read 8-bit values (0-255) on Raspberry (Wire.write(129) - for example):
int fd;
int data;
wiringPiSetup();
fd=wiringPiI2CSetup(0x04);
data=wiringPiI2CRead(fd);
ui->lcdNumber->display(data);
ui->lcdNumber->display((float)data);
– Code Gorilla