Using Pi-Lite
You want to use a Pi-Lite to display text messages on a 9 × 14 LED array.
Fit a Pi-Lite onto the GPIO port of your Raspberry Pi, and write a Python program to send it messages to display over the serial connection.
The Pi-Lite communicates using the Raspberry Pi’s serial port. So, the first thing that you need to do is disable the Raspberry Pi’s serial console by following the instructions in Recipe 8.7, and then install PySerial using the instructions in Recipe 8.8.
The Pi-Lite is a powerful board that covers most of the surface of the Raspberry Pi (Figure 13-5).
The Pi-Lite (see “Modules” on page 381) has its own processor that does the work of controlling the array of 9 x 14 LEDs. Serial commands can be sent to it and the default behavior is to simply display any text that is sent as horizontally scrolling text.
Power off the Raspberry Pi and attach the Pi-Lite board. When you power the Raspberry Pi back up, the board puts on a little self-test display using the LEDs.
We can try this board out using the Minicom program (Recipe 8.9), which you can install by typing:
$ sudo apt-get install minicom |
Now open a Minicom session with the command:
minicom -b 9600 -o -D /dev/ttyAMA0 |
Type in some text, and you will see it flit across the array of LEDs.
Discussion
Sending messages from Python, rather than using Minicom, is also pretty straightforward. You will, however, need to install the Python serial library (Recipe 8.8) using the command:
$ sudo apt-get install python-serial |
Open an editor (nano or IDLE) and paste in the following code. As with all the program examples in this book, you can also download the program from the Code section at http://www.raspberrypicookbook.com, where it is called pi_lite_message.py.
import serial ser = serial.Serial(‘/dev/ttyAMA0’, 9600) while True: message = raw_input(“Enter message: “) ser.write(message) |
The program prompts you for a message and then sends it to the Pi-Lite:
$ sudo python pi_lite_message.py Enter message: Hello Enter message: |
Besides displaying scrolling text, you can also control individual pixels of the display and put the display into a bar graph and other modes (see the link to the official guide in the See Also section).
The following example toggles individual pixels on and off (pi_lite_rain):
import serial import random ser = serial.Serial(‘/dev/ttyAMA0’, 9600) while True: col = random.randint(1, 14) row = random.randint(1, 9) ser.write(“$$$P%d,%d,TOGGLE\r” % (col, row)) |
See Also
The official Getting Started guide for the Pi-Lite can be found at http://bit.ly/1bAq375.
You can see Conway’s Game of Life on a Pi-Lite at http://www.youtube.com/watch?v=bVavjoeHuak.
Table A-8. Modules | |
Raspberry Pi camera module | Adafruit: 1367, MCM: 28-17733, CPC: SC13023 |
Arduino Uno | SparkFun: DEV-11021, Adafruit: 50, CPC: A000066 |
Level converter, four-way | SparkFun: BOB-11978, Adafruit: 757 |
Level converter eight-way | Adafruit: 395 |
LiPo boost converter/charger | SparkFun: PRT-11231 |
PowerSwitch tail | Adafruit: 268 |
16-channel servo controller | Adafruit: 815 |
Motor driver 1A dual | SparkFun: ROB-09457 |
RaspiRobot board | Sparkfun: KIT-11561, raspirobot.com |
PiFace digital interface board | MCM: 83-14472, CPC: SC12827 |
Humble Pi | MCM: 83-14637, CPC: SC12871 |
Pi Plate | Adafruit: 801 |
Gertboard | MCM: 83-14460, CPC: SC12828 |
Breakout board with paddle terminals | MCM: 83-14876, CPC: SC12885 |
PIR motion detector | Adafruit: 189 |
Venus GPS module | SparkFun: GPS-11058 |
Methane sensor | SparkFun: SEN-09404 |
Gas sensor breakout board | SparkFun: BOB-08891 |
ADXL335 triple-axis accelerometer | Adafruit: 163 |
4×7-segment LED with I2C backpack | Adafruit: 878 |
Bicolor LED square-pixel matrix with I2C backpack | Adafruit: 902 |
PiLite interface board | Ciseco, CPC: SC13018 |
aLaMode interface board | Makershed: MKWY1, Seeedstudio: ARD10251P |
Freetronics Arduino LCD shield | www.freetronics.com |
RTC module | Adafruit: 264 |
16 x 2 HD44780 compatible LCD module | SparkFun: LCD-00255, Adafruit: 181 |