Memorial day is 05/25/2015 – Orders will ship out on May 26th. There will not be any deliveries or shipping on Monday. Any order placed after 11am ET on Friday May 22nd will not start to ship out until Tuesday May 26th.

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:

Raspberry Pi E-Mail + LCD Tutorial Mashup

by bfesser on Tue Jan 29, 2013 3: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
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

gmail_user = "user" #gmail username without
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 +"")["feed"]["fullcount"]) #check email
   ip_address = run_cmd(cmd) #check IP address
   #lcd.message('%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!

Posts: 32
Joined: Mon Dec 31, 2012 2:01 pm

Re: Raspberry Pi E-Mail + LCD Tutorial Mashup

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

post up a photo, we'd love to see what it looks like live :)

Posts: 11904
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: Raspberry Pi E-Mail + LCD Tutorial Mashup

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

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

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.

Posts: 32
Joined: Mon Dec 31, 2012 2:01 pm