Getting Arduino to communicate with Gmail, from the class that I taught at Twin Cities Maker
The basics were getting Arduino to talk to Gmail and then turn on a LED.
Step one: Load you Arduino with PhysicalPixel. It’s under examples, Communication.
Step two: Install Python and Pyserial
Step three download the ArduinoandGmail.py code
Step Four: Edit the Python Code. You will need to edit two things:
s = serial.Serial('/dev/tty.usbserial-A6008dvx', 9600)
Between the first tick marks enter your serial connection, you can find this by going to the Arduino IDE and then Tools, Serial Port, what is checked is what goes between the tick marks.
#inser username then password
rc, resp = M.login('USERNAME', 'PASSWORD')
print rc, resp
Enter you username and password.
Step Five: Run the python script and you should be good to go, the python will send letter ‘H’ when you have 1 or more unseen emails and ‘L’ when you have 0.
Step Six: hook up a LED and Resistor to Pin 13, or hook something else up that you want to turn on.
the Python Code:
# Code my Mike Hord, Kelly, and Paul Sobczak
# Gmail and Arduino 3/19/11
# Twin Cites Maker
# interval change for less often
INTERVAL = 1 # check every INTERVAL minutes
last_check = time.time() – INTERVAL*60 # subtract so that we check first time
#change between the ticks your serial link on arduino
s = serial.Serial(‘/dev/tty.usbserial-A6008dvx’, 9600)
M = imaplib.IMAP4_SSL(IMAP_SERVER, IMAP_PORT)
#insert username then password
rc, resp = M.login(‘USERNAME’, ‘PASSWORD’)
print rc, resp
# main loop
if time.time() – last_check < INTERVAL*5:
last_check = time.time()
status_string = M.status(‘INBOX’, ‘(UNSEEN)’)
p = re.compile(‘\d+’)
unread_count = string.atoi(p.findall(status_string),10)
if unread_count > 0:
This code was written Mostly by Mike Hord who operates the Uptownmaker Blog, Kelly and myself.
Update: This is now hosted on a Google Project Page