Problem with Pyserial

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 :

import serial 

serie.port= 'COM10'

if serie.isOpen():

Arduino code :

int ledPin = 9;
byte incomingByte;

void setup() {
    pinMode(ledPin, OUTPUT);

void loop() {
    if (Serial.available() > 0) {
        incomingByte =;
        digitalWrite(ledPin, HIGH);

    digitalWrite(ledPin, LOW);}

Thank you !

So the host computer is Windows 10 I am guessing?

What version of Python?

Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

What version of PySerial?

[C:\Users\rsutherland>pip uninstall pyserial]
C:\Users\rsutherland>pip install pyserial
Collecting pyserial
  Using cached
Installing collected packages: pyserial
Successfully installed pyserial-3.4

Have a look at this Python - Arduino demo

Your PC program should open the serial port, allow time for the Arduino to reset before trying to send data and should then keep the serial port open until it is completely finished with the Arduino.


Yes I'm working with Windows 10.I have pyhton 3.6.4 and pyserial 3.4.
thank you ron_shutterland

I'm gonna test you program !
thank you Robin2

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
if ser.in_waiting:
    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.