I need to exchange data (roughly 100 bytes 10 times a second) between Teensy4.1 and RaspberyPi 4. I decided to do this via serial interface. There is Teensy code:
float r=191.699997;
byte * b = (byte *) &r;
Serial8.write(b, 4);
I have hard-coded 191.699997 for test purposes.
Please find below RaspberryPi Java part:
System.out.println("----------------");
System.out.format(7 + " : " + TEENSY.getData(7) + "\n");
System.out.format(8 + " : " + TEENSY.getData(8) + "\n");
System.out.format(9 + " : " + TEENSY.getData(9) + "\n");
System.out.format(10 + " : " + TEENSY.getData(10) + "\n");
data[0]=(byte)TEENSY.getData(7);
data[1]=(byte)TEENSY.getData(8);
data[2]=(byte)TEENSY.getData(9);
data[3]=(byte)TEENSY.getData(10);
System.out.format(7 + "' : " + data[0] + "\n");
System.out.format(8 + "' : " + data[1] + "\n");
System.out.format(9 + "' : " + data[2] + "\n");
System.out.format(10 + "' : " + data[3] + "\n");
ByteBuffer buffer = ByteBuffer.wrap(data);
int first = buffer.getInt();
float second = buffer.getFloat();
System.out.print("int: " + first); System.out.print("\n");
System.out.printf("float: %f \n", second);
System.out.println("----------------");
The output of the above code is the shown bellow:
----------------
7 : 51
8 : 179
9 : 63
10 : 67
7 : 51
8 : -77
9 : 63
10 : 67
int: 867385155
float: 0.000000
----------------
I understand why is the difference but have no idea how to make it working (by working I mean how to get 191.699997 on the Raspberry Pi side.
Thanks in advance for your hints.