I was trying to send some Serial Data with python to my Arduino and light a led on/off, over the Serial monitor of the Arduino IDE it works fine but once I try to do it over the Python code, it won't work
Here is the Arduino Code:
int LED = 7;
char serialData;
void setup() {
pinMode(LED, OUTPUT);
Serial.begin(9600);
}
void loop() {
serialData = Serial.read();
if(serialData == '1'){
digitalWrite(LED, HIGH);
}
if(serialData == '2'){
digitalWrite(LED, LOW);
}
}
And this is the Python Code:
import serial
import time
ser = serial.Serial()
ser.baudrate = 9600
ser.port = 'COM5'
time.sleep(10)
ser.write("1")
Now what it should do when I start the python code, is to send the "1"over Serial to the Arduino, the Arduino should receive it and light on the led.
ser.flush()to send it.delay(10)) afterdigitalWrite(LED, HIGH)anddigitalWrite(LED, LOW)inside theirifstatements ?