Thursday, June 19, 2014
On 11:23 AM by Anonymous
Overview
Put your work on 'display' with this tutorial . A step-by-step guide to adding a low-cost alpha-numeric Liquid Crystal Display to your BeagleBone project. Present useful information, measurement readings and messages . The LCD interfacing method provided uses only 3 pins from the BeagleBone, leaving most pins available for other parts of your project. How do we do this?... Let's see!What you will need
- BeagleBone Black
- BeagleBone expandable case Orange or Black (recommended)
- AC adapter 5 Volts, 2 Amp (optional)
- Medium Breadboard and Jumper Wire Pack for Breadboards
- Proto Parts Kit
- Integrated Circuit 74HC164 (DIP14)
- Liquid Crystal Display (HD44780 Controller compatible)
- (1) Potentiometer (10K) for contrast control {ptk-027}
- Download a copy of Adafruit_BBIO library for Python
Instructions
This project uses the Adafruit_BBIO Python library, to access the GPIO pins of the BeagleBone.You may need to download this library{Angstrom Linux}.
opkg update && opkg install python-pip python-setuptools pip install Adafruit_BBIO
Step 1
Connect the display circuit as shown.
Note this circuit only requires three signals (as well as power: +5V and ground) from the BeagleBone.
Some displays have extra pin for backlighting. Verify the LCD pin assignments in the datasheet for the display you are using.
Connection Summary
IC1= 74HC164 DIP14, potentiometer = 10 kilohmsFrom | To | Signal Description |
---|---|---|
LCD-1 | P9-1 | Ground |
LCD-2 | P9-7 | +5V |
LCD-3 | Potentiometer Pin 2 | Contrast (center pin /wiper) |
LCD-4 | P8-18 | Register select (also data in) |
LCD-5 | Ground | Read/write (always write) |
LCD-6 | P8-14 | LCD Enable (strobe) |
LCD-7 | IC1-3 | LCD Data 0 |
LCD-8 | IC1-4 | LCD Data 1 |
LCD-9 | IC1-5 | LCD Data 2 |
LCD-10 | IC1-6 | LCD Data 3 |
LCD-11 | IC1-10 | LCD Data 4 |
LCD-12 | IC1-11 | LCD Data 5 |
LCD-13 | IC1-12 | LCD Data 6 |
LCD-14 | IC1-13 | LCD Data 7 |
Ground (P9-1) | IC1-7 | IC ground |
+5V (P9-7) | IC1-14,9 | IC Power and Reset pin |
+5V | Potentiometer Pin 3 | High side of 10K potentiometer |
GND | Potentiometer Pin 1 | Low side of 10K potentiometer |
P8-16 | IC1-8 | Clock signal |
P8-18 | IC1-1,2 | Serial Data Input |
Step 2
Adjust the contrast level to approximately 0.7~1.0 V (depends on the display you are using).Step 3
Project Software Program
Download lcm.py File and save this file (as lcm.py) to a working location on your BeagleBone.Program Listing
#!/usr/bin/python # FileName: lcm.py # Author : Richard St-Pierre # Version : 0.0 Nov 6, 2013 Beagle Bone Black version # import Adafruit_BBIO.GPIO as GPIO import time # --- Interface Pins --- CSA_PIN = "P8_14" SCK_PIN = "P8_16" SDI_PIN = "P8_18" # --- LCD commands --- CMD_CLS = 0x01 CMD_HOME = 0x02 CMD_ENTRY = 0x06 CMD_SCROL = 0x07 CMD_OFF = 0x08 CMD_ON = 0x0C CMD_CURS = 0x0E CMD_LINE1 = 0x80 CMD_LINE2 = 0xC0 CMD_FSET = 0x30 CMD_FSET2 = 0x38 msg = ['A','B','C'] logo = 'Logic Supply' #--- Initialize pins --- GPIO.setup(SCK_PIN, GPIO.OUT) GPIO.setup(SDI_PIN, GPIO.OUT) GPIO.setup(CSA_PIN, GPIO.OUT) #--- Logo --- print "BBB SPI LCM test/demo" #--- Send DATA to LCM --- def lcm_data (data): GPIO.output(SCK_PIN, GPIO.LOW) for i in range (8): if ((data<<i) & 0x80): GPIO.output(SDI_PIN, GPIO.HIGH) else: GPIO.output(SDI_PIN, GPIO.LOW) GPIO.output(SCK_PIN, GPIO.HIGH) GPIO.output(SCK_PIN, GPIO.LOW) GPIO.output(SDI_PIN, GPIO.HIGH) #data GPIO.output(CSA_PIN, GPIO.LOW) #strobe/en GPIO.output(CSA_PIN, GPIO.HIGH) #--- Send CMD to LCM --- def lcm_cmd (cmd): GPIO.output(SCK_PIN, GPIO.LOW) for i in range (8): if ((cmd<<i) & 0x80): GPIO.output(SDI_PIN, GPIO.HIGH) else: GPIO.output(SDI_PIN, GPIO.LOW) GPIO.output(SCK_PIN, GPIO.HIGH) GPIO.output(SCK_PIN, GPIO.LOW) GPIO.output(SDI_PIN, GPIO.LOW) #cmd GPIO.output(CSA_PIN, GPIO.LOW) #strobe/en GPIO.output(CSA_PIN, GPIO.HIGH) def lcm_msg (msg): for char in msg: lcm_data(ord(char)) def lcm_init (): lcm_cmd(CMD_FSET) lcm_cmd(CMD_FSET) lcm_cmd(CMD_ENTRY) lcm_cmd(CMD_ON) lcm_cmd(CMD_CLS) #--- Init and Display --- lcm_init() time.sleep(0.1) while True: lcm_cmd(CMD_CLS) lcm_data(0x42) lcm_data(0x45) lcm_data(0x41) lcm_data(0x47) lcm_data(0x4C) lcm_data(0x45) lcm_data(0x20) lcm_data(0x42) time.sleep(2) lcm_cmd(CMD_CLS) time.sleep(0.1) lcm_cmd(CMD_CLS) lcm_msg("Logic") time.sleep(2) lcm_cmd(CMD_CLS) lcm_msg("Supply") time.sleep(2)
Step 4
To run the program start putty or open a terminal and enter the following:python lcm.py
Your display will sequence through a number of messages. You are on your way.
Customize the messages to suit your needs.
Program Overview
This program takes data (characters) and sends it serially one bit at-a-time to an IC (Integrated Circuit) that converts it back to 8-bits. This saves many pins that can be used for controlling other devices.Let's go through the program listing, and review the program flow.
This program imports the required libraries for GPIO and time. Then three pins are declared.
CSA (Enable) strobes the display with a command or data.
SCK (Serial Clock) controls the shifting of the serial data bits.
SDI (Serial Data In) is used to send serial data bits on the rise of the SCK signal.
The most common commands for the display are listed next.
We then initialize the three pins as outputs. An introduction message is sent to the computer terminal.
Next, we define four functions:
lcm_data(), lcm_cmd(), lcm_msg(), lcm_init()
lcm_data()
This function takes an 8-bit data value (a character to display) and sends it bit-by-bit to the IC chip. Each bit is shifted out (Most-Significant-Bit first) and each data bit is clocked out (8 times). Once the data has been sent, the SDI_Pin is set high. This signal to the display that the 8-bits of data is a characters to be displayed. Now that the data has been serially shifted out to the IC, the data is ready for the LCD display to read it. Rising the CSA_Pin signals the display to take and process this data.
lcm_cmd()
This function is similar to lcm_data(), with one small change. The SDI_PIN is set low after the 8-bits have been sent. This signal to the display, that the information sent is a command (such as clear display, set location, control cursors...)
lcm_msg()
This function is used to display a message, by calling lcm_data() for each character in the word or message to display.
lcm_init()
This final function simply sends the required commands to initialize the display. Setting the number of lines, entry mode, turning ON the display and clearing the display for a fresh start.
The last section of the program, is a simple loop that demonstrates the functions in use. Sending commands, individual characters and complete messages. Some pauses are inserted to allow the messages to be viewed before a new one is displayed.
There you have it.
Hope you get the "message"!