I am trying to have my arduino uno run when code is sent to it, however, nothing happens except the lights blinking back and forth for a second when it is sent and then nothing. I am just sending a string on serial, and using an if statement so it should be super straight forward but I am not sure what is happening to cause it not to work. Code below, any help would be awesome. Python
import serial, time
arduino = serial.Serial('/dev/ttyUSB0', 9600, timeout=1)
cmd = ''
while cmd != '0':
cmd = input('Enter a cmd ')
arduino.write(cmd.encode('ascii'))
Arduino
void setup() {
Serial.begin(9600);
}
void loop() {
delay(100);
if (Serial.available() > 0) {
String stringFromSerial = Serial.readString();
if (stringFromSerial == "1") {
Serial.println("1");
} else if (stringFromSerial == "2") {
Serial.println("2");
} else if (stringFromSerial == "3") {
Serial.println("3");
} else {
Serial.println("Not recognized cmd");
}
}
}
Update: Thanks for the help, I have updated the code to what actually works.