One of the ideas in my head involves a cup of jellybeans and an LCD display. Since I know how to operate the cup of jellybeans correctly, it was time to check if driving the LCD with Arduino and Raspberry Pi is equally easy. The short answer is: Yes!, if you read this post.
LCD with Arduino and Raspberry Pi
I have two 1602 LCDs which I will use to test with Arduino and Raspberry Pi. While most of the steps are straightforward, there is some voltage tweaking to get the display working correctly. If your display is correctly connected already, jump to the troubleshooting paragraph.
Connecting LCD
The 1602s have 16 pins. Not all will be used, but to drive the screen we going to need a fair bit of wires. Six of them are hooked up to the board, the rest one way or another will make their way to 5V and GND.
The 16 pins can be divided into groups:
- data pins (11, 12, 13, 14) – we are using 4bit data
- power pins (1, 2) – 5V operation
- rs – register select (4)
- rw – read/write (5) – GND as we are writing values only
- en – enable
- LED backlight (15, 16)
- LCD pixel brightness (3)
Most of the online tutorials will suggest a schematic that looks like this. It’s a bit confusing at first but there are things we can do to make it easy. The pins can be easily modified in the script.
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
The 16 pins LCD labels are:As long as you are consistent, you should not have any issues.
Everything is hooked up but LCD isn’t working?
I used two potentiometers in my schematics on purpose. Most of the guides give you some arbitrary resistor value that may, or may not work for you. This is where you can save yourself a headache and experiment a little.
I’m using two 10kΩ pots to estimate a value of the resistor:
- Pin3 – responsible for visibility of the LCD pixels (connected to GND)
- Pin15 – responsible for brightness of the LED highlight (connected to GND)
Try turning the pots left and right until you are happy with how the LCD displays the content. As the resistance of the pots varies from 0-10K – it’s pretty easy to estimate the position of the pot (ie 60% to the right would mean 6k resistance) and therefore adding a correct resistor for your screen.
If you don’t have potentiometers at hand, grab a range of resistors from 1k-10k and see what works best.
Arduino Test
If you set everything up correctly, you shouldn’t have any issues with a test “hello world” example. The example is included in the Arduino IDE – liquid crystal library. Visit the library manager and search for just that.
You should see a “hello world” with a small timer counting up in the second line.
Raspberry Pi test
Installing the libraries is not as neat as with Arduino IDE. However, it takes only a few steps to get the test code running. Download the git repository:
git clone https://github.com/adafruit/Adafruit_Python_CharLCD.git
Install the LCD library:
sudo pip install adafruit-charlcd
Navigate inside the folder Adafruit_Python_CharLCD and run the installer:
sudo python es_setup.py
Then you can have fun with samples located in the examples folder!
Conclusion
As you can see, driving an LCD with Arduino and Raspberry Pi are not as scary as you may think. Did I mention, that these libraries support NodeRED? No? Go and take a look! I’m going to use one in one of my next projects. You can download the files from the link below.
Project Download
Download project files here. Bear in mind that Patreon supporters have early access to project files and videos.