A derived version of the BSD licensed Adafrut GFX library for the SSD1306 controller for an OLED 128x32 or 128x64 display using SPI or I2C.

Dependents:   servo_sensor ArchPro_TFT BLE_Display SSD1306_demo ... more

Import libraryAdafruit_GFX

A derived version of the BSD licensed Adafrut GFX library for the SSD1306 controller for an OLED 128x32 or 128x64 display using SPI or I2C.

This is an SPI or I2C driver, font, and graphics drawing library as initially provided by Adafruit which has been modified for use in the mbed envionment.

128x32 OLED Display

Example

/*
 *  Copyright (c) 2012 Neal Horman - http://www.wanlink.com
 *  
 *  License: MIT open source (http://opensource.org/licenses/MIT)
 *      Summary;
 *      Use / modify / distribute / publish it how you want and 
 *      if you use it, or don't, you can't hold me liable for how
 *      it does or doesn't work.
 *      If it doesn't work how you want, don't use it, or change
 *      it so that it does work.
 */
 
#include "mbed.h"
#include "Adafruit_SSD1306.h"

DigitalOut myled(LED1);

// an SPI sub-class that provides a constructed default
class SPIPreInit : public SPI
{
public:
    SPIPreInit(PinName mosi, PinName miso, PinName clk) : SPI(mosi,miso,clk)
    {
        format(8,3);
        frequency(2000000);
    };
};

// an I2C sub-class that provides a constructed default
class I2CPreInit : public I2C
{
public:
    I2CPreInit(PinName sda, PinName scl) : I2C(sda, scl)
    {
        frequency(400000);
        start();
    };
};

SPIPreInit gSpi(p5,NC,p7);
Adafruit_SSD1306_Spi gOled1(gSpi,p26,p25,p24);

I2CPreInit gI2C(p9,p10);
Adafruit_SSD1306_I2c gOled2(gI2C,p27);

int main()
{   uint16_t x=0;

    gOled1.printf("%ux%u OLED Display\r\n", gOled1.width(), gOled1.height());
    gOled2.printf("%ux%u OLED Display\r\n", gOled2.width(), gOled2.height());
    
    while(1)
    {
        myled = !myled;
        gOled1.printf("%u\r",x);
        gOled1.display();
        gOled2.printf("%u\r",x);
        gOled2.display();
        x++;
        wait(1.0);
    }
}

History

removed test comments default tip

2014-11-11, by JojoS [Tue, 11 Nov 2014 22:08:20 +0000] rev 16

removed test comments


copy in line 211 requires index-1 because x starts at offset 1 and not at 0.

2014-11-11, by JojoS [Tue, 11 Nov 2014 22:02:52 +0000] rev 15

copy in line 211 requires index-1 because x starts at offset 1 and not at 0.


Code space optimizations;; Make simple set/getter functions inlined.; Fix ifdef around setTextSize() to be either GFX_WANT_ABSTRACTS or GFX_SIZEABLE_TEXT; ifdef drawBitmap() w/ GFX_WANT_ABSTRACTS.;

2014-10-25, by nkhorman [Sat, 25 Oct 2014 20:41:38 +0000] rev 14

Code space optimizations;; Make simple set/getter functions inlined.; Fix ifdef around setTextSize() to be either GFX_WANT_ABSTRACTS or GFX_SIZEABLE_TEXT; ifdef drawBitmap() w/ GFX_WANT_ABSTRACTS.;


flesh out the config defines

2014-10-21, by nkhorman [Tue, 21 Oct 2014 02:30:58 +0000] rev 13

flesh out the config defines


merge documentation

2014-10-21, by nkhorman [Tue, 21 Oct 2014 02:16:49 +0000] rev 12

merge documentation


Add some documentation

2014-10-21, by nkhorman [Tue, 21 Oct 2014 02:04:08 +0000] rev 11

Add some documentation


fix - missed this in the refactor

2014-10-20, by nkhorman [Mon, 20 Oct 2014 03:16:15 +0000] rev 10

fix - missed this in the refactor


c++'ify the SPI vs I2C driver portions, instead of compile time defines.; The SSD1306 driver can now be instantiated multiple times, supporting simultaneous displays of differing dimensions.

2014-10-19, by nkhorman [Sun, 19 Oct 2014 20:55:27 +0000] rev 9

c++'ify the SPI vs I2C driver portions, instead of compile time defines.; The SSD1306 driver can now be instantiated multiple times, supporting simultaneous displays of differing dimensions.


fix compile warning and error

2014-10-19, by nkhorman [Sun, 19 Oct 2014 04:45:11 +0000] rev 8

fix compile warning and error


missed this define change in the last change set

2014-10-18, by Neal Horman [Sat, 18 Oct 2014 12:05:58 -0500] rev 7

missed this define change in the last change set