OLED (I2C) With ATtiny85

NOTE: Prior pushing through with this article, I advised you to read and visit my article Miniaturizing Your Arduino Projects Using ATtiny85 if you haven’t yet. In this article, you will learn how to set up your ATtiny85 so that it would be ready to be uploaded with sketches through an ISP.

In one of my previous posts (LCD Display with ATtiny85), I detailed how LCD is used with an ATtiny85, or in my case the ATtiny85 Development Board. I tried the usual libraries which I use for my OLED with my Arduino boards (Uno, Pro Mini, Nano and Atmega328-based DIY boards), but these do not work well (does not compile successfully to ATtiny85). I was able to scout one from the Internet, and the library can be found here: ATTiny85 Connects to I2C OLED Display –  Great Things Can be Small article from Instructables. The article explains how soldering is done with the ATTiny85 kit, but we can skip that. The components/modules needed are the following:

  1. Arduino Board as ISP (You may use the Arduino board of your choice, but you need to take note of the pins used for your board when using it as an ISP.)
  2. ATtiny85 integrated chip (or in my case, the ATtiny85 Development Board)
  3. OLED (in my case, I am using the 0.96”-128×64 OLED Display (i2c).
  4. Jumper wires
  5. Breadboard
img_3375
Main components: Arduino Nano, ATtiny85 Development Board, 0.96″128×64 OLED Display

Again, we will show the ATtiny85 pinout, and study how to connect this to the Arduino board to upload sketches from it to the ATtiny85 integrated chip:

img_2937

ARDUINO TO ATTINY85 CONNECTIONS

Connect the following (I am using an Arduino Nano, so you have to take note the necessary pins of the board you are using when using it as an ISP):

  1. Arduino Board Digital Pin 10 connects to ATtiny85 PB5 (Chip Pin 1)
  2. Arduino Board Digital Pin 11 connects to ATtiny85 PB0 (Chip Pin 5)
  3. Arduino Board Digital Pin 12 connects to ATtiny85 PB1 (Chip Pin 6)
  4. Arduino Board Digital Pin 13 connects to ATtiny85 PB2 (Chip Pin 7)
  5. Arduino Board VCC connects to ATtiny85 VCC (Chip Pin 8)
  6. Arduino Board GND connects to ATtiny85 GND (Chip Pin 4)

img_3377

  • Green wire connects from Arduino Nano D11 to ATtiny85 P0
  • Yellow wire connects from Arduino Nano D12 to ATtiny85 P1
  • Blue wire connects from Arduino Nano D13 to ATtiny85 P2
  • White wire connects from Arduino Nano D10 to ATtiny85 P5
  • Red wire connects from Arduino Nano 5V to ATtiny85 Vin
  • Black wire connects from Arduino GND to ATtiny85 GND

ARDUINO AS ISP

  1. Attach the Arduino Nano (or your preferred board) to your computer.
  2. Go to File > Examples > ArduinoISP, and click on Arduino ISP.
  3. Go to Tools > Boards and select Arduino Nano (or your preferred board).
  4. Go to Tools > Port and select the port where your board is connected to.
  5. Upload the ArduinoISP sketch to your Arduino Nano (or your preferred board) by going to Sketch > Upload (or CTRL+U).
  6. At this stage, your Arduino UNO is ready to be used as a programmer / ISP.

ADDING THE REQUIRED LIBRARY

Next thing to be done is to add the required library, which can be found here. Once downloaded, install it in the Arduino IDE. You may want to open the embedded sample from the compressed file (ATTiny85_OLED_weather_demo.zip).

I made some modifications to the sketch, to simplify the example:

#include "SSD1306_minimal.h"
#include <avr/pgmspace.h>

#define DEG "\xa7" "C"

SSD1306_Mini oled; // Declare the OLED object

void splash() {
 oled.startScreen();
 oled.clear(); // Clears the display

 oled.cursorTo(0, 0); // x:0, y:0
 oled.printString("Hello World!");
 oled.cursorTo(0, 10); // x:0, y:23
 oled.printString("ATtiny85!");
}

void setup() {
 oled.init(0x3C); // Initializes the display to the specified address
 oled.clear(); // Clears the display
 delay(1000); // Delay for 1 second
 splash(); // Write something to the display (refer to the splash() method
}

void loop() {
}

Now, we need to connect the OLED display to the ATtiny85 chip (or in my case the ATtiny85 Development Board).

ATTINY85 TO OLED CONNECTIONS

Since our OLED display is using i2c, we only need 4 pins all in all: VCC, GND, SCL and SDA. From the ATtiny85 pinout, you will see VCC (chip pin 8), GND (chip pin 4), SCL (chip pin 7, PB2) and SDA (chip pin 5, PB0). Connect the corresponding pins for these two modules:

  1. ATiny85 Pin 7 (PB2) to OLED’s SCL pin
  2. ATiny85 Pin 5 (PB0) to OLED’s SDA pin
  3. ATiny85 Pin 8 (VCC) to OLED’s VCC pin
  4. ATiny85 Pin 4 (GND) to OLED’s GND pin

img_3379-2

  • Orange wire connects from ATtiny85 P2 to OLED Display’s SCL pin
  • Dark blue wire connects from ATtiny85 P0 to OLED Display’s SDA pin
  • Red wire connects from ATtiny85 5V (VCC) to OLED Display’s VCC pin
  • Black wire connects from ATtiny85 GND to OLED Display’s GND pin

UPLOADING SKETCH TO ATTINY85 DEVELOPMENT BOARD

  1. Make sure that the connections are in place (Arduino Nano to ATtiny85).
  2. Open the program / sketch you want uploaded to your ATtiny85 Development Board.
  3. Go to Tool and setup the following, as shown from the screenshot below:
    img_2945
  4. Upload your desired sketch to your ATtiny85 Development Board (or your preferred board) by going to Sketch > Upload Using Programmer (or CTRL+SHIFT + U).
  5. The sketch should be uploading to your ATtiny85 Development Board at this stage.

At this stage, you should be seeing something similar as pictured below:

img_3380

I removed the wires connecting the Arduino Nano and the ATtiny85 Development Board, and powered the module to its micro USB port. Power the OLED from ATtiny85’s 5V pin and GND pin.

img_3381-1img_3384-1

 

7 thoughts on “OLED (I2C) With ATtiny85

  1. thanks works gr8 on 128×64 i2c:)
    but on a 128×32 the fonts are garbled, could you help to solve it, i.e. to adjust library to 128×32 display?
    thx, wojtasl

  2. code uploads successfully but oled doesnt print anything i checked connections everything seems fine what could be the cause for this?

  3. Hi Eldon,
    Thank you for this tutorial.
    I have been looking for a simple ATtuny85 OLED implementarion to help verify & debug the code for a couple of my ATtiny85 projects. This tutorial is exactly what I have been looking for. It is much better with more specfic detail than other articles on this subject & that makes it easier to understand. It does not have superfluous info either. Best regards. Joe

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.