I have a setup with serial comm from Raspberry Pi to Arduino. It's communicating at baud 9600 on both devices, and from Raspberry Pi 3b+ GPIO-14,UART0,TX0 to Arduino Nano RX0. There's a level shifter in between setup as recommended by AdaFruit tutorials. I'm sending data from Raspberry Pi as such:
#loop here
m = []
m.append(255)
m.append(i) // index value between 0-150
m.append(p[0][i]) // value between 0-254
m.append(p[1][i]) // value between 0-254
m.append(p[2][i]) // value between 0-254
#print statement here
'''
Data: [255, 94, 0, 0, 0, 255, 95, 254, 0, 0, 255, 96, 0, 254, 0]
...
'''
And receiving data on Arduino as such:
void serialEvent() {
while (Serial.available()) {
// get the new byte:
byte inChar = (byte)Serial.read();
sprintf(printString, "Received: %d", inChar);
Serial.println(printString);
}
}
/*
Received: 255
Received: 94
Received: 0
Received: 255
Received: 95
Received: 254
Received: 0
Received: 255
Received: 96
Received: 0
Received: 254
Received: 255
Received: 94
Received: 0
Received: 0
Received: 0
Received: 255
Received: 254
Received: 255
...
*/
Any idea why there are so many missed bytes and how to fix this?
EDIT: @juraj There is a ground between both. I've measured with a portable oscilloscope. I can post the picture of the setup tomorrow.
@Edgar Bonet The loop function is empty, and looks as follows:
void loop() {
}
I also don't have any data being sent back to the Raspberry Pi. I have the Serial TX wire out from Arduino completely disconnected
Serial.println()
takes the same time in any case. Did you try to shorten the string, like just the hex representation of the received bytes?Serial.println(...)
means “please, send out this data”.