Skip to content

OLED display

Description

SensorIO's display is a monochrome (white) OLED screen with 128x32 pixels and based on SSD1306 controller. Communication is carried over SPI interface (SPI4).

Part details

Manufacturer: Univision Technology Inc.

Part number: UG-2832HSSWEG04

Datasheet: link

Code example

Compiling example

This example is based on Mbed OS and requires a simple setup. For full description check Code Setup page.

SSD1306 driver

Mbed OS driver for SensorIO can be found here: SSD1306 on Github.

Code

Pin definitions

1
2
3
4
5
6
    /**** OLED pins (SPI4) ****/
    OLED_CLK   = PE_2,
    OLED_RESET = PE_3,
    OLED_CS    = PE_4,
    OLED_DC    = PE_5,
    OLED_MOSI  = PE_6,

Example

This example shows basic usage of text display and image acceleration (scrolling and inverting).

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "SPI.h"
#include "ssd1306.h"
#include "ssd1306spibus.h"
#include "mbed_wait_api.h"

using mbed::SPI;

constexpr size_t OLED_WIDTH = 128;
constexpr size_t OLED_HEIGHT = 32;

int main(int argc, char **argv)
{
    SPI spi(OLED_MOSI, OLED_DC, OLED_CLK);
    Ssd1306SPIBus spiBus(spi, OLED_RESET, OLED_CS, OLED_DC);
    Ssd1306 oled(spiBus, OLED_WIDTH, OLED_HEIGHT);

    while(1)
    {
        oled.clear();
        oled.printf(FontSize::BIG,
                    0, // X offset in pixels
                    0, // Y offset in pixels
                    "SensorIO");
        wait(2);
        oled.scrollUp();
        wait(2);
        oled.stopScroll();
        oled.invert();
        wait(2);
        oled.clear();
        wait(2);
    }
}

Example main.cpp file can be downloaded from here.