Hello friends, I hope you all are doing great. Today, I am going to share the Nextion HMI Conveyor Control on Raspberry Pi 5 - Proteus Simulation, the ninety-fourth project of our IoT Projects series. If you have searched for a Nextion display with a Raspberry Pi, how an HMI talks over a UART, DC motor speed control with an encoder and a PI loop, or an L298N with a Raspberry Pi 5, here is a complete small production line in a Proteus simulation. Every machine on a factory floor has an operator panel next to it: a touchscreen with a big start button, the speed, and a graph of what the machine is doing.

This project builds one for a conveyor belt. A Nextion 3.2" HMI shows the state, the set speed, the belt's real speed and the motor's duty, and its ON, OFF and GRAPH buttons send touch events back to a Raspberry Pi 5 over the UART. The Pi drives a JGB37-520 gear motor through an L298N, counts its encoder pulses, and runs a PI speed loop that keeps the belt at its set speed when boxes load it down. It starts and stops the belt softly, and when the belt jams it switches the motor off and turns the screen red. A dashboard on the network sets the speed and shows the counters. In this tutorial, we will go through the circuit, the Nextion's instruction set and return frames, how the L298N and the encoder work, the PI loop with its feed-forward and anti-windup, and the code. Then we load the belt, watch the speed on the HMI's graph, jam it and restart it in the simulation. At the end, you can download the project with the program and every library file.

NOTICE: Our team has put a lot of effort into this project: the circuit, the code and every part in the simulation are our own work, and you get them all free. Your feedback is the fuel that keeps us going, so please tell us what you think in the comments below. And if our free projects help you, you can buy us a coffee. So, let's get started with the Nextion HMI conveyor control on Raspberry Pi 5 in Proteus simulation:

Figure: The Nextion HMI conveyor controller in a Proteus simulation.
Figure: The project working in the Proteus simulation (an animation of the main steps).

What Does This Nextion HMI Conveyor Controller Do?

  • An operator panel: ON, OFF and GRAPH on a Nextion 3.2" touchscreen; the state turns green when running, red on a jam.
  • Holds the speed: a PI loop on the motor's PWM duty, from the encoder's pulses, every 100 ms.
  • Starts and stops gently: the set speed ramps at 30 RPM a second, so nothing on the belt falls over.
  • Detects a jam: under 30 % of the set speed for one second at full duty stops the motor.
  • Draws the speed: the HMI's graph page plots the belt speed live, ten points a second.
  • Remote control: START, STOP and 30 / 45 / 60 / 75 RPM on a dashboard, with the metres run and the jams counted.

It is a great project for learning serial protocols, motor control and closed-loop control together. In the simulation, the Nextion's pop-up logs every instruction the Pi sends and every frame it sends back, and the motor's pop-up shows its speed, current and load, so we can check the loop from both ends.

Components Used in the Proteus Simulation

All the parts come from our Proteus libraries, each with its own tutorial. The project zip at the end includes every LIB and DLL file and our TEP Pi runtime.

The parts of the HMI conveyor controller and their library posts
PartProteus deviceLibrary postConnection
Raspberry Pi 5RASPBERRY PI 5Raspberry Pi 5 Library for ProteusPI1, conveyor.py, Ethernet 192.168.1.51:8000
Nextion 3.2" HMINEXTION32TEPNextion HMI Display Library for ProteusU1: RX from TXD (GPIO14), TX to RXD (GPIO15), 5 V
L298N motor driverL298NDRIVERTEPL298N Motor Driver Library for ProteusU2: ENA GPIO18, IN1 GPIO23, IN2 GPIO24, 12 V
JGB37-520 encoder gear motorJGB37MOTORTEPJGB37-520 Encoder Gear Motor Library for ProteusM1 on OUT1 / OUT2; C1 GPIO17, C2 GPIO27, encoder on 3.3 V
Laptop WiFi MonitorLAPTOP WIFI MONITORLaptop WiFi MonitorPC1
Mobile WiFi MonitorMOBILE WIFI MONITORMobile WiFi MonitorMOB1

Proteus Simulation of the HMI Conveyor: the Circuit

Figure: The complete circuit of the HMI conveyor on an A3 Proteus sheet.
The connections of the HMI conveyor
SignalPi 5 pinGoes to
TXD / RXDGPIO14 (8) / GPIO15 (10)the Nextion's RX / TX (crossed), 9600 baud
ENAGPIO18 (12)the L298N's enable A: a 500 Hz PWM
IN1 / IN2GPIO23 (16) / GPIO24 (18)the L298N's direction inputs (forward: IN1 high)
MA+ / MA--the L298N's OUT1 / OUT2 to the motor
C1 / C2GPIO17 (11) / GPIO27 (13)the motor's encoder channels
5V / 3V3pin 2 / pin 1the Nextion's supply / the encoder's supply

The Nextion talks on a plain UART, so its TX goes to the Pi's RX and the other way round. The L298N takes 12 V for the motor and three logic signals from the Pi; its OUT1 and OUT2 feed the motor. The encoder runs on 3.3 V so that its outputs suit the Pi's inputs directly. The second H-bridge of the L298N is not used here: it could drive a second belt.

How the HMI Conveyor Works

Talking to a Nextion

A Nextion runs its own screen: buttons, texts, numbers and graphs are designed in the Nextion Editor and stored in the display. The Raspberry Pi only changes their values. Every instruction is plain ASCII text ended by three bytes FF FF FF: t0.txt="RUNNING 60 RPM", n0.val=60, t0.bco=2016 (a colour in 5-6-5 format), add 2,0,90 to add a point to a waveform. The display answers with frames ended the same way: 65h page, component id, 1 for a press or 0 for a release when a button is touched; 88h when it has started; an error code such as 1Ah for a wrong component name. The library's model carries one built-in project: page 0 with t0, t1, n0, j0 and the buttons b0 ON (id 5), b1 OFF (id 6) and b2 GRAPH (id 7, which shows page 1), and page 1 with the waveform s0 (id 2) and BACK (id 3). At 9600 baud only about 960 bytes a second fit on the wire, so the Pi sends a value only when it has changed.

The L298N and the PWM

The L298N is two H-bridges. IN1 high and IN2 low turn motor A forward; both low let it coast; both high brake it. The enable pin switches the bridge on and off: a PWM on ENA sets the motor's average voltage, 500 times a second here. The L298N uses bipolar transistors, and they cost: about 2 V of the 12 V is lost in the bridge at 1 A. So the motor never sees the full 12 V, and at full duty this one turns at about 90 RPM instead of its 110.

Counting the Belt's Speed

The JGB37-520 has a magnet disc on its motor shaft and two Hall sensors: 11 pulses a motor turn on each channel, and through the 1:90 gearbox 990 pulses a turn of the output shaft. The two channels are 90 degrees apart, so their order gives the direction. The Pi counts the rising edges of C1 with an lgpio callback tally and looks at the count every 100 ms: at 60 RPM that is 99 pulses, so the speed is known to about 0.6 RPM ten times a second. With a 50 mm drive pulley, one turn moves the belt 157 mm: 60 RPM is 9.4 m/min.

A PI Loop with a Feed-Forward

Boxes on the belt load the motor, and a loaded motor slows down at the same duty. The controller fixes that in three parts. The feed-forward gives the duty that the set speed needs with no load: 100 / 92 % a RPM. The P term adds a correction in proportion to the speed error. The I term adds up the error over time; it keeps growing until the error is zero, which is what makes the belt return exactly to its set speed under a load. While the duty is stuck at 0 or 100 %, the integral stops growing (anti-windup), so the belt does not overshoot when the load goes away.

Soft Start and Jam Detection

A conveyor never jumps to full speed: boxes would slide or tip. The set speed ramps at 30 RPM a second, so 60 RPM is reached in two seconds, and STOP ramps down the same way. A jam is the opposite problem: something blocks the belt, the PI loop drives the duty to 100 %, and the motor still crawls. If the belt stays under 30 % of its set speed for one second at full duty, the Pi switches the motor off before it overheats, shows JAM in red on the HMI, and waits for the operator to clear the belt and press ON.

The Python Code Explained

The program is conveyor.py. It needs lgpio and serial, both in our TEP Pi runtime. The Nextion class wraps the UART: every instruction ends with FF FF FF, and a value is sent only when it changes:

            self.u.write(text.encode('latin-1') + b'\xff\xff\xff')
        if self.sent.get(key) != text:

A reader thread splits what comes back at FF FF FF; a touch frame starts with 65h:

                frame, buf = buf.split(b'\xff\xff\xff', 1)
        elif f[:1] == b'\x65' and len(f) >= 4:

The program acts on the release, like most Nextion projects; ids 5, 6 and 7 are ON, OFF and GRAPH on page 0:

    if page == 0 and cid == 5:

At start-up the display has already sent its 88h before the program opens the port, so the Pi asks: sendme makes the display answer 66h with the page it shows, and then the Pi knows it is there. Our first run waited for the 88h and never wrote a single instruction:

    hmi.cmd('sendme')

The encoder: an lgpio callback with no function counts C1's rising edges, and every 100 ms the new pulses become RPM. The division is by the real time since the last count: our second run divided by a fixed 100 ms and read 12 - 16 % high whenever a period ran a little long:

enc = lgpio.callback(chip, C1, lgpio.RISING_EDGE)             # (no function: it counts C1's rising edges)
        rpm = pulses / PPR / max(1e-3, t_now - t_last) * 60.0       # (the real time since the last count - probe 2 divided by DT and

The ramp, then the PI loop with its feed-forward, and the anti-windup that stops the integral while the duty is clamped:

            ramp = min(sp, ramp + RAMP * DT) if ramp < sp else max(sp, ramp - RAMP * DT)
            duty = FF * ramp + KP * err + integ
                integ += KI * err * DT                        # (no wind-up: the integral stops while the duty is clamped)

The jam check, and the L298N: forward on IN1, the duty as a 500 Hz PWM on ENA:

        if st == 'RUNNING' and duty >= 99.0 and rpm < JAM_FRAC * sp:
    lgpio.tx_pwm(chip, ENA, PWM_HZ if duty > 0 else 0, duty)

And the screen thread: on the graph page a point every 100 ms, on the main page the state in its colour:

            hmi.cmd('add 2,0,%d' % min(255, round(d['rpm'] * 1.5)))   # (150 px high: 100 RPM at the top)
        hmi.set('t0.bco', str({'RUNNING': GREEN, 'JAM': RED, 'STOPPED': GREY}.get(d['state'], TEAL)))

The dashboard's links are Refresh, START, STOP and 30 / 45 / 60 / 75 RPM; /data gives everything as JSON, with the HMI's touch events and errors.

How to Run the Proteus Simulation

  1. Download the project zip below and install the library files and the TEPPi folder (the steps are under the download button).
  2. Open Pi-5-HMI-Conveyor.pdsprj from the Proteus Simulation folder. Keep conveyor.py and the DLL files next to it.
  3. Press Play. The belt starts softly and runs at 60 RPM.
  4. Click the Nextion's frame for its pop-up: its chips touch ON, OFF, GRAPH and BACK.
  5. Click M1 for the motor's pop-up and put a load on the belt; open the Laptop WiFi Monitor (press Go) to change the speed.

Simulation Results: the HMI Conveyor in Proteus

We pressed Play and let the belt start by itself, then worked it the way an operator would: the touchscreen's GRAPH page, two loads on the belt from the motor's pop-up, two new speeds from the laptop, a jam, a restart from the HMI and a stop. The motor's pop-up measures its own speed, voltage and current, the L298N's pop-up its duty, and the Nextion's pop-up logs every instruction, so each number the Pi prints can be checked against the parts. The times are the program's clock; the whole run took 73.6 simulated seconds.

Starting at 60 RPM

The display answered the Pi's sendme at 0.9 s, the belt started at 1.1 s and reached its set speed after the two-second ramp: RUNNING at 60 RPM. From then on the Pi measured 60.0 RPM at 66 % duty, and the parts agreed: the motor at 60 RPM on 6.89 V and 0.15 A, the L298N switching bridge A at 66 %. The HMI showed RUNNING 60 RPM on green, 60 in the big number, the duty bar two-thirds full and SET 60 RPM 9.4 m/min with the metres run.

Figure: The belt at 60 RPM.
Figure: The Nextion: what the Pi wrote.
Figure: The motor: 60 RPM.
Figure: The L298N: 66 % duty.
Figure: The dashboard.

A Load on the Belt

We touched GRAPH, so the HMI showed the speed graph, and put 2 kg.cm on the motor's shaft: boxes on the belt. The speed fell to 52.1 RPM, the PI loop raised the duty, and within four seconds the belt was back at 60.0 RPM at 86 % duty: the motor now on 8.77 V and 0.53 A. Then 4 kg.cm: that is more than this motor can carry at 60 RPM with the L298N's 2 V lost. The duty went to 100 % and the belt settled at 54.5 RPM, the motor on 10.06 V and 0.90 A. No controller can give more than full duty; that is the motor's limit, not the loop's. With the load taken off, the belt went back to 60 RPM at 66 %.

Figure: 2 kg.cm: the speed held.
Figure: The motor: 60 RPM under load.
Figure: The duty raised to 86 %.
Figure: 4 kg.cm: the limit.
Figure: The motor at full duty.

New Speeds on the Graph

From the laptop, 30 RPM: the ramp took the belt down, and it settled at 30.3 RPM on 37 % duty. Then 75 RPM: up again to 75.2 RPM on 80 %. The HMI's graph page drew all of it, ten points a second: the steady line, the dip and recovery with 2 kg.cm, the deeper drop with 4 kg.cm, the step down to 30 and the ramp up to 75. BACK returned to the main page, where RUNNING 75 RPM and 11.8 m/min were waiting.

Figure: 30 RPM clicked.
Figure: 75 RPM clicked.
Figure: The graph page on the sheet.
Figure: The speed graph: loads and steps.
Figure: 75 RPM.
Figure: The main page at 75 RPM.

A Jam

Then a box wedged under the belt: 10 kg.cm at 75 RPM. The motor stalled, the PI loop drove the duty to 100 %, and one second later the Pi gave up: JAM: 1 RPM for 1.0 s at full duty - the motor stopped. The HMI turned red, JAM - clear the belt, and the motor's pop-up showed it stopped with no drive across its terminals: no current, no heat, while the load was still there.

Figure: The jam.
Figure: The HMI: JAM in red.
Figure: The motor switched off.

Restart and Stop

We took the load off, set 60 RPM on the laptop and touched ON on the HMI: the belt ramped up and reported RUNNING at 60 RPM two seconds later. Then OFF: the belt ramped down and stopped two seconds later, and the HMI went grey: STOPPED. In the whole run the display took 473 instructions without one error and sent eight touch events. The phone shows the same dashboard, and the Pi's terminal holds every event of the run.

Figure: Restarted from the HMI.
Figure: Running again.
Figure: OFF: a soft stop.
Figure: STOPPED.
Figure: The phone: the same dashboard.
Figure: The terminal: the whole run.

The PI loop held 60 RPM under a load the motor could carry and said plainly when it could not, the jam detection stopped the motor within a second, and the HMI and the Pi never lost a frame between them.

Download the Project Files

Click the button below to download Nextion-HMI-Conveyor-Control-Raspberry-Pi-5-Proteus-Simulation-v1.0.zip (about 13.7 MB, without the source code of the models):

Nextion HMI Conveyor Control on Raspberry Pi 5 - Proteus Simulation V1.0
  • Proteus Simulation: Pi-5-HMI-Conveyor.pdsprj, conveyor.py and copies of the models.
  • Python Code: conveyor.py, the program.
  • Proteus Library Files: the LIB files of every part.
  • Proteus Model Files: the DLL models and the TEPPi folder (Python and our Pi runtime).
  • README.txt: the installation steps, the properties, the test results and the links to every library post.

No Proteus yet? Read How to Download and Install Proteus 7 and 8. New to libraries? Follow How to Install a New Library in Proteus.

How to Install the Project Files

  1. Close Proteus and extract the whole zip file, for example to your Desktop.
  2. Copy the files from Proteus Library Files into the LIBRARY folder of Proteus.
  3. Copy everything in Proteus Model Files, the DLL files and the TEPPi folder, into the MODELS folder.
  4. Start Proteus and open the project from the Proteus Simulation folder.

Changing the Code

conveyor.py is plain Python: edit it next to the project and press Play again. The PI gains, the ramp, the jam limits and the speeds are near the top. On a real Raspberry Pi 5, enable the serial port with raspi-config (no login shell on it) and install python3-lgpio and python3-serial.

Ideas to Extend the Project

  • Design your own HMI in the Nextion Editor: a speed slider, a counter of boxes, an alarm history page.
  • Add a photoelectric sensor at the end of the belt and count the boxes on the HMI.
  • Use the L298N's second bridge for a second belt, and synchronise the two speeds.
  • Publish the speed and the jams to MQTT for a factory dashboard.
  • Measure the motor's current with an INA219 and detect a jam before the speed drops.
  • Run the belt in reverse with IN2, and use C2 to read the direction.

From Simulation to Real Hardware

  • The UART: the Pi 5's GPIO14 / GPIO15 are /dev/serial0 once the serial port is enabled; a Nextion works on 3.3 V signal levels.
  • Power: a Nextion 3.2" draws up to about 85 mA at full brightness; the motor and the L298N need their own 12 V supply with a common ground.
  • The L298N: for a motor above 2 A, or to save the 2 V it loses, use a MOSFET driver such as a BTS7960 or a TB6612FNG.
  • The encoder: keep its wires short and away from the motor leads; a small capacitor on each channel helps against noise.
  • Safety: a real conveyor needs a hard-wired emergency stop that cuts the motor's power, not only a touch button.

Troubleshooting

  • The HMI shows nothing from the Pi: TX and RX not crossed, the baud rate not 9600, or the FF FF FF missing.
  • Error frames from the HMI: a wrong component name or value; the dashboard counts them.
  • The motor does not turn: ENA, IN1 and IN2 wired, 12 V on the driver.
  • The speed hunts: the PI gains are too high for the load; lower KP first.
  • JAM at once: the load is too heavy for the motor at that speed.

Limitations of the Simulation

  • The Nextion, the L298N and the motor are our libraries' models, built from their datasheets, not every detail of real parts.
  • The Nextion model carries one fixed demo project; a real display runs the project you design in the Nextion Editor.
  • The belt is a load torque on the motor's shaft; slip of the belt on the pulley is not modelled.
  • Raspberry Pi is a trademark of Raspberry Pi Ltd and Nextion of ITEAD Studio; this project is not made or endorsed by them or by Labcenter.

So, that was all about the Nextion HMI Conveyor Control on Raspberry Pi 5 - Proteus Simulation. I hope it helps you understand how an HMI and a controller talk over a UART, how an encoder measures speed, and how a PI loop with a feed-forward holds a belt at its speed under load, all tested in a simulation before you build the machine. More projects with the ESP32 and the Raspberry Pi 5 are coming. If you have any questions, ask in the comments and I will help you out. Till the next tutorial, take care and have fun!