Hi All
My Name is Dave and I'm a .........newbie
Ok. I am trying to set up the classic James Matthews gmail notifier.
Here is the Python code on my PC
import serial
import time
import imaplib, re
ser = serial.Serial(1)
print "Starting on " +ser.portstr;
conn = imaplib.IMAP4_SSL("imap.gmail.com", 993)
while (True):
conn.login('user','password')
unreadCount = int(re.search("UNSEEN (\d+)", conn.status("INBOX", "(UNSEEN)")[1][0]).group(1))
ser = serial.Serial(4)
if(unreadCount > 0):
print str(unreadCount) + " new mails!"
ser.write('M')
else:
print "no mail :("
ser.write('N')
time.sleep(5)
and here is the code on the Arduino Uno:
int outPin = 2; // Output connected to digital pin 2
int mail = LOW; // Is there new mail?
int val; // Value read from the serial port
void setup()
{
pinMode(outPin, OUTPUT); // sets the digital pin as output
Serial.begin(9600);
Serial.flush();
}
void loop()
{
// Read from serial port
if (Serial.available())
{
val = Serial.read();
Serial.println(val);
if (val == 'M') mail = HIGH;
else if (val == 'N') mail = LOW;
}
// Set the status of the output pin
digitalWrite(outPin, mail);
}
Points to make:
- The hardware is fine. I have a LED connected to Pin 2 through a resistor. This has been tested with Blink and othe programs and works fine.
- The python code (with proper username and password) accesses gmail and provides the positive message "xxx emails" etc
The issue is the serial transmission of a character "M" or "N" that should trigger the LED. It simply isn't happening.
The only change to what I call the "standard" code is that I have included a line to access port 5 (that only works when I use serial.Serial(4) ). I say works in that the TX/RX LEDs on the Uno flicker - only with this this port initiated.
It seems to me that the character "M" is not being transmitted or received on the serial port.
I'm sure this is a simple issue but not for this newbie!
Help much appreciated
Regards
Dave