Raspberry Pi Industrial Automation HMI/GUI designing using PYQT5

(Last Updated On: November 2, 2019)

Raspberry Pi Industrial Automation

Description:

Raspberry Pi Industrial Automation HMI/GUI designing using PYQT5- The components used in this project are sponsored by the DFrobot. DFrobot is a leading robotics and open source hardware provider. They create innovative, user-friendly hardware & software products that become the building blocks in all kinds of electronic projects. I personally recommend you should definitely visit www.dfrobot.com.

Raspberry Pi Industrial Automation- In this tutorial, you will learn how to make Raspberry Pi based Industrial Automation system using Raspberry Pi 3 b+, 5.5inch Oled touch screen, Wifi keyboard, and Mouse. The HMI or GUI application is designed using the PYQT5 software and the Python programming is done using the Thonny IDE.

This is part1 of the Raspberry Pi Industrial Automation System which only covers how to design an HMI application for the Raspberry Pi and control some relays. For the demonstration purposes I have connected 220Vac Bulbs.  In part2 I will explain how to design an HMI application for the Raspberry Pi for monitoring different Sensors.

While in Part3 of the Raspberry Pi industrial Automation system, I will design a complete HMI application for the Raspberry Pi, which will be able to monitor different sensors and control different electrical loads. Subscribe right now so that you never miss any of my upcoming tutorials.

Without any further delay let’s get started!!!


The components and tools used in this project can be purchased from Amazon, the components Purchase links are given below:

DFrobot components purchase links:

Raspberry pi 3 b+ : https://www.dfrobot.com/product-1703.html?search=raspberry%20pi%203%20b%20

Night Vision Camera: https://www.dfrobot.com/product-1295.html?search=night%20vision%20camera

5.5 inch HDMI Oled capacitive Touchscreen: https://www.dfrobot.com/product-1886.html?search=RASPBERRY%20PI%20TOUCH%20SCREEN

Wireless Keyboard and Mouse Combo: https://www.dfrobot.com/product-1178.html?search=raspberry%20pi%20keyboard

Amazon Purchase links:

5.5 inch HDMI touch LCD: https://amzn.to/2ZKOMCu
Raspberry Pi 3 B+ https://amzn.to/2LigNNP
Wireless Keyboard and Mouse Combo “Black Color”: https://amzn.to/2MPf5p3
Night vision Camera for Raspberry Pi: https://amzn.to/2LdUg4x
LM7805 Voltage Regulator: https://amzn.to/2IZEl5x
Potentiometer: https://amzn.to/2JSLbfg
330-ohm resistors pack: https://amzn.to/2NtlAeh
5v 2A adaptor: https://amzn.to/2GsNfcw
2n2222 NPN transistors: https://amzn.to/2EmXsIb
10k Resistor: https://amzn.to/2KTd6OW
lm7805 Voltage Regulator: https://amzn.to/2IZEl5x
330-ohm resistors pack: https://amzn.to/2NtlAeh
LDR pack: https://amzn.to/2m2khGR
female DC power jack socket: https://amzn.to/2KEo1gt
470uf capacitors: https://amzn.to/2xDCOzf
5×7 cm Vero board: https://amzn.to/2OHGbvn
female headers: https://amzn.to/2zqmtiJ
connection wires: https://amzn.to/2DpBuW7
Super Starter kit for Beginners: https://amzn.to/2KJvmKG
Jumper Wires: https://amzn.to/2KMoVXs
Bread Board: https://amzn.to/2MS4q8X
12v Adaptor: https://amzn.to/2Ntr6h1
PCB plate: https://amzn.to/2IUwpCt
Variable Supply: https://amzn.to/2MT4Qfj
Digital Multimeter: https://amzn.to/2Nvft9i
Vero Board / stripboard: https://amzn.to/2MTf9jD
Soldering iron kit: “best” You guys should definitely purchase this: https://amzn.to/2zfoNuJ
Solder wire: https://amzn.to/2ufUMWf
Wire Stripper: https://amzn.to/2KOqxfU
wirecutter: https://amzn.to/2ucIq14
PCB small portable drill machine: https://amzn.to/2Nu62XF

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!


Raspberry Pi Industrial Automation Components interfacing:

Raspberry Pi Industrial Automation

This is a 7 channel relay module, currently, I am using only 4 relays which are connected with the Raspberry Pi GPIO pins 26, 19, 13, and 21. While the grey wire is connected with the Raspberry Pi GND pin. This relay module is powered up using a 12v Adaptor.

Raspberry Pi Industrial Automation

The touch screen is powered up using the Raspberry Pi USB port. The LCD is connected with the HDMI port of the Raspberry Pi using the HDMI Adaptor. That’s all about the connections.

PYQT 5 Software Installation:

After you have installed the Operating System in the Raspberry Pi 3 B+, The next step is to configure your 5.5 inch O LED touch screen. If you don’t know how to set up your 5.5 inch HDMI supported touch screen then watch the following video tutorial.

After you are done with all the settings, the next step is to install the PYQT5 software which is really simple.

Steps:

  • Before you continue, make sure that the system is updated to the latest version for this simply write this command on the Raspberry Pi terminal sudo apt-get upgrade and then press the enter key on your keyboard to continue.
  • Next, you have to update the apt-get package so that you can install the pyqt5, in the next step, for now simply write sudo apt-get update and press enter on your keyboard.
  • Now you will need to install the pyqt5 development headers using the command sudo apt-get install qt5-default and press enter.
  • Now install the pyqt5 qtcreator using the command sudo apt-get install qtcreator and press enter.

That’s it, you are done with the installation.


Raspberry Pi Industrial Automation HMI/GUI Designing and Programming:

This is a good designing and programming practice to keep all your project files in one place. I started off by creating a folder for my project files. While you are on the Raspberry Pi desktop, right-click and select Create New and then click on the folder. Enter the folder name as Industrial HMI System or any other name you like. This will create a new folder on the desktop with the name Industrial HMI System. I will save all my project files in this folder.

Raspberry Pi Industrial Automation

Open the Qt 5 designer software for designing the HMI or GUI application.

Raspberry Pi Industrial Automation

The Qt 5 designer software is provided with all the components and tools which can be used to design advanced level Raspberry PI HMI systems. The Qt 5 designer software is very user-friendly; drag and drop the component you want to use. In my case, I am going to use a Pushbutton. On the New Form – Qt Designer select Dialog without Buttons and then click on the create button.

Enter the form dimensions:

Width: 19200

Height: 1000

Now, select a label, drag and drop it on the form. Delete the default text and write any text you want, in my case I wrote “Industrial Raspberry Pi HMI System”.


Raspberry Pi Industrial Automation

Select a horizontal line from the left side components Widget Box, and drop it on the form, change the width of the line as per your requirement. This line is optional and is only used for designing purposes to make the application looks attractive. If you don’t want to use this line, it’s just fine.

Select a Push Button Drag and drop it on the form. Change the dimensions of the Push Button as per your requirement.

Raspberry Pi Industrial Automation

On the right side, you can see the Property Editor, you can change the width and height values, the X and Y axis values, then scroll down and set the font size, again scroll down until you see the text, click and delete the text PushButton. This will delete the text written on the Push Button and write Load1 OFF. This will display the text Load1 OFF on the Push Button.

Now repeat the same steps for the remaining 3 Push Buttons.

After adding all the four buttons change the objectName of all the buttons.



Raspberry Pi Industrial Automation

Select Button number 1 and write the objectname as load_1.

Select Button number 2 and write the objectname as load_2

Select Button number 3 and write the objectname as load_3

Select Button number 4 and write the objectname as load_4

This is how the final Raspberry Pi Industrial Automation HMI application looks.

Raspberry Pi Industrial Automation

Finally, I saved the design with the name “design” in the folder which I created on the Raspberry Pi desktop.

Now we will start the Raspberry Pi Industrial Automation programming.

Raspberry Pi Industrial Automation

We will do the programming in Thonny Python IDE. After you click on the Thonny Python IDE, this will open the editor where you can write your program. Simply copy and paste the following program into the editor.


Raspberry Pi Industrial Automation HMI PYQT 5 Programming in Thonny Python IDE:


Raspberry Pi Industrial Automation HMI PYQT 5 Program Explanation:

I started off with the following instruction

import sys

import sys is used in the python to load the module named sys into the current namespace so, that we can use the name of the module to access the functions and anything else which is defined in the module.

from PyQt5.QtCore import pyqtSlot

The QtCore module contains the core non-GUI modules, including the event loop and the slot and signal function of Qt.

from PyQt5.QtWidgets import QApplication,QDialog

The Qt Widgets Module provides a set of UI elements to build user interfaces in the classic desktop style.

from PyQt5.uic import loadUi this code is used for loading the design.ui file

 

import RPi.GPIO as gpio

Inside RPi. GPIO, there are two ways to count the IO pins on a Raspberry Pi. The first one uses the numbering system of the BOARD. This refers to the Raspberry Pi board’s P1 header pin numbers. The advantage of using this numbering system is that irrespective of the RPi board revision, your hardware will always work. You won’t have to re-wire or update the code.

BCM numbers are the second numbering system. This is a way of working at a lower level. it applies to the channel numbers on the Broadcom SOC. You always have to deal with a diagram which channel number goes to which pin on the RPi panel. Your script might break with Raspberry Pi board revisions.

To specify which one you use (mandatory):

GPIO.setmode(GPIO.BOARD)

or

GPIO.setmode(GPIO.BCM)

The following GPIO pins are used to control the relays. You can increase or decrease the number of GPIO pins.

load1=26 variable initialization for load

load2=19

load3=13

load4=21

gpio.setmode(gpio.BCM) // this code is already define above

gpio.setwarnings(False)

set all the GPIO pins as the output. Because these pins will be used to control the relays.

gpio.setup(load1,gpio.OUT)

gpio.setup(load2,gpio.OUT)

gpio.setup(load3,gpio.OUT)

gpio.setup(load4,gpio.OUT)

 

class industrial(QDialog):

def init(self):

super(industrial,self).init()

loadUi(‘design.ui’,self) // calling the main gui design which we create in pyqt5 designer

self.setWindowTitle(‘Industrial Hmi System’)

self.load_1.clicked.connect(self.load1) // this code is used for calling the button function

self.load_2.clicked.connect(self.load2)

self.load_3.clicked.connect(self.load3)

self.load_4.clicked.connect(self.load4)

@pyqtSlot()

def load1(self):

if gpio.input(load1):

gpio.output(load1,gpio.LOW)

self.load_1.setText(‘Load1 OFF’)

else:

gpio.output(load1,gpio.HIGH)

self.load_1.setText(‘Load1 ON’)

 

def load2(self):

if gpio.input(load2):

gpio.output(load2,gpio.LOW)

self.load_2.setText(‘Load2 OFF’)

else:

gpio.output(load2,gpio.HIGH)

self.load_2.setText(‘Load2 ON’)

def load3(self):

if gpio.input(load3):

gpio.output(load3,gpio.LOW)

self.load_3.setText(‘Load3 OFF’)

else:

gpio.output(load3,gpio.HIGH)

self.load_3.setText(‘Load3 ON’)

def load4(self):

if gpio.input(load4):

gpio.output(load4,gpio.LOW)

self.load_4.setText(‘Load4 OFF’)

else:

gpio.output(load4,gpio.HIGH)

self.load_4.setText(‘Load4 ON’)

app=QApplication(sys.argv)

widget=industrial()// variable initialization for main industrial class

widget.show()

sys.exit(app.exec_())

If you have any questions regarding this project let me know in a comment. Don’t forget to subscribe to my Website and my YouTube Channel “Electroniclinic”.


Watch Video Tutorial:

 

 

Recommended For You

About the Author: Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Leave a Reply

Close