How to Connect 16x2 Lcd With Raspberry Pi
by sarful in Circuits > Raspberry Pi
2403 Views, 2 Favorites, 0 Comments
How to Connect 16x2 Lcd With Raspberry Pi
In this tutorial, I go through the steps on how to How to connect 16x2 LCD with Raspberry pi4.
let's go
Equipment
The equipment that you will need for this Raspberry Pi 4LCD tutorial is listed below.- Raspberry Pi4
- Micro SD Card
- 16×2 LCD with header pins
- 10k Ohm Potentiometer
- Breadboard
- Breadboard Wire
The LCD
The LCDWhenever you come across a LCD that looks like it has 16 connectors it is most likely using a HD44780 controller. These devices provide the same pinouts making them relatively easy to work with. The LCD uses a parallel interface meaning that we will need many pins from our raspberry pi4 to control it. In this tutorial we will use 4 data pins (4-bit mode) and two control pins.
The data pins are straightforward. They are sending data to the display (toggled high/low). We will only be using write mode and not reading any data.
The register select pin has two uses. When pulled low it can send commands to the LCD (like position to move to, or clear the screen). This is referred to as writing to the instruction or command register. When toggled the other way (1) the register select pin goes into a data mode and will be used to send data to the screen.
The read/write pin will be pulled low (write only) as we only want to write to the LCD based on this setup.
The enable pin will be toggled to write data to the registers.
LCD PinoutGround VCC - 5v not 3.3v Contrast adjustment (VO) from potentiometer
Register Select (RS). RS=0: Command, RS=1: Data Read/Write (R/W). R/W=0: Write, R/W=1: Read (we won't use this pin)
Clock (Enable). Falling edge triggered Bit 0 (Not used in 4-bit operation) Bit 1 (Not used in 4-bit operation) Bit 2 (Not used in 4-bit operation) Bit 3 (Not used in 4-bit operation) Bit 4 Bit 5 Bit 6 Bit 7 Backlight LED Anode (+) Backlight LED Cathode (-)Before wiring, check that your LCD has an LED backlight, not an EL backlight. LED backlights use 10-40mA of power, EL backlights use 200+ma! EL backlights are often cheap to get but are not usable, make sure you don't use one or you will overload the Pi. Some cheap LCDs that have LED backlights do not include a resistor on the LCD module for the backlight, if you're not sure, connect a 1Kohm resistor between pin 15 and 5V instead of connecting directly. All Adafruit LCDs have LED backlights with built in resistors so you do not need an extra resistor!
Wiring Diagram How to connect 16x2 LCD with Raspberry pi4First, connect the Cobbler power pins to the breadboard power rail. +5.0V from the cobbler goes to the red striped rail (red wire) and GND from the cobbler goes to the blue striped rail (black wire)
In order to send data to the LCD, we are going to wire it up as follows Pin #1 of the LCD goes to ground Pin #2 of the LCD goes to +5V Pin #3 (Vo) connects to the middle of the potentiometer Pin #4 (RS) connects to the Cobbler #21 Pin #5 (RW) goes to ground Pin #6 (EN) connects to Cobbler #20 Skip LCD Pins #7, #8, #9 and #10 Pin #11 (D4) connects to cobbler #16 Pin #12 (D5) connects to Cobbler #12 Pin #13 (D6) connects to Cobber #1 Pin #14 (D7) connects to Cobber #25 Pin #15 (LED +) goes to +5V (red wire) Pin #16 (LED -) goes to ground (black wire)
Then connect up the potentiometer, the left pin connects to ground (black wire) and the right pin connects to +5V (red wire)
Required Library
In this example, I am going to install and use the library from Adafruit. It’s designed for Adafruit LCD boards but will also work with other brands as well. If your display board uses an HD44780 controller, then it should work with no issues at all.
First, clone the required git directory to the Raspberry Pi4 by running the following command.
git clone https://github.com/adafruit/Adafruit_Python_CharL...Next change into the directory we just cloned and run the setup file.
cd ./Adafruit_Python_CharLCD sudo python setup.py install
P Previous Project Raspberry pi4
PIR Motion Sensor using Raspberry Pi4 | Interfacing Tutorial
Raspberry pi4 Workshop PIR Sensor -Email Sending Movement Detector using IFTTT
Controlling a DC Motor with Raspberry Pi4
How to Use the Raspberry Pi4 Camera And PIR Sensor to Send Emails
Code#MechatronicsLab.Net import time import Adafruit_CharLCD as LCD # Raspberry Pi pin setup lcd_rs = 21 lcd_en = 20 lcd_d4 = 16 lcd_d5 = 12 lcd_d6 = 1 lcd_d7 = 25 lcd_backlight = 2 # Define LCD column and row size for 16x2 LCD. lcd_columns = 16 lcd_rows = 2 lcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows, lcd_backlight) lcd.message('Mechatronics\Lab!') # Wait 5 seconds time.sleep(5.0) lcd.clear() text = raw_input("Type Something to be displayed: ") lcd.message(text+"\nHow Are You") # Wait 5 seconds time.sleep(10.0) lcd.clear() lcd.message('Thanks \Mechatronics') time.sleep(5.0)
lcd.clear()