Hi Guys,
I got my Arduino Duemilanove the other day and I wrote a little python script to light up an LED when I have unread emails in my Gmail account.
The script has the following logic:
1.) Connect to gmail, check unread email count 2.) Set signal to 'H' if unread emails exist unless set to 'L' 3.) open serial port, wait 1 sec. write the signal to the port. Disconnect 4.) Sleep for 3 minutes before doing it all over again.
The sketch on the arduino looks like this:
int ledPin = 13;
int signal;
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop()
{
if (Serial.available() > 0)
{
signal = Serial.read();
Serial.write( signal );
}
// if it's a capital H (ASCII 72), turn on the LED:
if (signal == 'H')
{
digitalWrite(ledPin, HIGH);
}
// if it's an L (ASCII 76) turn off the LED:
if (signal == 'L')
{
digitalWrite(ledPin, LOW);
}
delay( 1000 );
}
Everything works fine but I'm seeing some strange behaviour:
The script will successfully connect to the Arduino and set the LED pin HIGH but the LED will go dead when the python script disconnects from the serial port. I've seen the same behavour when using "Serial Monitor".
Can someone explain to me how Arduino serials ports work in relation to the Serial library ?
Your comments are appreciated.
Lee