OUTPUT

Free HTML5 Bootstrap Template by FreeHTML5.co

My today's assignment is to add an output device to a microcontroller board you've designed, and program it to do something.

I decided to work on the LCD because in my project I will use it to display the data from the infant incubator in real time. I used I2C LCD with 20 column and 4 rows. To make this LCD working with Attiny45 was not an easy task. I spent two days, struggling with this LCD, I tried different libraries unfortunately many of them didn't work for me.

20×4 LCD Display I2C Black on Green

This 20×4 lcd display with I2C adapter board is based on the common HD44780 parallel interface chipset. The LCD display includes an I2C adapter board based on PCF8574 I2C chip, it converts I2C serial data to parallell data for the LCD display, thus, significantly reducing the number of I/O pins used on the micro-controller to send data to the LCD.

A picture of a house! A picture of a house!

Serial LCD I2C Module–PCF8574

A regular LCD requires a lot of wires (parallel interface) to be connected with a Microcontroller.The Serial LCD backpack built on PCF8574 IC uses the I2C bus to convert the parallel interface to a serial one.This needs only 2 wires SDA & SCL , apart from the power connections. The blue preset is to adjust the contrast of the LCD. The black jumper on the left is to enable the Backlight of LCD. The I2C device has a HEX address by which a microcontroller can communicate with it.This is set by the 3 bits A0,A1 ,A2 .If no jumper is present , it is HIGH & a jumper means LOW. By default all the 3 jumpers are open . ie., A0,A1 A2 all are 1s.

A picture of a house!

How I2C Communication Works

Each I2C bus consists of two signals: SCL and SDA. SCL is the clock signal, and SDA is the data signal. The clock signal is always generated by the current bus master; some slave devices may force the clock low at times to delay the master sending more data (or to require more time to prepare data before the master attempts to clock it out). This is called “clock stretching” and is described on the protocol page.

A picture of a house!

With I2C, data is transferred in messages. Messages are broken up into frames of data. Each message has an address frame that contains the binary address of the slave, and one or more data frames that contain the data being transmitted. The message also includes start and stop conditions, read/write bits, and ACK/NACK bits between each data frame:

A picture of a house!

Start Condition: SThe SDA line switches from a high voltage level to a low voltage level before the SCL line switches from high to low.

Stop Condition: The SDA line switches from a low voltage level to a high voltage level after the SCL line switches from low to high.

Address Frame: A 7 or 10 bit sequence unique to each slave that identifies the slave when the master wants to talk to it.

How to Connect I2C Lcd Display to Attiny 45

A picture of a house!

A picture of a house!

Wiring Instructions

A picture of a house!

To accomplish this assignment I used the PBC board designed for the ELECTRONICS DESIGN assignment more details.

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. I spent time looking for a working library and finaly I found The 'Bro Hogan' library . 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'.

Programming the Attiny 45

This time no need of burning the bootloader to set the fuses of the attiny 45 from factory mode, to the mode you want to use it in. This is because I am using the board that is already used in my previous assignments.

Results

To program the board I used arduino UNO working as ISP programmer but initially the obtained results was not good because the LCD displayed only the first letter means letter on row 0 and column 0 (0,0) and frst letter on the second line (1,0), it seems that others letters were hidden. Therefore, I spent more than 3 hours on this issue but I edited the program and things went well as I expected.

Source codes

A picture of a house! A picture of a house!

Source codes

A picture of a house! A picture of a house! A picture of a house! A picture of a house!

Used files

download icon