Wednesday 9 March 2016

Arduino 16x2 LCD/Keypad Shield

Many embedded projects benefit from a user interface, and shields with a 16x2 LCD and a 5 button keypad are popular with Arduino users. Most are almost exactly like this one. As with many Arduino peripherals, they are very inexpensive - less than 6 GBP at the time of writing for the one I chose with first class postage within the UK, less still if you can wait for one from China.

Arduino LCD/keypad Shield
Arduino LCD/keypad Shield
Boards such as this are often referred to as "1602A" type, with various manufacturers adding various prefixes and suffixes. They all seem to be based on the Hitachi HD44780 LCD controller (or a compatible clone). And most seem to use a 4-bit parallel interface to this controller (which can also support 8-bit operation). The keypad buttons are wired with a resistor ladder between the power rails so that a unique voltage corresponding to each button is delivered into one of the MCU's ADC inputs.

There are various examples and drivers available for 1602A display/keypad boards running on the Arduino, but I wanted to understand it from first principles, so I coded my own simple driver in C after studying the controller datasheet and the board schematic. This allows you to clear and write strings to the display, and read debounced key presses. I wrote a quick demo program in C using Atmel Studio 7 for this which you can download here.

Note that the documentation is not reliable when it comes to the character set burned into the controller's ROM. The upper 128 character codes in my module did not match the data sheet, so - for example - I had to create a user defined character to get a "degree" symbol for the temperature reading shown in the above picture.

Here's a video showing the demo program running:


1 comment:

  1. The codes in the ROM are determined by the original user order,all contain basic letters and numerals however some have two or more roms with extra characters per original user order. What we are getting is the left overs ,out of date stock,refills for companies that are out of business thats why they are so cheap.

    ReplyDelete