Jump to content

NLCbanner2024.jpg.2478be509670e60c2d6efd04834b8b47.jpg

Arduino uno control of 2 stepper motors ?


fwm891

Recommended Posts

I want to control a second stepper motor via an arduino uno and 2 Easy Driver boards. I have 1 working at the moment controlling a focuser and want to control a second focuser independently of the first (don't want both running at the same time), I'm sure this must be possible but how?

I'm running the first motor via an SGL sketch which allows me to tell the motor to turn 'x' number of steps in or out. I'd like to do the same with the second motor...

Link to comment
Share on other sites

Just write the software. Nothing is totally for free in the Arduino world. Use the sketch you have as a base and write more code. It is more or less standard C/C++ code so nothing out of the ordinary. I published a skeleton stepper application in another thread. It can be used to control umpteen steppers if you like ;)

Here it is:

//Assume buttons go high...//This is not complete in any way but illustrates how to code//so that the thing never stands in daly loops more than absolutely//necessary.int buttonCount = 0;int lastButtonState = LOW;int prescale = 100;bool stepping = false;void loop(){    delayMicroSeconds(100);    if (--prescale < 0)    {    // inner loop. Handle buttons first        if (digitalRead(button) == lastButtonState)        {            buttonCount++;            if (buttonCount > 5)            {                  //button was the same for five successive loops                  //set stepping flag to whatever the button was                  stepping = (lastButtonState == HIGH);             }        }        else        {            //button is different to last time - reset counter            buttonCount = 0;            lastButtonState = (lastButtonState == HIGH ? LOW : HIGH);        }//next thing in inner loop is step the motor if we're stepping//(add code for choosing direction above...)        if (stepping)        {            digitalWrite(enablePin, HIGH); //make sure we're always enabled when stepping            digitalWrite(directionPin, direction);            digitalWrite(stepPin, HIGH);            delayMicroseconds(1);            digitalWrite(stepPin, LOW);        }        else        {            //not stepping. Set enable low (only if we are not in microstep mode            digitalWrite(enablePin, LOW);        }        //do other things which fits this time interval...        //finally, reset pre-scaler        prescale = 100;    }    //This is place in the code in the outer, faster loop.    //Do important things that have to be done often}
Link to comment
Share on other sites

I too wrote a thread with an Arduino controlling 2 stepper motors.  Just add the second stepper code to the sketch and then arrange to control one or the other.  It si quite possible to control both at the same time but I didn't I just added a toggle switch to input to a digital Arduino input to select which focuser I was controlling.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. By using this site, you agree to our Terms of Use.