GUI control of LCD in Raspberry using Qt Creator

In this tutorial we will be interfacing 16×2 LCD display with Raspberry PI2 and controlling the same through GUI designed using Qt Creator. Like in my earlier tutorial where we have shown the GPIO control of the Raspberry PI2 using GUI interface, this tutorial as well is in line with the same, however in this we have used LCD display. I have divided this tutorial in two parts. First we will be designing the GUI framework using Qt Creator and then will be concentrating on hardware aspect of interfaces of LCD with Raspberry Pi and Python code.

GUI Interface Design

For this tutorial I have been using Qt Creator 3.5.0 (opensource) version to explain and design the GUI framework.

Abot Qt Creator

Launch the Qt Creator and click File > New Project or File, this will open up the window as shown below:

New-Project-Qt Creator

Choose in Projects column as Application > Qt Widget Application and click of Choose button. This will take you to next window as shown below:

New-Project-Qt Creator01

Enter the Project Name and location to create your project and click on Next button. This will open up the next setting window as shown below:

New-Project-Qt Creator02

Enter the proper class name, header file, source file and Form file name. We will be only concerned with Class name and Form file names only. Click Next and Finish. This will open up the .cpp source file, we will not worry about this as we will be using python to keep the GUI some action controls.

New-Project-Qt Creator03

Now navigate to Forms and .ui file in Project column and click on .ui to open up the GUI design field. This is only the file we will be concerned of and will be using with python.


On the left hand side there are different form fields which you can just drag and drop in to the workspace to create any GUI which takes your input and displays the same. On the left hand side you have all the object and class settings which you can alter accordingly to change the form field actions and controls.

In this tutorial we have used the following form controls:

  • QtabWidget
  • QLabel
  • QLineEdit
  • QPuchButton

New-Project-Qt Creator07

Just drag and drop them on the work are and align them accordingly to create the GUI as shown below:

New-Project-Qt Creator04

For the LineEdit to restrict to accept only 16 character, click on both the LineEdit field one by one and navigate to Property window on the right. In the Property window under maxLength type 16. This will restrict the LineEdit to accept the first 16 characters only since our LCD (16×2) which we are interfacing has maximum single line character length of 16.

New-Project-Qt Creator05

Now next to display the text by default in out-of focus form i.e. “Enter Line 1 Text or Enter Line 2 Text” in LineEdit navigate to placeholder Text settings in the Property tab as shown below and enter the text of your choice.

New-Project-Qt Creator06The .ui file code is as below:

Hardware Connections

Next step is to interface the 16×2 LCD display with Raspberry Pi. Follow the image below which gives the complete view of electrical connections which I have followed. This is a bit clutter as I m not very much good with Fritzing design tool. I have used Oriole Make 16×2 LCD display.

Untitled Sketch_bbGiven below is the netlist of the electrical connection between the LCD and Raspberry Pi.

Raspberry Pi GPIO Pinout LCD Pinout
PIN2 (5V Power) PIN02
No connection left open PIN03 (Contrast Adjustment)
GPIO21 PIN04 Resgister Select RS
PIN34 (GND) PIN05 Read/Write (R/W)
GPIO20 PIN06 Enable
NC PIN07 DB0 – Not used for 4 Bit Interface
NC PIN08 DB1 – Not used for 4 Bit Interface
NC PIN09 DB2 – Not used for 4 Bit Interface
NC PIN10 DB3 – Not used for 4 Bit Interface
PIN2 (5V Power) PIN15 LED Backlight Anode (+)
PIN39 (GND) PIN16 LED Backlight Cathode (-)


Python Programming 

Now we have to link the .ui file which we have created in Qt Creator for the GUI¬† with the Python Script. Moreover we have also to code for the actions which two buttons in our GUI i.e. “Clear Display” & “Click to Display” will perform with click action.

Listed below is the python script which is properly commented where ever required for better understanding:

Copy and paste the code in Idle3 editor and run the module. This will fire up the GUI as shown below.


Note: Both Python Script file and .ui GUI file must be in same directory.

The Line 1 & Line 2 text input accepts only 16 characters each as the LCD is a 16×2 one. The two buttons have following set of functions:

  1. Button1 Clear Display : This will clear the LCD display and the input text in the GUI Application
  2. Button 2 Click TO DISPLAY: This will outputs the characters entered in Lin 1 & Line 2 of the GUI Application to the LCD.

Just tryout this tutorial and if there is any help or clarifications required kindly comment below.

Download Source Code

One Comment

Add a Comment

Your email address will not be published. Required fields are marked *