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 DisplayBase > Ssd1306 > Ssd1309 |
Inherited Members | DisplayBase.IgnoreOutOfBoundsPixels |
Namespace | Meadow.Foundation.Displays |
Assembly | Ssd130x.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
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
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 |
spiPeripheral
SSD1306 SPI display
Declaration
protected ISpiPeripheral spiPeripheral
Field Value
Type | Description |
---|---|
ISpiPeripheral |
Properties
ColorMode
Declaration
public override DisplayBase.DisplayColorMode ColorMode { get; }
Property Value
Type | Description |
---|---|
DisplayBase.DisplayColorMode |
Overrides
Contrast
Get / Set the contrast of the display.
Declaration
public byte Contrast { get; set; }
Property Value
Type | Description |
---|---|
System.Byte |
Height
Declaration
public override int Height { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Overrides
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 int Width { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Overrides
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. |
Overrides
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. |
Overrides
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 |
Overrides
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 |
Overrides
InvertPixel(Int32, Int32)
Declaration
public override void InvertPixel(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | |
System.Int32 | y |
Overrides
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 |
Overrides
Show()
Send the internal pixel buffer to display.
Declaration
public override void Show()
Overrides
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.