Arduino y Python

Hola a todos, estoy tratando de comunicar arduino con python pero he tenido algunos problemas

La idea es prender y apagar un led
este el codigo arduino(Blink example)

const int ledPin = 13; // the pin that the LED is attached to
int incomingByte;      // a variable to read incoming serial data into

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // see if there's incoming serial data:
  if (Serial.available() > 0) {
    // read the oldest byte in the serial buffer:
    incomingByte = Serial.read();
    // if it's a capital H (ASCII 72), turn on the LED:
    if (incomingByte == 'H') {
      digitalWrite(ledPin, HIGH);
    }
    // if it's an L (ASCII 76) turn off the LED:
    if (incomingByte == 'L') {
      digitalWrite(ledPin, LOW);
    }
  }
}

Este es el codigo en python

import serial
from time   import sleep
serialport = serial.Serial('COM3', 9600)
serialport.setDTR(False) # Drop DTR
sleep(0.022)    # Read somewhere that 22ms is what the UI does.
serialport.setDTR(True)  # UP the DTR back
while 1:
     serialport.write('H')
     sleep(1)
     serialport.write('L')    

serialport.close()

El led se mantiene prendido y no se apaga, que estoy haciendo mal?

Yo no sé Python pero parece lógico. Yo intentaría localizar en que lado está el problema, por ejemplo puedes enviar la H o la L con el terminal del IDE de Arduino (o con cualquier otro) para ver si funciona esa parte.

Creo que te puede funcionar mejor así:

import serial
from time import sleep
serialport = serial.Serial('COM15', 9600)
serialport.setDTR(False) # Drop DTR
sleep(0.022) # Read somewhere that 22ms is what the UI does.
serialport.setDTR(True) # UP the DTR back

serialport.write('H')
sleep(5)
serialport.write('L')

serialport.close()

Vale, en ocasiones estamos un poco "espesos" :wink:

Yo creo que sería así:

while 1:
     serialport.write('H')
     sleep(1)
     serialport.write('L')
     sleep(1)

Necesitas dos esperas una para determinar el tiempo que está encendido y otra el que está apagado