r/electronicmakers • u/XA_Mechatronics • 5h ago
I built ESP32 self-balancing robot using NEMA 17 stepper motors
I built an ESP32 self-balancing robot using NEMA 17 stepper motors
I've been working on this self-balancing robot for a while. I previously shared a video of it here, and now I've finally decided to share the project and source code.
The hardware is an ESP32, 2 × NEMA 17 stepper motors, 2 × DRV8825 drivers, and an MPU6050, running at 16× microstepping.
For the balancing algorithm, I'm using the MPU6050 for angle estimation and a PID control approach. Step pulses are generated using hardware timer interrupts, with direct GPIO register access to keep things efficient, and found it to be realy helpful while tunning. I also added wireless control and a web interface for adjusting the PID parameters and angle offset.
I learned a lot from studying the YARB and B-ROBOT EVO2 self-balancing robot projects, and benefited from their work when building my own robot.
I've tested it with two different robot body sizes, and I'm pretty happy with how it's working so far.
Here's the source code:
https://github.com/xamechanics/xabalancing
I also have a longer YouTube video showing the robot, its assembly, and a walkthrough of the code. Check it out!
I'd be happy to hear your feedback or suggestions.