I am trying to build a simple motor test sketch, currently, to test a NEMA 23 stepper motor and the DM542T stepper driver.
Here is the code, and I am having trouble figuring out how to properly wire the 5-lead button (+, -, Common, NO, NC)
Here is the code
// Pin numbers
const int buttonPin = 2;
const int directionPin = 8;
const int stepPin = 9;
// Other constants
const int NumSteps = 5000; // steps
const int Speed = 500;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
pinMode(directionPin, OUTPUT);
pinMode(stepPin, OUTPUT);
digitalWrite(directionPin, LOW);
digitalWrite(stepPin, LOW);
}
void loop() {
if (digitalRead(buttonPin)) {
// Move in one direction
for (int distance = 0; distance < NumSteps; distance++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(Speed);
digitalWrite(stepPin, LOW);
delayMicroseconds(Speed);
}
// Reverse direction
digitalWrite(directionPin, !digitalRead(directionPin));
}
delay(5);
}
The button is a momentary button, so I am holding it in to simulate a latching button.
I have the buttons Common and Neg leads wired together, and connected to the Gnd pin on the Arduino (mega rev3)
I have the buttons Positive and the NC wired together and connected to pin 2.
Wiring that button in that manner, works fine in the button-controlled blink sketch, but is not working here (LED on the button doesn't light up and the motor test doesn't run).
Note:
I am using a 5 lead momentary button as that what the project these motors will be for will be using.
The DM542T Dir - and Pul - are wired to Gnd on the mega and the Dir + is pin 8 and Pul + is pin 9
Further Notes:
When I separate the common and neg and send the common to Gnd and the Negative to Pin 2, the LED is off on the Arduino and the button turns it on, but it doesn't turn on the LED on the button. If I switch those two, so common goes to Pin 2 and Negative goes to Gnd, the LED on the Arduino AND the LED on the button stay lit but the button does nothing.
Objective:
Find the proper wiring for the 5 leads so that when the button is pressed it turns on the light on the button because if it does that means it's signaled the pin and the motor functionality should work.
Any help appreciated.