Primal Display: Build a Raspberry Pi LCD Temperature Monitor
This guide shows how to connect a 16x2 HD44780‑compatible LCD to a Raspberry Pi 3 and display live temperature and humidity readings from a DHT11 sensor. The instructions cover hardware selection, wiring (both 4‑bit and 8‑bit modes), required libraries, and a complete Python script.
Story
Introduction
An LCD display is a versatile add‑on for any Raspberry Pi project. By wiring an HD44780‑compatible screen directly to the GPIO pins, you can present sensor data or custom messages without needing I2C or SPI adapters.
Hardware
- HD44780‑compatible 16x2 LCD (cost <$10)
- Raspberry Pi 3 (or newer)
- DHT11 temperature/humidity sensor
- Micro‑SD card with Raspbian OS
- 1–2 10 kΩ potentiometers (contrast/brightness)
- Breadboard, jumper wires, and a 5 V power supply
We’ll use six GPIO pins for the LCD; this direct method keeps the Pi’s serial port free and eliminates the need for I2C drivers.
Wiring Things Up
Two wiring options are available:
- 4‑bit mode – uses 4 data lines, one potentiometer for contrast.
- 8‑bit mode – uses 8 data lines, two potentiometers (contrast and brightness).
In 4‑bit mode the 8‑bit command byte is split into two 4‑bit halves, so the data bus is half the width. In practice, the LCD’s internal processing time masks any speed advantage of 8‑bit mode, so choose based on available pins.
LCD Pin Connections (4‑bit)
- Pin 1 (GND) – Ground
- Pin 2 (+5 V) – Power
- Pin 3 (Vo) – Potentiometer wiper (contrast)
- Pin 4 (RS) – GPIO 37
- Pin 5 (RW) – Ground (write‑only)
- Pin 6 (EN) – GPIO 35
- Pin 7–10 – unused
- Pin 11 (D4) – GPIO 33
- Pin 12 (D5) – GPIO 31
- Pin 13 (D6) – GPIO 29
- Pin 14 (D7) – GPIO 23
- Pin 15 (LED+) – +5 V
- Pin 16 (LED−) – Ground
LCD Pin Connections (8‑bit)
- Pin 1 – Ground
- Pin 2 – +5 V
- Pin 3 – Potentiometer wiper (contrast)
- Pin 4 – GPIO 37 (RS)
- Pin 5 – Ground (RW)
- Pin 6 – GPIO 35 (EN)
- Pin 7 (D0) – GPIO 40
- Pin 8 (D1) – GPIO 38
- Pin 9 (D2) – GPIO 36
- Pin 10 (D3) – GPIO 32
- Pin 11 (D4) – GPIO 33
- Pin 12 (D5) – GPIO 31
- Pin 13 (D6) – GPIO 29
- Pin 14 (D7) – GPIO 23
- Pin 15 – +5 V
- Pin 16 – Ground
DHT11 Sensor Wiring
The DHT11 uses three pins: VCC, Data, GND. Connect VCC to 3.3 V (pin 1); if readings are unstable, switch to 5 V (pin 2). Wire the Data pin to GPIO 18 (physical pin 12). A pull‑up resistor (4.7 kΩ) is recommended between VCC and Data.
Required Libraries
Ensure the system has the build tools and Python headers:
sudo apt-get update
sudo apt-get install build-essential python-dev
Install RPLCD for LCD control:
sudo apt-get install python-pip
sudo pip install RPLCD
Install the Adafruit DHT11 library from GitHub:
sudo apt-get install git
git clone https://github.com/adafruit/Adafruit_Python_DHT.git
cd Adafruit_Python_DHT
sudo python setup.py install
Python Script (8‑bit)
Create temperature.py using your preferred editor (e.g., nano):
#!/usr/bin/env python3
import RPi.GPIO as GPIO
import time
import Adafruit_DHT
from RPLCD import CharLCD
GPIO.cleanup()
# LCD configuration – 8‑bit mode
lcd = CharLCD(
numbering_mode=GPIO.BOARD,
cols=16,
rows=2,
pin_rs=37,
pin_e=35,
pins_data=[40, 38, 36, 32, 33, 31, 29, 23]
)
while True:
humidity, temperature = Adafruit_DHT.read_retry(11, 18)
if humidity is None or temperature is None:
print('Failed to retrieve data from sensor')
continue
print(f'Temp: {temperature:.1f} C Humidity: {humidity:.1f} %')
lcd.clear()
lcd.cursor_pos = (0, 0)
lcd.write_string(f'Temp: {int(temperature)} C')
lcd.cursor_pos = (1, 0)
lcd.write_string(f'Humidity: {int(humidity)} %')
time.sleep(5)
Make the script executable and run:
chmod +x temperature.py
./temperature.py
4‑bit Mode Alternative
Replace the pins_data list with four GPIO pins (e.g., [33, 31, 29, 23]) and adjust the LCD initialization accordingly.
Summary
By following these steps, you’ll have a fully functional LCD display that shows real‑time temperature and humidity, perfect for weather stations, IoT dashboards, or educational projects.
Read More Detail
For deeper insight into LCD drivers and advanced configuration, explore the Adafruit DHT repository and the RPLCD documentation.
Manufacturing process
- Liquid Crystal Display (LCD): Technology, Manufacturing, and Future Outlook
- Display BMP Images from SD Card on Arduino 2.4″ TFT LCD Shield
- DIY Arduino Nano Oscilloscope (10 Hz–50 kHz) with 128×64 LCD
- Build the Fridgeye App Using a Nextion Display: Step‑by‑Step Guide
- DIY Arduino LCD Project: Assemble with Resistors, Pushbutton, and 16x2 Display
- 128x64 LCD Smart Clock with Analog/Digital Time & Temperature – Arduino Nano + DS3231 RTC
- Real-Time Soil Moisture Monitoring with LCD Display – Arduino DIY Kit
- ArduTester Millennium: The Ultimate Arduino UNO & Mega 2560 Starter Kit
- Advanced RFID Attendance System v2.0 – Ethernet‑Free Solution
- Understanding Portable Braille Displays: Key Insights & Innovations