README.md
Version

Overview

SSD1306 is a monochrome OLED driver.

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

1582693265810.jpg

You can get monochrome OLED displays from belows:

Wiring (SPI)

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

1582693298519.png

Usage (SPI)

You can initialize SSD1306 driver using SPI interface as below:

var SPI = require('spi').SPI;
var spi0 = new SPI(0);
var SSD1306 = require('@niklauslee/ssd1306').SSD1306;
var ssd1306 = new SSD1306();
ssd1306.setup(spi0, {width: 128, height: 64, dcPin: 8, rstPin: 9, csPin: 17}, () => {
  var gc = ssd1306.getContext();
  // Use graphics APIs
  // gc.drawRect(0, 0, width, height);
  // gc.display();
});

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()

Create an instance of SSD1306 driver.

ssd1306.setup(spi[, options[, callback]])

  • spi <SPI> An instance of SPI to communicate.
  • options <object> Options for initialization.
    • width <number> Width of display in pixels.
    • height <number> Height of display in pixels.
    • dcPin <number> Pin number for DC.
    • 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.
  • callback <Function> A function called when setup is complete.

Setup SSD1306 driver for a given SPI bus and options.

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)