Interfacing a I2C 0.96″ OLED Display with ATtiny85

> 2 min read

Time to use a tiny OLED screen with a ATtiny85 to display something! This can be useful to display some text, or display sensor values. In this tutorial, I’ll be showing you how to interface a I2C 0.96″ OLED Display with the ATtiny85. To be frank, I can’t find much information about interfacing the ATtiny 85 with this I2C display, so hopefully this tutorial can help you in doing this.

Why use a small OLED Display?

OLED Displays do not require much power to turn it own, since no backlight is required to read the display. Furthermore, ATtiny projects do not need to have such a large screen to display all the value, and the screen of this size may be enough. Finally, with a small screen, you can make your ATtiny projects even more compact!


What Library am I using?

For this tutorial, I’m using the Tinysaur ssd1306xled library for displaying the text on the OLED Display, as that is the only library I think is small enough to display text on the ATtiny85, although there are limitations such as there is ony 2 sizes of fonts,etc. The tinsaur library can be downloaded here.

I wanted to use the Adafruit ssd1306 library at first, for it has many graphical options such as drawing shapes and lines, but I realised that the library was too big for the ATtiny85. Therefore, I have to find a smaller library. And that is when I found the TinySaur ssd1306xled library.


Connecting the ATtiny


The Tinysaur library has specified the pins of where the SDA & SCL of the OLED Display should be connected to the ATtiny85. The SCL pin should be connected to ATtiny85 pin 0, and the SDA pin should be connected to ATtiny85 pin 1.



I used the Tinysaur Library for this project. I changed the F_CPU constant from 1000000 to 8000000. The F_CPU constant is actually to be changed according to what speed your ATtiny is clocked. At 1000000, the flickering or the screen refresh is too obvious, so I think clocking the CPU clock at 8000000Hz would be much better. To do this, you have to burn the 8Mhz bootloader. (The flickering would not be so obvious)

#define F_CPU 8000000UL      //ATtiny85 CPU Clock speed (8MHz optimal[8000000], 1MHz Default[1000000])

#include <stdlib.h>
#include <avr/io.h>
#include <util/delay.h>
#include <avr/pgmspace.h>

// ----------------------------------------------------------------------------

// ---------------------	// Vcc,	Pin 1 on SSD1306 Board
// ---------------------	// GND,	Pin 2 on SSD1306 Board
#define SSD1306_SCL		PB0	// SCL,	Pin 3 on SSD1306 Board
#define SSD1306_SDA		PB1	// SDA,	Pin 4 on SSD1306 Board

#define SSD1306_SA		0x78	// Slave address

// ----------------------------------------------------------------------------

#include "ssd1306xled.h"

void setup(){	
  // Small delay is necessary if ssd1306_initis the first operation in the application.

  ssd1306_char_f8x16(1, 2, "Photon OS");
  ssd1306_char_f6x8(1, 5, "Loading test...");

  uint8_t p = 0xff;

  for (uint8_t i = 0; i < 4; i++)
    p = (p >> i);

void loop()
  ssd1306_char_f6x8(1, 0, "I'm a ATtiny85"); //Cannot start at 0 for x. Gives problem

  ssd1306_char_f6x8(1, 0, "I'm a small and mighty.");

  ssd1306_char_f6x8(1, 0, "Who says I can't run this LED screen?");

  ssd1306_char_f6x8(1, 0, "There am I running it now.");



You may also like...