Connect stepper to Arduino/ESP32
Posted: Tue Sep 12, 2023 10:56 am
Hello,
I am complete newbie in electronic. I have suceeded to connect my stepper motor to the DM542T stepper driver and to an arduino UNO like this:
So now I am trying to use my ESP-32 and I have connected like this. But of course if I am here it is because it doesn't work
Here is the pin diagram provided by Az-Delivery:
As I will also connect a screen I would like to use only the free pin left:
I have use the exact same program on both except that I have modify the PIN_DIR and PIN_PUL to adapt the the correct pins I have used.
Did I missed something?
Regards,
I am complete newbie in electronic. I have suceeded to connect my stepper motor to the DM542T stepper driver and to an arduino UNO like this:
So now I am trying to use my ESP-32 and I have connected like this. But of course if I am here it is because it doesn't work
Here is the pin diagram provided by Az-Delivery:
As I will also connect a screen I would like to use only the free pin left:
I have use the exact same program on both except that I have modify the PIN_DIR and PIN_PUL to adapt the the correct pins I have used.
Code: Select all
#include <Arduino.h>
#include "StepperMotor.h"
// Define pins for the motor
const int dirPin = 8; // DIR+
const int stepPin = 9; // PUL
// Create an instance of the StepperMotor class
StepperMotor myStepper(dirPin, stepPin);
void setup() {
// No need for setup here, everything is handled in the class constructor
}
void loop() {
// Rotate the motor 1000 steps in one direction
myStepper.moveStepperTo(1000);
delay(1000); // Wait for one second
// Rotate the motor 1000 steps in the other direction
myStepper.moveStepperTo(0);
delay(1000); // Wait for one second
}
Code: Select all
#ifndef STEPPER_MOTOR_H
#define STEPPER_MOTOR_H
#include <AccelStepper.h>
class StepperMotor {
private:
AccelStepper stepper;
const int dirPin;
const int stepPin;
public:
StepperMotor(int dirPin, int stepPin);
void moveStepperTo(int position);
};
#endif // STEPPER_MOTOR_H
Regards,