# Running two motors on one ESP32

**URL:** https://community.simplefoc.com/t/running-two-motors-on-one-esp32/7894
**Category:** applications
**Created:** [December 28, 2025, 10:42am UTC](https://community.simplefoc.com/t/running-two-motors-on-one-esp32/7894 "2025-12-28T10:42:14Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![leon1](https://community.simplefoc.com/letter_avatar_proxy/v4/letter/l/a88e57/32.png) [@leon1](https://community.simplefoc.com/u/leon1)
#### Post date: [December 28, 2025, 10:42am UTC](https://community.simplefoc.com/t/running-two-motors-on-one-esp32/7894/1 "2025-12-28T10:42:15Z")

</div>

Hello guys!

Just a quick question for you, if I want to control two motors with one ESP32 is it possible to do it like this or do I need to use RTOS or some other operating system?

Here is the code I was talking about

> #include \<SimpleFOC.h\>
> 
> #define M1\_PWM\_U 16

> #define M1\_PWM\_V 4

> #define M1\_PWM\_W 32
> 
> #define M1\_HA 25
> 
> #define M1\_HB 26
> 
> #define M1\_HC 27
> 
> #define M2\_PWM\_U 27
> 
> #define M2\_PWM\_V 26
> 
> #define M2\_PWM\_W 25
> 
> #define M2\_HA 4
> 
> #define M2\_HB 15
> 
> #define M2\_HC 35
> 
> float target\_velocity\_common = 400.0; // rad/s
> 
> BLDCMotor motor1 = BLDCMotor(1);
> 
> BLDCMotor motor2 = BLDCMotor(1);
> 
> BLDCDriver3PWM driver1 = BLDCDriver3PWM(M1\_PWM\_U, M1\_PWM\_V, M1\_PWM\_W);
> 
> BLDCDriver3PWM driver2 = BLDCDriver3PWM(M2\_PWM\_U, M2\_PWM\_V, M2\_PWM\_W);
> 
> HallSensor sensor1 = HallSensor(M1\_HA, M1\_HB, M1\_HC, 1);
> 
> HallSensor sensor2 = HallSensor(M2\_HA, M2\_HB, M2\_HC, 1);
> 
> // void doA1(){sensor1.handleA();}
> 
> // void doB1(){sensor1.handleB();}
> 
> // void doC1(){sensor1.handleC();}
> 
> // void doA2(){sensor2.handleA();}
> 
> // void doB2(){sensor2.handleB();}
> 
> // void doC2(){sensor2.handleC();}
> 
> void setup() {
> 
> Serial.begin(115200);
> 
> SimpleFOCDebug::enable(&Serial);
> 
> sensor1.init();
> 
> sensor2.init();
> 
> motor1.linkSensor(&sensor1);
> 
> motor2.linkSensor(&sensor2);
> 
> driver1.voltage\_power\_supply = 12;
> 
> driver2.voltage\_power\_supply = 12;
> 
> if (!driver1.init() || !driver2.init()) {
> 
> Serial.println(“Driver init failed!”);
> 
> while (1);
> 
> }
> 
> motor1.linkDriver(&driver1);
> 
> motor2.linkDriver(&driver2);
> 
> motor1.controller = MotionControlType::velocity;
> 
> motor2.controller = MotionControlType::velocity;
> 
> motor1.voltage\_sensor\_align = 1;
> 
> motor2.voltage\_sensor\_align = 1;
> 
> motor1.PID\_velocity.P = 0.01f;
> 
> motor1.PID\_velocity.I = 0.1f;
> 
> motor1.PID\_velocity.D = 0;
> 
> motor1.voltage\_limit = 5;
> 
> motor1.PID\_velocity.output\_ramp = 100;
> 
> motor1.LPF\_velocity.Tf = 0.05f;
> 
> motor1.sensor\_direction = Direction::CW;
> 
> motor2.PID\_velocity = motor1.PID\_velocity;
> 
> motor2.voltage\_limit = motor1.voltage\_limit;
> 
> motor2.LPF\_velocity.Tf = motor1.LPF\_velocity.Tf;
> 
> motor2.sensor\_direction = Direction::CW;
> 
> motor1.init();
> 
> motor2.init();
> 
> motor1.initFOC();
> 
> motor2.initFOC();
> 
> }
> 
> void loop() {
> 
> // FOC Loops
> 
> motor1.loopFOC();
> 
> motor2.loopFOC();
> 
> motor1.move(target\_velocity\_common);
> 
> motor2.move(target\_velocity\_common);
> 
> }

---

<div class="post-metadata">

### Author: ![quentin](https://community.simplefoc.com/letter_avatar_proxy/v4/letter/q/e47c2d/32.png) [@quentin](https://community.simplefoc.com/u/quentin)
#### Post date: [December 28, 2025, 8:13pm UTC](https://community.simplefoc.com/t/running-two-motors-on-one-esp32/7894/2 "2025-12-28T20:13:46Z")

</div>

Yes, your approach will work (notice that I haven’t verified the implementation details except for one critical omission: you’re missing the `motor.motion_downsample` option, which is essential to prevent noise).

---

<div class="post-metadata">

### Author: ![leon1](https://community.simplefoc.com/letter_avatar_proxy/v4/letter/l/a88e57/32.png) [@leon1](https://community.simplefoc.com/u/leon1)
#### Post date: [December 29, 2025, 4:28pm UTC](https://community.simplefoc.com/t/running-two-motors-on-one-esp32/7894/3 "2025-12-29T16:28:16Z")

</div>

Thanks for your answer!

How exactly is the motor.motion\_downsample to implement?

---

<div class="post-metadata">

### Author: ![quentin](https://community.simplefoc.com/letter_avatar_proxy/v4/letter/q/e47c2d/32.png) [@quentin](https://community.simplefoc.com/u/quentin)
#### Post date: [December 29, 2025, 5:08pm UTC](https://community.simplefoc.com/t/running-two-motors-on-one-esp32/7894/4 "2025-12-29T17:08:22Z")

</div>

> [@leon1](#):
>
> How exactly is the motor.motion\_downsample to implement?

It’s a parameter specific to your system, just like the PID values. I usually start at 10 and modify it until my system behaves correctly.

---

<div class="post-metadata">

### Author: ![leon1](https://community.simplefoc.com/letter_avatar_proxy/v4/letter/l/a88e57/32.png) [@leon1](https://community.simplefoc.com/u/leon1)
#### Post date: [December 31, 2025, 2:46pm UTC](https://community.simplefoc.com/t/running-two-motors-on-one-esp32/7894/5 "2025-12-31T14:46:56Z")

</div>

thank you very much!
