Interface a 16x2 Character LCD

Last updated May 2019

Introduction

Welcome to ProteShea – one of our favorite peripherals to use in an embedded system is a LCD (Liquid Crystal Display) to get quick visual feedback on how a system is doing! It can be used to display data acquired from sensors, create an interactive menu, or as a debugging tool. In this tutorial, we’ll be showing you how to interface a 16×2 character LCD to the Arduino Uno (rev 3). 

Disclaimer

ProteShea, LLC is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com

Some links may be affiliate links, in which ProteShea, LLC earns a commission if you use that affiliate link. Please note that this is at no additional cost to you and helps us in creating more content.

Liquid Crystal Display (LCD)

The LCD consists of 16 pins that are used for power, control, and data. It uses an industry standard Hitachi controller so the basic operation is similar across different vendors that sell them. They have both a 4-bit parallel and an 8-bit parallel interface. We’ll be using it in 4-bit mode instead of 8-bit. That means we have to send the higher nibble (1 nibble = 4 bits) first, then the lower nibble to send the byte of data required for each command or character. The most common LCD is a 16×2 or a 20×4 which means that it can display 16 characters on each of its 2 lines and 20 characters on each of its 4 lines, respectively. A pinout of the LCD is below.

NOTE: The LCD does not come with a 16-pin male header so you’ll have to solder one on.

LCD Pinout

Pin 1 and pin 2 are used to power the LCD and should be connected to GND and +5Vdc, respectively. Pin 3 is used to adjust the contrast – this will be connected to a 10KΩ potentiometer (pot) so the output voltage to pin 3 can be varied. The Register Select (RS) on pin 4 is used to either send commands when it is low, or data when it is high. Pin 5 is for Read/Write (R/W) and is used to read or write data from the LCD. The LCD has the capability to execute a program and display information which justifies the need for this pin. However, we will only be writing to the LCD, so we can ground this pin which will place it permanently in write mode. 

Furthermore, the next eight pins (7-14) are used to send the data. Since we’re using the LCD in 4-bit mode, D0-D3 (pins 7-10) are not used. Pins 15 and 16 are the anode and cathode of the LED backlight, respectively. We will need to use an external resistor in series with this backlight to limit the current. Otherwise, the LED could burn out.

The LCD has a timing diagram that must be followed to be able to send commands and character data. There are also set-up and hold times which also must be taken into account. This allows the signal levels to settle and ensure that pins are sampled at the right time. The diagram below shows the timing diagram for sending a command to the LCD in 4-bit mode. If we want to send the command to clear the display, we have to send 0000 (upper nibble) on the data bus and then send 0001 (lower nibble) on the data bus.

Send Command to LCD in 4-bit Mode

The diagram below shows the timing diagram for sending data to the LCD in 4-bit mode. For example, let’s say we want to send the character 1 to the LCD. The 8-bit ASCII equivalent is 0x30 or 0011 0000, so we would send 0011 on the data bus and then 0000.

Send Data to LCD in 4-bit Mode

You do not have to write your own driver for the LCD since there is a library that we can use called LiquidCrystal.h. The library is simple to use and allows us to input the specs of the LCD such as the number of columns and rows, and whether to use a 4-bit or 8-bit interface. We can also send data and up to 19 different commands.

Wiring the LCD

We are using the Modulus Canister to mount the LCD. Please watch the video below if you are using Modulus.

Once you are done with mounting the LCD to Modulus, we can then attach the male end of each jumper wire to the Uno’s female header pins. You should have 6 jumpers: one on pins 4, 6, and 11-14. Pins 4, 6, and 11-14 of the LCD will connect to Uno pins 2,3, and 4-7, respectively. 

If you are using a breadboard, a high-level schematic is shown below. We will be supplying +5V and GND to the breadboard via the FuelCan, which is described further in the next section.

Circuit Schematic with LCD Mounted to Breadboard

FuelCan Wiring

First, place the breadboard in the bottom storage compartment to limit the length of the jumper wires, mount the Arduino Uno to the FuelCan’s prototyping area, and plug in Modulus to the FuelCan’s 4×26 pin connector. You’ll need to supply +5V and GND to the power and ground rails on the breadboard by using the provided banana jack to test-lead clip cables. You will need two male header pins to mount the test-lead clips on the breadboard side. Plug the Type A side of the USB cable into USB1 receptacle and the Type B side into the Uno’s receptacle. Power up the FuelCan with the AC-DC power adapter.

For additional information about the Fuelcan-910, click here or download the user guide.

Software

Once the wiring is complete and the FuelCan is powered up, we can now load the sketch onto the Uno. The sketch is below. The LiquidCrystal library contains nineteen different functions that you can use. We don’t show you all of them, but we show the most commonly used ones such as lcd.print, lcd.clear, lcd.home, lcd.createChar, lcd.write, lcd.setCursor, lcd.blink, lcd.noBlink, lcd.cursor, lcd.noCursor, lcd.scrollDisplayLeft, and lcd.scrollDisplayRight. 

About Author

Eric Shea is the founder of ProteShea and is an electrical engineer. He wishes to have a major impact on bridging the gap between engineering theory and real-world applications. He has worked at Kratos Defense, SpaceX, Air Force Research Laboratory, and Polaris Industries. He received a M.S. in electrical engineering from the University of Pittsburgh and a B.S. in electrical engineering from the University of Florida.

Categories
Share on facebook
Share on twitter
Share on linkedin
Share on pinterest
Share on google
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
ProteShea

Learn. Apply. Create.

290 NW Peacock Blvd #880143
Port Saint Lucie, FL 34988