Remarks

SSD1306
Status
Source code GitHub
NuGet package

The SSD1306 is a display controller used to control small, low resolution, single color OLED displays. OLED displays generate their own light - no backlight is included or required.

SDD1306 displays can be found supporting both I2C and SPI and come in resolutions of 32x128, 64x128, 16x96 and 64x96.

You may find mutlicolor variants, however, the color is achieved by placing one or more color filter over the single color display.

Purchasing

There are a number of breakout board available using these displays. This driver has been tested with the following:

Board are also available from Adafruit.

Code Example

The following example shows how to initialize a TEA5767 and look for radio stations:

public class MeadowApp : App<F7Micro, MeadowApp>
{
    Ssd1306 display;
    GraphicsLibrary graphics;

    public MeadowApp()
    {            
        var i2CBus = Device.CreateI2cBus();         
        display = new Ssd1306(i2CBus, 60, Ssd1306.DisplayType.OLED128x32);
        graphics = new GraphicsLibrary(display);

        TestDisplayGraphicsAPI();
    }

    void TestDisplayGraphicsAPI() 
    {
        graphics.Clear();

        graphics.CurrentFont = new Font8x12();
        graphics.DrawText(0, 0, "Meadow F7");
        graphics.DrawRectangle(5, 14, 30, 10, true);

        graphics.Show();
    }  
}

Sample projects available on GitHub

Wiring Example

To wire a Ssd1306 to your Meadow board using I2C, connect the following:

Ssd1306 Meadow Pin
GND GND
VCC 3V3
SCL D08 (SCL Pin)
SDA D07 (SDA Pin)

The OLED displays are available with a SPI or I2C interfaces. Wiring for the I2C interface is as follows:

Characteristic Locus
Inheritance System.Object > Ssd1306 > Ssd1309
Namespace Meadow.Foundation.Displays
Assembly Ssd1306.dll

Syntax

public class Ssd1306 : DisplayBase

Constructors

Ssd1306(II2cBus, Byte, Ssd1306.DisplayType)

Create a new SSD1306 object using the default parameters for

Declaration
public Ssd1306(II2cBus i2cBus, byte address = 60, Ssd1306.DisplayType displayType = Ssd1306.DisplayType.OLED128x64)

Parameters

Type Name Description
II2cBus i2cBus
System.Byte address

Address of the bus on the I2C display.

Ssd1306.DisplayType displayType

Type of SSD1306 display (default = 128x64 pixel display).

Remarks

Note that by default, any pixels out of bounds will throw and exception. This can be changed by setting the property to true.

Ssd1306(IIODevice, ISpiBus, IPin, IPin, IPin, Ssd1306.DisplayType)

Create a new SSD1306 object using the default parameters for

Declaration
public Ssd1306(IIODevice device, ISpiBus spiBus, IPin chipSelectPin, IPin dcPin, IPin resetPin, Ssd1306.DisplayType displayType = Ssd1306.DisplayType.OLED128x64)

Parameters

Type Name Description
IIODevice device
ISpiBus spiBus
IPin chipSelectPin
IPin dcPin
IPin resetPin
Ssd1306.DisplayType displayType

Type of SSD1306 display (default = 128x64 pixel display).

Remarks

Note that by default, any pixels out of bounds will throw and exception. This can be changed by setting the property to true.

Fields

chipSelectPort

Declaration
protected IDigitalOutputPort chipSelectPort

Field Value

Type Description
IDigitalOutputPort

Command

Declaration
protected const bool Command = false

Field Value

Type Description
System.Boolean

connectionType

Declaration
protected Ssd1306.ConnectionType connectionType

Field Value

Type Description
Ssd1306.ConnectionType

Data

Declaration
protected const bool Data = true

Field Value

Type Description
System.Boolean

dataCommandPort

Declaration
protected IDigitalOutputPort dataCommandPort

Field Value

Type Description
IDigitalOutputPort

resetPort

Declaration
protected IDigitalOutputPort resetPort

Field Value

Type Description
IDigitalOutputPort

spi

Declaration
protected SpiBus spi

Field Value

Type Description
SpiBus

spiDisplay

SSD1306 SPI display

Declaration
protected ISpiPeripheral spiDisplay

Field Value

Type Description
ISpiPeripheral

Properties

ColorMode

Declaration
public override DisplayColorMode ColorMode { get; }

Property Value

Type Description
DisplayColorMode

Contrast

Get / Set the contrast of the display.

Declaration
public byte Contrast { get; set; }

Property Value

Type Description
System.Byte

Height

Declaration
public override uint Height { get; }

Property Value

Type Description
System.UInt32

InvertDisplay

Invert the entire display (true) or return to normal mode (false).

Declaration
public bool InvertDisplay { get; set; }

Property Value

Type Description
System.Boolean

Remarks

See section 10.1.10 in the datasheet.

Sleep

Put the display to sleep (turns the display off).

Declaration
public bool Sleep { get; set; }

Property Value

Type Description
System.Boolean

Width

Declaration
public override uint Width { get; }

Property Value

Type Description
System.UInt32

Methods

Clear(Boolean)

Clear the display buffer.

Declaration
public override void Clear(bool updateDisplay = false)

Parameters

Type Name Description
System.Boolean updateDisplay

Immediately update the display when true.

DrawBitmap(Int32, Int32, Int32, Int32, Byte[], BitmapMode)

Copy a bitmap to the display.

Declaration
public override void DrawBitmap(int x, int y, int width, int height, byte[] bitmap, BitmapMode bitmapMode)

Parameters

Type Name Description
System.Int32 x

Abscissa of the top left corner of the bitmap.

System.Int32 y

Ordinate of the top left corner of the bitmap.

System.Int32 width

Width of the bitmap in bytes.

System.Int32 height

Height of the bitmap in bytes.

System.Byte[] bitmap

Bitmap to transfer

BitmapMode bitmapMode

How should the bitmap be transferred to the display?

Remarks

Currently, this method only supports copying the bitmap over the contents of the display buffer.

DrawBitmap(Int32, Int32, Int32, Int32, Byte[], Color)

Declaration
public override void DrawBitmap(int x, int y, int width, int height, byte[] bitmap, Color color)

Parameters

Type Name Description
System.Int32 x
System.Int32 y
System.Int32 width
System.Int32 height
System.Byte[] bitmap
Color color

DrawPixel(Int32, Int32)

Draw a pixel to the display using the pen

Declaration
public override void DrawPixel(int x, int y)

Parameters

Type Name Description
System.Int32 x

Abscissa of the pixel to the set / reset.

System.Int32 y

Ordinate of the pixel to the set / reset.

DrawPixel(Int32, Int32, Color)

Draw a pixel to the display - coordinates start with index 0

Declaration
public override void DrawPixel(int x, int y, Color color)

Parameters

Type Name Description
System.Int32 x

Abscissa of the pixel to the set / reset.

System.Int32 y

Ordinate of the pixel to the set / reset.

Color color

Black - pixel off, any color - turn on pixel

DrawPixel(Int32, Int32, Boolean)

Draw a pixel to the display - coordinates start with index 0

Declaration
public override void DrawPixel(int x, int y, bool colored)

Parameters

Type Name Description
System.Int32 x

Abscissa of the pixel to the set / reset.

System.Int32 y

Ordinate of the pixel to the set / reset.

System.Boolean colored

True = turn on pixel, false = turn off pixel

SetPenColor(Color)

Set the pen color, black is off, any other color is on

Declaration
public override void SetPenColor(Color pen)

Parameters

Type Name Description
Color pen

Show()

Send the internal pixel buffer to display.

Declaration
public override void Show()

StartScrolling(Ssd1306.ScrollDirection)

Start the display scrollling in the specified direction.

Declaration
public void StartScrolling(Ssd1306.ScrollDirection direction)

Parameters

Type Name Description
Ssd1306.ScrollDirection direction

Direction that the display should scroll.

StartScrolling(Ssd1306.ScrollDirection, Byte, Byte)

Start the display scrolling.

Declaration
public void StartScrolling(Ssd1306.ScrollDirection direction, byte startPage, byte endPage)

Parameters

Type Name Description
Ssd1306.ScrollDirection direction

Direction that the display should scroll.

System.Byte startPage

Start page for the scroll.

System.Byte endPage

End oage for the scroll.

Remarks

In most cases setting startPage to 0x00 and endPage to 0xff will achieve an acceptable scrolling effect.

StopScrolling()

Turn off scrolling.

Declaration
public void StopScrolling()

Remarks

Datasheet states that scrolling must be turned off before changing the scroll direction in order to prevent RAM corruption.