Hello friends, I hope you all are doing great. Today, I am going to share the Brushless Gimbal Stabilizer with ESP32 and BNO055 - Proteus Simulation, the eighty-seventh project of our IoT Projects series. If you have searched for a brushless gimbal with an ESP32, how a camera stabilizer works, the BNO055 with an ESP32, SimpleFOC, or how to drive a BLDC gimbal motor with field-oriented control, here is a complete one in a Proteus simulation. A handheld gimbal is a small marvel: you walk, turn and stumble, and the camera on top stays perfectly level, as if it floated.

Inside are brushless gimbal motors, an orientation sensor and a controller that, hundreds of times a second, turns each motor against the motion of the hand. This ESP32 does exactly that on two axes, roll and pitch. A BNO055 on the handle fuses its accelerometer, gyroscope and magnetometer into the handle's roll, pitch and heading. Two 2204 gimbal motors, each driven by a SimpleFOC Mini, are turned with open-loop field-oriented drive: the ESP32 rotates a magnetic field inside each motor, and the magnets follow it. In this tutorial, we will go through the circuit, how gimbal motors differ from drone motors, three-phase sine drive, electrical and mechanical angles, the load angle and the torque it gives, the BNO055's fusion, the stabilizing rule and the pole slip, the weak point of open loop. Then we watch the handle turn, roll, pitch and shake in the simulation while the camera stays level, aim the camera from a dashboard, and overload a motor on purpose. At the end, you can download the project with the sketch 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 brushless gimbal stabilizer with ESP32 and BNO055 in Proteus simulation:

Figure: The brushless gimbal stabilizer in a Proteus simulation.
Figure: The project working in the Proteus simulation (an animation of the main steps).

What Does This Brushless Gimbal Do?

  • Senses the handle: a BNO055 in NDOF fusion mode gives the handle's roll, pitch and heading 100 times a second.
  • Drives two brushless motors: open-loop field-oriented drive through two SimpleFOC Mini drivers, 500 updates a second.
  • Keeps the camera level: each motor turns by the handle's angle the other way, with a speed limit that keeps the magnets in step.
  • Aims the camera: LEVEL, DOWN 30 and UP 15 on the dashboard set the camera's tilt.
  • Reports: every steady attitude and every second of motion with the camera's error, on the OLED, the dashboard and the serial monitor.

It is a great project for learning brushless motor control, sensor fusion and the idea of feed-forward stabilization in one go. In the simulation, the BNO055's pop-up moves the handle through a scene by itself, and the motors' pop-ups show the field, the magnets, the load angle and the torque, so we can see why the camera stays level.

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.

The parts of the brushless gimbal and their library posts
PartProteus deviceLibrary postConnection
ESP32 DevKit V1ESP32 DEVKIT V1ESP32 DevKit V1 Library for ProteusU1, ESP32_Brushless_Gimbal.hex, Wi-Fi 192.168.1.101
SimpleFOC Mini (x2)SIMPLEFOCMINITEPSimpleFOC Mini Driver Library for ProteusU2 roll (D25, D26, D27), U3 pitch (D32, D33, D14), EN D13
2204 gimbal motor (x2)GIMBAL2204TEP2204 Gimbal Motor Library for ProteusM1 roll, M2 pitch, A / B / C from their driver
BNO055 orientation sensorORIENTBNO055TEPBNO055 Orientation Sensor Library for ProteusU4 on the handle, I2C 0x28
OLED SSD1306 128x64OLED12864WHITEADVTEPOLED SSD1306 Library for ProteusOLED1 on I2C, 0x3C
Laptop WiFi MonitorLAPTOP WIFI MONITORLaptop WiFi MonitorPC1
Mobile WiFi MonitorMOBILE WIFI MONITORMobile WiFi MonitorMOB1

Proteus Simulation of the Brushless Gimbal: the Circuit

Figure: The complete circuit of the brushless gimbal on an A3 Proteus sheet.
The connections of the brushless gimbal
SignalESP32Goes to
R_IN1 / R_IN2 / R_IN3D25 / D26 / D27U2 IN1 / IN2 / IN3: the roll motor's three PWMs
P_IN1 / P_IN2 / P_IN3D32 / D33 / D14U3 IN1 / IN2 / IN3: the pitch motor's three PWMs
ENMD13EN of U2 and U3: HIGH = the outputs on
SDA / SCLD21 / D22U4 (BNO055) and OLED1, 400 kHz
M1 / M2 / M3-each driver to its motor's A / B / C
+12V-V+ of both drivers

Each SimpleFOC Mini carries a DRV8313: three half-bridges, one per motor phase. A HIGH input connects that phase to 12 V, a LOW one to ground; with PWM, each phase gets an average voltage set by its duty. The nRT and nSP pins are pulled up on the board, so they are left open.

How the Brushless Gimbal Works

Feed-Forward Stabilization

The camera sits on the roll motor, which sits on the pitch motor, which the handle holds. The camera's angle is the handle's angle plus the motor's angle. To keep the camera at a target angle, each motor must turn to the target minus the handle's angle: if the handle rolls 30 degrees clockwise, the roll motor turns 30 degrees anticlockwise. Measuring the handle and correcting in advance is called feed-forward. Commercial gimbals put the sensor on the camera instead and close a feedback loop around it; with the sensor on the handle, this project shows the principle in its plainest form.

Gimbal Motors Are Not Drone Motors

A drone motor has few turns of thick wire: low resistance, high speed, tens of amps. A gimbal motor is wound with many turns of thin wire: the 2204 has about 8 ohm between two leads and is rated at 600 mA. It is built to hold a position with a small current and turn slowly and smoothly, never to spin fast. Its bell carries 14 magnets, 7 north-south pairs, so it has 7 pole pairs.

Turning a Field: Three-Phase Sine Drive

The ESP32 does not switch the motor's phases in steps as a drone ESC does. It gives the three phases three sine voltages, 120 degrees apart, around the middle of the supply: U = 6 V + Vq x sin(theta - 0, 120 or 240 degrees). Together they make a magnetic field of fixed strength pointing at the electrical angle theta. Turn theta and the field turns; the magnets follow it. Because the motor has 7 pole pairs, one full electrical turn moves the shaft only 360 / 7 = 51.4 degrees: the electrical angle is 7 times the shaft angle. Worked example: to hold the shaft at -30 degrees, the field points at 7 x -30 = -210 degrees, which is the same as 150 degrees. With Vq = 2 V on 12 V, each duty swings between 33 % and 67 % around 50 %.

The Load Angle and the Torque

The field pulls the magnets with a torque that depends on the angle between them, the load angle: T = Tmax x sin(load angle). With no load the magnets sit right under the field; a load pushes them back until the sine gives enough torque. In the simulation the motor's pop-up shows it: at Vq = 2 V the windings carry 0.47 A, and the most torque the field can give is 15.0 mN.m, at a load angle of 90 degrees. The camera's small 2 mN.m load needs sin(load angle) = 2 / 15, about 8 degrees; the pop-ups showed load angles of 5 to 7 degrees and 1.3 to 1.9 mN.m while holding. That reserve, more than seven times the load, is what keeps the camera in place against bumps.

The BNO055 and Its Fusion

An accelerometer knows which way is down but is fooled by every bump; a gyroscope measures turning smoothly but drifts; a magnetometer knows north but is disturbed by iron. The BNO055 has all three and a small processor that fuses them. In NDOF mode (OPR_MODE 0x0C) it delivers ready-made Euler angles: heading at register 0x1A, roll at 0x1C and pitch at 0x1E, each as a 16-bit number with 16 counts per degree. The ESP32 reads all six bytes in one I2C transfer every 10 ms. A heading of 90.0 degrees reads as 1440.

Keeping the Magnets in Step: the Slew Limit

In open loop the ESP32 cannot see where the magnets are; it can only move the field and trust that they follow. They follow as long as the field never gets 90 degrees electrical ahead of them. So each motor's angle is changed by at most 400 degrees a second (0.8 degrees per 2 ms update). Is that safe? The rotor and camera plate have 42 g.cm2 of inertia: with 13 mN.m to spare, the motor can accelerate at 13e-3 / 4.2e-6 = about 3,100 rad/s2, reaching 400 degrees a second (7 rad/s) in about 2 ms. And at that speed its back-EMF is only 66.7 RPM / 260 RPM per volt = 0.26 V, small beside the 2 V drive. The camera's error is whatever the slew limit has not caught up with yet.

The Pole Slip: the Weak Point of Open Loop

If the load needs more than the 15 mN.m the field can give, the magnets cannot keep up: they fall back past 90 degrees, the torque reverses, and they drop to the next pole pair, 51.4 degrees behind. That is a pole slip. The field then holds them there as firmly as before, so the camera simply stays 51 degrees off, and the ESP32 never knows. That is why serious gimbals and robot joints use closed-loop FOC: a magnetic encoder (such as an AS5600) on each motor tells the controller where the rotor really is.

The Arduino Code Explained

The sketch is ESP32_Brushless_Gimbal.ino, built for our ESP32 DevKit V1 with the WiFi, WebServer, Wire and Adafruit SSD1306 libraries. The settings:

const float VSUP = 12.0, VQ = 2.0, PAIRS = 7, SLEW = 400.0;        // V, V, pole pairs, deg/s

The BNO055 in NDOF mode, and the Euler angles at 16 counts a degree:

    bnoWrite(0x3D, 0x0C); delay(20);
  const float r = v[1] / 16.0, p = v[2] / 16.0;

The field: the electrical angle is 7 times the shaft angle, and each phase gets its sine as a 10-bit duty:

  const long e = lround(a.motor * PAIRS * 256.0 / 360.0);           // the electrical angle in 1/256 of a turn
    const int d = (int)(511.5 + VQ / VSUP * 1023.0 * s / 32767.0);  // 6 V + Vq sin(...) as a 10-bit duty

The stabilizing rule and the slew limit:

  const float want = a.target - a.base;                             // turn the camera against the handle
  a.motor += constrain(want - a.motor, -step, step);                // (the slew limit: no faster than the field can drag the magnets)

The PWM, and the update rates:

  for (byte k = 0; k < 3; k++) { ledcAttach(ROLL_PIN[k], 20000, 10); ledcAttach(PITCH_PIN[k], 20000, 10); }
const unsigned long DT_US = 2000, IMU_US = 10000;                   // the motors at 500 Hz, the BNO055 at 100 Hz

The camera's error, which does not count the moment the camera is aimed somewhere new:

float camErr(const Axis &a) { return a.target - a.base - a.motor; }
  if (millis() - aimAt > 400) errMax = max(errMax, max(fabs(camErr(roll)), fabs(camErr(pitch))));   // (aiming the camera is no error)

Is the handle still? The rates are measured over 100 ms, because over a single 10 ms reading one count of the BNO055's jitter (1/16 degree) would already look like 6 degrees a second:

    rateR = (r - r0) / 0.1; rateP = (p - p0) / 0.1; rateH = dh / 0.1; r0 = r; p0 = p; h0 = heading; n = 0;

The OLED shows the handle, the motors and the camera, the heading and the tilt, and the camera's largest error in the last second. The dashboard's links are LEVEL, DOWN 30, UP 15, OFF and ON; /data gives everything as JSON.

How to Run the Proteus Simulation

  1. Download the project zip below and install the library files (the steps are under the download button).
  2. Open ESP32-Brushless-Gimbal.pdsprj from the Proteus Simulation folder. Keep the HEX and the DLL files next to it.
  3. Press Play. The handle turns, rolls, pitches, levels and shakes by itself; watch the motors turn against it.
  4. Open the Laptop WiFi Monitor (press Go): DOWN 30, UP 15 and LEVEL aim the camera, OFF and ON switch the motors.
  5. Click U4 for the BNO055's pop-up and tilt the handle with its chips; click a motor for its field, load angle and torque.

Simulation Results: the Gimbal in Proteus

We pressed Play and let the BNO055's scene move the handle: a turn, a roll, a pitch, back to level and a shake. Then we aimed the camera from the dashboard, overloaded the pitch motor on purpose and switched the motors off. The times are the simulation's clock; the whole run took 35.5 simulated seconds. At 0.81 s the ESP32 found the BNO055 (CHIP_ID 0xA0) and set NDOF fusion; at 1.22 s both motors were aligned with 0.47 A in their windings.

The Handle Turns

From 2 s the handle turned to a heading of 90 degrees. Roll and pitch stayed at zero, so both motors stayed at zero too: with no yaw motor, the camera simply turns with the handle, as on any two-axis gimbal. The OLED shows the handle, the motors and the camera all level, the heading 90.

Figure: The handle turned to heading 90: nothing for roll and pitch to do.
Figure: The BNO055: the heading from its fusion.
Figure: The OLED: the handle, the motors and the camera.

Rolled 30 Degrees

At 6.5 s the handle rolled 30 degrees. In that second it swung 23.3 degrees, and the camera never got more than 0.7 degrees off level: the roll motor turned the other way as fast as the handle rolled. The OLED then read handle roll 30.0, roll motor -30.0, camera 0.0. The roll motor's pop-up shows the field 7 degrees (electrical) from the magnets, holding 1.7 mN.m.

Figure: The handle rolled 30: the roll motor turned back 30.
Figure: Handle +30, motor -30, camera 0.
Figure: The roll motor: the field against the magnets, the load angle and the torque.
Figure: The BNO055: the handle rolled.

Rolled and Pitched

At 8.5 s the handle pitched 20 degrees as well. The pitch motor followed with the camera within 1.6 degrees, and at 10.73 s the ESP32 reported STEADY: handle roll 29.9, pitch 20.1 - motors roll -30.1, pitch -20.1: the camera at roll -0.1, pitch 0.1. The pitch driver's pop-up shows the three duties (39, 66 and 44 %) adding up to one 1.99 V voltage vector, 0.46 A in the windings: the field that holds the pitch motor's magnets 20 degrees back.

Figure: Rolled 30 and pitched 20: the camera still level.
Figure: Both motors at work.
Figure: The pitch motor holding.
Figure: The SimpleFOC Mini: three duties, one voltage vector.
Figure: The BNO055: roll 30, pitch 20.

Level Again, and a Shake

At 11 s the handle came back to level and both motors returned to zero, the camera within 1.4 degrees on the way. At 13 s came the shake. The BNO055's Shake scene is mostly vibration: its accelerometer jumps, but the fused angles moved by only 1.6 degrees, and the camera stayed within 0.6 degrees. A real hand shakes the angles more; the 400 degrees a second of slew is what limits how much of a fast shake the motors can follow.

Figure: The shake: the camera held within 0.6 degrees.
Figure: The BNO055 shaken: the angles barely move.
Figure: The roll motor during the shake.

Aiming the Camera From the Dashboard

After the turn to 45 degrees the dashboard showed everything level. We clicked DOWN 30: the pitch motor turned to -30 degrees and the camera looked 30 degrees down, the error counter ignoring the moment the target jumped. Then we rolled the handle 30 degrees with the BNO055's Roll 30 chip: at 24.62 s the motors were at roll -30.1 and pitch -30.1, and the camera at roll 0.1 and pitch -30.2. Stabilizing and aiming work together, because the rule is simply motor = target - handle on each axis.

Figure: The dashboard: the handle, the motors and the camera.
Figure: DOWN 30 clicked.
Figure: The camera looking 30 degrees down.
Figure: TILT -30: the pitch motor at -30.
Figure: The pitch motor at -30.
Figure: Looking down while the handle rolls.
Figure: The roll motor compensates, the pitch motor keeps the aim.
Figure: The roll motor at -30 again.

A Pole Slip

Then we broke it on purpose. On the pitch motor's pop-up we chose the 25 mN.m load, a brake stronger than the 15 mN.m the field can give, and clicked LEVEL. The ESP32 turned the field 30 degrees, but the rotor could not follow: the load angle reached -142 degrees, the torque reversed, and the pop-up counted 1 pole slip with the shaft still at 316.2 degrees. The ESP32 knew nothing of it: its OLED showed the pitch motor at 0.0 and the camera level. When we removed the brake, the rotor jumped to the nearest place the field could hold it: 295.6 degrees, a pole pair (51 degrees) away from where it had started. In a real gimbal the camera would now point 51 degrees off, and only an encoder would tell the controller.

Figure: LEVEL, with a brake on the pitch motor.
Figure: The field moved; the rotor stayed.
Figure: The load angle past 90 degrees: a pole slip.
Figure: The ESP32 cannot see the slip.
Figure: With the brake gone: held a pole pair away.

Motors Off

Last, OFF pulled EN low: both drivers showed DISABLED with all six switches open, no current flowed, and the motors stopped holding. The phone shows the same dashboard as the laptop, and the serial monitor holds every event of the run.

Figure: OFF from the dashboard.
Figure: The motors off.
Figure: The driver: EN low, all six switches open.
Figure: The motor: no current, no field.
Figure: The phone: the same dashboard.
Figure: The serial monitor: the whole run.

On every move the camera stayed within 1.6 degrees of its target, and the one thing open loop cannot do, notice a slip, showed itself exactly as the theory says.

Download the Project Files

Click the button below to download Brushless-Gimbal-Stabilizer-ESP32-BNO055-Proteus-Simulation-v1.0.zip (about 4.1 MB, without the source code of the models):

Brushless Gimbal Stabilizer with ESP32 and BNO055 - Proteus Simulation V1.0
  • Proteus Simulation: ESP32-Brushless-Gimbal.pdsprj, ESP32_Brushless_Gimbal.hex and copies of the models.
  • Arduino Code: ESP32_Brushless_Gimbal.ino, the sketch.
  • Proteus Library Files: the LIB files of every part.
  • Proteus Model Files: the DLL models.
  • 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 the files from Proteus Model Files into the MODELS folder.
  4. Start Proteus and open the project from the Proteus Simulation folder.

Changing the Code

Open the sketch in the Arduino IDE with the TEP Boards for Proteus installed, select ESP32 Dev Module (TEP Proteus), and use Sketch > Export Compiled Binary. Put the new HEX next to the project. The supply, Vq, the pole pairs, the slew limit and the update rates are near the top.

Ideas to Extend the Project

  • Add a third motor for yaw with a "follow" mode: the camera turns with the handle, but smoothly.
  • Close the loop: put a magnetic encoder (AS5600) on each motor and run real FOC with a position PID.
  • Move the BNO055 onto the camera and turn the feed-forward into feedback, as commercial gimbals do.
  • Lower Vq while the handle is still and raise it while moving, to save power and heat.
  • Add a joystick for smooth pans and tilts, with a speed ramp.
  • Store the BNO055's calibration offsets so it starts calibrated.

From Simulation to Real Hardware

  • Balance the camera first: a balanced camera needs almost no torque, so a small Vq holds it and the motors stay cool.
  • Watch the heat: Vq / R is the current even at rest; 2 V on 8 ohm is fine, but more warms a gimbal motor quickly.
  • Supply: the SimpleFOC Mini takes 8 to 35 V; a 3S battery (about 11 V) is typical.
  • Mounting: the BNO055's axes must match the motors' axes; check the signs with the motors off first.
  • Vibration: mount the sensor on soft dampers; vibration fools the accelerometer.

Troubleshooting

  • "BNO055 not found at 0x28": SDA and SCL on D21 and D22, VIN on VCC; it needs 650 ms after power-up.
  • A motor buzzes but does not hold: EN low, no 12 V on V+, or Vq too small for the load.
  • The camera turns the wrong way: swap two of that motor's wires, or change the sign of the target.
  • The camera ends up about 51 degrees off: a pole slip; raise Vq or balance the camera better.
  • The OLED stays dark: SDA and SCL on D21 and D22, VCC on 3.3 V; it is redrawn only while the handle moves slowly.

Limitations of the Simulation

  • The motors are our library's models: three windings with a sine back-EMF, friction, a load and inertia, not every detail of a real motor.
  • The two axes are treated as independent; for large combined tilts the exact geometry needs rotation matrices or quaternions.
  • The handle's motion comes from the BNO055's scene; the motors do not move the sensor in the simulation.
  • ESP32 is a product of Espressif Systems and the BNO055 of Bosch Sensortec; this project is not made or endorsed by them or by Labcenter.

So, that was all about the Brushless Gimbal Stabilizer with ESP32 and BNO055 - Proteus Simulation. I hope it helps you understand how a turning field drives a brushless gimbal motor, why the electrical angle is seven times the shaft angle, how the load angle sets the torque, and why open loop can slip a pole without knowing it, all tested in a simulation before you balance a real camera. 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!