Adafruit 16x2 Character LCD Plus Keypad For Raspberry Pi
Adafruit 16x2 Character LCD Plus Keypad For Raspberry Pi
Raspberry Pi
Created by lady ada
https://learn.adafruit.com/adafruit-16x2-character-lcd-plus-keypad-for-raspberry-pi
Overview 3
Parts List 4
• 1) Resistors
• 2) Potentiometer
• 3) Pushbuttons
• 4) i2c Port Expander Chip
• 5) Male Header Pins
• 6) Printed Circuit Board
• 7) Raspberry Pi Plate Header
• 8) Bumper
• Additional
Assembly 7
• Model B+ Protection
Python Usage 26
• Python Installation of CharLCD Library
• Python Code
• Full Example Code
Python Docs 29
Download 29
This new Adafruit plate makes it easy to use a 16x2 Character LCD. We really like the
range of LCDs we stock in the shop, such as our classic blue & white (http://adafru.it/
181) as well as the fancy RGB negative (http://adafru.it/399) and RGB positive (http://
adafru.it/398). Unfortunately, these LCDs do require quite a few digital pins, 6 to
control the LCD and then perhaps another 3 to control the RGB backlight for a total of
9 pins. That's nearly all the GPIO available on a Raspberry Pi!
WARNING: The new Raspberry Pi model B+ with 4 USB ports overlaps closely
with backlight resistor leads on the char LCD plate. You will need to cover the
USB port and back of resistors with electrical tape to protect them from
touching. See more details and pictures on the assembly page of this guide.
This plate is perfect for when you want to build a stand-alone project with its own
user interface. The 4 directional buttons plus select button allows basic control
without having to attach a bulky computer.
If you want plug in a Cobbler or Gertboard at the same time, check out our Stacking
Header, you can fit an IDC cable over it if the Plate is assembled with this part. (http://
adafru.it/1112)
Parts List
Check to make sure your kit comes with the following parts.Sometimes we make
mistakes so double check everything and email support@adafruit.com if you need
We recently adjusted the kit so the buttons are on the RIGHT side instead of the left.
The parts list is otherwise the same, its just a little more stable than before
1) Resistors
There is a total of 3 resistors in this kit. For resistors labeled RED and BLUE on the
PCB, they are 1/4W 5% 220 ohm resistors (Red, Red, Brown, Gold). For the resistor
labeled GREEN on the PCB, it is a 1/4W 5% 330 ohm resistor (Orange Orange Brown
Gold).
2) Potentiometer
There is one 10k trim potentiometer. This part will go in the spot labeled Contrast
3) Pushbuttons
There are a total of 5 x 6mm tactile switch pushbuttons. These will be used in the UP,
DOWN, LEFT, RIGHT and SELECT locations on the PCB.
There is one of these MCP23017 i2c (16 input/output) port expander chips in the kit.
This is how we are able to only use 2 R-Pi pins to run the entire LCD and buttons. Clic
k here for more info on this chip. (http://adafru.it/732)
There is one strip of 36 male header pins in the kit. These will be used to attach the
LCD to the PCB.
There will be one extra-tall 26 pin female header for plugging into the Pi
8) Bumper
Additional
Your LCD may have 16 pins (Monochrome) or 18 pins (RGB) and may have 2 rows of
connectors or one. This is normal and does not affect the display
Assembly
Check the kit against the parts list to verify
you have all the parts necessary
WARNING: If you're using the new Raspberry Pi model B+ with 4 USB ports you
will need to take some extra steps to ensure the backlight resistor leads do not
touch the USB ports and short out. See the steps below for more details.
Model B+ Protection
With the new Raspberry Pi model B+ and its extra USB ports there's a slight problem
with the layout of the character LCD shield. As you can see in the photo below, the
three through-hole backlight resistors have their leads right above one of the metal
USB ports. Unfortunately these leads are quite close and can potentially short against
the metal USB port.
Note that if you are using a Raspberry Pi model A or B (i.e. Pi with only 1 or 2 USB
ports) you can skip this step and move on. You only need to add this tape if you're
using a Raspberry Pi model B+, the Pi with 4 USB ports.
Python Usage
It's easy to use the I2C 16x2 RGB LCD Pi plate with Python and the Adafruit
CircuitPython CharLCD () library. This library allows you to easily write Python code
that controls the RGB character LCD.
Assemble the plate as shown in the previous pages and attach to your Pi.
You'll need to set up your Raspberry PI to work with I2C before this will work!
Check out the CircuitPython on Raspberry Pi guide for details: https://
learn.adafruit.com/circuitpython-on-raspberrypi-linux
Once that's done, from your command line run the following command:
If your default Python is version 3 you may need to run 'pip' instead. Just make sure
you aren't trying to use CircuitPython on Python 2.x, it isn't supported!
First, you'll need to import necessary modules, initialize the I2C bus, and create an
instance of the character LCD class. Paste the following code into your REPL:
import board
import busio
import adafruit_character_lcd.character_lcd_rgb_i2c as character_lcd
lcd_columns = 16
lcd_rows = 2
i2c = busio.I2C(board.SCL, board.SDA)
lcd = character_lcd.Character_LCD_RGB_I2C(i2c, lcd_columns, lcd_rows)
Now you're ready to start writing text and characters on the display! The usage of the
LCD class is exactly the same as shown in the parallel LCD wiring guide (). Be sure to
check out that guide () for a complete discussion of LCD usage.
As a quick test though you can run the following code to use the color property to
set the backlight to red and the message property to write text to the display:
lcd.color = [100, 0, 0]
lcd.message = "Hello\nCircuitPython"
See the parallel LCD guide for more functions you can call to control the LCD! ()
If you don't see anything, adjust the potentiometer on the plate until the message
shows up. The potentiometer is located below the LCD on the side opposite the
buttons.
That's all there is to using the RGB character LCD Pi Plate with Python and the
Adafruit CircuitPython CharLCD library!
lcd.clear()
# Set LCD color to red
lcd.color = [100, 0, 0]
time.sleep(1)
# Print two line message
lcd.message = "Hello\nCircuitPython"
# Wait 5s
time.sleep(5)
# Set LCD color to blue
lcd.color = [0, 100, 0]
time.sleep(1)
# Set LCD color to green
lcd.color = [0, 0, 100]
time.sleep(1)
# Set LCD color to purple
lcd.color = [50, 0, 50]
time.sleep(1)
lcd.clear()
# Print two line message right to left
lcd.text_direction = lcd.RIGHT_TO_LEFT
lcd.message = "Hello\nCircuitPython"
# Wait 5s
time.sleep(5)
# Return text direction to left to right
lcd.text_direction = lcd.LEFT_TO_RIGHT
# Display cursor
lcd.clear()
lcd.cursor = True
lcd.message = "Cursor! "
# Wait 5s
time.sleep(5)
# Display blinking cursor
lcd.clear()
lcd.blink = True
lcd.message = "Blinky Cursor!"
# Wait 5s
time.sleep(5)
lcd.blink = False
lcd.clear()
Python Docs
Python Docs ()
Download
• Adafruit's Pi Python codebase ()
• EagleCAD PCB files on GitHub ()
• Fritzing object in the Adafruit Fritzing Library ()
Check the Usage page for how to install the example python code directly from your
Pi using git.