Trying to make sense of SSD1306 display behaviour

I recently discovered that I could flash and debug MBED code on my old Particle.io Xenon (nRF52840) feather dev board using MBED Studio.

I happened to have a Featherwing 128x32 OLED display, which uses the SSD1306 driver.

So I thought it worth trying out… and it works!

BUT, for some reason, the value does not increment sequentially on the display, even though it does on the serial monitor. So on the display you get, for example, 0… 2… 4… 6 etc.

Does anyone know why?

Screenshot at 2020-08-07 11-26-27

I found this library via MBED compiler - Adafruit_SSD1306.h and was able to import this library into MBED Studio.

The code is fairly simple:

#include <mbed.h>

#include "USBSerial.h"

#include "Adafruit_SSD1306.h"//include the adafruit library for the oled display

//DigitalOut led1(LED1);

I2C i2c(I2C_SDA0, I2C_SCL0);

Adafruit_SSD1306_I2c oled(i2c,0x78); //0111 1000

 

void OLEDInitialise(){

 

    ThisThread::sleep_for(500ms);

    oled.clearDisplay();

    oled.setTextCursor(0,0); 

    oled.display();

}

 

int main()

{   

    USBSerial serial;

    OLEDInitialise();

    serial.wait_ready();

    serial.printf("OLED Print Demo\r\n");

    ThisThread::sleep_for(3000ms);

    uint32_t xx=0;

    char displayText[32];

    while(1) {

        memset(displayText, '\0', 32);

        sprintf(displayText, "Hello MBED:%u", xx);

        oled.clearDisplay();

        oled.setTextSize(2);

        oled.setTextCursor(0,0);

        oled.printf("%s", displayText);

        oled.display();

        serial.printf("%s\r\n", displayText);

        xx++;

        ThisThread::sleep_for(1000ms);

        //led1 = !led1;

    }

}

Hi Gerriko,

what version of the OS are you using?

Regards
Anna

I’m using OS 6.2.

Now that I’m working through trying to port other OS5.x libraries across to OS6.2 this must’ve been a case of beginners luck that it actually worked (it had highlighted only 1 error in the library, which was easy to resolve)…

I resolved by applying a double “clear” and then “display” command (as I reasoned it must be something to do with a buffer)

Adafruit_SSD1306_I2c oled(i2c,0x78); //0111 1000

void OLEDdisplay_Handler(void)

{

    static uint32_t xx=0;

    char displayText[32] = {'\0'};

    sprintf(displayText, "Hello MBED:%u", xx);

    oled.clearDisplay();        

    oled.display();

    oled.clearDisplay();        

    oled.setTextSize(2);

    oled.setTextCursor(0,0);

    oled.printf("%s", displayText);

    oled.display();

    serial.printf("%s\r\n", displayText);

    xx++;

}

int main()

{   

    queue.call_every(1s, OLEDdisplay_Handler);

    queue.dispatch_forever();

}