raspberrypi:wiringpi:lcd
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| raspberrypi:wiringpi:lcd [2017/01/27 20:21] – created aistis | raspberrypi:wiringpi:lcd [2017/01/30 11:59] (current) – aistis | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | Kaip prijungti ekrana 1602A prie raspberry pi | ||
| + | {{: | ||
| http:// | http:// | ||
| + | {{: | ||
| + | kodas is interneto kuris suveike: | ||
| + | <code python> | ||
| + | # | ||
| + | # | ||
| + | # ___ ___ _ ____ | ||
| + | # / _ \/ _ \(_) __/__ __ __ | ||
| + | # / , _/ ___/ /\ \/ _ \/ // / | ||
| + | # / | ||
| + | # /_/ /___/ | ||
| + | # | ||
| + | # lcd_16x2.py | ||
| + | # 16x2 LCD Test Script | ||
| + | # | ||
| + | # Author : Matt Hawkins | ||
| + | # Date : 06/04/2015 | ||
| + | # | ||
| + | # http:// | ||
| + | # | ||
| + | # | ||
| + | |||
| + | # The wiring for the LCD is as follows: | ||
| + | # 1 : GND | ||
| + | # 2 : 5V | ||
| + | # 3 : Contrast (0-5V)* | ||
| + | # 4 : RS (Register Select) | ||
| + | # 5 : R/W (Read Write) | ||
| + | # 6 : Enable or Strobe | ||
| + | # 7 : Data Bit 0 - NOT USED | ||
| + | # 8 : Data Bit 1 - NOT USED | ||
| + | # 9 : Data Bit 2 - NOT USED | ||
| + | # 10: Data Bit 3 - NOT USED | ||
| + | # 11: Data Bit 4 | ||
| + | # 12: Data Bit 5 | ||
| + | # 13: Data Bit 6 | ||
| + | # 14: Data Bit 7 | ||
| + | # 15: LCD Backlight +5V** | ||
| + | # 16: LCD Backlight GND | ||
| + | |||
| + | #import | ||
| + | import RPi.GPIO as GPIO | ||
| + | import time | ||
| + | |||
| + | # Define GPIO to LCD mapping | ||
| + | LCD_RS = 7 | ||
| + | LCD_E = 8 | ||
| + | LCD_D4 = 25 | ||
| + | LCD_D5 = 24 | ||
| + | LCD_D6 = 23 | ||
| + | LCD_D7 = 18 | ||
| + | |||
| + | # Define some device constants | ||
| + | LCD_WIDTH = 16 # Maximum characters per line | ||
| + | LCD_CHR = True | ||
| + | LCD_CMD = False | ||
| + | |||
| + | LCD_LINE_1 = 0x80 # LCD RAM address for the 1st line | ||
| + | LCD_LINE_2 = 0xC0 # LCD RAM address for the 2nd line | ||
| + | |||
| + | # Timing constants | ||
| + | E_PULSE = 0.0005 | ||
| + | E_DELAY = 0.0005 | ||
| + | |||
| + | def main(): | ||
| + | # Main program block | ||
| + | GPIO.setwarnings(False) | ||
| + | GPIO.setmode(GPIO.BCM) | ||
| + | GPIO.setup(LCD_E, | ||
| + | GPIO.setup(LCD_RS, | ||
| + | GPIO.setup(LCD_D4, | ||
| + | GPIO.setup(LCD_D5, | ||
| + | GPIO.setup(LCD_D6, | ||
| + | GPIO.setup(LCD_D7, | ||
| + | |||
| + | # Initialise display | ||
| + | lcd_init() | ||
| + | |||
| + | while True: | ||
| + | |||
| + | # Send some test | ||
| + | lcd_string(" | ||
| + | lcd_string(" | ||
| + | |||
| + | time.sleep(3) # 3 second delay | ||
| + | |||
| + | # Send some text | ||
| + | lcd_string(" | ||
| + | lcd_string(" | ||
| + | |||
| + | time.sleep(3) | ||
| + | |||
| + | # Send some text | ||
| + | lcd_string(" | ||
| + | lcd_string(" | ||
| + | |||
| + | time.sleep(3) | ||
| + | |||
| + | def lcd_init(): | ||
| + | # Initialise display | ||
| + | lcd_byte(0x33, | ||
| + | lcd_byte(0x32, | ||
| + | lcd_byte(0x06, | ||
| + | lcd_byte(0x0C, | ||
| + | lcd_byte(0x28, | ||
| + | lcd_byte(0x01, | ||
| + | time.sleep(E_DELAY) | ||
| + | |||
| + | def lcd_byte(bits, | ||
| + | # Send byte to data pins | ||
| + | # bits = data | ||
| + | # mode = True for character | ||
| + | # False for command | ||
| + | |||
| + | GPIO.output(LCD_RS, | ||
| + | |||
| + | # High bits | ||
| + | GPIO.output(LCD_D4, | ||
| + | GPIO.output(LCD_D5, | ||
| + | GPIO.output(LCD_D6, | ||
| + | GPIO.output(LCD_D7, | ||
| + | if bits& | ||
| + | GPIO.output(LCD_D4, | ||
| + | if bits& | ||
| + | GPIO.output(LCD_D5, | ||
| + | if bits& | ||
| + | GPIO.output(LCD_D6, | ||
| + | if bits& | ||
| + | GPIO.output(LCD_D7, | ||
| + | |||
| + | # Toggle ' | ||
| + | lcd_toggle_enable() | ||
| + | |||
| + | # Low bits | ||
| + | GPIO.output(LCD_D4, | ||
| + | GPIO.output(LCD_D5, | ||
| + | GPIO.output(LCD_D6, | ||
| + | GPIO.output(LCD_D7, | ||
| + | if bits& | ||
| + | GPIO.output(LCD_D4, | ||
| + | if bits& | ||
| + | GPIO.output(LCD_D5, | ||
| + | if bits& | ||
| + | GPIO.output(LCD_D6, | ||
| + | if bits& | ||
| + | GPIO.output(LCD_D7, | ||
| + | |||
| + | # Toggle ' | ||
| + | lcd_toggle_enable() | ||
| + | |||
| + | def lcd_toggle_enable(): | ||
| + | # Toggle enable | ||
| + | time.sleep(E_DELAY) | ||
| + | GPIO.output(LCD_E, | ||
| + | time.sleep(E_PULSE) | ||
| + | GPIO.output(LCD_E, | ||
| + | time.sleep(E_DELAY) | ||
| + | |||
| + | def lcd_string(message, | ||
| + | # Send string to display | ||
| + | |||
| + | message = message.ljust(LCD_WIDTH," | ||
| + | |||
| + | lcd_byte(line, | ||
| + | |||
| + | for i in range(LCD_WIDTH): | ||
| + | lcd_byte(ord(message[i]), | ||
| + | |||
| + | if __name__ == ' | ||
| + | |||
| + | try: | ||
| + | main() | ||
| + | except KeyboardInterrupt: | ||
| + | pass | ||
| + | finally: | ||
| + | lcd_byte(0x01, | ||
| + | lcd_string(" | ||
| + | GPIO.cleanup() | ||
| + | </ | ||
raspberrypi/wiringpi/lcd.1485541278.txt.gz · Last modified: by aistis
