keyestudio
Share your creative ideas with us here
By ran | 26 August 2024 | 0 Comments

HOW to Use LCD_128X32_DOT Module with ESP32

Description

This is a 128*32 pixel LCD module, which uses IIC communication mode and ST7567A driver chip. At the same time, the code contains all the English letters and common symbols of the library that can be directly called. When used, we can also set English letters and symbols to display different text sizes in our code. To make it easy to set up the pattern display, we also provide a mold capture software that can convert a specific pattern into control code and then copy it directly into the test code for use.

In the experiment, we will set up the display screen to display various English words, common symbols and numbers.

Working Principle

The module uses the IIC communication principle, the underlying functions have been encapsulated in the library surface, we can directly call the library function, if interested, you can also go to understand the underlying driver of the module.

Components

img

img

img

img

img

ESP32 Board*1

ESP32 Expansion Board*1

Keyestudio LCD 128X32
DOT Module*1

4P Dupont Wire*1

Micro USB Cable*1

Connection Diagram

Add Library

Open “Thonny”, click “This computer” → “D:” → “2. ESP32_code_MicroPython” → “lesson 43. lcd128_32”. Select “lcd128_32.py” and “lcd128_32_fonts.py”, right-click and select “Upload to /”, waiting for the “lcd128_32.py” and “lcd128_32_fonts.py” to be uploaded to the ESP32.

Test Code

import machine
import time 
import lcd128_32_fonts
from lcd128_32 import lcd128_32

#i2c config
clock_pin = 22
data_pin = 21
bus = 0
i2c_addr = 0x3f
use_i2c = True

def scan_for_devices():
    i2c = machine.I2C(bus,sda=machine.Pin(data_pin),scl=machine.Pin(clock_pin))
    devices = i2c.scan()
    if devices:
        for d in devices:
            print(hex(d))
    else:
        print('no i2c devices')

if use_i2c:
    scan_for_devices()
    lcd = lcd128_32(data_pin, clock_pin, bus, i2c_addr)
        
    lcd.Clear()
    lcd.Cursor(0, 7)
lcd.Display("KEYES")
lcd.Cursor(1, 0)
lcd.Display("ABCDEFGHIJKLMNOPQR")
lcd.Cursor(2, 0)
lcd.Display("123456789+-*/<>=$@")
lcd.Cursor(3, 0)
lcd.Display("%^&(){}:;'|?,.~\\[]")

while True:
    #scan_for_devices()
    time.sleep(0.5)

Code Explanation

Scan_for_devices()

This function is an IIC addressing function; if an IIC device is identified, the IIC address of the device is printed, as shown in the figure:

If the device is not recognized, print no i2c devices, and then report an error, as shown in the figure:

lcd.Cursor(0, 7)

In order to set the cursor function, that is, to set the position where the character is displayed on the lcd, the first parameter is the parameter of the row, the second is the parameter of the column, then it is expressed as, the first row, the seventh column starts to display the characters.

lcd.Display(“KEYES”)

In order to set the character content to be displayed, “KEYES” is displayed here

Test Result

Connect the wires according to the experimental wiring diagram and power on.

Click “Run current script”, the code starts executing, the first line of the 128X32LCD module displays “KEYES”, the second line displays “ABCDEFGHIJKLMNOPQR”, the third line displays “123456789±*/<>=$@”, the fourth line displays “%^&(){}:;’|?,.~\[]”, as shown in the following image.

Press “Ctrl+C”or click “Stop/Restart backend”to exit the program.

 

Leave a Reply

Your email address will not be published.Required fields are marked. *
Name
E-mail
Content
Verification code