Ola, I'm connecting a DM452t to NEMA 23 to Arduino Leonardo to joystick. I can get the data from the joystick but I cannot get the motor to move. I've connected the DM452t to motor black to A+, green to A-, red to B+, and blue B-. My code is:
// Define pins for DM452T Driver
const int stepPin = 5; // PUL+ for Driver
const int dirPin = 6; // DIR+ for Driver
const int enablePin = 7; // ENA+ for Driver (optional)
// Define pin for joystick Y-axis
const int joyYAxis = A1;
// RPM settings
const int rpm = 60; // Set desired RPM
const int stepsPerRevolution = 200; // Set based on your stepper motor
const int stepDelay = 60000000L / (rpm * stepsPerRevolution); // Calculate delay between steps
// Variables to store joystick value
int joyYValue;
void setup() {
// Set pin modes for the stepper driver
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(enablePin, OUTPUT);
// Enable the driver (assuming LOW enables the driver)
digitalWrite(enablePin, LOW);
// Initialize serial communication for debugging
Serial.begin(9600);
}
void loop() {
// Read the value from the joystick Y-axis
joyYValue = analogRead(joyYAxis);
// Print joystick value to the serial monitor (for debugging)
Serial.print("Joystick Y: ");
Serial.println(joyYValue);
// Set motor direction based on joystick value
if (joyYValue > 512) {
digitalWrite(dirPin, HIGH); // Set direction to forward
} else {
digitalWrite(dirPin, LOW); // Set direction to backward
}
// Move motor
digitalWrite(stepPin, HIGH);
delayMicroseconds(stepDelay);
digitalWrite(stepPin, LOW);
delayMicroseconds(stepDelay);
// Add a small delay before the next loop
delay(10); // Adjust as needed
}
Any help is much appreciated