LCD (I2C) with ATtiny85

NOTE: Prior pushing through with this tutorial, I encourage you  (if you haven’t yet) to visit Miniaturizing Your Arduino Project using ATtiny85, which demonstrates how to set up your ATtiny85 with Arduino UNO and Arduio IDE.

I am a bit into programming the ATtiny85 currently, and was looking for some libraries to use for my 16×2 LCD via i2c. I tried testing the current library I had (refer to my previous tutorial : Displaying Text to LCD via I2C Module on DIY Arduino Board), but this does not work with the ATtiny85.

By the way, I am using the ATtin85 Development Module like the one shown below:

img_2931-1

The LCD and I2C modules I am using are the ones pictured below:

lcd-moduleimage-5

Using the same modules, we will be displaying text to the LCD via I2C from out ATtiny85 Development Board. Here’s how:

INSTALLING THE LIBRARY

  1. Download the LCD library ( for ATtiny85 by clicking on this link : ATtiny85 LCD Library.
  2. Adding the library to Arduino is a bit tricky here. After downloading the library as ZIP above, extract the LiquidCrystal_ATtiny folder from the compressed file to your local machine (directory of your choice).
  3. Open the folder and compress all files in one ZIP file (name the compressed file LiquidCrystal_ATtiny.zip). This .zip file is the one to be added to your Arduino IDE. When you open the compress file, these files should show up:
    • examples (folder)
    • LiquidCrystal_attiny.h
    • LiquidCrystal_attiny.cpp
    • keywords.txt
  4. Now, add this to the Library by going to Sketch > Include Library > Add .ZIP library. Then locate the compressed file, and add it. The status bar at the bottom of the Arduino IDE will tell you that the library has been added successfully or not.
  5. To verify that the sample code has also been added, go to File > Examples > LiquidCrystal_ATtiny > i2c_lcd_attiny.

 

WIRING THE MODULE

The I2C module has 4 pins in it: SCL, SDA, VCC and GND. (In the I2C image above, SCL has the yellow jumper wire attached to it, SDA has the blue jumper wire attached to it, VCC has the red one, and GND has the black jumper wire attached to it.

In my previous article, we’ve somehow shown the pinout for the ATtiny85 (in my case the ATtiny85 Development Board, but no much of a difference actually:
img_2937
Pinout for ATtiny85 integrated circuit above.

img_2923-2

Pinout labels correspond to those in ATtiny85 Development Board as well.

Wire the I2C module as follows:

  1. Connect SCL pin from the I2C module to PB02 of the ATtiny85 IC or Development Board.
  2. Connect SDA pin from the I2C module to PB0 of the ATtiny85 IC or Development Board.
  3. Connect VCC pin from the I2C module to 5V of the ATtiny85 IC or Development Board.
  4. Connect GND pin from the I2C module to GND of the ATtiny85 IC or Development Board.

 

IMPORTANT: If tou have a separate power supply for the ATtiny85 IC or Development board, you must connect GND from the Arduino UNO to the GND of the power supply.

Now, connect your Arduino UNO as demonstrated in my previous post. We will use the Arduino UNO as ISP to upload sketches to the ATtiny85 IC or Development Board.

UPLOADING THE SKETCH

  1. I kinda modified the source file, to make it simpler:
    /*
     * Interactive nametag sketch for ATtiny85. Based on the Digispark
     * ATtiny LCD example and the Adafruit "Measuring Sound Levels" example.
     * Every 12000 milliseconds will change the display from my name to my website.
     * On the second line, will measure and display sound levels.
     * For more info check: https://platis.solutions/blog/2015/03/22/diy-interactive-name-tag/
     * ATtiny85 I2C pins:
     * ATtiny Pin 5 = SDA on DS1621 & GPIO
     * ATtiny Pin 7 = SCK on DS1621 & GPIO
     */
     
    #include <TinyWireM.h> // I2C Master lib for ATTinys which use USI - comment this out to use with standard arduinos
    #include <LiquidCrystal_attiny.h> // for LCD w/ GPIO MODIFIED for the ATtiny85
    
    #define GPIO_ADDR 0x3F // the address of i2c for LCD
    LiquidCrystal_I2C lcd(GPIO_ADDR, 16, 2); // set address & 16 chars / 2 lines
    
    void setup() {
     lcd.init();
     lcd.noBacklight();
     delay(100);
     lcd.backlight();
     lcd.clear();
    }
    
    void loop() {
     for (int num = 0; num <= 1000; num++) {
     lcd.clear();
     lcd.setCursor(0, 0);
     displayText("Basic counting:");
     lcd.setCursor(0, 1);
     displayText("Number : ");
     displayText((String) num);
     delay(200);
     }
    }
    
    void displayText(String str) {
     char charBuf[16];
     str.toCharArray(charBuf, 16);
     for (int ind = 0; ind < str.length(); ind++) {
     lcd.print(charBuf[ind]);
     }
    }
  2. You may copy the source code above. NOTE: Before uploading the sketch, please verify the address of your i2c module.
  3. Upload the sketch through the instructions I had in my post : Miniaturizing Your Arduino Project using ATtiny85.
  4. You should have a similar output to the LCD module as the one shown below:

Now you’re done! Please let me know how you go. I would be happy to update this article if you have anything to suggest that would make this article as accurate as it should, especially for beginners like me.

This article serves as a documentation for me, and for others who might want to try the steps I did in this exercise.

Thanks!

4 thoughts on “LCD (I2C) with ATtiny85

  1. Hi Eldon,
    Your tutorial was of great help in connecting my Attiny85 board to a small LCD 8×2, which was included in Pololu A-Star Prime board (https://www.pololu.com/product/3109). The library works fine.
    I program the Attiny85 board directly from the Arduino IDE via a simple USB cable. I see you use Arduino Uno : for this purpose only?

  2. Thank you very much for this tutorial. Out of all the tutorial on web and youtube this one worked for me to drive lcd with Attiny85. Appreciated.

  3. I am grateful for this contribution. I finally found what I was looking for. Simple and functional guide ATtiny85. My goal was to display I2C on the LCD. I am developing a tachometer for CNC3018. I hope it will be ok.
    Zdeněk.ttz
    Thank you very much.

Leave a comment

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