3.1 Introduction
An LCD, or liquid crystal display, is a simple screen that can display commands, bits of
information, or readings from your sensor - all depending on how you program your board.
Moreover, a Liquid Crystal Display (LCD) is a sophisticated module that can be used to display
Letters and numbers can easily be created using seven segment LED displays using a
simple wiring scheme obtained from the optoelectronic component's datasheet. Although seven
segment LED displays are energy efficient and easy to use, a major problem for the optoelectronic
component in sunlight is washout. The liquid crystal display (LCD) was developed to remove heat
and washout.
LCD 16x2 is a character type liquid crystal display, which can display 32 (16*2) characters
at the same time. It has 16 pins, of which at least 7 would be used each time.
In this paper, you’ll learn the basics of incorporating an LCD into your project. The
Raspberry Pi will allow simple text messages to be displayed on an LCD using the Python
programming language.
3.2 Objective
The aim of this paper is to make necessary codes to perform the required tasks using
Raspberry Pi.
on it.
2. Write a program in Python to send the appropriate commands to the LCD through GPIO
3. Make a program where the Raspberry Pi is connected to a LCD character display and
4. Make a program where the Raspberry Pi is connected to a LCD character display and
3.3 MATERIALS
Raspberry Pi LDR
Header Laptop/PC
3.4 Procedures
The LCD has a 16-pin male header attached to it along the top edge. Pin 1 is the pin
and the other side to GND (pin number 6). The potentiometer that’s in the circuit is
Note : If you do not have one, then you can try swapping this out for a resistor. If you do use a
normal resistor, try using anything between 5k and 10k ohms. You may need to try out a few different
(A ) goes to 5V.
Note: You are going to power the 16x2 LCD through the +5V rail. You can send control
signal of +3.3v to LCD but for working of LCD you need to power it by +5V. The LCD will not work
with +3.3V.
5. You may use your own module (Refer to Experiment 2) for the LED and switch. For the
LED, connect the anode to GPIO 20 (Pin 38) and cathode to the GND. Connect one side
of the switch to GPIO 21 (Pin 40) and the other side to 3.3V (Pin1).
6. Once everything is connected as per the schematic diagram (Figure 2), turn on the
7. Open the LXTerminal because you need to install/add the library from Adafruit.
1. Download the software files in a specific order. To obtain the files in the correct
order, open the LXTerminal and type the Linux command ~sudo apt-get install
git.
2. Then, download the files from Github using the following Linux command:
$cd Adafruit-Raspberry-Pi-Python-code
4. Inside the directory, install the Adafruit_CharLCD using the Linux command:
10. After writing the program and executing it, the Raspberry Pi sends characters to LCD one
11. “BUTTON PRESSED” should pop up on your LCD as you press the button. Furthermore,
you may adjust the contrast using the potentiometer if you can’t make out the words
clearly.
12. Make sure the code is correct and double-check the connections.
2. Plug your 10K potentiometer. Connect one side of the potentiometer to 5V (pin number
2), and the other side to GND (pin number 6). The potentiometer that’s in the circuit is
Note : If you do not have one, then you can try swapping this out for a resistor. If you do use a
resistor, try using anything between 5k and 10k ohms. You may need to try out a few different
(A ) goes to 5V.
Note: You are going to power the 16x2 LCD through the +5V rail. You can send control
signal of +3.3v to LCD but for working of LCD you need to power it by +5V. The LCD will not work
with +3.3V.
4. You may use the Arduino as ADC Converter. Connect GND (Pin 39) of Raspberry Pi
5. Since LDR changes only the resistance, so you must connect it to 5V of the Arduino.
Then, connect the LDR to analog. Moreover, connect the output of the LDR to digital
which is the Arduino. Lastly, connect the Arduino to Raspberry Pi. Just simply refer to
6. Once everything is connected as per the circuit diagram (Figure 3), turn on the
8. Since you’ve already added the library from Adafruit, proceed to the next step
9. Use the BCM instead of using the BOARD numbering.
10. After writing the program and executing it, the Raspberry Pi sends characters to
LCD one by one and the LCD displays the characters on the screen.
11. “LIGHT DETECTED” should pop up on the LCD. Furthermore, you may adjust the
contrast using the potentiometer if you can’t make out the words clearly.
12. Make sure the code is correct and double-check the connections.
try:
while True: #keeps the program running unless CTRL+C is press
if GPIO.input(21) == True:
GPIO.output(20, GPIO.HIGH) #set LED to turn on
lcd.message('Button Pressed!\nLED on')
time.sleep(1) #time delay of 1 s
lcd.clear()#clear the message
GPIO.output(20, GPIO.LOW) #set LED to turn off
except KeyboardInterrupt: #set GPIO alarm warning
try:
while True: #keeps the program running unless CTRL+C is press
if GPIO.input(21) == True:
GPIO.output(20, GPIO.HIGH) #set LED to turn on
lcd.message('Sensor On, Detecting…!') #display message
time.sleep(1) #time delay of 1 s
lcd.clear()#clear the message
GPIO.output(20, GPIO.LOW) #set LED to turn off
except KeyboardInterrupt: #set GPIO alarm warning
const int analogInPin = A0; # Analog input pin that the potentiometer is attached to
const int OutPin = 8; # Analog output pin that the LED is attached to
void setup() {
# initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
# read the analog in value:
sensorValue = analogRead(analogInPin);
# map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 1000);
if (sensorValue > SensorThres)
{
digitalWrite(OutPin, HIGH);
}
else
{
digitalWrite(OutPin, LOW);
}
Communicating with the Raspberry Pi LCD 16×2 display is easy because of the library
provided by Adafruit. It is incredibly easy to write Python scripts to setup and alter the display.
Based on the experiment, it is easy to interface the LCD to Raspberry Pi although many
GPIO pin will be used in Raspberry Pi .When the LCD is added to any project it gives a good way
3.8 Exercise
1. Create a program using a temperature sensor. Display the temperature on the LCD.