SSD1306 for I2C Interface: @niklauslee/ssd1306-i2c

Overview

SSD1306 is a monochrome OLED driver.

SSD1306

You can get monochrome OLED displays from belows:

Usage (SPI)

If you need I2C version, go to @niklauslee/ssd1306-i2c.

Here is a wiring example for SPI0 of Kameleon Core.

SSD1306 (OLED) Kameleon Core
3V3 3V3
GND GND
DATA 12 (SPI0-MOSI)
CLK 10 (SPI0 CLK)
D/C 8
RST 9
CS 17

You can initialize SSD1306 driver using SPI interface as below:

var SSD1306 = require('@niklauslee/ssd1306').SSD1306;
var SPI = require('spi').SPI;

var spi0 = new SPI(0);
var dc = 8;
var rst = 9;
var cs = 17;
var width = 128;
var height = 64;

var ssd1306 = new SSD1306(width, height, spi0, dc, {
  rstPin: rst,
  csPin: cs
});
var gc = ssd1306.getContext();
// Use graphics APIs
// e.g.) gc.drawRect(0, 0, width, height);

API (SPI)

If you need I2C version, go to @niklauslee/ssd1306-i2c.

Class: SSD1306

A class for SSD1306 driver communicating with SPI interface.

new SSD1306(width, height, spi, dcPin[, options])

  • width <number> Width of display in pixels.
  • height <number> Height of display in pixels.
  • spi <SPI> An instance of SPI to communicate.
  • dcPin <number> Pin number for DC.
  • options <object> Options for initialization.
    • rstPin <number> Pin number for RST (Reset).
    • csPin <number> Pin number of CS (Chip select).
    • extVcc <boolean> Indicate whether to use external VCC. Default: false.
    • rotation <number> Rotation of screen. One of 0 (0 degree), 1 (90 degree in clockwise), 2 (180 degree in clockwise), and 3 (270 degree in clockwise). Default: 0.

Create an instance of SSD1306 driver for SPI interface.

ssd1306.getContext()

  • Returns: <BufferedGraphicsContext> An instance of buffered graphic context for SSD1306.

Get a graphic context so that you can use Graphics APIs.

ssd1306.on()

Turn on the display.

ssd1306.off()

Turn off the display.

ssd1306.setContrast(contrast)

  • contrast <number> Contrast value.

Set contrast of the display.

Examples

  • ex_128x32.js (128x32 resolution via SPI)
  • ex_128x64.js (128x64 resolution via SPI)