I'm working on a simple project which requires me to write a Python script that will send data through a serial port from a PC to an Arduino. As part of this project I want to be able to check how many bytes are in the 64 byte input buffer of the Arduino. The issue is that when I try to write data and then use pySerial's out_waiting method, it always returns zero. This is a toy model I have been using for testing.
Arduino code:
void setup() {
Serial.begin(9600);
}
void loop() {
}
Python code:
import serial
import time
Arduino = serial.Serial('COM5',9600)
for i in range(20):
Arduino.write('1'.encode())
time.sleep(1)
print(Arduino.out_waiting)
Arduino.flushOutput()
Arduino.flushInput()
print(Arduino.out_waiting)
Arduino.close()
I would expect the first print statement to output 20 and the second to output 0. They both output 0, and I really can't figure out why.
Here is a link to the pySerial documentation: pySerial docs
Thanks in advance for any help.