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?
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;
}
}