I'm using python to send a short serial message to an Arduino UNO over USB. This is run from terminal on an OSX machine.
import serial
ser = serial.Serial('/dev/tty.usbmodem14121', 9600)
ser.write('H')
ser.close()
Previously the Arduino was running code to read this message and react to it, but this was causing the Arduino to crash and restart. Simplifying the code led to the exact same result.
int ledRed = 3;
int ledGreen = 5;
int ledBlue = 6;
void setup()
{
pinMode(ledRed, OUTPUT);
pinMode(ledGreen, OUTPUT);
pinMode(ledBlue, OUTPUT);
}
void red()
{
digitalWrite(ledRed, HIGH);
digitalWrite(ledGreen, LOW);
digitalWrite(ledBlue, LOW);
}
void green()
{
digitalWrite(ledRed, LOW);
digitalWrite(ledGreen, HIGH);
digitalWrite(ledBlue, LOW);
}
void loop()
{
green();
delay(1000);
red();
delay(1000);
}
Can anyone shed a light on why sending serial to the board is causing it to crash and restart?
Thanks All
setup()
, maybe there's a mismatch? What happens if you addSerial.begin(9600)
tosetup()
? – Roger Rowland