Thursday, November 25, 2010

Arduino Output : LCD Modules, Part 1 - Hardware


20x4 LCD module

For myself, one of the first useful projects I ever did with an Arduino besides blinking the LED is to wire up a LCD module. A LCD module is a character based liquid crystal display (LCD) that is used commonly to display status in control panels or a simple way to interface with human in a parking payment machine. These display are considered ancient in today offering of colour based and large screen touch sensitive display found everywhere from ATM to control panels for home automation.

LCD Control Panel


As a curious person, I always wanted to know about how LCD works and of course, how to program and use them. Here are some information I found out.

Most of the common ones are based on Hitachi HD44780 (or compatible) with common sizes like  16 columns with 2 rows (16x2) or a much larger version of 20 columns with 4 rows (20x4). There are smaller or bigger combinations but these two are the most commonly found in stores or online.

The common colours are  black on green/yellow or white on blue with a backlight. For Arduino, there are a few ways to add a LCD to your circuit. First method is to buy a LCD shield, the second method is to buy a LCD module, solder the header pins and hook it up to a breadboard.

LCD Shield with buttons

My favorite is the third method,  as most of my projects are "Arduino on a breadboard"  with enough space for a LCD module and some breadboard area for other electronic components with easy access to the power rails.

Arduino breadboard with LCD


These LCD modules comes with 16 connectors/holes for you to either solder 16 header pins or  solder a flat cable directly to the module for permanent use. The pins are either one single row on the top or bottom of the module or 2 rows of 8 connectors located at the side of the module.

I will go over the LCD pinout and will be focus more on how to connect them up to an Arduino using the common 4bit mode. You will only use up 6 digital pins from the Arduino.

The LCD module should come with a datasheets that have the following pinout. I will translate the datasheets information into english as most datasheets are very hard to read or understand for beginners!!!

Pin 1 - Vss ( Ground )
Pin 2 - Vdd ( Supply voltage for logic )
Pin 3 - Vo ( Operating voltage for the display/contrast, voltage controlled by a potentiometer )
Pin 4 - RS ( Register Select, HIGH: data LOW:instructions )
Pin 5 - R/W ( HIGH:read LOW:write, we use only LOW to write data to display )
Pin 6 - E ( Enable signal )
Pin 7 -   DB0 ( Data bit 0 )
Pin 8 -   DB1 ( Data bit 1 )
Pin 9 -   DB2 ( Data bit 2 )
Pin 10 - DB3 ( Data bit 3 )
Pin 11 - DB4 ( Data bit 4 )
Pin 12 - DB5 ( Data bit 5 )
Pin 13 - DB6 ( Data bit 6 )
Pin 14 - DB7 ( Data bit 7 )
Pin 15 - A ( Backlight, Anode, LED+ )
Pin 16 - K ( Backlight, Cathode, LED- ) 

Male-male jumper cables


For a beginner, wiring up a LCD can be a daunting task without the proper components and cables. Firstly, you will need the LCD module, header pins, lots of male-male jumper cables and a 5K or 10K mini variable resistors called preset/rimpot like the picture below.

16x2 LCD, 16 pin male header & trimpot


Let start with the power first, wire up pin 1 to Gnd, pin 2 to +5V and pin 3 to the trimpot/preset middle connector (voltage divider), with +5V and Gnd to the other two pins on the pot. For the backlight, hook up +5V to pin 15 and Gnd to pin 16. Put a correct resistors between either pin 15 or 16 to limit the current. You will need to refer to your LCD datasheet for the backlight forward voltage (Vf) and forward current (If).  The formula for the resistor to use is : R = (Vcc - Vf ) / If.

The LCD should lit up, with a full single line bar. If the bar is not visible, adjust the trimpot/preset/ for the contrast level until it is visible. If you do not have a trimpot/preset, just wire pin 3 to the common Gnd but you cannot control the LCD contrast level.

Remember to hook up the +5V and Ground from the Arduino to the power rails on the breadboard. For my cables, red is +5V, while is ground.

Arduino 16x2 LCD power connections


Next hook up the bus wiring from the Arduino to the LCD. To save pins, we will hook up using the 4bit method so that other pins are available for other sensors/application. The pin setting I am using are as follows. You can choose other pin configuration but you will need to change your codes to match your wiring setup.

Arduino 16x2 LCD Data connections



Arduino digital pins (Atmega chip) - LCD pins :-

Arduino Digital pin 5 (11) - LCD pin 11 (DB4)
Arduino Digital pin 6 (12) - LCD pin 12 (DB5)
Arduino Digital pin 7 (13) - LCD pin 13 (DB6)
Arduino Digital pin 8 (14) - LCD pin 14(DB7)

The reason I hook up this way is because on the breadboard, Atmega 328 chip, the 4 closest pins to the LCD are pin 11 to 14 and somehow it also correspond to the LCD pin number. If you are using an Arduino board, the digital pins are 5 to 8.

Arduino 16x2 LCD all connections


For pins  RS (pin 4), R/W (pin 5)  and Enable (pin 6) , the hookup is as follows :-

Arduino Digital pin 11 (17) - LCD pin 6 (Enable)
Arduino Digital pin 12 (18) - LCD pin 4 (Register Select)
Ground   - LCD pin 5 (LOW, write only)

I use the Arduino digital pin 11and 12 is so that pin 9 and 10 are available for other sensors nearer to the empty breadboard area and I always reverse pin 13 for the LED. The LCD pin 5 is pull low to the ground as we always just write data to the LCD instead of reading data from the LCD module.

20x4 LCD with large fonts

The above is a photo of Arduino on breadboard with 20x4 LCD module displaying custom large fonts.

LCD on Protoshield
This is an idea of hooking up a 16x2 LCD Module on to the Protoshield mini breadboard.

Protoshield LCD connections
This is the picture of the LCD module connections without the LCD Module attached.



Part 2 will explain about the LCD library and setting up the display.

No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...