Kaluma library for SSD1306 (Monochrome OLED Display)
You can get monochrome OLED displays from belows:
- 1" 128x32 - I2C (from Adafruit)
- 1.3" 128x64 - I2C/SPI (from Adafruit)
- 0.96" 128x64 - I2C/SPI (from Adafruit)
- 1" 128x32 - SPI (from Adafruit)
Here is a wiring example for I2C0
.
Raspberry Pi Pico | SSD1306 (OLED) |
---|---|
3V3 | VCC (VDD) |
GND | GND |
GP4 (I2C0 SDA) | SDA |
GP5 (I2C0 SCL) | SCL (SCK) |
Here is a wiring example for SPI0
.
Raspberry Pi Pico | SSD1306 (OLED) |
---|---|
3V3 | 3V3 |
GND | GND |
GP19 (SPI0 TX) | DATA |
GP18 (SPI0 CLK) | CLK |
GP20 | D/C |
GP21 | RST |
GP17 | CS |
You can initialize SSD1306 driver using I2C interface as below:
const {SSD1306} = require('ssd1306/i2c');
const ssd1306 = new SSD1306();
ssd1306.setup(board.i2c(0), {
width: 128,
height: 64
});
const gc = ssd1306.getContext();
// Use graphics APIs
// gc.drawRect(0, 0, width, height);
// gc.display();
You can initialize SSD1306 driver using SPI interface as below:
const {SSD1306} = require('ssd1306/spi');
const ssd1306 = new SSD1306();
ssd1306.setup(board.spi(0), {
width: 128,
height: 64,
dc: 20,
rst: 21,
cs: 17
})
const gc = ssd1306.getContext();
// Use graphics APIs
// gc.drawRect(0, 0, width, height);
// gc.display();
A class for SSD1306 driver communicating with I2C interface.
Create an instance of SSD1306 driver.
i2c
<I2C>
An instance ofI2C
to communicate.options
<object>
Options for initialization.width
<number>
Width of display in pixels. Default:128
.height
<number>
Height of display in pixels. Default:64
.rst
<number>
Pin number for reset. Default:-1
.address
<number>
I2C slave address. Default:0x3c
.extVcc
<boolean>
Indicate whether to use external VCC. Default:false
.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 SSD1306 driver for a given I2C bus and options.
- Returns:
<BufferedGraphicsContext>
An instance of buffered graphic context for SSD1306.
Turn on the display.
Turn off the display.
contrast
<number>
Contrast value.
Set contrast of the display.
A class for SSD1306 driver communicating with SPI interface.
Create an instance of SSD1306 driver.
spi
<SPI>
An instance ofSPI
to communicate.options
<object>
Options for initialization.width
<number>
Width of display in pixels.height
<number>
Height of display in pixels.dc
<number>
Pin number for DC.rst
<number>
Pin number for RST (Reset).cs
<number>
Pin number of CS (Chip select).extVcc
<boolean>
Indicate whether to use external VCC. Default:false
.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 SSD1306 driver for a given SPI bus and options.
- Returns:
<BufferedGraphicsContext>
An instance of buffered graphic context for SSD1306.
Turn on the display.
Turn off the display.
contrast
<number>
Contrast value.
Set contrast of the display.
examples/ex_i2c_128x32.js
(128x32 resolution via I2C)examples/ex_i2c_128x64.js
(128x64 resolution via I2C)examples/ex_spi_128x32.js
(128x32 resolution via SPI)examples/ex_spi_128x64.js
(128x64 resolution via SPI)
# example for 128x64 (I2C)
kaluma flash ./examples/ex_i2c_128x64.js --bundle --port <port>