Introduction: 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.
I2C
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
Library
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'
done.
Then upload the program (see next step) to the IDE
Go to 'Sketch-Upload using programmer'
done
"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.backlight(); 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.
35 Comments
Tip 2 months ago on Step 1
"Everything compiled fine, but I just don't see anything on my screen."
Check also the I2C address from the code. It's easy to ignore that. I had same problems then I went through the code and discovered that "LiquidCrystal_I2C lcd(0x20,16,2)" portion had to be modified to contain my address "0x27" instead!
Question 3 months ago on Introduction
Yeah, exactly, I have an issue of the I2C libraries.
#include <TinyWireM.h> => OK
#include <LiquidCrystal_I2C.h> => compiling error
Downloaded and installed Bro Hogan => still error
Add the Bro Hogan libraries to the sketch folder, and changed to
#include "LiquidCrystal_I2C.h" => still error
Any help will be appreciated!
8 months ago
LiquidCrystal_I2C lcd(0x20,16,2); helyete LiquidCrystal_I2C lcd(0x27,16,2);
6 years ago
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.
Reply 6 years ago
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 :-)
Reply 6 years ago
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.
Reply 4 years ago
Could you please send the link for Attiny library you used finally to work, I'm facing the same problem. All connections are verified and library is only Hogan's one, but first line shows blocks only.
Reply 4 years ago
Used TinyWireM from BroHogan, dated 1/21/2011; and LiquidCrystal_ATtiny v2.0, originally from BroHogan but modified to support ATtiny85. I don't know where I got them from, but type them in Google, and the first you encounter (from PlatisD) is the one. The second one same: TinyWireM BroHogan
Reply 4 years ago
Hi, I try not to forget: currently not at my desk, + it was more than a year ago so I need to delve in my archives but for sure I have the info on my pc. If no response in a few weeks plse remind me. Grts, Erik
Reply 6 years ago
OK would be interested to get your feedback. tnx
7 years ago
I get no errors but only black squares. Followed the instructions carefully and tested the LCD with Arduino Nano first.
Reply 6 years ago
try this address:0x3F for PCF8574A chip
Reply 6 years ago
Exactly the same happens to me, try with 0x3F and again the same problem, any ideas ?
Reply 6 years ago
Here is what I did in the end: https://arduino.stackexchange.com/questions/29546/attiny85-i2c-lcd
Reply 6 years ago
Thanks a lot, finally it is working perfect ! Easy to follow and make it.
Reply 6 years ago
I am happy you got it working :-)
Reply 6 years ago
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
Reply 6 years ago
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.
Reply 6 years ago
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.
Reply 6 years ago
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