Sunday, 16 September 2012
Blog move
This will be my last post at this address as I've moved over to a new blogging platform: Jekyll. Jekyll is much more versatile and has allowed me to start playing around with CSS, HTML and gives me more flexibility on what I choose to do.
I'm using github pages to host the new site and I'll be writing a little bit about my experiences in the near future.
http://willprice.github.com/
Saturday, 7 January 2012
Gmail Notifier
4 Years ago Tom Paton posted this and I asked him about his code, thus prompting him to post this. 4 Years later, now finally equipped with some know how and a little bit more experience with microcontrollers and programming, I thought this a fairly ideal project to have a bash at.
I'll be updating this post as I go, with pictures and videos. I've currently put a servo in a little mailbox made out of card and when I have an email the flag is raised. I'm working on getting the right sized enclosure and am currently using a Arduino Pro Mini which has no USB interface and I have to work out how to remedy this. Admittedly, this is a total waste of an Arduino as it's overkill for this project, but at the moment I don't have enough time to learn how to write C code for AVR micros, but when I do, I'll make this a little less wasteful and hopefully use a micro with USB support built in. But for the time being -- Arduino and USB to UART Adapter.
I adapted his python code to something a little more appropriate for my usage:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python2 | |
# Author: Will Price | |
# Date: Jan 2011 | |
# Import statements: | |
# - Feedparser - needed to extract mailcount | |
# - Serial - needed to send command to Arduino | |
# - Time - waiting for gmail to be read | |
import feedparser, serial, time | |
# Variables | |
checkPeriod = 60 # Time between check in seconds | |
username = "username" | |
password = "pass" | |
label = " " #Label of folder to check no. of unread messages | |
# Define 'msgCount' function, returns number of unread messages (CREDIT TO: Tom Paton) | |
def msgCount(uid, pwd, filter): | |
inbox = feedparser.parse("https://%s:%s@gmail.google.com/gmail/feed/atom%s" % (uid, pwd, filter)) | |
return len(inbox["entries"]) | |
# Loop | |
while True: | |
# Serial port setup | |
com = serial.Serial("/dev/ttyUSB0",9600,timeout=0.25) | |
msgs = msgCount(username, password, label) | |
if (msgs > 0): # If number of unread messages is greater than 0, then tell the arduino | |
com.write("%c" % (msgs) ) | |
# print "You have %d messages to read" % msgs # For debugging purposes | |
com.close() | |
while (msgs > 0): | |
msgs = msgCount(username, password, label) | |
time.sleep(10) | |
com = serial.Serial("/dev/ttyUSB0",9600,timeout=0.25) | |
com.write("%c" % 0) | |
# print "Inbox is empty" # For debugging purposes | |
com.close() | |
time.sleep(checkPeriod) |
(replace username and password with your username and password. You might also need to fiddle with the serial port I've got mine setup as /dev/ttyUSB1)
Here's the Arduino code:
Here's the Arduino code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Gmail Notifier | |
// Author: Will Price | |
// Date: Jan 2011 | |
// Website: willprice94.blogspot.com | |
// Description: | |
// | |
// A simple sketch that waits for the number of unread messages to come over serial | |
// Use 'gmail_daemon' inconjunction for a physical mail notification system | |
// Macros | |
#include <Servo.h> | |
#define ServoPin 9 // The pin that the servo is connected to | |
// Variables | |
int msgs = 0; // Number of messages unread | |
//Setup Servo | |
Servo myservo; | |
//Initial Setup | |
void setup() { | |
pinMode(ServoPin, OUTPUT); | |
myservo.write(90); // Down position | |
myservo.attach(ServoPin); | |
Serial.begin(9600); | |
} | |
//Loop | |
if (Serial.available() > 0) { // Waiting to read from serial, if the buffer > 0 BYTES then execute code below | |
int msgs = Serial.read(); | |
if (msgs == 1) { | |
myservo.write(0); // Up position | |
} | |
else if (msgs == 0){ | |
myservo.write(90); // Down position | |
} | |
} | |
} |
Subscribe to:
Posts (Atom)