Raspberry Pi 1605 LCD Display
Electronics
Embedded
Provide Power to the LCD module:
| LCD | Power | Description |
|---|---|---|
| VDD | 5V | board power |
| VSS | 0V | board ground |
| RW | 0V | read/write select, 0V for write only |
| A | 5V | backlight power |
| K | 0V | backlight ground |
Connect the potentiometer (trimmer) to the LCD module:
| LCD | Input | Description |
|---|---|---|
| V0 | POT (middle pin) | control the contrast of the LCD |
Connect the LCD to the Pi in 4 bit mode:
| LCD | BMC | BOARD | Description |
|---|---|---|---|
| RS | GPIO07 | 26 | register selectHIGH store in data registerLOW store in instruction register |
| E | GPIO08 | 24 | write enable, write data to register when ready |
| D4 | GPIO25 | 22 | 4 data lines… |
| D5 | GPIO24 | 18 | …send 4 bits at a time… |
| D6 | GPIO23 | 16 | …4 high bits …followed by 4 low bits… |
| D7 | GPIO18 | 12 | …complete the 8 bit character or instruction |
CircuitPython
Install the required packages from AdaFruit [01]…
# install required Python packages
apt-get install python3 python3-pip
pip3 install adafruit-blinka adafruit-circuitpython-charlcdSimple hello world example…
#!/usr/bin/env python3
import board
import digitalio
from adafruit_character_lcd.character_lcd import Character_LCD_Mono
lcd_cols = 16
lcd_rows = 2
lcd_rs = digitalio.DigitalInOut(board.D7)
lcd_en = digitalio.DigitalInOut(board.D8)
lcd_d4 = digitalio.DigitalInOut(board.D25)
lcd_d5 = digitalio.DigitalInOut(board.D24)
lcd_d6 = digitalio.DigitalInOut(board.D23)
lcd_d7 = digitalio.DigitalInOut(board.D18)
lcd = Character_LCD_Mono(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_cols, lcd_rows)
lcd.clear()
lcd.message = 'Hello World...'C
Install WiringPi packages [02]…
# install the required C library
apt install wiringpi
# list all GPIO pin values
gpio readall
# compile the example
gcc -lwiringPi -lwiringPiDev -o hello_world hello_world.cSimple hello world example…
#include <stdio.h>
#include <wiringPi.h>
#include <lcd.h>
#define LCD_COLS 16
#define LCD_ROWS 2
#define LCD_MODE 4 // use 4 data lines
#define LCD_RS 26
#define LCD_EN 24
#define LCD_D4 22
#define LCD_D5 18
#define LCD_D6 16
#define LCD_D7 12
int main() {
// Initialise WiringPi
wiringPiSetup();
// Initialise the LCD
int lcd;
if (lcd = lcdInit (LCD_ROWS,
LCD_COLS,
LCD_MODE,
LCD_RS,
LCD_EN,
LCD_D4,
LCD_D5,
LCD_D6,
LCD_D7,
0, 0, 0, 0)) {
printf("LCD initialise failed\n");
return -1;
}
lcdClear(lcd);
//Position cursor on the first line in the first column
lcdPosition(lcd,0,0);
//Print the text on the LCD at the current cursor postion
lcdPuts(lcd, "Hello, world in C...");
}Reference
[01] Drive a 16x2 LCD with the Raspberry Pi
[02] How to Setup an LCD on the Raspberry Pi and Program it With C
[03] Drive an LCD 16x2 display with Raspberry Pi
[04] Interfacing 16x2 LCD with Raspberry Pi using GPIO & Python