www.joy-it.net
Pascalstr. 8 47506 Neukirchen-Vluyn
To use the display completely, you can download the example code
here or you can create yourself a file and copy the following code into
that file.
To create a new file, you use the following command:
sudo nano lcd20x4.py
from Adafruit_CharLCD import Adafruit_CharLCD
import Adafruit_GPIO.PCF8574 as PCF
import RPi.GPIO as GPIO
LCD = PCF.PCF8574(address=0x27)
LCD.setup(5,0)
LCD.output(5,0)
# Declares which PCF pin is connected to which LCD pin
lcd_rs = 4# RegisterSelect pin is connected to GPIO4
lcd_en = 7# Enable pin is connected to GPIO7
d4,d5,d6,d7 = 0,1,2,3 # Data pins 4,5,6,7 is connected to GPIO 0,1,2,3
cols,lines = 20,4 # Number of columns and rows of the display
# Declares the pins of the Raspberry Pi to the buttons
SW1 = 4 #GPIO 4
SW2 = 16 #GPIO 16
SW3 = 10 #GPIO 10
SW4 = 9 #GPIO 9
GPIO.setmode(GPIO.BCM)
GPIO.setup(SW1, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(SW2, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(SW3, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(SW4, GPIO.IN, pull_up_down = GPIO.PUD_UP)
# Initializes the LCD
lcd = Adafruit_CharLCD(lcd_rs, lcd_en, d4, d5, d6, d7,cols, lines, gpio=LCD)
lcd.clear()
lcd.message('xx RB-LCDV2 Test xx\n 1234567890\n abcdefgh \n 0987654321')
# Watch the buttons:
try:
while True:
if GPIO.input(SW1) == GPIO.LOW:
lcd.clear()
lcd.message ("Button 1 pressed!")
if GPIO.input(SW2) == GPIO.LOW:
lcd.clear()
lcd.message ("Button 2 pressed!")
if GPIO.input(SW3) == GPIO.LOW:
lcd.clear()
lcd.message ("Button 3 pressed!")
if GPIO.input(SW4) == GPIO.LOW:
lcd.clear()
lcd.message ("Button 4 pressed!")
except KeyboardInterrupt:
lcd.clear()
GPIO.cleanup()