I'm trying to send a uint8_t and two floats as bytes (not as the actual characters in the numbers) from a Python program over a serial connection to an Arduino (ATtiny1614 using megaTinyCore). Currently, on the Python side, I have this:
Serial.write(b"\x01" + struct.pack("<ff", float1, float2))
On the Arduino, I have this:
struct DATA_W {
float f1;
float f2;
} wStruct
if (Serial.available() >= (sizeof(uint8_t)+(sizeof(float)*2))) {
uint8_t cmd = (uint8_t) Serial.read();
Serial.readBytes((char *) &wStruct.f1, sizeof(float));
Serial.readBytes((char *) &wStruct.f2, sizeof(float));
}
The uint8_t would be in the cmd variable, and the two floats would be in the wStruct struct. I can read the cmd just fine, but when I read the two floats, I get very different values than what I should be getting. Most of the time, I just read -0.00 and 0.00, but sometimes, I get very large numbers. An example would be me sending 100 and 94.1999, but getting -14336 and 20608 (those values are after I converted the float to an int, but the issue still shows up before the conversion).
What am I doing wrong, and how can I fix it?