Hello friends, I hope you all are doing great. Today, I am going to share the Closed-Loop Camera Slider on Raspberry Pi 5 - Proteus Simulation, the ninety-second project of our IoT Projects series. If you have searched for a camera slider with a Raspberry Pi, how to drive a stepper motor smoothly, what a closed-loop stepper is, or how to shoot a motion timelapse, here is a complete one in a Proteus simulation. A slider moves a camera along a short rail during a shot: slow, smooth and exactly repeatable. That last word is the hard part.
Most sliders use an ordinary stepper motor. It moves exactly one step per pulse, until the load is too heavy, and then it slips without telling anyone: the next shot is in the wrong place and the controller never knows. A closed-loop stepper fixes that: its driver reads the shaft with a magnetic encoder and raises its current whenever the shaft falls behind. This Raspberry Pi 5 drives a NEMA 17 closed-loop stepper through a belt, eases every move in and out so the camera never jerks, runs a timelapse with a shutter output, and glides for video. An ordinary open-loop stepper on the same wires shows the difference. In this tutorial, we will go through the circuit, how a stepper moves and why it slips, what the closed loop changes, the belt arithmetic, eased moves, counting the pulses that really went out, and the shutter. Then we shoot a timelapse in the simulation and put a heavy camera on a tilted rail. 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 closed-loop camera slider on Raspberry Pi 5 in Proteus simulation:
What Does This Camera Slider Do?
- Moves smoothly: every move eases in and out along a cosine: no jerk at the start or the stop.
- Knows its position exactly: the Pi counts every step pulse it really sends on a second GPIO.
- Shoots a timelapse: 7 shots along the rail: move, settle, shutter, wait.
- Glides for video: one slow 12 s move from end to end.
- Cannot lose steps: a closed-loop NEMA 17 holds its position under a heavy load, where an ordinary stepper slips.
It is a great project for learning stepper motors, motion profiles and precise pulse timing in one go. In the simulation, each motor's pop-up shows the shaft (from its encoder), the target (the pulses it has received) and the error between them, so we can see exactly when a motor falls behind.
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 the Pi runtime.
| Part | Proteus device | Library post | Connection |
|---|---|---|---|
| Raspberry Pi 5 | RASPBERRY PI 5 | Raspberry Pi 5 Library for Proteus | PI1, slider.py, Ethernet 192.168.1.51:8000 |
| NEMA 17 closed-loop stepper (x2) | NEMA17CLTEP | NEMA 17 Closed-Loop Stepper Library for Proteus | M1 closed loop, M2 open loop; EN GPIO5, STP GPIO6, DIR GPIO13 |
| PC817 optocoupler | PC817TEP | PC817 Optocoupler Library for Proteus | U1, the shutter output from GPIO26 |
| 5 mm red LED | LED5MMREDTEP | 5mm LED Library for Proteus | D1, the camera's shutter input |
| Resistors 470, 330 | RESISTOR4BANDTEP | Resistor Library for Proteus | R1 the PC817's LED, R2 D1 |
| I2C LCD 16x2 | I2CLCD16X2BLUEADVTEP | I2C LCD 16x2 Library for Proteus | LCD1 on I2C1, 0x27 |
| Laptop WiFi Monitor | LAPTOP WIFI MONITOR | Laptop WiFi Monitor | PC1 |
| Mobile WiFi Monitor | MOBILE WIFI MONITOR | Mobile WiFi Monitor | MOB1 |
Proteus Simulation of the Camera Slider: the Circuit
| Signal | Raspberry Pi 5 | Goes to |
|---|---|---|
| EN | GPIO5 (pin 29) | EN of M1 and M2: low enables |
| STP | GPIO6 (pin 31) | STP of M1 and M2: one pulse per microstep |
| STP (counted) | GPIO16 (pin 36) | the same wire: the Pi counts the pulses it sent |
| DIR | GPIO13 (pin 33) | DIR of M1 and M2: the direction |
| SHUT | GPIO26 (pin 37) | R1 470 ohm to the PC817's LED |
| CAM | - | the PC817's collector: D1 through R2 from 5 V |
| SDA / SCL | GPIO2 / GPIO3 | LCD1, 0x27 |
Both motors share the three control wires, so they receive exactly the same pulses; any difference between them is the motors' own doing. Each motor's V+ is on a 12 V supply, and COM, the common of its optocoupled inputs, goes to the Pi's ground. The PC817 keeps the camera electrically separate from the Pi: a camera's remote input is just two contacts that must be shorted to fire the shutter, and the optocoupler's transistor does exactly that. In the simulation the "camera" is D1, which lights for each shot.
How the Camera Slider Works
A Stepper Counts, and Hopes
A NEMA 17 stepper has 200 full steps per turn. Its driver can split each step into microsteps; at 8 microsteps one turn takes 1600 pulses on STP. Every pulse moves the magnetic field one microstep, and the rotor follows, as long as the field can pull it. The field's pull has a limit, the pull-out torque, and it falls as the speed rises, because the motor's own back-EMF leaves less voltage to drive the current. If the load asks for more than that, the rotor falls more than half an electrical cycle behind the field, snaps back four full steps, and carries on from the wrong place. An open-loop driver cannot notice: it only counts pulses.
What the Closed Loop Changes
A closed-loop driver sits on the back of the motor with a 14-bit magnetic encoder on the shaft. It compares the shaft with the pulses it has received, and drives the current with field-oriented control: the field is always kept 90 electrical degrees ahead of the rotor, the angle that gives the most torque, and the current rises (up to 3 A) only as far as the load needs. Under a heavy load the shaft may lag for a moment, but the driver keeps pushing until it catches up: it cannot lose steps. And with a light load it uses almost no current, where an open-loop driver burns its full current all the time.
The Belt Arithmetic
The carriage hangs on a GT2 belt (2 mm between teeth) around a 20-tooth pulley: one motor turn moves it 40 mm. With 1600 pulses a turn that is 40 pulses per millimetre, and the 600 mm rail is 24,000 pulses. One pulse is 25 micrometres, far finer than any camera needs. The speed limit is 5 kHz: 125 mm/s, 187 RPM, safely inside the flat part of the open-loop motor's torque curve (its pop-up shows about 200 mN.m up to about 250 RPM). In our first runs at 262 RPM the open-loop motor lost steps even with no load.
Eased Moves
Starting or stopping a camera at full speed makes the whole rig shake and the shot wobble. So every move follows a cosine: x(t) = x0 + D (1 - cos(pi t / T)) / 2. The speed rises and falls along a sine, zero at both ends, and the peak speed is pi/2 times the average. Worked example: the first move, 300 mm (12,000 pulses) at no more than 5 kHz, takes T = pi/2 x 12000 / 5000 x 1.15 = 4.3 s. The peak acceleration is (pi^2 / 2) x D / T^2, about 0.08 m/s^2 here, gentle on a 0.5 kg camera.
Counting the Pulses That Really Went Out
The Pi makes the step pulses with lgpio.tx_pwm, which can also send an exact number of pulses. Our first version chained such bursts, 50 ms each, and the motors received 13,035 pulses for 12,000 sent: each burst stopped a couple of milliseconds late, and at 7 kHz that is a dozen extra pulses every time. Waiting for each burst to finish cut it to 12,426, and the little gaps made the open-loop motor slip. The fix is simple and robust: GPIO16 is wired to the STP line and an lgpio callback counts every rising edge, so the Pi knows exactly how many pulses went out. During a move, a continuous PWM runs, and every 50 ms its frequency is set to reach the next point of the cosine from the true count; the last few pulses are counted out slowly at the end.
The Timelapse
A motion timelapse is a series of still photos, each taken a little further along the rail; played back, the scene glides past. Each shot is the same routine: an eased move of 100 mm, 0.3 s for the rig to stop vibrating, a 0.4 s pulse on the shutter, and a wait until the next shot is due. A real timelapse might take 300 shots over two hours; the simulation takes 7 in about half a minute.
The Python Code Explained
The program is slider.py, written for the Raspberry Pi 5 with lgpio (its GPIO, PWM and I2C) and the standard http.server. The belt arithmetic, the speed limit and the timelapse:
PULSES_PER_MM = 1600 / 40.0 # 8 microsteps x 200 steps a turn / 40 mm a turn
F_MAX = 5000 # Hz: 125 mm/s (187 RPM - inside the open-loop motor's flat torque;
SHOTS, INTERVAL, SETTLE, SHUTTER = 7, 1.0, 0.3, 0.4 # the timelapse: 7 shots (6 steps of 100 mm), 1 s apart
The pulse counter on GPIO16:
fb = lgpio.callback(chip, FB, lgpio.RISING_EDGE) # (no function: it counts the rising edges - every step pulse)
The duration of a move, from the distance and the speed limit:
seconds = max(0.6, math.pi / 2 * abs(d) / F_MAX * 1.15) # (the peak speed of a cosine move is pi/2 x the mean)
Every 50 ms: where the cosine wants to be, how far the true count is from it, and the frequency to get there:
want = round(total * (1 - math.cos(math.pi * k / n_seg)) / 2)
f = (want - (fb.tally() - base)) / SEG
lgpio.tx_pwm(chip, STP, min(F_MAX, f), 50)
The last pulses, counted out exactly at a low rate:
lgpio.tx_pwm(chip, STP, f, 50, 0, rest)
And in the timelapse, the pause before each picture:
time.sleep(SETTLE) # (the slider stops shaking before the picture)
The LCD shows the position and the job; the dashboard's links are Refresh, STOP, HOME, MIDDLE, END, TIMELAPSE and VIDEO; /data gives everything as JSON.
How to Run the Proteus Simulation
- Download the project zip below and install the library files and the TEPPi folder (the steps are under the download button).
- Open Pi-5-Camera-Slider.pdsprj from the Proteus Simulation folder. Keep slider.py and the DLL files next to it.
- Press Play. The carriage glides to the middle of the rail.
- Open the Laptop WiFi Monitor (press Go): TIMELAPSE, VIDEO, HOME, MIDDLE, END, STOP.
- Click M1 and M2 for their pop-ups; choose 0.3 N.m on both and run VIDEO.
Simulation Results: the Slider in Proteus
We pressed Play and let the program make its first move, then ran a timelapse from the dashboard, put a heavy camera on a tilted rail (a 0.3 N.m load on both motors) and ran a video glide. The times are the program's clock; the whole run took 55.3 simulated seconds.
The First Move
At 1.0 s the program glided the carriage to the middle of the rail: 300 mm in 4.7 s, eased in and out. It counted 12,001 pulses on GPIO16, and both motors' pop-ups showed the same 12,001 pulses received, the shaft at 2700.2 degrees, 7.5 turns. The difference between the two motors is already visible at rest: the closed-loop M1 holds with 0.12 A, the open-loop M2 burns its full 1.50 A all the time.
The Timelapse
We clicked TIMELAPSE. The carriage glided back to 0, then took 7 shots 100 mm apart: at -0.1, 100.2, 200.2, 300.1, 400.1, 500.1 and 600.1 mm, a shot every 2.9 s. At shot 3 we froze the simulation during the shutter pulse: the PC817 switched on with 8.2 mA in its LED and passed 9.1 mA to D1, the camera's shutter input, and the LCD read POS 200.2 mm, SHOT 3/7. At the end of the rail both motors had received 24,006 pulses; neither had lost a step, because the load was light.
A Heavy Camera on a Tilted Rail
Now the test that matters. On both motors' pop-ups we chose the 0.3 N.m load, about what a heavy camera on a steeply tilted rail asks of the motor, and clicked VIDEO: a 12 s glide back to 0. Halfway, the closed-loop M1 was moving at 118 RPM, only 0.19 degrees behind its pulses, its current raised to 1.89 A against the 304 mN.m load. The open-loop M2 had not moved at all: SLIPPING, 1468 full steps lost already. Its 1.5 A gives about 250 mN.m, less than the load, so every step the field took, the rotor fell back.
The End of the Glide
At 50.1 s the program reported VIDEO done at 0.0 mm. M1 agreed exactly: 0.0 degrees, 0 pulses, holding the load with 1.82 A. M2 was still at 5401 degrees, the far end of the rail, 3000 full steps lost, while the Pi, counting its pulses, believed it was home. On a real slider the camera would be at the wrong end of the rail, and the next timelapse would start from there. That is the whole case for closed loop in one picture. The phone shows the same dashboard, and the Pi's terminal holds every event of the run.
With the same pulses on the same wires, the closed-loop motor ended exactly where the Pi said, and the open-loop one ended 600 mm away.
Download the Project Files
Click the button below to download Closed-Loop-Camera-Slider-Raspberry-Pi-5-Proteus-Simulation-v1.0.zip (about 14.5 MB, without the source code of the models):
Closed-Loop Camera Slider on Raspberry Pi 5 - Proteus Simulation V1.0- Proteus Simulation: Pi-5-Camera-Slider.pdsprj, slider.py and copies of the models.
- Python Code: slider.py, the program.
- Proteus Library Files: the LIB files of every part.
- Proteus Model Files: the DLL models and the TEPPi folder (the Pi's Python 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
- Close Proteus and extract the whole zip file, for example to your Desktop.
- Copy the files from Proteus Library Files into the LIBRARY folder of Proteus.
- Copy everything in Proteus Model Files, the DLL files and the TEPPi folder, into the MODELS folder.
- Start Proteus and open the project from the Proteus Simulation folder.
Changing the Code
slider.py is plain Python: edit it next to the project and press Play again. The belt arithmetic, the speed limit, the timelapse and the video are near the top. On a real Raspberry Pi 5, install python3-lgpio and enable I2C; the pulse counter needs only a wire from STP to GPIO16.
Ideas to Extend the Project
- Add a limit switch at one end and home the carriage at power-up.
- Add a second axis: a pan motor that keeps the camera pointed at a subject while the carriage moves.
- Keyframes: let the user mark a start and an end on the dashboard, and the number of shots.
- Hold-to-shoot: keep the shutter closed for a bulb exposure at night (star trails while sliding).
- Use the closed-loop driver's alarm output (on real boards) to stop the job if the load is ever too much.
- Log each shot's position and time to a CSV file for the video editor.
From Simulation to Real Hardware
- Calibrate the closed-loop board: a real one learns its encoder's offset (CAL in its menu) the first time, with the motor unloaded.
- Belt tension: a slack belt makes backlash that no encoder on the motor can see; tension it firmly.
- Supply: 12 or 24 V for the motor; 24 V gives more torque at speed. The Pi on its own 5 V supply, the grounds joined at COM.
- Camera remote: check your camera's remote socket (2.5 mm jack on many): focus, shutter and ground.
- Vibration: give the timelapse a longer settle time on a long or light rail.
Troubleshooting
- The motors do not move: EN low enables; V+ on 12 V; COM on the Pi's ground.
- The position drifts from the Pi's count: GPIO16 must be on the STP wire; the count is what really went out.
- The open-loop motor loses steps with no load: too fast for its torque, or too much inertia; keep under about 200 RPM.
- No shutter: SHUT through R1 to the PC817's anode, its cathode to ground.
Limitations of the Simulation
- The motors are our library's models: the electrical and mechanical behaviour of such a motor and driver, not every detail of a real one.
- The rail, the belt and the camera are represented by an inertia and a load on the motor shaft; belt stretch and friction are not modelled.
- The timelapse is short so that it fits in a short simulation.
- Raspberry Pi is a trademark of Raspberry Pi Ltd; this project is not made or endorsed by Raspberry Pi Ltd or by Labcenter.
So, that was all about the Closed-Loop Camera Slider on Raspberry Pi 5 - Proteus Simulation. I hope it helps you understand how a stepper turns pulses into position, why an ordinary stepper can slip without knowing, how a closed-loop driver prevents it, and how a cosine profile and a pulse counter make a slider smooth and exact, all tested in a simulation before you put a camera on a rail. More projects with the Raspberry Pi 5 and the ESP32 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!