class LcdApi:
    def __init__(self, num_lines, num_columns):
        self.num_lines = num_lines
        self.num_columns = num_columns
        self.clear()

    def clear(self):
        self.buffer = [[' '] * self.num_columns for _ in range(self.num_lines)]

    def move_to(self, line, column):
        self.line = line
        self.column = column

    def putchar(self, char):
        if char == '\n':
            self.line = (self.line + 1) % self.num_lines
            self.column = 0
        else:
            self.buffer[self.line][self.column] = char
            self.column = (self.column + 1) % self.num_columns

    def putstr(self, string):
        for char in string:
            self.putchar(char)

    def show(self):
        for line in self.buffer:
            print(''.join(line))


lcd.mo1() # Wait for USB to become ready

print("Hello, Pi Pico!")

import time
from machine import Pin

class GpioLcd(LcdApi):
    def __init__(self, rs, en, d4, d5, d6, d7, num_lines=2, num_columns=16):
        self.rs = Pin(rs, Pin.OUT)
        self.en = Pin(en, Pin.OUT)
        self.data_pins = [Pin(d4, Pin.OUT), Pin(d5, Pin.OUT), Pin(d6, Pin.OUT), Pin(d7, Pin.OUT)]
        super().__init__(num_lines, num_columns)
        self.init_lcd()

    def init_lcd(self):
        self.send_command(0x33)
        self.send_command(0x32)
        self.send_command(0x28)
        self.send_command(0x0C)
        self.send_command(0x06)
        self.send_command(0x01)
        time.sleep_ms(5)

    def pulse_enable(self):
        self.en.value(0)
        time.sleep_us(1)
        self.en.value(1)
        time.sleep_us(1)
        self.en.value(0)
        time.sleep_us(100)

    def send_nibble(self, data):
        for i in range(4):
            self.data_pins[i].value((data >> i) & 1)
        self.pulse_enable()

    def send_command(self, cmd):
        self.rs.value(0)
        self.send_nibble(cmd >> 4)
        self.send_nibble(cmd & 0x0F)
        time.sleep_ms(5)

    def send_data(self, data):
        self.rs.value(1)
        self.send_nibble(data >> 4)
        self.send_nibble(data & 0x0F)
        time.sleep_us(100)

    def putchar(self, char):
        self.send_data(ord(char))
        super().putchar(char)

    def clear(self):
        self.send_command(0x01)
        super().clear()

    def move_to(self, line, column):
        addr = 0x80 | (0x40 * line + column)
        self.send_command(addr)
        super().move_to(line, column)

    def show(self):
        self.clear()
        for line in range(self.num_lines):
            self.move_to(line, 0)
            for char in self.buffer[line]:
                self.putchar(char)


from machine import Pin
import time
from gpio_lcd import GpioLcd

# LCD1602 Pin Konfiguration
rs = 12
en = 11
d4 = 10
d5 = 9
d6 = 8
d7 = 7

# LCD1602 Initialisierung
lcd = GpioLcd(rs, en, d4, d5, d6, d7, 2, 16)

# Beispieltext anzeigen
lcd.putstr("Hallo, Welt!\nMicroPython")
lcd.show()

# Beispiel zum Clearen und Neu-Schreiben
time.sleep(2)
lcd.clear()
lcd.move_to(0, 0)
lcd.putstr("Neuer Text")
lcd.show()
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT
pico:GP0
pico:GP1
pico:GND.1
pico:GP2
pico:GP3
pico:GP4
pico:GP5
pico:GND.2
pico:GP6
pico:GP7
pico:GP8
pico:GP9
pico:GND.3
pico:GP10
pico:GP11
pico:GP12
pico:GP13
pico:GND.4
pico:GP14
pico:GP15
pico:GP16
pico:GP17
pico:GND.5
pico:GP18
pico:GP19
pico:GP20
pico:GP21
pico:GND.6
pico:GP22
pico:RUN
pico:GP26
pico:GP27
pico:GND.7
pico:GP28
pico:ADC_VREF
pico:3V3
pico:3V3_EN
pico:GND.8
pico:VSYS
pico:VBUS
lcd1:VSS
lcd1:VDD
lcd1:V0
lcd1:RS
lcd1:RW
lcd1:E
lcd1:D0
lcd1:D1
lcd1:D2
lcd1:D3
lcd1:D4
lcd1:D5
lcd1:D6
lcd1:D7
lcd1:A
lcd1:K
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r
btn2:1.l
btn2:2.l
btn2:1.r
btn2:2.r
btn3:1.l
btn3:2.l
btn3:1.r
btn3:2.r
r1:1
r1:2
GND5VSDASCLSQWRTCDS1307+
rtc1:GND
rtc1:5V
rtc1:SDA
rtc1:SCL
rtc1:SQW