example
ssd1306-i2c
SSD1306 driver (I2C) for monochrome OLED display
26001.0.0kameleon-core
ssd1306oleddisplay
README.md

Overview

SSD1306 is a monochrome OLED driver (I2C).

If you need SPI version, go to @niklauslee/ssd1306.

1582693403736.jpg

You can get monochrome OLED displays from belows:

Wiring (I2C)

Here is a wiring example for I2C0 of Kameleon Core.

SSD1306 (OLED)Kameleon Core
VCC (VDD)3V3
GNDGND
SCL (SCK)8 (I2C0 SCL)
SDA9 (I2C0 SDA)

1582693461067.png

Usage (I2C)

You can initialize SSD1306 driver using I2C interface as below:

var SSD1306 = require('@niklauslee/ssd1306-i2c').SSD1306;

var I2C = require('i2c').I2C;
var i2c0 = new I2C(0);
var ssd1306 = new SSD1306();
ssd1306.setup(i2c0, {width: 128, height: 64}, () => {
  var gc = ssd1306.getContext();
  // Use graphics APIs
  // gc.drawRect(0, 0, width, height);
  // gc.display();
});

API (I2C)

Class: SSD1306

A class for SSD1306 driver communicating with I2C interface.

new SSD1306()

Create an instance of SSD1306 driver.

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

  • i2c <I2C> An instance of I2C 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.
    • rstPin <number> Pin number for RST (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 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 I2C 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 I2C)
  • ex_128x64.js (128x64 resolution via I2C)