Use arduino to check gmail !
This is what I got :
A LED that lights up when I got unread mail in my INBOX on Gmail.
This is what you need :
- an arduino
- python 2.7.2
- python-pyserial 2.6
- something for output, a LED is good
This is how I did :
1. The arduino code :
int outPin = 9; // Output connected to digital pin 9
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 == '1') mail = HIGH;
else if (val == '0') mail = LOW;
}
// Set the status of the output pin
digitalWrite(outPin, mail);
}
2. The python code :
#!/usr/bin/python2
# Check new mail on gmail, pass it to arduino
import time, imaplib, re, serial, sys
SERIALPORT = "/dev/ttyACM0" # Change this to your serial port!
# Set up serial port
try:
ser = serial.Serial(SERIALPORT, 9600)
except serial.SerialException:
sys.exit()
conn = imaplib.IMAP4_SSL("imap.gmail.com", 993)
conn.login('username', 'YOURPASSWORD')
unreadCount = re.search("UNSEEN (\d+)", conn.status("INBOX", "(UNSEEN)")[1][0]).group(1)
# to avoid race
time.sleep(1)
# for debugging
#print unreadCount
# Output data to serial port
if unreadCount != '0':
ser.write('1')
else:
ser.write('0')
# Close serial port
ser.close()
3. Add a cronjob every minute :
$ crontab -e
*/1 * * * * python2 /path/to/script/checkmail.py >> /dev/null 2&>1
I added a resistance, otherwise it’s too much light !
ENJOY !


