I need an example of initializing two DRV8323 on Arduino Uno

The code below doesn’t work

BLDCMotor motor = BLDCMotor(7);
BLDCMotor motorX= BLDCMotor(7);
// BLDCDriver3PWM driver = BLDCDriver3PWM(pwmA, pwmB, pwmC, Enable(optional));
BLDCDriver3PWM driver = BLDCDriver3PWM(11, 10, 9, 8);
BLDCDriver3PWM driverX = BLDCDriver3PWM(6, 5, 4, 3);
//target variable
float target_velocity = 0;
float target_velocityX = 5;
// instantiate the commander
Commander command = Commander(Serial);
void doTarget(char* cmd) { command.scalar(&target_velocity, cmd); }
void doLimit(char* cmd) { command.scalar(&motor.voltage_limit, cmd); }
void doTargetX(char* cmd) { command.scalar(&target_velocityX, cmd); }
void doLimitX(char* cmd) { command.scalar(&motorX.voltage_limit, cmd); }

What doesn’t work?
There is a lot to configure beyond just initializing the motor and driver objects

Thanks for your reply.
I repeat the project as in the example: https://docs.simplefoc.com/mini_example

My changes are the absence of encoders and a second motor.
one motor works great.

When I try to initialize and start the second motor, both do not work.
For novice hobbyists it would be nice to get an example of working with two motors.If it is possible

Good afternoon. when running the code below. only one motor is running. Where could I have gone wrong?

// Open loop motor control example
#include <SimpleFOC.h>
BLDCMotor motor = BLDCMotor(8);
BLDCMotor motorX = BLDCMotor(8);
BLDCDriver3PWM driver = BLDCDriver3PWM(6, 5, 4, 3);
BLDCDriver3PWM driverX = BLDCDriver3PWM(11, 10, 9, 8);
float target_velocity = 5;
float target_velocityX = 3;
Commander command = Commander(Serial);
Commander commandX = Commander(Serial);
void doTarget(char* cmd) { command.scalar(&target_velocity, cmd); }
void doLimit(char* cmd) { command.scalar(&motor.voltage_limit, cmd); }
void doTargetX(char* cmd) { commandX.scalar(&target_velocityX, cmd); }
void doLimitX(char* cmd) { commandX.scalar(&motorX.voltage_limit, cmd); }

void setup() {

driver.voltage_power_supply = 12;
driverX.voltage_power_supply = 12;
driver.voltage_limit = 11;
driverX.voltage_limit = 11;
driver.init();
driverX.init();
motor.linkDriver(&driver);
motorX.linkDriver(&driverX);
motor.voltage_limit = 4; // [V]
motorX.voltage_limit = 3;
motor.controller = MotionControlType::velocity_openloop;
motorX.controller = MotionControlType::velocity_openloop;

motor.init();
motorX.init();

command.add(‘T’, doTarget, “target velocity”);
command.add(‘L’, doLimit, “voltage limit”);
commandX.add(‘T’, doTarget, “target velocity”);
commandX.add(‘L’, doLimit, “voltage limit”);

Serial.begin(115200);
Serial.println(“Motor ready!”);
Serial.println(“Set target velocity [rad/s]”);

_delay(1000);
}

void loop() {
motor.move(target_velocity);
motorX.move(target_velocityX);

command.run();
commandX.run();
}

This is running on an actual “uno”? The CPU is not really up to the task of running two motors. You might try ESP32 as they cost half as much as ther Uno, are smaller but an order of magnitude more powerfull

But you might check if pins 6,5,4 suport PWM. If not try this
BLDCDriver3PWM driverX = BLDCDriver3PWM(6, 5, 3, 4);

1 Like