Product Description
LCD can display 20 characters on four lines, backlight is blue and has a backpack that lets you adjust brightness and connect the Raspberry Pi using 8 wires mother-mother.
Further down are the instructions needed to run the source code in Python.
1. Login via SSH Raspberry and navigehaza the Desktop directory.
$ Cd Desktop
2. Create a file called lcd.py and copy the code below to copy paste.
$ Sudo nano lcd.py
import RPi.GPIO as GPIO import time LCD_RS = 7 LCD_E = 8 LCD_D4 = 25 LCD_D5 = 24 LCD_D6 = 23 LCD_D7 = 18 LED_ON = 15 LCD_WIDTH = 20 LCD_CHR = True LCD_CMD = False LCD_LINE_1 = 0x80 LCD_LINE_2 = 0xC0 LCD_LINE_3 = 0x94 LCD_LINE_4 = 0xD4 E_PULSE = 0.0005 E_DELAY = 0.0005 def main(): GPIO.setmode(GPIO.BCM) GPIO.setup(LCD_E, GPIO.OUT) GPIO.setup(LCD_RS, GPIO.OUT) GPIO.setup(LCD_D4, GPIO.OUT) GPIO.setup(LCD_D5, GPIO.OUT) GPIO.setup(LCD_D6, GPIO.OUT) GPIO.setup(LCD_D7, GPIO.OUT) lcd_init() while True: lcd_string("--------------------",LCD_LINE_1,2) lcd_string("Robofun.ro",LCD_LINE_2,2) lcd_string("Raspberry Pi 2",LCD_LINE_3,2) lcd_string("--------------------",LCD_LINE_4,2) def lcd_init(): lcd_byte(0x33,LCD_CMD) lcd_byte(0x32,LCD_CMD) lcd_byte(0x06,LCD_CMD) lcd_byte(0x0C,LCD_CMD) lcd_byte(0x28,LCD_CMD) lcd_byte(0x01,LCD_CMD) time.sleep(E_DELAY) def lcd_byte(bits, mode): GPIO.output(LCD_RS, mode) GPIO.output(LCD_D4, False) GPIO.output(LCD_D5, False) GPIO.output(LCD_D6, False) GPIO.output(LCD_D7, False) if bits&0x10==0x10: GPIO.output(LCD_D4, True) if bits&0x20==0x20: GPIO.output(LCD_D5, True) if bits&0x40==0x40: GPIO.output(LCD_D6, True) if bits&0x80==0x80: GPIO.output(LCD_D7, True) lcd_toggle_enable() GPIO.output(LCD_D4, False) GPIO.output(LCD_D5, False) GPIO.output(LCD_D6, False) GPIO.output(LCD_D7, False) if bits&0x01==0x01: GPIO.output(LCD_D4, True) if bits&0x02==0x02: GPIO.output(LCD_D5, True) if bits&0x04==0x04: GPIO.output(LCD_D6, True) if bits&0x08==0x08: GPIO.output(LCD_D7, True) lcd_toggle_enable() def lcd_toggle_enable(): time.sleep(E_DELAY) GPIO.output(LCD_E, True) time.sleep(E_PULSE) GPIO.output(LCD_E, False) time.sleep(E_DELAY) def lcd_string(message,line,style): if style==1: message = message.ljust(LCD_WIDTH," ") elif style==2: message = message.center(LCD_WIDTH," ") elif style==3: message = message.rjust(LCD_WIDTH," ") lcd_byte(line, LCD_CMD) for i in range(LCD_WIDTH): lcd_byte(ord(message[i]),LCD_CHR) def lcd_backlight(flag): GPIO.output(LED_ON, flag) if __name__ == '__main__': try: main() except KeyboardInterrupt: pass finally: lcd_byte(0x01, LCD_CMD) lcd_string("www.RoboFun.ro",LCD_LINE_1,2) GPIO.cleanup()
3.Use Ctrl + A to save your changes and Ctrl + X to close the text editor.
Leave a reply
Returns and Exchanges
There are a few important things to keep in mind when returning a product you purchased.You can return unwanted items by post within 7 working days of receipt of your goods.
- You have 14 calendar days to return an item from the date you received it.
- Only items that have been purchased directly from Us.
- Please ensure that the item you are returning is repackaged with all elements.
Ship your item back to Us
Firstly Print and return this Returns Form to:
30 South Park Avenue, San Francisco, CA 94108, USA
Please remember to ensure that the item you are returning is repackaged with all elements.
For more information, view our full Returns and Exchanges information.
Reviews
There are no reviews yet.