Raspberry Pi E-Mail + LCD Tutorial Mashup
Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/

Raspberry Pi E-Mail + LCD Tutorial Mashup

by bfesser on Tue Jan 29, 2013 2:59 pm

Just thought I'd share a simple little mashup I made between two of the Adafruit Learning System Raspberry Pi Tutorials. I've never done anything in Python before (only C++ and other languages), so this might look sloppy, but it seemed to work. I'd appreciate any suggestions on how to clean it up. I'm especially unsure about the inclusions (or as you may call them, imports?).

I combined the 16x2 LCD tutorial with the email LED tutorial to get the LCD to display the RasPi's IP (I was running headless) and how many unread emails I had in my Gmail inbox. Here's what I came up with:
Code: Select all | TOGGLE FULL SIZE
#!/usr/bin/python
from Adafruit_CharLCD import Adafruit_CharLCD
from subprocess import *
from time import sleep, strftime
from datetime import datetime

#!usr/bin/env python
import RPi.GPIO as GPIO, feedparser, time

lcd = Adafruit_CharLCD() #instantiate Adafruit_CharLCD
lcd.begin(16,1)

gmail_user = "user" #gmail username without @gmail.com
gmail_pass = "pass" #plaintext gmail password

cmd = "ip addr show eth0 | grep inet | awk '{print $2}' | cut -d/ -f1" #what is the IP address

#run the shell command to do our bidding
def run_cmd(cmd):
        p = Popen(cmd, shell=True, stdout=PIPE)
        output = p.communicate()[0]
        return output

#the main loop
while True:
   mail_count = int(feedparser.parse("https://"+gmail_user+":"+gmail_pass +"@mail.google.com/gmail/feed/atom")["feed"]["fullcount"]) #check email
   ip_address = run_cmd(cmd) #check IP address
   lcd.clear()
   #lcd.message(datetime.now().strftime('%b %d  %H:%M:%S\n')) #this prints the date and time if you prefer
   lcd.message('IP %s'%(ip_address)) #output IP address to LCD
   lcd.message('%s unread email'%(mail_count)) #output unread email count to LCD
   sleep(60) #refresh once every minute or so
Please, post suggestions.

Happy hacking!
bfesser
 
Posts: 30
Joined: Mon Dec 31, 2012 1:01 pm

Re: Raspberry Pi E-Mail + LCD Tutorial Mashup

by adafruit on Thu Jan 31, 2013 10:37 pm

post up a photo, we'd love to see what it looks like live :)
User avatar
adafruit
 
Posts: 11669
Joined: Thu Apr 06, 2006 3:21 pm
Location: nyc

Re: Raspberry Pi E-Mail + LCD Tutorial Mashup

by bfesser on Sat Mar 02, 2013 3:31 pm

Image
Raspberry Pi + IP/Gmail LCD by blfesser, on Flickr

Image
IP/Gmail LCD by blfesser, on Flickr

Sorry it took so long to get the photo.
The leads to the LED backlight broke off; had to get solder wick.
The LCD is a SHARP LM16 x 21A (pins 1-right to 14-left, HD44780A00).
I hope to upgrade to an Adafruit LCD Plate, and re-write the script.
bfesser
 
Posts: 30
Joined: Mon Dec 31, 2012 1:01 pm