Table of Contents
Raspberry Pi Industrial Automation Project 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:
5.5 inch HDMI Oled capacitive Touchscreen:
Amazon Purchase links:
Other Tools and Components:
*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:
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.
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.
- 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.
Open the Qt 5 designer software for designing the HMI or GUI application.
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:
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”.
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.
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.
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.
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.
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:
import sys from PyQt5.QtCore import pyqtSlot from PyQt5.QtWidgets import QApplication,QDialog from PyQt5.uic import loadUi import RPi.GPIO as gpio load1=26 load2=19 load3=13 load4=21 gpio.setmode(gpio.BCM) gpio.setwarnings(False) 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) self.setWindowTitle('Industrial Hmi System') self.load_1.clicked.connect(self.load1) 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() widget.show() sys.exit(app.exec_())
Raspberry Pi Industrial Automation HMI PYQT 5 Program Explanation:
I started off with the following instruction
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):
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
gpio.setmode(gpio.BCM) // this code is already define above
set all the GPIO pins as the output. Because these pins will be used to control the relays.
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
widget=industrial()// variable initialization for main industrial class
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: