Using LCDs on Raspberry Pi

About: I like to tinker with RaspberryPi and Arduino, fix or build just about anything, fly all kinds of R/C aircraft, and LOVE to race dirtbikes.

In this Instructable I will show you how to use a 16x2 LCD screen with a Raspberry Pi using my specialized code. My code is a modified version of Matt Hawkins' LCD server code, which makes it easier to send text to the screen. All it takes: run the code, and it will ask what you want to print on the LCD. Type it in and hit 'Enter'. Done. Then it will ask if you want to clear the screen. Just hit enter and the whole thing repeats. Let's get started.

Step 1: The Wiring

The first step is the wiring. If your LCD doesn't already have headers soldered on you will have to add them. After that, use a breadboard and jumper wires to connect all but four of the LCD pins to the Pi. Using a breadboard is not necessary, but makes wiring a lot easier. All of the GPIO pin numbers are BCM format, not BOARD format.

01. Gound
02. 5V
03. Ground with 2.2k Ohm resistor
04. GPIO 26
05. Ground
06. GPIO 19
07. N/A
08. N/A
09. N/A
10. N/A
11. GPIO 13
12. GPIO 6
13. GPIO 5
14. GPIO 11
15. 5V with 270 Ohm resistor
16. Ground

Step 2: The Code

Next is to open the code below in Python 2; I prefer IDLE 2. Then save.


Step 3: Run

Next run the program*. The Python shell will do nothing for three seconds then will ask what you want on line one. Type your text and hit enter. Make sure that the text is no longer than 16 characters. Then it will ask for what to print on line two. Do the same thing as before. If no text is wanted, just hit enter. As you will see, the text will appear on the LCD and 'Clear?' will appear in the shell. There are 6 clear commands.

1. Enter - simply clears the LCD
2. 'Y' or 'y' then enter - simply clears the LCD
3. 'N' or 'n' then enter - doesn't take the text off of the screen
4. '-kill-' - kills the program
5. '1' - only clears line 1
6. '2' - only clears line 2

Type the corresponding clear command and hit enter. Now the entire program will repeat.

* The Python code may not work the first time. If so close IDLE and open the terminal. Type 'sudo idle' and IDLE 2 will open. Now open the code file and run.

Step 4: Done

That's it. You can have hours of fun using the LCD. Feel free to modify the code and use it for your own projects.

Share

    Recommendations

    • Make it Glow Contest 2018

      Make it Glow Contest 2018
    • Optics Contest

      Optics Contest
    • Plastics Contest

      Plastics Contest

    Discussions