This lesson is for using the LCM1602 I2C LCD interface. It is a popular It has four wires:
GND - connect to any GND pin
VCC - connect to 3V3(out) pin unless you have a 3.3 to 5v voltage converter
SDA - connect to GP0
SCL - connect to GP1
The photo above shows the use of a 3.3 to 5v voltage converter. This allows us to use the full 5v to the LCD backlight so we get bright contrast. You can connect the VCC to the 3V3(out) pin but the display will be harder to read.
I2C Address Scanner Test
Our first task is to make sure that the 1602 chip's I2C circuits are working. We use the following I2C scanner code to do this.
1 2 3 4 5 6 7 8 91011121314
importmachineI2C_SDA_PIN=0I2C_SCL_PIN=1i2c=machine.I2C(0,sda=machine.Pin(I2C_SDA_PIN),scl=machine.Pin(I2C_SCL_PIN),freq=400000)print('Scanning I2C bus.')devices=i2c.scan()# this returns a list of devicesdevice_count=len(devices)ifdevice_count==0:print('No i2c device found.')else:print(device_count,'devices found.')fordeviceindevices:print('Decimal address:',device,", Hex address: ",hex(device))