Hello, I am working on automated chess project.
I need to send data from Arduino to Python and then process it and send back some data to Arduino. If i understand this mechanism right, I can send data to serial monitor and then my data is in buffer and whenever this data is read, it is removed from serial monitor? What if i send data to serial monitor in Arduino (which have to be read in Python) and a few instructions later i read data from serial monitor in Arduino - is it gonna read data send a few instructions earlier? How can I know whether Python or Arduino is going to read data if they are working at the same time? Unfortunately I cant open serial monitor in Arduino while Python code is working. I hope you understand my problem, I know i made it little bit confusing.
The serial line works both ways so Python can send data to arduino and arduino can send data to Python
There is a small buffer on the Arduino side so as long as your code does come back frequently to check if there is some data waiting you’ll be fine
When the Arduino sends data via the Serial link it neither knows or cares whether it has been read or not, nor can it find out. It is the responsibility of whatever the Arduino is connected to to read the data at the rate that it is sent
So, if the data has not been read then it is not available to be read back by the Arduino
When data is sent to the Arduino over the Serial link it is the Arduino's responsibility to read it fast enough, but it will never read back data that it previously sent whether it has been read or not
You mention the Serial monitor a number of times but, that is only a way of seeing the data and in practice it would not be used in a project such as yours except for information and/or debugging messages. In fact, you should not use the same hardware Serial pins as the Serial monitor because there will be a clash of resources. Depending on which Arduino you have it may have more than one Serial interface or you might need to use SoftwareSerial to create a second iserial nterface
You can't use the Arduino-IDE serial monitor.
Your python-code must establish its own serial connection
to send back and forth data over this serial connection
actually you can if you have 2 distinct Serial ports
if you have only a UNO and don't want to use SoftwareSerial, if you don't use the USB cable but a couple FTDI adapter then you can too as the Tx and Rx do not need to go to the same port
I don't remember the details and I have not fallen foul of it myself, but I have a recollection of it causing problems but cannot be sure, hence "I believe", which was possibly too strong a phrase to use
It is very possible that the circumstances were different than those pertaining to this topic but as I can't provide a reference then I may well be wrong