[SOLVED] Erraneous transmission at high baud rate for serial communications

Hi Coding Badly,

I feel that this post deviated far enough from the OP, as I have made progresses to narrow down the source of the problem. People will get lost if I keep posting here. Could you please help review whether the following post is OK to create a new one? It would be OK to say no too and I really appreciate your work in help organizing this forum.

Subject: Sending constant int from Arduino to PC causes error

I am using Arduino Uno Rev 3, and according to this link we can achieve 2000000 baud rate.

This problem can be easily repeated by the following code:

void setup() {
  Serial.begin(2000000);
}

void loop() {
  int val = 234;
  Serial.println(val);
}

I am using the serial-USB cable. To read the data, I used Python pyserial (< 20 lines of code including empty lines and import lines):

import serial
import matplotlib.pyplot as plt

LEN = 10000
data = []
ser = serial.Serial('COM3', baudrate=2000000)
for i in range(LEN):
    try:
        data.append(int(ser.readline()))
    except:
        pass
ser.close()

# %% Plot data
plt.figure(figsize=(6, 4))
plt.plot(data)
plt.savefig('data.png')

Here is what I got: