37 lines
2.2 KiB
Text
37 lines
2.2 KiB
Text
From: https://learn.adafruit.com/adafruit-16x2-character-lcd-plus-keypad-for-raspberry-pi/usage
|
|
|
|
NOTE: if i2c does not appear to work,
|
|
edit /boot/config.txt and add: dtparam=i2c1=on
|
|
(cf. http://raspberrypi.stackexchange.com/questions/27073/firmware-3-18-x-breaks-i2c-spi-audio-lirc-1-wire-e-g-dev-i2c-1-no-such-f)
|
|
|
|
NOTE #2: on later Raspbians and/or RasPi3, must enable i2c in raspi-config
|
|
(go to "Interfacing Options" screen)
|
|
|
|
* edit /etc/modules, add i2c-bcm2708 and i2c-dev
|
|
* sudo apt-get install i2c-tools python-smbus
|
|
* confirm that the lcd was detected by running:
|
|
sudo i2cdetect -y 0 (if you are using a version 1 Raspberry Pi)
|
|
sudo i2cdetect -y 1 (if you are using a version 2 Raspberry
|
|
you should see it show up at 0x20
|
|
* sudo apt-get update
|
|
* sudo apt-get install build-essential python-dev python-smbus python-pip git
|
|
* sudo pip install RPi.GPIO
|
|
* git clone https://github.com/adafruit/Adafruit_Python_CharLCD.git
|
|
* cd Adafruit_Python_CharLCD
|
|
* sudo python setup.py install
|
|
* test by running:
|
|
cd examples
|
|
sudo python char_lcd_plate.py
|
|
|
|
Look at the contents of the char_lcd_plate.py file to see the basic usage of the character LCD plate class. The basic usage is to import the library and create an instance of the Adafruit_CharLCDPlate class. The char LCD plate class is smart enough to know how to talk to the character LCD plate without any configuration or parameters.
|
|
|
|
Once you have an instance of the Adafruit_CharLCDPlate class there are a few functions you can call to interact with the display:
|
|
message(text)
|
|
Print the provided string message to the display. The text string can include linebreak characters ('\n') and will move to the next line when found in the string.
|
|
clear()
|
|
Clear the display and reset the position of message printing to the first column and first line.
|
|
set_color(red, green, blue)
|
|
Set the color of the red, green, and blue backlight LEDs. Each color value should be a 1 for on or 0 for off. For example to set a red backlight call set_color(1,0,0) or to set a purple color call set_color(1,0,1).
|
|
You can find a more detailed write-up of the library in this character LCD guide (see the Usage and Raspberry Pi Char LCD Plate pages).
|
|
|
|
more at: https://learn.adafruit.com/character-lcd-with-raspberry-pi-or-beaglebone-black/overview
|