Hi guys,
I am a complete noob when it comes to anything Arduino and i'm working with a buddy to get our program working. Our goal is literally to just drive two stepper motors up and down on the switch command. We are using the following:
DPDT Switch: (Baomain Momentary 6 Pin DPDT Button On/Off/On Rocker Switch AC 250V/10A 125V/15A)
Stepper Motors: (STEPPERONLINE CNC Stepper Motor Nema 23)
Controllers: (SainSmart CNC Micro-Stepping Stepper Motor Driver)
Arduino DUE
The current code that we have allows the steppers to rotate CCW when we press down on our switch but nothing for the up direction. Could anyone help point us in the right direction? Current concerns are internal pull-up resistors (logic switch), pulse inversion, or the switch itself using 3.3 volts as high.
Here is the code:
// ARDUINO DUE Conrol of 2x ST-M5045 Stepper Motor Controllers
const int interval = 700; // Pulse inteval. Controls RPM
// 500 likely max speed // Full wave in 700 mircosconds
// 1000 is med speed
// 1400 is slow speed
//const int flatline = 10000000; // forced low or zero logic value for testing
boolean pulse = LOW;
void setup() {
Serial.begin(9600); // start serial connection
pinMode(8, OUTPUT); // Dir - Pin MOTOR1
pinMode(9, OUTPUT); // Pul - Pin MOTOR1
//digitalWrite(7 & 9, HIGH); // Shunt?
pinMode(3, OUTPUT); // Dir - Pin MOTOR2
pinMode(5, OUTPUT); // Pul - Pin MOTOR2
pinMode(A1, INPUT_PULLUP); // WHT. Switch Pin 1 (HOT) DPDT flipped logic setup
pinMode(A2, INPUT_PULLUP); // GRN. Switch Pin 5 (HOT) DPDT
pinMode(A4, INPUT_PULLUP); // BLK Switch Pin 2 (GND) DPDT
pinMode(A5, INPUT_PULLUP); // BLU Switch Pin 6 (GND) DPDT
pinMode(13, OUTPUT); // Onboard LED for testing
//pinMode(, INPUT_PULLUP); // Enables onboard 10k_ohm resistor
digitalWrite(8, LOW); // Low CCW / High CW MOTOR 1
digitalWrite(9, LOW); // Pulse MOTOR 1 // throwing early?
digitalWrite(3, LOW); // Low CCW / High CW MOTOR 2
digitalWrite(5, LOW); // Pulse MOTOR 2 // throwing early?
}
void loop() {
int sensorA1 = digitalRead(A1); //read pin A11 WHT (HOT)
int sensorA2 = digitalRead(A2); // Inverted logoc UP in DPDT switch (top off hot, prong 3)
int sensorA5 = digitalRead(A5); // BLU (GND)
int sensorA4 = digitalRead(A4); // GREN LED
Serial.println(sensorA1); //print out the value of the pushbutton (sceen if connected)
if (sensorA5 == HIGH) { // UP DIR Button DPDT, Blue LED ////////UP/////////
//digitalWrite(13, LOW);
digitalWrite(8, LOW); // Low CCW / High CW MOTOR 1
digitalWrite(9, pulse); // Pulse MOTOR 1 ***************
digitalWrite(3, LOW); // Low CCW / High CW MOTOR 2
digitalWrite(5, LOW); // Pulse MOTOR 2 ******************
pulse = !pulse; // inverts pulse value
//digitalWrite(9, pulse); // Writes new value to port MOTOR 1
//digitalWrite(5, pulse); // Writes new value to port MOTOR 2
delayMicroseconds(interval);
}
if (sensorA1 == HIGH) { // DOWN Dir Button DPDT, LED Pin 13 onboardLED ///DOWN//// ***works rn. toggles action
digitalWrite(13, LOW);
digitalWrite(8, HIGH); // Low CCW / High CW MOTOR 1
digitalWrite(9, LOW); // Pulse MOTOR 1
digitalWrite(3, HIGH); // Low CCW / High CW MOTOR 2
digitalWrite(5, LOW); // Pulse MOTOR 2
pulse = !pulse; // inverts pulse value
//digitalWrite(9, pulse); // Writes new value to port MOTOR 1
//digitalWrite(5, pulse); // Writes new value to port MOTOR 2
delayMicroseconds(interval);
}
else { // Neutral- No Manual DPDT Switch Input ***works rn.
//pulse = !pulse; // inverts pulse value
//digitalWrite(9, pulse); // Writes new value to port MOTOR 1
// digitalWrite(5, pulse); // Writes new value to port MOTOR 2
//delayMicroseconds(flatline);
digitalWrite(13, HIGH); // NO LED 13
}
}
//////////// Revised Lines of Code- Ref. - ////////////////////
// readingA5_0 = analogRead(A5);
//Serial.println(sensorA5);
//if (sensorA1 == HIGH) { // UP LIGHT 13
// digitalWrite(13, LOW);
//if (sensorA5 == HIGH) {
//digitalWrite(13, LOW); // DOWN LIGHT LED 13
// digitalWrite(9, HIGH); // "||" for OR /// CANNOT USE OR FN
//delayMicroseconds(interval);
//digitalWrite(9, LOW);
//delayMicroseconds(interval);
//int sensorA2 = digitalRead(A2); // GRN (HOT)
//int sensorA3 = digitalRead(A4); // BKL (GND
//pinMode(7, OUTPUT); // ENA - ALWAYS READ POS V MOTOR1