A high-performance native C MicroPython module that drives the 5-inch, 800×480 IPS capacitive DSI LCD designed for Raspberry Pi, but running on Espressif ESP32-P4 with MicroPython.
| Panel | 5" IPS, 800 × 480, 5-point capacitive touch |
| Interface | Raspberry-Pi DSI (adapted to ESP32-P4 MIPI-DSI) |
| Brightness | 550 cd/m², full-laminated, anti-glare, anti-fingerprint |
| Colors | 16-bit RGB (16.7 M) |
| Touch | Capacitive, I²C 0x38 |
- Pure C implementation for blazing speed and minimal RAM usage
- MicroPython bindings – use the display exactly like any other Python object
- Graphic primitives: point, line, rectangle, circle, filled shapes
- Text rendering (bitmap fonts) with size & color control
- Blit full-color images from
bytearray/memoryview - Pre-defined color constants (
WHITE,BLACK,RED, …)
Clone the repository inside the MicroPython ports/esp32/modules/ directory:
cd micropython/ports/esp32/modules
git clone https://github.com/Vincent1-python/esp32p4-micropython-dfrobot-rpi-dsi-driver.git Rebuild MicroPython:
cd ../../
make USER_C_MODULES=modules/esp32p4-micropython-dfrobot-rpi-dsi-driver/src/micropython.cmakeFlash the resulting firmware to your ESP32-P4 board.
| Name | Hex Value |
|---|---|
WHITE |
0xFFFF |
BLACK |
0x0000 |
RED |
0xF800 |
GREEN |
0x07E0 |
BLUE |
0x001F |
YELLOW |
0xFFE0 |
CYAN |
0x07FF |
MAGENTA |
0xF81F |
| …and more |
| Function | Signature | Description |
|---|---|---|
| init | lcd.init() |
Initialize the LCD controller (safe to call multiple times; initialization runs only once). |
| clear | lcd.clear(color: int) |
Fill the entire screen with the given 16-bit RGB565 color. |
| point | lcd.point(x: int, y: int, color: int) |
Draw a single pixel. |
| fill | lcd.fill(sx: int, sy: int, ex: int, ey: int, color: int) |
Draw a filled rectangle from (sx,sy) to (ex,ey) inclusive. |
| line | lcd.line(x1: int, y1: int, x2: int, y2: int, color: int) |
Draw a straight line between the two points. |
| hline | lcd.hline(x: int, y: int, len: int, color: int) |
Draw a horizontal line starting at (x,y) with length len. |
| rectangle | lcd.rectangle(x0: int, y0: int, x1: int, y1: int, color: int) |
Draw an empty rectangle outline. |
| circle | lcd.circle(x0: int, y0: int, r: int, color: int) |
Draw an empty circle centered at (x0,y0) with radius r. |
| fill_circle | lcd.fill_circle(x: int, y: int, r: int, color: int) |
Same as above, but filled. |
| char | lcd.char(x: int, y: int, ch: int, size: int, mode: int, color: int) |
Draw one ASCII character (ch) with the given font size and color. |
| num | lcd.num(x: int, y: int, n: int, length: int, size: int, color: int) |
Print the decimal integer n, padding to length digits. |
| xnum | lcd.xnum(x: int, y: int, n: int, length: int, size: int, mode: int, color: int) |
Print an integer in hex or decimal depending on mode. |
| string | lcd.string(x: int, y: int, w: int, h: int, size: int, text: str, color: int) |
Draw a complete string inside the clipping rectangle (w,h). |
| image | lcd.image(x: int, y: int, w: int, h: int, buffer) |
Blit raw RGB565 pixel data (bytes, bytearray, or memoryview) to screen. |
import lcd
from machine import Pin
from machine import I2C
i2c = I2C(0,scl=Pin(8), sda=Pin(7))
i2c.writeto_mem(0x45, 0x86, b'\xff')
# Initialize the display (only once)
lcd.init()
# Clear screen
lcd.clear(lcd.WHITE)
# Draw primitives
lcd.line(0, 0, 100, 100, lcd.RED)
lcd.circle(120, 120, 30, lcd.BLUE)
lcd.fill_circle(200, 120, 20, lcd.GREEN)
# Text
lcd.string(10, 10, 200, 24, 24, "Hello ESP32-P4!", lcd.BLACK)
# Blit raw RGB565 buffer
import ustruct
w, h = 100, 50
buf = bytearray(w * h * 2)
for i in range(0, len(buf), 2):
buf[i:i+2] = ustruct.pack("<H", lcd.MAGENTA) # Fill magenta
lcd.image(50, 50, w+50, h+49, buf)esp32p4-micropython-dfrobot-rpi-dsi-800x480-driver
├── examples
│ └── lcd_test.py
├── README.md
└── src
├── esp_lcd_nodsiconf.c
├── esp_lcd_nodsiconf.h
├── lcd.c
├── lcdfont.h
├── lcd.h
├── micropython.cmake
├── micropython.mk
└── mplcd.c
Pull requests and issues are welcome! Please keep the coding style consistent with the existing code base.
MIT © 2024 Vincent1-python