Stepper motor haptic connection

I’m trying to use some adapted code to make a haptic connection between two nema 17 stepper motors using two as5600 sensors and l298n drivers. I am using the following code with an esp32 in the arduino ide. Unfortunately, I cant seem to get any response from the motors now matter how hard i try. Any advice would be greatly appreciated! Thanks.

Blockquote

//NOTES ABOUT ESP32
//GPIOs 34 to 39 can’t generate PWM

#include <SimpleFOC.h>

#include <Wire.h>
#define IN1_1 32
#define IN2_1 33
#define IN3_1 25
#define IN4_1 26

#define IN1_2 16
#define IN2_2 4
#define IN3_2 0
#define IN4_2 2

MagneticSensorI2C sensor0 = MagneticSensorI2C(AS5600_I2C);
MagneticSensorI2C sensor1 = MagneticSensorI2C(AS5600_I2C);

// motor instance
StepperMotor motor = StepperMotor(50); // StepperMotor(int pp, (optional R, KV))
StepperMotor motor2 = StepperMotor(50); // StepperMotor(int pp, (optional R, KV))

// driver instance
StepperDriver4PWM driver1 = StepperDriver4PWM(IN1_1, IN2_1, IN3_1, IN4_1); // StepperDriver4PWM(IN1, IN2, IN3, IN4, ENB, ENA)
StepperDriver4PWM driver2 = StepperDriver4PWM(IN1_2, IN2_2, IN3_2, IN4_2); // StepperDriver4PWM(IN1, IN2, IN3, IN4, ENB, ENA)

Commander command = Commander(Serial);
void onMotor(char* cmd){ command.motor(&motor, cmd); }

void setup() {

Serial.begin(115200);
_delay(750);

Wire.setClock(400000);
Wire1.setClock(400000);

// Normally SimpleFOC will call begin for i2c but with esp32 begin() is the only way to set pins!
// It seems safe to call begin multiple times
Wire1.begin(16, 17, (uint32_t)400000);

sensor0.init();
sensor1.init(&Wire1);

// link motor to the sensor
motor.linkSensor(&sensor0);
motor2.linkSensor(&sensor1);

// choose FOC modulation
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
motor2.foc_modulation = FOCModulationType::SpaceVectorPWM;

// power supply voltage [V]
driver1.voltage_power_supply = 12;
driver1.init();
driver2.voltage_power_supply = 12;
driver2.init();

// link the motor to the sensor
motor.linkDriver(&driver1);
motor2.linkDriver(&driver2);

// motor limits
motor.current_limit = 1.0;
motor2.current_limit = 1.0;

// set control loop to be used
motor.controller = MotionControlType::torque;
motor2.controller = MotionControlType::torque;

// initialise motor
motor.init();
motor2.init();

// align encoder and start FOC
motor.initFOC();
motor2.initFOC();
motor.useMonitoring(Serial);
command.add(‘M’,onMotor,“my motor”);

_delay(1000);

}

void loop() {

motor.loopFOC();
motor.move(5*(motor2.shaft_angle - motor.shaft_angle));
motor2.loopFOC();
motor2.move(5*(motor.shaft_angle - motor2.shaft_angle));
motor.monitor();
command.run();
}

Blockquote

I’m guessing your sensors are returning angles but the motors are not moving.

The l298n, I believe, requires 6pins to be connected but your code suggests you only have 4 pins connected or you’ve forgotten to specify ENA and ENB pins in StepperDriver4PWM constructor.

Maybe this old thread might help, their StepperDriver4PWM has 6 pins defined: