DOCUMENTATION DRIVERS SSD1306 display
Overview
Getting Started
BASE
Reference
Worker
Setup modules
COMMODETTO
Reference
Poco Renderer
Outlines
Creating Fonts
Crypt
Data
DEVICES
Moddable One
Moddable Two
Moddable Three
Moddable Four
Moddable Display
ESP32
ESP8266
nRF52
nRF52 Low Power Notes
Raspberry Pi Pico
M5Core Ink
M5Paper
Wasm
SiLabs Gecko
QCA4020
Moddable Zero
DISPLAYS
Overview
Adafruit 1.8" ST7735
Adafruit OLED Display
BuyDisplay 2.8" CTP - ESP8266
Crystalfontz ePaper
DotStar
Generic 1.44"
Generic 2.4" & 2.8" (Resistive Touch) - ESP32
Generic 2.4" & 2.8" (Resistive Touch) - ESP8266
Generic 2.4" & 2.8" (Resistive Touch) - Pico
Sharp Memory
Sharp Memory Screen 1.3"
SparkFun TeensyView
Switch Science Reflective LCD
DRIVERS
DESTM32S display
DotStar display
ILI9341 display
LPM013M126A display
LS013B4DN04 display
MCP230XX GPIO expander
NeoStrand
SSD1306 display
SSD1351 display
ST7735 display
Files
IO
TC53 IO
Firmata
NETWORK
Reference
TLS (SecureSocket)
BLE
Ethernet
Web Things
PINS
Reference
Audio Output
PIU
Reference
Localization
Keyboard
Expanding Keyboard
Die Cut
Using After Effects Motion Data
TOOLS
Reference
Manifest
Defines in Manifests
Testing
XS
Handle
JavaScript language considerations on embedded devices using the XS engine
Mods – User Installed Extensions
ROM Colors
Using XS Preload to Optimize Applications
XS Conformance
XS Marshalling
XS Platforms
XS in C
XS linker warnings
xsbug
xst
XS Compartment
XS Profiler

SSD1306 display driver

Copyright 2017 Moddable Tech, Inc.
Revised: December 28, 2017

The SSD1306 OLED display controller drives monochrome (1-bit) displays. Displays are 128 pixels wide, and available in heights of 32, 64, and 128 pixels. The SSD1306 controller may be connected using SPI or I2C.

Adding SSD1306 to a project

To add the SSD1306 driver to a project, include its manifest:

"include": [
	/* other includes here */
	"$(MODULES)/drivers/ssd1306/manifest.json",
],

If using Commodetto or Piu, set the screen property of the config object in the manifest to ssd1306 to make SSD1306 the default display driver. Since there is no touch input, disable that in the manifest by setting the touch driver name to an empty string.

"config": {
	"screen": "ssd1306",
	"touch": "",
},

Pixel format

The SSD1306 driver requires 8-bit gray (gray256) pixels as input. When building with mcconfig, set the pixel format to gray256 on the command line:

mcconfig -m -p esp -f gray256

Defines

In the defines object, declare the pixel width and height. The default connection is SPI, but it is recommended to explicitly set the connection type in the application manifest:

"defines": {
	"ssd1306": {
		"width": 128,
		"height": 32,
		"spi": true,
		"i2c": false,
	}
}

Dither

The SSD1306 driver implements optional dithering. Dithering allows an approximation of gray pixels on black and white OLED displays. Enabling dithering uses about an additional 520 bytes of RAM and renders slower. Whether dithering is best for a given application depends on what it draws and the required frame rate. Dithering is disabled by default. To enable dithering, set the dither property to true in the defines section of the manifest.

"defines": {
	"ssd1306": {
		/* other properties here */
		"dither": true,
	}
}

Using SPI

When using a SPI interface, the defines object must contain the spi_port, along with the DC and CS pin numbers. If a RST pin is provided, the device will be reset when the constructor is invoked. If the cs_port, dc_port, or rst_port properties are not provided, they default to NULL.

"defines": {
	"ssd1306": {
		/* other properties here */
		"cs_pin": 4,
		"dc_pin": 2,
		"rst_pin": 0,
		"spi_port": "#HSPI",
		"spi": true,
		"i2c": false,
	}
}

The hz property, when present, specifies the SPI bus speed.

Using I2C

When using an I2C interface, the defines object may contain the I2C address of the device. If not provided, it defaults to 0x3C or may be passed the constructor as the address property of the dictionary. The scl_pin and sda_pin properties define the pins to use for I2C. If not present, they may be provided by the constructor as the scl and sda properties of the dictionary. If they are not passed to the constructor, the default I2C interface is used.

"defines": {
	"ssd1306": {
		/* other properties here */
		"scl_pin": 4,
		"sda_pin": 5,
		"address": 0x3c,
		"spi": false,
		"i2c": true,
	}
}

The hz property, when present, specifies the I2C bus speed.

Note: The I2C interface typically operates at a slower speed, so SPI is preferred when available.

Drawing

The SSD1306 driver always updates the full display area; partial updates are not supported. Piu automatically takes care of this, so script using Piu do not need to take this into account. Using Poco, an easy way to update the entire screen is to call poco.begin() with no parameters.

It may be possible to implement partial updates quantized to 8-pixel high full width bands.