I have written a small program to send serial commands from Python to the Arduino Micro. This is my code for both:
Python
import serial
ser = serial.Serial('COM5', 9600)
ser.write(b'0')
ser.write(b'1')
# ser.write(b'2')
print('done')
Arduino
void setup()
{
Serial.begin(9600);
}
void loop()
{
while (!Serial.available()){}
Serial.println(Serial.read()-48);
}
If I keep the ser.write(b'2')
line in the Python code commented out, the code executes nearly instantly, and I am able to see both transmissions in the serial monitor. If I uncomment it, the Python code takes about 5-7 seconds to execute, and none of the data comes through the serial monitor.
I've tried different baud rates but that hasn't helped. I've also tried sending an integer rather than b'#'
, and the same thing happens, no data is transmitted if I have all three serial commands active.
What is happening in my code? Is the serial buffer overloaded by the three successive writes and the buffer ends up flushing?
write
lines?