Uladzislau Bayouski
Published © MIT

Exhibit: The Primal Display

This very simple protip connects an LCD to a Raspberry Pi to display any data you need, like readings from a temperature sensor.

BeginnerProtip2 hours1,495
Exhibit: The Primal Display

Things used in this project

Hardware components

Elegoo Mega 2560 Ultimate Starter Kit
×1
Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1
Micro SD Card 8GB+
×1
Standard LCD - 16x2 White on Blue
Adafruit Standard LCD - 16x2 White on Blue
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×2
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Microsoft Visual Studio 2017
Python
Raspbian
Raspberry Pi Raspbian

Story

Read more

Schematics

Raspberry Pi GPIO/Pins Scheme

Simple 4-bit connection circuit diagram

Simple 4bit connection circuit diagram with one potentiometer to control contrast and brightness.

Advanced 8-bit connection circuit diagram

8bit connection with advanced control over contrast and brightness with 2 potentiometers.

Code

4-bit Display Connection

Python
#!/usr/bin/python

import RPi.GPIO as GPIO
import time
import Adafruit_DHT

from RPLCD import CharLCD

# We call a RPi.GPIO built-in function GPIO.cleanup() to clean up all the ports we've used
GPIO.cleanup()

# Now setup LCD display pins (4-bit mode)
lcd = CharLCD(numbering_mode=GPIO.BOARD, cols=16, rows=2, pin_rs=37, pin_e=35, pins_data=[33, 31, 29, 23])

# Get senosr readings and render them in a loop
while True:

    # Get sensor's readings
    # IMPORTANT: 11 is sensor type (DHT11) and 18 is GPIO number (or physical pin 12)
    humidity, temperature = Adafruit_DHT.read_retry(11, 18)

    print('Temp: {0:0.1f} C  Humidity: {1:0.1f} %'.format(temperature, humidity))

    # Clear and set initial cursor position for LCD display
    lcd.clear()
    lcd.cursor_pos = (0, 0)

    # Render temperature readings
    lcd.write_string("Temp: %d C" % temperature)

    #  Move cursor to second row
    lcd.cursor_pos = (1, 0)

    # Render humidity readings
    lcd.write_string("Humidity: %d %%" % humidity)

    # Pause execution for 5 seconds
    time.sleep(5)

8-bit Display Connection

Python
#!/usr/bin/python

import RPi.GPIO as GPIO
import time
import Adafruit_DHT

from RPLCD import CharLCD

# We call a RPi.GPIO built-in function GPIO.cleanup() to clean up all the ports we've used
GPIO.cleanup()

# Now setup LCD display pins (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])

# Get senosr readings and render them in a loop
while True:

    # Get sensor's readings
    # IMPORTANT: 11 is sensor type (DHT11) and 18 is GPIO number (or physical pin 12)
    humidity, temperature = Adafruit_DHT.read_retry(11, 18)

    print('Temp: {0:0.1f} C  Humidity: {1:0.1f} %'.format(temperature, humidity))

    # Clear and set initial cursor position for LCD display
    lcd.clear()
    lcd.cursor_pos = (0, 0)

    # Render temperature readings
    lcd.write_string("Temp: %d C" % temperature)

    #  Move cursor to second row
    lcd.cursor_pos = (1, 0)

    # Render humidity readings
    lcd.write_string("Humidity: %d %%" % humidity)

    # Pause execution for 5 seconds
    time.sleep(5)

Github

Credits

Uladzislau Bayouski

Uladzislau Bayouski

6 projects • 65 followers
Thanks to Circuit Basics.

Comments