I'm trying to communicate between arduino and my pc.
For the moment is very simple , i just want to switch on a LED when i send data but it doesn't work.
I use pySerial. The problem is the following : when i send data to my arduino the led TX blinks but the part of my code wich is after if ( serial.available()>0) doesn't run.
Here is my code :
Python code :
Most likely you are not waiting for the bootloader. I struggle with the encode and decode of the Python strings. Some of my programs encode 'ascii' for serial write and others encode 'utf-8'.
import serial, struct, time
ser = serial.Serial('COM10',9600, timeout=3)
time.sleep(3) # wait for the bootloader to run
junk = ser.readline().strip() # clean any junk from the buffer
print("junk: " + junk[-10:].decode("utf-8"))
a = ord('a') # send the code for 'a'
# Python 3.6 strings are utf-8, they seem to need encode to ascii for Pyserial
echo = ser.readline().strip()
print("debug: " + echo[-10:].decode("utf-8"))
There are more complex ways to send data with Python, an example I was looking at is
in that case, _connection.write is like your serie.write... unfortunately it is at the edge of what I can understand.