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.
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 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.
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.
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:
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.
To accomplish this assignment I used the PBC board designed for the ELECTRONICS DESIGN assignment more details.
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'.
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.