4th Inning

From LVL1
Jump to navigation Jump to search

Introduction

LCD display


Components Needed

  • Freeduino or Arduino or clone
  • USB cable for Freeduino
  • Freeduino development software - download here!
  • Solderless Breadboard
  • Hookup wire 22gauge solid
  • LCD display
  • Potentiometer

How to

There are 16 pins on the LCD numbered 1 to 16 going left to right in the breadboard picture shown below. The 5V pin on the arduino supplies the power for the backlight and the logic of the LCD display. In the breadboard picture all the wires that carry 5V are red and all the wires connected to ground are black.

Step 1

Connect 5V and ground from the adruino to the power bus on the breadboard.

The upper two rows in the breadboard form the power bus. All the holes on the first row are connected together under the board. Likewise, all the holes on the second row are connected together under the board. Connect the +5V pin of the arduino to the upper row and the ground pin of the arduino to the second row.

Step 2

Supply power to the LCD's backlight.

The backlight gets power on pins 15 and 16 of the LCD. Pin 15 goes to 5V and pin 16 goes to ground.

Step 3

Connect the contrast circuit.

The contrast of the LCD can be adjusted by varying the voltage on pin 3. We'll use a potentiometer to provide the voltage. The left and right pins of the potentiometer go to 5V and ground respectively. The middle pin of the potentiometer is connected to pin 3 of the LCD. When the knob of the potentiometer is moved the voltage on the middle pin, and this pin 3 of the LCD, varies between 0V and 5V.

Step 4

Provide power to the LCD's logic circuit.

The logic circuits of the LCD get their own power connections on pins 1 and 2. Pin 1 gets connected to ground and pin 2 gets connected to 5V.

Step 5

Test.

Plug the arduino into the USB and you should see the backlight on the LCD come on. Turn the potentiometer to left and right and verify that the contrast changes. If it doesn't work check your wiring. Make sure the everything is connected to the correct pins.

Step 6

Make the data connections.

There are 3 control pins on the LCD: RS, EN, RW and 4 data pins: D4, D5, D6, D7. Commands and characters are written to the LCD via the data pins. RS tell the LCD whether the data being sent is a character or a control command. EN tells the LCD that data is ready for reading. RW tells the LCD whether we want to write data to it or read data from it. Since we will always be writing data we don't have to hook the RW pin to the arduino. We simply hook it to ground.

Here are the pins and their functions:

LCD pins and their functions
LCD pin 4 5 6 11 12 13 14
Function RS RW EN D4 D5 D6 D7

RW is hooked to the ground. Each of the other 6 LCD pins get connected to a digital pin on the arduino according to this table

LCD pins to Arduino pins
LCD pin 4 5 6 11 12 13 14
Arduino pin 7 ground 8 9 10 11 12

Step 7

Load the sketch from the code section below and give it a try!

Schematic

Fritzing

Breadboard:

LCD bb.svg

Code

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void setup() {

  // set up the LCD's number of rows and columns: 
  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
}

Troubleshooting