The 128×64 OLED is controlled by a SSD1306 circuit and could be interfaced over I²C.
The code could be divided in 3 pieces:
- Communication over I²C with the SSD1306;
- Sending graphical commands to the display;
- 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.
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:
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.
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(x00); ssd1306_setpos(, 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:
The above function call specifies (0,0) coordinates, width of 128 pixels and height of 8 bytes – 64 pixels.
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.
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.
For more detail: SSD1306xLED Tinusaur ATtiny85 Library for SSD1306