I’ve been really interested in doing J4mie’s Physical Gmail Notifier ever since it came out in February. I only recently dropped into the project and got to learn a lot about python, plists, and arduino auto-reset functionality. I’m going to share what I’ve learned because I think there are lots of other people out there struggling to make it work. This page doesn’t really offer much that J4mie didn’t already say – it just says it in a different way.
I’ll post the code below – one issue with the way J4mie posted his was that it appended line numbers to everything and messed with formatting. Python is _really_ picky about formatting! All of the files are zipped HERE. It consists of three documents -
1) one python script that logs into your gmail rss feed and checks your total number of new messages. It then sends either an ‘m’ or an ‘n’ to the serial port.
2) one arduino sketch that tells the arduino to turn on or off a light based on the serial input
3) one .plist file that tells your mac (sorry pcs!) to run the python script every 60 seconds. If you run windows or linux then I’m sure there is something you can do to schedule this. You could also just set it to loop until quit. (to quit a script in terminal hit control-c)
Section 1- Python. You will need to change the python script so that it has your email and password, as well as your serial port info. This assumes you are checking a gmail account. It also works if you are using gmail as your email host for a private domain. The serial port info you can grab from the arduino program or by typing “ls /dev/tty.*” into the terminal. Save that file and put it somewhere on your computer. I picked my Documents folder. You will also need to download and install feedparser. This is what helps python parse the rss feed into useable chunks.
Section two – Arduino. Now go ahead and open the arduino sketch included in the zip file, paste it into your arduino window, and upload it to your arduino. You don’t need to change anything on this.
Section three – .plist. Next you should open the plist file and change it so that it points to the python script you changed earlier. If you want to change the frequency that it checks your mail at, that is the “integer” tag towards the end of the file. It is measured in seconds. The plist file should go in your user folder under Library/LaunchAgents. If the folder isn’t there then go ahead and make it.
Until you restart the plist won’t do anything, so the simplest thing to do is to restart. If not then you can manually run the python script. To do that type “python ” into terminal and drag in the python file. Hit return to run it. Once it has run, you can hit the up arrow to recall the last command typed, and return to run it again.
Section four – Wiring The wiring is very easy. Hook up a led and an appropriate resistor (i (should have) used a
22 47 ohm – if you are unsure – use a led calculator) between pin 12 and +5v. The negative (shorter) lead goes to the pin side. Done! (footnote: Make sure that not only are you within spec for your led, but you also aren’t sourcing more than 40ma from the pin. Otherwise you could do damage to your Arduino! My initial setup sources 100ma and could have fried the pin.)
Open up the serial monitor in arduino and wait for a signal to come in. It should come in once every 60 seconds, so be patient. If it isn’t sending data, then it could be either sending it on the wrong port (check your serial port settings) or the plist could not be working yet (restart, or run it manually) You should be seeing either an “n” or an “m”. That should also be turning on or off the LED
One final thing to look out for is that any arduino with auto-reset enabled will only work while the arduino application is running _with_ serial monitor open. Otherwise it will just reset itself every time the data comes in. To check out how to remove arduino auto reset from a bare bones board go here, for other boards, ask the google.
One thing about this is that I didn’t really like the bright light shining at me, so I mounted it under my desk, with it pointing up towards the wall. Now it’s a subtle glow, and it’s much easier to ignore when I have a lot of work.
Summary The plist file should run your python script every 60 seconds. The ‘n’ or ‘m’ should be sent from the python script and received by the arduino. Then the arduino tells the led to turn on or off. I tested both statuses (statii?) by logging in and marking messages as read or unread until I was happy with the results.
This has been the first project where I have been able to send serial data in a useable way. I’m excited about moving on to a version that scrapes email info and posts it to an lcd screen, or maybe a project that sends data back to the computer to do something. There is also the distinct possibility that you could script the python carefully enough so that the arduino was not needed for a serial lcd version. a serial port would be the only necessity…