Introduction: Using an I2C LCD on Attiny85

Picture of  Using an I2C LCD on Attiny85

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

Picture of 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.


Thijxx (author)2016-09-24

I get no errors but only black squares. Followed the instructions carefully and tested the LCD with Arduino Nano first.

Mir FarhadJ (author)Thijxx2017-03-18

try this address:0x3F for PCF8574A chip

iohy (author)Mir FarhadJ2017-06-29

Exactly the same happens to me, try with 0x3F and again the same problem, any ideas ?

Thijxx (author)iohy2017-06-29

Here is what I did in the end:

iohy (author)Thijxx2017-06-30

Thanks a lot, finally it is working perfect ! Easy to follow and make it.

diy_bloke (author)iohy2017-07-01

I am happy you got it working :-)

iohy (author)diy_bloke2017-07-05

Hi, come back again, it is working just after loading the program, but when i disconnect the circuit from the power and reconnect the display does not work properly it is displaying only in the first row crazy data as appears in the pictures. Not doing anything else apart of unplug the usb wire from the computer and after 2 secs. plug again the same wire to the same usb port. Any idea ?

SDA -> Pin5 - Pull-up with 4,7 resistor

SCL -> Pin7 - Pull-up with 4,7 resistor

Thijxx (author)iohy2017-07-05

I had the same issue for a while. It is probably caused by a poor connection or the code starting the display. Try other jumper cables and try some delay before you print the text. And please try without Arduino connected, just the Tiny powered.

iohy (author)Thijxx2017-07-06

Was checking the paperduino (based in Attiny85) design and notice that there are pull-ups around all the pins and also some diode connections (don't understand so much what is the diode function here by my ignorance in electronics) to the pull-up. In any case plug the Attiny to my paperduino and the lcd works perfect not issues.

diy_bloke (author)iohy2017-07-09

I agree withThijx, could be loose connection

I think i did not use any pull-ups as in my case the i2c module had pull ups.

Anyway, I am happy you got it working

diy_bloke (author)Thijxx2016-09-24

I replied in the original Q&A

james.bowen2 made it! (author)2017-06-21

Hey, I got this working. No problems, but i am confused if I need a 'pull resistors' (47.K) for SDA and SLC/SCK lines?

From what I've been reading, I do require resistors, but it's working??

diy_bloke (author)james.bowen22017-06-23

if working noneed to change. As far as iknow the i2c lcd module has pull ups

47k is by theway an unusual value for i2c. I presume you mean 4k7

ErikA45 (author)2017-01-17

Followed instructions, but LCD backlight flashes every 2 seconds for about 1/50 of a second, and first row all blocks. When I use LiquidCrystal_attiny (dated 21/03/2015) it works.

diy_bloke (author)ErikA452017-01-18

Although I and others have repeated reproducable succes by using the program here, apparently a number of people didnt get it to work.
Might be a number of reasons for that: wrong address, wrong pins, bad luck, difference in libraries or whatever. Nevertheless I am happy you did get it to work with the attiny lib. Thanks for that feedback. Would you mind leaving a link? Thanks :-)

ErikA45 (author)diy_bloke2017-01-18

You probably have a point with issue in difference in libraries. Address, pins etc are ok but Arduino is not very selective in library usage, In my case I only have one single library for LiquidCrystal as downloaded from you but I would not be surprised there would be an issue. I have several other computers on which to experiment, amongst them a almost virgin one: I will try there too and post the result.

diy_bloke (author)ErikA452017-01-19

OK would be interested to get your feedback. tnx

TheCritter (author)2017-01-12

Thijxx: you need to use address 0x27, not 0x20

diy_bloke (author)2016-08-06

If you keep having problems with compiling download my files: Pu them all in one sketch directory (except for the picture file).
Works with IDE 1.6.9

tuttlesmow (author)2016-07-30

I've been trying for a week now, I continue to get this error:

error: 'TWEN' undeclared (first use in this function)


any help would be appreciated- Michael

diy_bloke (author)tuttlesmow2016-07-30

Michael, it is the first time i come upon an undeclared TWEN. TWEN is the TWI enable bit and that doesnt exist in the attiny85, so I get the impression that somehow your compiler doesnt get the proper files. Are you using my exact program? Do you have the proper libraries/cores? I saw yr twi directory is in another structure than mine

Which IDE are u using?

tuttlesmow (author)diy_bloke2016-07-30

Thank you for your quick response. I have been wrestling with this on multiple computers. I think having lcd capabilities would greatly aid in debugging my marginal coding skills.

On the computer that currently sits in front of me, I am running ide V1.6.9 . It is only loaded with the "built-in" library's, "TinyWireM by adafruit version 1.0.0", and "LiquidCrystal_I2c by Frank de Brabander version 1.1.2".

both custom library's were located in the library manager

I have copied and pasted the exact sketch.

The core I am using is "attiny by David A. Mellis version 1.0.2 found in the boards manager.

if my core/librarys are insufficient, could you please provide links to the appropriate files?

diy_bloke (author)tuttlesmow2016-08-05

see my other replies as well (with link to the proper library) can you do a verbose report so you can see which library is being linked

diy_bloke (author)tuttlesmow2016-08-05

I apologise I didnt see yr follow up comment earlier. I do not know the version of Frank de Brabander. I am using Bro Hogan's library

I am not sure anymore which core I used but you may want to try the Arduino Tiny core

ArcAiN6 (author)2016-07-01

Try as i might, i can't get this work for my LCD.
I've tried pretty much every library on the planet it seems, and still can't get it to function.

The LCD is a 20x4 with a PCF8574T i2c backpack.
The LCD does work on the mega with address 0x27

However, when i try to load it onto the attiny85, the screen powers on, and i get 1 line solid white, second line empty, 3rd line solid white, fourth line empty.

I've read somewhere that the Chinese clones of this backpack has a pin reversed, and a special library is needed, but after testing that library on the mega, i found it wasn't the cause of my issue.

In all honesty, i would sell these attiny85's on eBay, and buy some of the cheap nano3 clones floating around, but it bugs me to no end that i can't seem to get this working.

ArcAiN6 (author)ArcAiN62016-07-01

Yea, so.. i guess it is my library.. Seems i'm going to have to figure out how to alter my library to use TinyWireM, as every other LCD library i've tried doesn't work with this LCD.

diy_bloke (author)ArcAiN62016-08-05

Oddly I replied to yr follow up, but now I cant see it at all anymore. I used this library

I have used a 4 line LCD as well as a two line and both did OK, both 'chinese webshop'

diy_bloke (author)ArcAiN62016-07-02

ArcAin6, I understand your frustrationand, in fact i have been in contact with someone else who just couldnt get it to work while for me it worked the first time and it repeatedly works.

Adafruit has a TinyLiquidCrystal library that works with their i2c backpack. That has a port expander, but it is still i2c. You may want to go over to their github and check.

I understand yr inclination to use cheap nanos over the attiny85. I must say i really like the attiny, but cost wise it seems foolish. they are around a dollar in the dil version while a complete pro mini can be had for 1.35 USD.

tuttlesmow (author)2016-08-05

If anyone is successful in replicating diy_bloke's success, please post links to librarys with versions and names. I've tried in ways i've never tried before .Even downloading extractors to gain access to .rar files (whatever they are). BroHogan has his name on half a dozen library's. (or more). I've gotten the closest with Francisco Malpartida' library. so far I have only being able to print to the lcd using wire.h on an atmel328. links to working tutorials outside instructables would also be appreciated.

diy_bloke (author)tuttlesmow2016-08-05

I understand it is frustrating, yet others have been succesfull. Look here for instance

tuttlesmow (author)2016-07-30

the mentioned error seems to be pointing to a file in the wire library:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src\utility\twi.

why is that?

About This Instructable




Bio: 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 ... More »
More by diy_bloke:Working With the Funduino W5100 Ethernet Module.Uploading Data to ThingSpeak With MQTTAdding an MCP23017 I/O Extender to Arduino or ESP8266
Add instructable to: