I am trying to send six integers at a time through Serial.write() on arduino and send them to python. so far, I have managed to turn the Integers into byte pointers (I think thats the name) and send them over serial. however, when I try to reassemble them on the python side, I get some strange numbers that I did not intend to see.
Arduino Code:
int myInts[6]= {1455, 1446, 6766, 974, 365, 455};
void setup()
{
Serial.begin(9600);
}
void loop()
{
byte *p = (byte)myInts;
for(byte i = 0; i < sizeof(myInts); i++){
Serial.write(p[i]);
}
}
Python Code
import argparse
import numpy
import time
import serial
import struct
ser = serial.Serial('/dev/ttyACM0', 9600)
while True:
b = ser.read(4)
i = struct.unpack('i' ,b)
print(i)
Output:
(-1090650113,) (285341695,) (10683141,) (-1090650177,) (285341695,) (10683141,)
Thanks!
Vik