WarBerryPi – LCD screen

I mentioned in the hardware requirement section that I use an LCD to display some basic information. My personal preference is the Display-O-Tron 3000, but you can use anything you like. What I like about this LCD is that it is a shield, meaning that it snaps on the Raspberry Pi pins, avoiding the need for any soldering.

Picture1

If you want to duplicate this setup, it is not difficult at all.

 cd /home/pi/WarBerry
mkdir init_scripts

Create a new file called lcd_init.sh and paste the following code:

#!/bin/sh   
cd /home/pi/WarBerry/init_scripts/   
sudo python lcd_on.py 

  
Now create a new file called lcd_on.py and paste the following code:

import dothat.lcd as lcd  
import dothat.backlight as backlight  
import math  
import os, subprocess  
import time  
	  
time.sleep(0.05)  
	  
backlight.off()  
backlight.set_graph(0)  
lcd.clear()  
backlight.rgb(100, 255, 255)  
lcd.set_contrast(50)  
lcd.set_cursor_position(3, 0)  
lcd.write("WarBerryPi")  
subprocess.call("sudo /sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}' > eth_ip_ad", shell = True)  
subprocess.call("sudo /sbin/ifconfig wlan0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}' > wlan_ip_ad", shell = True)  
subprocess.call("sudo /sbin/ifconfig eth1 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}' > eth1_ip_ad", shell = True)  
	  
	  
lcd.set_cursor_position(0, 1)  
	lcd.write("E: ")  
	with open('eth_ip_ad', 'r') as eth_ip:  
	    eth = eth_ip.readline()  
	if eth == "":  
	    lcd.set_cursor_position(2, 1)  
	    lcd.write("N/A")  
	else:  
	    e = eth.strip()  
	    lcd.set_cursor_position(2, 1)  
	    lcd.write(e)  
	  
	lcd.set_cursor_position(0, 2)  
	lcd.write("W: ")  
	with open('wlan_ip_ad', 'r') as wlan_ip:  
	    wlan = wlan_ip.readline()  
	if wlan == "":  
	    lcd.set_cursor_position(2, 2)  
	    lcd.write("N/A")  
	else:  
	    w = wlan.strip()  
	    lcd.set_cursor_position(2, 2)  
	    lcd.write(w)  

The lcd_on.py script is the script responsible for putting the information on screen. Basically what the script does is extract the IP addresses of eth0, eth1, and wlan0, saving them in text files that are then read by the script to display the information at the right location on the LCD.

Now we need to instruct the lcd_init.sh to start at boot time.

 sudo nano /etc/rc.local 

Scroll to the end of the file and add the line

 sudo bash /home/pi/WarBerry/init_scripts/lcd_init.sh & 

And that’s it. If you have downloaded the correct libraries for the LCD, it should work like a charm.