MicroPython ST7789V LCD Display
The Sitronix ST7789 is a driver chip for small color IPS LCD displays that supports SPI interfaces. This example uses a 2-inch color LDC display manufactured by Waveshare with a retail price of approximately $13 or $14.75 on Amazon Prime.
Specifications
- Resolution: 240(V) x 320(H) RGB
- 18 bit color (6 bits for R, G and B)
- 1,382,400 bits of display memory
- Interface: 4-wire SPI (kind of)
- Operating voltage: 3.3V
Note: The ST7789 uses a SPI interfaces but not a true standard SPI protocol. The device only uses MOSI (DIN) to send data from master to slave for LCD display. Only four wires are needed to connect from the Pico to the device.
Device Interface
Interface
- VCC Power (3.3V input)
- GND Ground
- DIN SPI data input
- CLK SPI clock input
- CS Chip selection, low active
- DC Data/Command selection (high for data, low for command)
- RST Reset, low active
- BL Backlight - tie to GND to turn the backlight on
Although the device has eight wires, your Pico only needs a few of them to be controlled by the GPIO ports.
Uploading the ST7789V Python Firmware
The firmware contains pre-compiled objects for various devices with the st7789 C driver and frozen python font files.
The library for the driver is delivered as a single firmware.uf2 file available here:
https://github.com/russhughes/st7789_mpy/tree/master/firmware/RP2
To load this file you will need to hold down the BOTSEL button on the Pico and drag this file into the RP2 folder that is mounted.
MicroPython Initialization
I used the following SPI Device ID 1 pinout on the lower left corner of the Pico:
Pin | GP Number | Label on LCD |
---|---|---|
14 | (GP10) | BL |
15 | (GP11) | RST |
16 | (GP12) | DC |
17 | (GP13) | CS |
18 | (GND) | GND |
19 | (GP14) | CLK |
20 | (GP15) | DIN |
Sample Device Initialize
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
Sample Hello World In Four Colors
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
Driver Implementation Notes
The ST7789V supports RGB444, RGB565 and RGB666 three formats. The Waveshare LCD uses RGB565. For most LCD controllers, the communication method of the controller can be configured, they are usually using 8080 parallel interface, 3-line SPI, 4-line SPI, and other communication methods. This LCD uses a 4-line SPI interface for reducing GPIO and fast speed.LCD
- RESX: Reset, should be pull-down when power on, set to 1 other time.
- CSX: Slave chip select. The chip is enabled only CS is set Low
- D/CX: Data/Command selection; DC=0, write command; DC=1, write data
- SDA: Data transmitted. (RGB data)
- SCL: SPI clock
Timing Diagram
You can see what data needs to be changing from the timing diagram below:
- The SPI communication protocol of the data transmission uses control bits: clock phase (CPHA) and clock polarity (CPOL)
- CPOL defines the level while the synchronization clock is idle. If CPOL=0, then it is LOW.
- CPHA defines at whish clock’s tick the data transmission starts. CPHL=0 – at the first one, otherwise at the second one
This combination of two bits provides 4 modes of SPI data transmission. The commonly used is SPI0 mode, i.e. GPHL=0 and CPOL=0.
According to the figure above, data transmitting begins at the first falling edge, 8bit data are transmitted at one clock cycle. It is SPI0. MSB.