Hello SimpleFOC Community,
First of all, thank you very much for developing and maintaining such a wonderful project.
I have been studying the SimpleFOC library source code and experimenting with it for about 20 days, but unfortunately I have not been able to get my motor to rotate correctly.
My setup is:
-
SimpleFOC Shield v3.2
-
Motor: ipower motor gm4108
I purchased the SimpleFOC Shield v3.2 from AliExpress because it was out of stock in the official store.
I am a beginner in electronics and motor control, so I honestly do not know whether the problem is caused by my code, wiring, hardware setup, or my misunderstanding of the library.
I would greatly appreciate any advice or guidance. If there is any information missing, please let me know and I will provide it immediately.
Thank you very much for your time and assistance.
The code is shown below:
// Open loop motor control example
#include <SimpleFOC.h>
BLDCMotor motor = BLDCMotor(7);
BLDCDriver3PWM driver = BLDCDriver3PWM(6, 10, 5, 8);
float target_velocity = 2;
Commander command = Commander(Serial);
void doTarget(char* cmd) { command.scalar(&target_velocity, cmd); }
void doLimit(char* cmd) { command.scalar(&motor.voltage_limit, cmd); }
void setup() {
Serial.begin(115200);
SimpleFOCDebug::enable(&Serial);
driver.voltage_power_supply = 12;
driver.voltage_limit = 6;
if(!driver.init()){
Serial.println(“Driver init failed!”);
return;
}
motor.linkDriver(&driver);
motor.voltage_limit = 3; // [V]
motor.controller = MotionControlType::velocity_openloop;
if(!motor.init()){
Serial.println(“Motor init failed!”);
return;
}
command.add(‘T’, doTarget, “target velocity”);
command.add(‘L’, doLimit, “voltage limit”);
Serial.println(“Motor ready!”);
Serial.println(“Set target velocity [rad/s]”);
_delay(1000);
}
void loop() {
motor.move(target_velocity);
command.run();
}
The serial monitor output is shown below:
MOT: Init
MOT: Enable driver.
Motor ready!
Set target velocity [rad/s]

Thank you very much for your help. That was exactly the issue. I was using the latest SimpleFOC library, and the motor would not rotate with the original example code. I was using the Arduino IDE example:
– colapunchExamples -> Examples from Custom Libraries -> Simple FOC -> Motion Control -> Open Loop Motor Control -> open_loop_velocity_example(open_loop_velocity_example.ino) and it appears thatmotor.loopFOC();was missing from that example. After addingmotor.loopFOC();to the main loop, the motor started rotating correctly. I truly appreciate your help and guidance. Thank you again fo