Menu

Attiny85 LCD with I2C

October 31, 2017 - Arduino, Attiny
Attiny85 LCD with I2C

How to Add an LCD with I2C to Your Attiny85

I will start by saying that this project was result of many days of trial and error. In general it is easy to connect an I2C adapter to an LCD and drive it with a micro-controller. But this was not the case for me! My I2C adapter was refusing to cooperate with any common library. The screen was either flickering or it was displaying white squares.

I will not pretend that I know what was wrong, but based on what I read all these days I conclude to this:

Many Chinese I2C adapters have PCF8574T chip installed with the pins swapped. So my guess is that this lib is setting up the pins correctly. 

LCD not working

Other people told me that the pins are defined the same way as are in other libraries, so if anyone know exactly what is going on feel free to post it in comments. One of the main libraries that are out there is build by BroHogan and I will add a link here just as reference. This library didn’t work for me.

BroHogan’s Library

More detail here:

Arduino Playground USIi2c – by bHogan

At some point it came to me that I had a library that was working for this specific LCD with Arduino as my controller. So I start searching my computer for this code, and  managed to make my LCD work with this one. Keep reading for the solution. 

Required Components

ItemsDescriptionQTYPriceLink
Attiny85x11$eBay
16x2 LCDx11.5$eBay
I2C Adapter x11$eBay
4.7K Resistorsx20.1$eBay

 

Installation

 

1.First connect the hardware together. We are going to use TinyWireM library, so we have to use pin 5 for SDA and pin 7 for SCL of Attiny.

Attiny85 pinout     

Don’t forget to add two 4.7K resistors between SDA,SCL and the 5v supply (required if I2C does not already have them)

SDA SCL Pull up capacitors

Note: to get the LCD’s address you must use an I2C scanner. I used this one: I2CScanner and find out that my address is 0x27.

2. Download the following libraries:

VirtualWireM

You can download this lib from Arduino IDE by selecting: Sketch -> Include Library -> Manage Libraries… Then search for the lib and install it

New LiquidCrystal by Francisco Malpartida

Download the repository from here: NewLiquidCrystal, decompress the file and place the folder under D:\userdata\<user>\My Documents\Arduino\libraries

Alternative link: fmalpartida-new-liquidcrystal

Note: Please make sure that there are no other LiquidCrystal libraries in this folder or under the path C:\Program Files (x86)\Arduino\libraries. Usually in program files there is a LiquidCrystal lib. Just delete it!

More info about this lib can be found at repository’s home page: Bitbucket

3. Install Attiny Core

Add the following link in Arduino IDE at File-> Preferences-> Additional Boards Manager URLs

https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json 

Then go to Tools-> Board-> Board Manager, search for “attiny” and install the manager (I used version 1.0.2)

Restart Arduino IDE

More details are available here: highlowtech

4. We will use an Arduino as programmer for Attiny so we have to upload the following sketch to it

To program your Attiny connect it to Arduino based on the following schematic

 

 

5. Setup Attiny manager in Arduino IDE

I used an arduino nano as programmer and selected “Arduino as ISP” for that reason. Also make sure that all the board setting are the same as in the image bellow. Board: Attiny85, Processor: Attiny85, Clock: Internal 8MHz (it is very important to select internal clock), Port: whatever port arduino is connected to

Setup Attiny85 core

6. Upload the LCD code to Attiny.

Make sure that you set the correct I2C address.

 

7. Done! Your Attiny85 LCD is up and running

Attiny85 LCD with I2C working

 

 

Let me know if you experience any problems with the installation and I will try to guide you through it. 

Sharing is caring!