You can output pretty much anything you want to AndyPi’s LCD. It is controlled using Python, making use of the wiringpi and RPi.GPIO libraries, but you can also use C. Step-by-step instructions below show you how to display your IP address and a scrolling message from the BBC news RSS feed. You could also output something like a twitter feed or anything else you have in mind. For more information on how to program with python, do a google search, check out the Raspberry Pi forum, and look at the relevant section of the Raspberry Pi Educational Manual for a start.
PART A – Wire up the LCD to your Raspberry’s GPIO ports
Follow the instructions on this page. This gives assembly instructions for the kit version (no soldering required if you have AndyPi’s Plug & Go version), and details of how to wire the LCD to the Raspberry Pi GPIO ports.
PART B – Software installation
1. I’m assuming you are starting with a fresh install of Raspbian Wheezy 2013-07-26, with an internet connection already setup. There might be some changes for different systems, or you may have some of these things installed already. You might need to answer ‘y’ to some questions asking you if you are ready to install. Make sure your system is up to date with:
sudo apt-get update
sudo apt-get upgrade
2. Install the programming language Python, and some related tools:
sudo apt-get install python python-dev python-setuptools python-pip
3. Install WiringPi, a library which allows PWM control of the backlight:
sudo pip install wiringpi
4. Download AndyPi_LCD python class and to your home directory
cd $home
sudo wget http://download.andypi.co.uk/AndyPi_LCD.py
5. This class contains the following functions which you can call from another script – see the examples in part C & D below.
Initialization functions:
lcd.lcd_init(); required to initialised LCD
lcd.led(value); turn on backlight, value = 0:512
lcd.cls(); clears LCD & turns off backlight
Static display function:
lcd.static_text(line, “justification”, “Static Message”); displays a static message (max 16 characters)
Continuously updating functions (infinite loops!):
lcd.clock(line, “justification”); line = 1,2; justification =l,r,c
lcd.scroll_clock(line, “justification”, speed, “Scrolling Message”); line & justification refer to clock; speed = 0:1, try 0.3 for a good speed
lcd.scroll(line, speed, “Scrolling Message”);
Part C – Static script displaying your IP address
The script below uses the AndyPi_LCD class to display your IP address and a static message on the LCD, using the function AndyPi_LCD.static_text(). You can download and run it with the following commands:
sudo wget http://download.andypi.co.uk/IP_Script.py
sudo python IP_Script.py
To edit the script, and see how it works, open it in the text editor, nano:
sudo nano IP_Script.py
If you want to clear the display, you’ll have to write a new python script and call the lcd.cls() function!
PART D – Scrolling script displaying the BBC News RSS feed
Since the LCD is only 16 characters wide, scrolling text across it is really useful! However, to scroll text, python needs to continually write to the LCD, so the AndyPi_LCD class contains some functions to do this. However, these are infinite loops, and so to continue to do useful things in python (such as check for the latest news feed every minute!), we need to put these loops in a separate thread process. To use this script, you’ll need to install a couple of python modules:
sudo pip install feedparser (a module used in the script to select RSS feeds)
sudo pip install processing (a module used in the script to use multiple threads/processes)
Download the Scroller Script and run it with the following commands:
sudo wget http://download.andypi.co.uk/Scroll_Script.py
sudo python Scroll_Script.py
This script downloads the BBC world news RSS feed, and scrolls it across the display, with the time displayed on line 1. Every 30 seconds, the script checks for new news. This script is continuously running, so to stop it and clear the display, press CTRL-C.
Of course, you can substitute your own message – perhaps your latest tweets, or output of something else from your Raspberry Pi.
Note: The video shows a combination of the scripts in Part C and D, to output the current news feed (but doesn’t check every 30 seconds) and your IP address.