I am operating two stepper motors with two sperate drivers from Arduino Mega 2560 rev3. The steppers will be operating at the same time speed and direction. My Question is can I use one pin for step on both and one pin for direction on both. Meaning only use enough pins to run one but have them trigger both. I've looked on the forms didn't seem to find a clear answer.
Why do you want to do this ?
Have you really run out of pins on the Mega ?
Probably. Try it and let us know if it works.
This build is for the b9 from lost in space. Trying to have less wires because there are a lot and space is tight I've already done the wiring outside the body of the b9 with 4 motors and there own pins just seeing if i can save myself the trouble of having to keep track of and ungodly amout of wires every little bit helps. There are lights and other motors, pneumatics and lots of other stuff crammed in there. oh also some neon lights and voice playback. Voice playback needs a different solution though but as I said lots to keep track of
Is it full scale?
yes
Yes. Dual Z-axis 3d printers do this. The popular Protoneer CNC shield for an Uno does this cloning with jumpers on the board:
4th Axis Configuration
Using two jumpers the 4th axis can be configured to clone the X or Y or Z axis. It can also run as an individual axis by using Digital Pin 12 for Stepping signal and Digital Pin 13 as direction signal. (GRBL only supports 3 axis’s at the moment)
only need the two everything else is different timing
only pointing out that cloning stepper drivers signals is a common feature tested and demonstrated by the wide availability of commercially available driver boards.
Love it!!!!!
That looks awesome!
code compiles right but any suggestions on efficiency would be greatly appreciated have not tested yet and more to be added
//NEW CODE
const byte ButtonPin = 22;
const byte PinPul1 = 5;
const byte PinDir1 = 4;
const byte PinPul2 = 7;
const byte PinDir2 = 6;
const byte PinPul3 = 9;
const byte PinDir3 = 8;
const byte PinOut1 = 34;
const byte PinOut2 = 35;
const byte PinOut3 = 36;
const byte PinOut4 = 37;
const byte PinOut5 = 38;
const byte PinOut6 = 39;
const byte PinOut7 = 40;
const byte PinOut8 = 41;
const byte ENABLE_PIN1 = 32;
const byte ENABLE_PIN2 = 33;
const byte ENABLE_PIN3 = 27;
byte butState;
bool run = false;
int x = 0;
int Cnt = 25000; // 25000;
void setup ()
{
Serial.begin (115200);
pinMode (PinPul1, OUTPUT);
pinMode (PinDir1, OUTPUT);
pinMode (PinPul2, OUTPUT);
pinMode (PinDir2, OUTPUT);
pinMode (PinPul3, OUTPUT);
pinMode (PinDir3, OUTPUT);
digitalWrite (PinDir1,HIGH);
digitalWrite (PinDir2,HIGH);
pinMode (PinOut1, OUTPUT);
pinMode (PinOut2, OUTPUT);
pinMode (PinOut3, OUTPUT);
pinMode (PinOut4, OUTPUT);
pinMode (PinOut5, OUTPUT);
pinMode (PinOut6, OUTPUT);
pinMode (PinOut7, OUTPUT);
pinMode (PinOut8, OUTPUT);
pinMode (ButtonPin, INPUT_PULLUP);
butState = digitalRead (ButtonPin);
pinMode(ENABLE_PIN1, OUTPUT);
pinMode(ENABLE_PIN2, OUTPUT);
digitalWrite(ENABLE_PIN1, LOW); // Disable motor controller initially
digitalWrite(ENABLE_PIN2, LOW);
}
void loop ()
{
byte but = digitalRead (ButtonPin);
if (butState != but) {
butState = but;
delay (20); // debounce
if (LOW == but) {
if (! run) {
Serial.println ("run");
run = true;
x = 0;
// Energize Valve
digitalWrite (PinOut1, LOW);
digitalWrite (PinOut2, HIGH);
digitalWrite (PinOut3, HIGH);
digitalWrite (PinOut4, LOW);
digitalWrite (PinOut5, LOW);
digitalWrite (PinOut6, HIGH);
digitalWrite (PinOut7, HIGH);
digitalWrite (PinOut8, LOW);
// Enable motor controller
digitalWrite(ENABLE_PIN1, HIGH);
digitalWrite(ENABLE_PIN2, HIGH);
}
else {
Serial.println ("stop");
run = false;
// de-Energize Valve
digitalWrite (PinOut1, HIGH);
digitalWrite (PinOut2, LOW);
digitalWrite (PinOut3, LOW);
digitalWrite (PinOut4, HIGH);
digitalWrite (PinOut5, HIGH);
digitalWrite (PinOut6, LOW);
digitalWrite (PinOut7, LOW);
digitalWrite (PinOut8, HIGH);
// Disable motor controller
digitalWrite(ENABLE_PIN1, LOW);
digitalWrite(ENABLE_PIN2, LOW);
}
}
}
// step motor up to Cnt times
if (run) {
// generate pulse
digitalWrite (PinPul1,HIGH);
delayMicroseconds (10);
digitalWrite (PinPul1,LOW);
delayMicroseconds (10);
digitalWrite (PinPul2,HIGH);
delayMicroseconds (10);
digitalWrite (PinPul2,LOW);
delayMicroseconds (10);
}
}
A set of variables with a numeric suffix always shouts "consider using arrays" instead
lol. Easy for my brain to sus out when writing
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.