SSD1306xLED is a C library for working with the SSD1306 display driver to control dot matrix OLED/PLED 128×64 displays. It is intended to be used with the Tinusaur board but should also work with any other board based on ATtiny85 or similar microcontroller.

SSD1306xLED library for OLED/PLED 128x64The 128×64 OLED is controlled by a SSD1306 circuit and could be interfaced over I²C.

The code could be divided in 3 pieces:

  1. Communication over I²C with the SSD1306;
  2. Sending graphical commands to the display;
  3. High-level functions such as printing characters.

The I²C communication part is based on a code from the IIC_wtihout_ACK library that is available on the Internet but its original website (http://www.14blog.com/archives/1358) is no longer functional. Basically, the SSD1306xLED library  makes SSD1306 to work with ATtiny85 and Tinusaur.

How to use it

Using this library to control an OLDE display is very easy. The necessary header files that should be included with the program could be found in the source code repository – the link is at the bottom of this document.

First, the controlling PINs should be specified in the source code:

#define SSD1306_SCL PB2 // SCL, Pin 3 on SSD1306 Board
#define SSD1306_SDA PB0 // SDA, Pin 4 on SSD1306 Board

There are defaults, of course, but make sure they work for you.

There is also I2C slave address specified in the source code but you probably don’t want to change that.

Second, the display controller should be initialized.

    _delay_ms(40);
    ssd1306_init();

The delay is necessary if the initialization is at the beginning of the program. This is required by the SSD1306 circuit as it needs time to initialize itself after power-on.

Then, the simplest example would be to clear the screen (fill it out with blanks) and output some text.

    ssd1306_fillscreen(0x00);
    ssd1306_setpos(0, 10);
    ssd1306_string_font6x8("Hello World!");

The ssd1306_string_font6x8 function call will output at the specified by the ssd1306_setpos function coordinates the provided text using 6×8 character font.

Similarly, a bitmap could be output on the screen with the following code:

    ssd1306_draw_bmp(0,0,128,8, img1_128x64c1);

The above function call specifies (0,0) coordinates, width of 128 pixels and height of 8 bytes – 64 pixels.

Documentation

This project often changes so more current information could be found in the source code repository – in the text files and source files as well.

Source code

The source code along with very simple example is available on Bitbucket at this address: https://bitbucket.org/tinusaur/ssd1306xled

This SSD1306xLED library still needs more work and some improvements.

 

55 thoughts on “SSD1306xLED

  1. Ol´á,

    How do I use this SSD1306xLED library for my 6-pin display?

    OLED_MOSI 9 //=> SDA
    OLED_CLK 10 //=> SCK = SCL
    OLED_DC 11 //=> A0 = D/C
    OLED_CS 12 //=> não usa
    OLED_RESET 13 //=> Reset

    It is possible?

  2. Olá,

    How do I use this SSD1306xLED library for my 6-pin display?

    OLED_MOSI 9 //=> SDA
    OLED_CLK 10 //=> SCK = SCL
    OLED_DC 11 //=> A0 = D/C
    OLED_CS 12 //=> não usa
    OLED_RESET 13 //=> Reset

    It is possible?

  3. You should first verify if your display has the I2C interface or not. The SSD1306xLED library is specifically developed for the I2C interface – that’s why it runs so fast.

    You’ve got a “MOSI” pin and that may mean that it is serial OLED which means that it will not be supported by the library.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s