I have designed some code that should turn an led on and off when "high" or "low" are typed into the python interface. As I am using pyserial I make it write a character across serial that should then turn the led on and off. For some reason unknown to me it isn't though. Here is the code for the arduino side:
int led = 13;
void setup() {
Serial.begin(9600); // set the baud rate
Serial.println("Ready"); // print "Ready" once
pinMode(led, OUTPUT);
}
void loop() {
char inByte = ' ';
if (Serial.available()) { // only send data back if data has been sent
char inByte = Serial.read(); // read the incoming data
Serial.println(inByte); // send the data back in a new line so that it is not all one long line
}
delay(100); // delay for 1/10 of a second
if (inByte == '1');
{
digitalWrite(led, HIGH);
delay(1000);
}
if (inByte == '0')
{
digitalWrite(led, LOW);
delay(1000);
}
}
and here is the code for the python side
import serial
tries = 0
Arduino = serial.Serial(port="COM5", baudrate="9600")
while tries < 100:
ans = raw_input("High or Low??")
if ans == "low":
Arduino.write('1')
if ans == "high":
Arduino.write('0')
I know that you could do this just with the arduino language before anyone makes a comment about that because I wanted to test how well that they interface together.
P.S:
When I run the program the LED is constantly on and the TX pin is flashing but the RX pin isn't doing anything...