user75474: 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

user7508: Without the full codes, we can only guess. My guess would be the serial
receive buffer on the Arduino is overflowing.
One reason this could happen is if serialEvent() is not called
frequently enough. This function is called by the Arduino core on every
loop iteration, just after loop() returns. If your loop() takes too
long (e.g. you are using delay() or blocking waits), the receive
buffer can overflow before serialEvent() has a chance to empty it.
Another reason is if the Raspberry Pi is sending too much data, too
fast. For every byte the Arduino receives, it must send back
between 13 and 15 bytes. If too much data comes too fast, the transmit
buffer will eventually get full, and then Serial.println() becomes
really slow, because it has to wait for the bytes to actually get out
on the wire. This in turn slows down serialEvent() to the point where
it can make the receive buffer overflow.
Edit: If this (the Raspberry sending data too fast) is the cause of
the problem, the obvious solution is to have it send data more slowly,
as:
repeat:
    send a message
    delay for some suitable time


75474: <p>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 <a href="https://learn.adafruit.com/neopixels-on-raspberry-pi/raspberry-pi-wiring" rel="nofollow noreferrer">as recommended by AdaFruit tutorials</a>. I'm sending data from Raspberry Pi as such:</p>
<pre class="lang-py prettyprint-override"><code>#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]
...
'''
</code></pre>
<p>And receiving data on Arduino as such:</p>
<pre class="lang-c prettyprint-override"><code>void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    byte inChar = (byte)Serial.read();
    sprintf(printString, &quot;Received: %d&quot;, 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
...
*/
</code></pre>
<p>Any idea why there are so many missed bytes and how to fix this?</p>
<p>EDIT: @juraj There is a ground between both. I've measured with a portable oscilloscope. I can post the picture of the setup tomorrow.</p>
<p>@Edgar Bonet The loop function is empty, and looks as follows:</p>
<pre class="lang-c prettyprint-override"><code>void loop() {
}
</code></pre>
<p>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</p>
 7508: <p>Without the full codes, we can only guess. My guess would be the serial
receive buffer on the Arduino is overflowing.</p>
<p>One reason this could happen is if <code>serialEvent()</code> is not called
frequently enough. This function is called by the Arduino core on every
loop iteration, just after <code>loop()</code> returns. If your <code>loop()</code> takes too
long (e.g. you are using <code>delay()</code> or blocking waits), the receive
buffer can overflow before <code>serialEvent()</code> has a chance to empty it.</p>
<p>Another reason is if the Raspberry Pi is sending too much data, too
fast. For every byte the Arduino receives, it must send back
between 13 and 15 bytes. If too much data comes too fast, the transmit
buffer will eventually get full, and then <code>Serial.println()</code> becomes
<em>really slow</em>, because it has to wait for the bytes to actually get out
on the wire. This in turn slows down <code>serialEvent()</code> to the point where
it can make the receive buffer overflow.</p>
<p><strong>Edit</strong>: If this (the Raspberry sending data too fast) is the cause of
the problem, the obvious solution is to have it send data more slowly,
as:</p>
<pre><code>repeat:
    send a message
    delay for some suitable time
</code></pre>
