Kaluma library for ST7789 (Color TFT/IPS LCD Display)
Display boards with ST7789:
- Adafruit 1.14" 240x135 TFT LCD
- Adafruit 1.3" 240x240 TFT LCD
- Adafruit 1.54" 240x240 TFT LCD
- Adafruit 1.69" 280x240 IPS LCD
- Adafruit 2.0" 320x240 TFT LCD
- Pimoroni 1.54" 240x240 Color Square LCD
- Pimoroni 1.3" 240x240 Color Square LCD
- Pimoroni 1.3" 240x240 Color Round LCD
- Pimoroni 1.14" 240x135 Pico Display Pack (TESTED)
- Pimoroni 2.0" 320x240 Pico Display Pack 2.0
- Pimoroni 1.54" 240x240 PicoSystem (TESTED)
Here is a wiring example for SPI0.
| Raspberry Pi Pico | ST7789 |
|---|---|
| 3V3 | 3V3 |
| GND | GND |
| GP19 (SPI0 TX) | MOSI |
| GP18 (SPI0 SCK) | SCK |
| GP20 | DC |
| GP21 | RST |
| GP17 | CS |
| GP16 | BL |
npm i https://github.com/niklauslee/st7789You can initialize ST7789 driver using SPI interface as below:
const {ST7789} = require('st7789');
const st7789 = new ST7789();
var options = { // ST7789 1.14"
width: 240,
height: 135,
dc: 20,
rst: 21,
cs: 17
}
// turn on backlight (GP16) if needed
pinMode(16, OUTPUT);
digitalWrite(16, HIGH);
st7789.setup(board.spi(0), options);
const gc = st7789.getContext();
gc.drawRect(0, 0, width, height);You can use BufferedGraphicsContext instead of general callback-based graphics context as below:
// buffered graphic context
var gc = st7789.getContext('buffer');
gc.drawRect(0, 0, width, height);
gc.display(); // must call if buffered graphic context
...Note that
BufferedGraphicsContextallocates a lot of memory (approximately 64KB for 240x135 and 112KB for 240x240 resolution). You may need to check available heap memory with.memcommand in REPL during development.
A class for ST7789 driver communicating with SPI interface.
Create an instance of ST7789 driver for SPI interface.
spi<SPI>An instance ofSPIto communicate.options<object>Options for initialization.width<number>Width of display in pixels. Default:240.height<number>Height of display in pixels. Default:240.dc<number>Pin number for DC. Default:-1.rst<number>Pin number for RST (Reset). Default:-1.cs<number>Pin number of CS (Chip select). Default:-1.rotation<number>Rotation of screen. One of0(0 degree),1(90 degree in clockwise),2(180 degree in clockwise), and3(270 degree in clockwise). Default:0.
type: Optional. Type of graphic context ("buffer"or"callback"). If"buffer"is given,BufferedGraphicContextis returned.- Returns:
<GraphicContext>An instance of graphic context for ST7789.
Get a graphic context.
Note that
BufferedGraphicContextis much faster, but it consumes memory a lot.
Note that
gc.getPixel(x, y)function is supported only ifBufferedGraphicsContext.
examples/ex_240x135_callback.js(callback-type GC with 1.14" 240x135 resolution)examples/ex_240x135_buffer.js(buffer-type GC with 1.14" 240x135 resolution)examples/ex_240x135_picodisplay.js(Pimoroni's Pico Display Pack)examples/ex_240x135_picosystem.js(Pimoroni's Pico System)
kaluma flash ./examples/ex_240x135_picodisplay.js --bundle --port <port>