Closed cezarg1410 closed 1 year ago
I've just done futher checks and here is the interesting part. Consider following part of code
if (leftStepper && rightStepper) {
leftStepper->setDirectionPin(14);
leftStepper->setEnablePin(ENABLE_PIN);
leftStepper->setAutoEnable(true);
leftStepper->setSpeedInHz(1000); // 500 steps/s
leftStepper->setAcceleration(500); // 100 steps/s²
rightStepper->setDirectionPin(27);
rightStepper->setEnablePin(ENABLE_PIN);
rightStepper->setAutoEnable(true);
rightStepper->setSpeedInHz(1000); // 500 steps/s
rightStepper->setAcceleration(500); // 100 steps/s²
Serial.println("Direction pins: ");
Serial.println(leftStepper->getDirectionPin());
Serial.println(rightStepper->getDirectionPin());
}
The output should be 27 and 14. But it its:
Direction pins:
27
27
The code was wrong. It should't create separate FastAccelStepperEngine
Instead it should be:
FastAccelStepperEngine engine = FastAccelStepperEngine();
FastAccelStepper *leftStepper = NULL;
FastAccelStepper *rightStepper = NULL;
void setup() {
SerialBT.begin("ESP32test"); //Bluetooth device name
engine.init();
leftStepper = engine.stepperConnectToPin(STEP_LEFT_PIN);
rightStepper = engine.stepperConnectToPin(STEP_RIGHT_PIN);
if (leftStepper && rightStepper) {
leftStepper->setEnablePin(ENABLE_PIN);
leftStepper->setAutoEnable(true);
leftStepper->setSpeedInHz(2000);
leftStepper->setAcceleration(500);
leftStepper->setDirectionPin(DIR_LEFT_PIN);
rightStepper->setEnablePin(ENABLE_PIN);
rightStepper->setAutoEnable(true);
rightStepper->setSpeedInHz(2000);
rightStepper->setAcceleration(500);
rightStepper->setDirectionPin(DIR_RIGHT_PIN);
}
}
Hello, I am trying to build a robot with four stepper engines. They will work in pairs (left and right).
The thing is: i develoepd very simple programm to controll my robot. But the problem is that only one stepper is controller well - the second one always moves forward (no chance to move it back).
So i uplaoded my code into ESP32 WROOOM and removed that esp from robot. Here is what i can see:
runBackward
and 3.3V when i run commandrunForward
Here is my code: