Kaluma library for ST7735 (Color TFT LCD driver).
You can get displays from belows:
Here is a wiring example for SPI0.
| Raspberry Pi Pico | ST7735 |
|---|---|
| 3V3 | 3V3 |
| GND | GND |
| GP19 (SPI0 TX) | DATA (MOSI) |
| GP18 (SPI0 CLK) | CLK |
| GP20 | D/C |
| GP21 | RST |
| GP17 | CS |
npm i https://github.com/niklauslee/st7735You can initialize ST7735 driver using SPI interface as below:
const {ST7735} = require('st7735');
const st7735 = new ST7735();
var options = { // ST7735R 1.44"
dc: 20,
rst: 21,
cs: 17
};
/*
var options = { // ST7735R 1.8"
width: 128,
height: 160,
xstart: 0,
ystart: 0,
dc: 20,
rst: 21,
cs: 17
}
*/
st7735.setup(board.spi(0), options);
const gc = st7735.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 = st7735.getContext('buffer');
gc.drawRect(0, 0, width, height);
gc.display(); // must call if buffered graphic context
...Note that
BufferedGraphicsContextallocates a lot of memory (32KB for 128x128 resolution).
A class for ST7735 driver communicating with SPI interface.
Create an instance of ST7735 driver for SPI interface.
spi<SPI>An instance ofSPIto communicate.options<object>Options for initialization.width<number>Width of display in pixels. Default:128.height<number>Height of display in pixels. Default:128.xstart<number>x-start of display in pixels. Default:2.ystart<number>y-start of display in pixels. Default:3.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.
Setup ST7735 driver for a given SPI bus and options based on the below table.
| Display Types | height |
width |
xstart |
ystart |
|---|---|---|---|---|
| 1.44" | 128 | 128 | 2 | 3 |
| 1.8" | 128 | 160 | 0 | 0 |
type: Optional. Type of graphic context. If"buffer"is given,BufferedGraphicContextis returned.- Returns:
<GraphicContext>An instance of graphic context for ST7735.
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.
ex_144.js(1.44" 128x128 resolution)ex_18.js(1.8" 128x160 resolution)
