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

Syntax

public class SSD1306 : DisplayBase

Remarks

OLED displays based upon the SSD1306 chip set are small, high contrast, single color displays. These displays generate their own light; no backlight is required.

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:

using System;
using System.Threading;
using Meadow;

namespace SSD1306_Sample
{
    public class Program
    {
        static IApp _app; 
        public static void Main()
        {
            _app = new MeadowApp();
        }
    }

    public class MeadowApp : AppBase<F7Micro, MeadowApp>
    {
        protected SSD1306 display;
        protected GraphicsLibrary graphics;

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

            Console.WriteLine("Test display API");
            TestRawDisplayAPI();
            Thread.Sleep(1000);

            Console.WriteLine("Create Graphics Library");
            TestDisplayGraphicsAPI();
        }

        void TestRawDisplayAPI()
        {
            display.Clear(true);

            for (int i = 0; i < 30; i++)
            {
                display.DrawPixel(i, i, true);
                display.DrawPixel(30 + i, i, true);
                display.DrawPixel(60 + i, i, true);
            }

            display.Show();
        }

        void TestDisplayGraphicsAPI() 
        {
            graphics.Clear();

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

            graphics.Show();
        }
    }
}

Circuit Example

To wire a SSD1306 to your Meadow board, 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. The driver currently only supports I2C displays. Wiring for the I2C interface is as follows:

Constructors

View Source

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.

View Source

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

View Source

chipSelectPort

Declaration
protected IDigitalOutputPort chipSelectPort

Field Value

Type Description
IDigitalOutputPort
View Source

Command

Declaration
protected const bool Command = false

Field Value

Type Description
System.Boolean
View Source

connectionType

Declaration
protected SSD1306.ConnectionType connectionType

Field Value

Type Description
SSD1306.ConnectionType
View Source

Data

Declaration
protected const bool Data = true

Field Value

Type Description
System.Boolean
View Source

dataCommandPort

Declaration
protected IDigitalOutputPort dataCommandPort

Field Value

Type Description
IDigitalOutputPort
View Source

resetPort

Declaration
protected IDigitalOutputPort resetPort

Field Value

Type Description
IDigitalOutputPort
View Source

spi

Declaration
protected SpiBus spi

Field Value

Type Description
SpiBus
View Source

spiDisplay

SSD1306 SPI display

Declaration
protected ISpiPeripheral spiDisplay

Field Value

Type Description
ISpiPeripheral

Properties

View Source

ColorMode

Declaration
public override DisplayColorMode ColorMode { get; }

Property Value

Type Description
DisplayColorMode
View Source

Contrast

Get / Set the contrast of the display.

Declaration
public byte Contrast { get; set; }

Property Value

Type Description
System.Byte
View Source

Height

Declaration
public override uint Height { get; }

Property Value

Type Description
System.UInt32
View Source

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.

View Source

Sleep

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

Declaration
public bool Sleep { get; set; }

Property Value

Type Description
System.Boolean
View Source

Width

Declaration
public override uint Width { get; }

Property Value

Type Description
System.UInt32

Methods

View Source

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.

View Source

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.

View Source

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
View Source

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.

View Source

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

View Source

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

View Source

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
View Source

Show()

Send the internal pixel buffer to display.

Declaration
public override void Show()
View Source

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.

View Source

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.

View Source

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.