Hi,
I am having some trouble with I2CCommander running 2 motors.
I am testing this with only MCUs attached (skipping motor calibration).
This is how I initialized I2CCommander on the controlling MCU (ESP32)
commander.addI2CMotors(SLAVE2_ADDRESS, 2);
commander.init();
This is how I send the commands to both motors from the controlling MCU
float targetSpeed = RPMtoRADS(req_rpm.motor1);
Serial.print(targetSpeed);
Serial.print("\t");
if (commander.writeRegister(0, REG_TARGET, &targetSpeed, 4)!=4) {
Serial.println("Error Motor 0");
}
targetSpeed = RPMtoRADS(req_rpm.motor2);
Serial.println(targetSpeed);
if (commander.writeRegister(1, REG_TARGET, &targetSpeed, 4)!=4) {
Serial.println("Error Motor 1");
}
This is how I add motors on the MCU running simpleFOC algorithm to drive the motors
commander.addMotor(&motor1); // add a motor
commander.addMotor(&motor2); // you could add more than one motor
commander.init(i2c_addr); // initialize commander
Wire2.onReceive(onReceive); // connect the interrupt handlers
Wire2.onRequest(onRequest);
To get some information what’s going on, I modified I2CCommander.cpp to provide me some output
case REG_TARGET:
Serial.print("Motor ");
Serial.print(motorNum);
Serial.print(":\t");
Serial.println(motors[motorNum]->target);
readBytes(&(motors[motorNum]->target), 4);
These are console outputs from both MCU’s - left is the MCU driving the motors, right is the controlling MCU
Either I am doing something wrong, or there is an issue with motorNum variable.
@runger I’d appreciate it if you had some time to look into this.