Introduction: Using an I2C LCD on Attiny85

About: I am a physician by trade. After a career in the pharmeceutical world I decided to take it a bit slower and do things I like. Other than my hobbies that involves grassroots medicine in S.E.&P Asia. I have buil…

Some people experience problems. Usually that is because of not having the right library, not having that library installed properly or have it overwritten by an update.
In this link you will find the configuration that works for me on IDE 1.6.9. Put all those files (except the picture) in ONE directory, where also your INO file goes

Using an LCD on a small chip like an attiny85 is not really that hard and till recent I didnt even think it warranted an instructable, but I have received questions about it, so I may as well expand on the process.

With the attiny only having a max of 6 pins available, it goes without saying that it cannot directly control all the pins of the standard Hitachi based LCD's
A little bit over a year ago, I described how to add an LCD to an Attiny or other chip, using only 2 pins. That circuit made use of an HC164 shift register, but as I2C modules for LCD's are extremely cheap and even LCD's with a module already in place also are dirt cheap, one might as well use I2C on the Attiny85.

The attiny85 can simulate I2C on PB2 (pin 7) (SCL) and PB0 (pin 5) (SDA). The 'Wire' library that is used to read and write bytes from and to the I2C port on the arduino doesnt work on the attiny. It needs the TinyWireM library to act as an I2C master

The standard Arduino library cannot be used for I2C on the Attiny because it does a call to 'Wire.h' and that one is not compatible with the Attiny.
The 'NewLCD' library from Francisco Malpartida is my favorite library, but also that one fails in using I2C for the Attiny because it makes a call to the Wire library. A modification to make it work with Attiny85 can be found here.
The 'Bro Hogan' library however does work. It is basically the same library as the standard arduino LCD library, but it is modified to recognize the Attiny85 and the Attiny2313 and then makes a call to 'TinyWireM' rather than 'Wire'.
Adafruit also provides a libray that works with the Attiny85 and that is described in another instructable. I will be using the Bro Hogan library here.

Avoiding problems
Most problems you may encounter are related to the IDE getting confused regarding the libraries. If you are using the standard Arduino LCD library, best replace it by the Bro Hogan library. If you are using Malpartida's library and want to keep that (as it is a great library), move it out of the way. Grab the entire folder and move it out of your sketchbook/libraries folder. Make sure you have the TinyWireM library installed and make sure your libraries are up to date.
If for whatever reason you cannot or do not want to move the Malpartida library out of the way, either rename the LiquidCrystal_I2C.h and LiquidCrystal_I2C.cpp modules in that library, or put the BroHogan LiquidCrystal_I2C.h and LiquidCrystal_I2C.cpp files in your sketch directory (and change the fishhook call into parenthesis).

Programming the Attiny
I presume you know how to do that. Nevertheless I'll run you through some pitfalls:
Burn the bootloader!!! I am probably saying things most people already know but you'd be surprised how many people dont know.
Now obviously there is no bootloader for the attiny85, but the process of burning the bootloader sets the fuses of the attiny from factory mode, to the mode you want to use it in. So, presuming you use the Arduino as ISP,:
upload the ISP program to your Arduino,
put the attiny in your program shield
Go to 'Tools-Board' -> Choose 'Attiny'
Go to 'Tools-Processor' -> Choose Attiny85
Go to 'Tools-Clock' -> Choose 8Mhz (or 1 if you prefer)
Go to 'Tools-Burn bootloader'

Then upload the program (see next step) to the IDE
Go to 'Sketch-Upload using programmer'

"Hey, my IDE says there are updates for some libraries"
The newer versions of the IDE will tell you when there are updates for some of your libraries and often, the Liquid Crystal library is also suggested for an update. Don't If you have the Bro Hogan library, it will be replaced by for instance the YW robot library, while the Malpartida library will probably be completely deleted.

Connecting the LCD.
The I2C module has 4 connections: Vcc, SCL, SDA, Ground.
they connect as follows to the Attiny:
Attiny85 <---> LCD

Vcc (pin8) <-----> Vcc
SCL (pin7) <-----> SCL
SDA (pin5) <-----> SDA
GND (pin4)<-----> GND

Step 1: I2C LCD on Attiny 85: the Program

I am always a bit hesitant to put a program including libraries on instructables as sometimes the so called 'fishhooks' around the library are interpreted as html code and make the name of the library disappear, even after I made sure they were there.
Nevertheless, you will find the code below, but just make sure to compare it to the screenshot in the IDE that I have attached in this step

#include <TinyWireM.h>                 
#include <LiquidCrystal_I2C.h>         

LiquidCrystal_I2C lcd(0x20,16,2);  // set address & 16 chars / 2 lines

void setup()

  TinyWireM.begin();                    // initialize I2C lib
  lcd.init();                           // initialize the lcd 
  lcd.clear();  // Print a message to the LCD.

void loop()
  lcd.setCursor(0, 0);
  lcd.print("Hello World on Attiny85");

Step 2: Using an I2C LCD on Attiny85: Still Problems

Hey, I did everything you said, but it doesn't work
I realize that is frustrating, but I can give you the assurance that the program and the libraries will work as they have for me.
When I first did this.... months ago, it worked immediately, without any problems. But when I tried this again for the sake of helping someone out (and this instructable) I got error message after error message on compilation.
However, that was on a computer that was pretty loaded with sketches and libraries and processor cores. Fortunately I also had a system that I just freshly put a new Linux on with just the basic 1.6.9 IDE installed, without further libraries added. I put the 85 core on it, put the Bro Hogan I2C code in the library and it immediately compiled without problems. So if you have compilation problems, it is probably because you do not have the proper libraries installed or the IDE gets confused about the libraries.
What compilation errors do you get?
-I just get a compilation error status 1
That means that for whatever reason your IDE couldnt link and compile all the required modules
-It tells me there is no 'int' for my 't_backlight'
It is pulling in the wrong library, most likely the Malpartida library.
-I get a bunch of USI errors
Your TinyWireM library might be corrupt or wrongly installed
-I have the right I2C library, but I suddenly see a LiquidCrystal_I2C.o file that wasnt there before + some other files.
Most likely you inadvertedly let your library manager do an update and your library got replaced

If you get errors 99% of these have to do with the wrong libraries. Make sure that in your preferences you set 'verbose reporting' and check what libraries are being linked. Are these the correct ones?
Also, whenever you change something in your libraries, close and restart your IDE, otherwise it will just keep using the old versions.

Everything compiled fine, but I just don't see anything on my screen.
Have you used this LCD before and did it work then?
There is a (blue) variable resistor on yr LCD module, try turn that, your contrast may be too low.
Did you make the right connections?
Did you connect the PSU?
Did you actually plug it in a wall socket or USB?

Adafruit has published the TinyLiquidCrystal Library especially for the Attiny85/Trinket.