Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen RevisionVorhergehende Überarbeitung | |||
| lcd_display_klein [2016/06/28 11:39] – peltzer | lcd_display_klein [2023/07/03 10:15] (aktuell) – Externe Bearbeitung 127.0.0.1 | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| + | === Bild === | ||
| + | |||
| + | {{lcd_klein.jpg? | ||
| + | |||
| + | === Anschlüsse === | ||
| + | |||
| + | 1 GND | ||
| + | 2 +5V | ||
| + | 3 Kontrast, hier ein Spindelpotentiometer zwischenschließen | ||
| + | 4 Register Select (RS) an GPIO anschließen (26) | ||
| + | 5 Read Write (RS) —> auf GND legen | ||
| + | 6 Enable an GPIO anschließen (19) | ||
| + | 7 unbenutzt | ||
| + | 8 unbenutzt | ||
| + | 9 unbenutzt | ||
| + | 10 unbenutzt | ||
| + | 11 D4 an GPIO anschließen (13) | ||
| + | 12 D5 an GPIO anschließen (6) | ||
| + | 13 D6 an GPIO anschließen (5) | ||
| + | 14 D7 an GPIO anschließen (11) | ||
| + | 15 Backlight +5V —-> hier kann man auch ein Potentiometer einbauen | ||
| + | 16 Backlight GND | ||
| + | (Hinweis : wenn ihr andere als die im Code angegebenen PINs verwenden | ||
| + | wollt, dann stellt das im Python Code entsprechend um) | ||
| + | |||
| + | === Spindelpotentiometer === | ||
| + | |||
| + | {{spindelpoti.jpg? | ||
| + | |||
| + | Das Spindelpotentiometer (ihr könnt auch ein anderes Potentiometer | ||
| + | nehmen, jeweils seitlich und in der Mitte verbinden) dient dazu, den Kontrast | ||
| + | einzustellen. Wird der Kontrastpin auf GND gesetzt, ist das Display schlecht | ||
| + | zu lesen | ||
| + | |||
| + | === CODE === | ||
| + | <file Python LCD_klein.py > | ||
| + | # The wiring for the LCD is as follows: | ||
| + | # 1 : GND | ||
| + | # 2 : 5V | ||
| + | # 3 : Contrast (0-5V)* --> hier das Spindelpotentiometer zwischen GND und LCD PIN anschliessen | ||
| + | # 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** --> wer will, kann auch hier ein Potentiometer einbauen, um die Helligkeit zu regulieren | ||
| + | # 16: LCD Backlight GND | ||
| + | |||
| + | #import | ||
| + | import RPi.GPIO as GPIO | ||
| + | import time | ||
| + | |||
| + | # Define GPIO to LCD mapping --> wer das Shield des RPi weiterverwendet, | ||
| + | LCD_RS = 26 | ||
| + | LCD_E = 19 | ||
| + | LCD_D4 = 13 | ||
| + | LCD_D5 = 6 | ||
| + | LCD_D6 = 5 | ||
| + | LCD_D7 = 11 | ||
| + | |||
| + | |||
| + | # 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) # 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() | ||
| + | |||
| + | </ | ||
| + | |||
| + | === Weitere Quellen === | ||
| + | |||
| + | Anleitung Youtube: | ||
| + | https:// | ||
| + | Anleitung Webseite: | ||
| + | http:// | ||
| + | |||