Go Down

Topic: multiple motors solenoids _ 1 arduino _ accelstepper (Read 1 time) previous topic - next topic

GuyJustHere

Dec 10, 2012, 05:30 pm Last Edit: Dec 10, 2012, 08:16 pm by GuyJustHere Reason: 1
3 bipolar stepper motors (LN298)
3 solenoids (NPN)
3 leds
3 buttons
1 POT

INPUT
So, I use a 19V 4.74A for the motor & a 12V 2A for the solenoid. (This sucks)
Arduino is running of USB (for now) [single power source for all in the future]

Parts
Motor https://www.sparkfun.com/products/9238
Solenoid https://www.sparkfun.com/products/10391
H-Bridge https://www.sparkfun.com/products/9479


The motors will rotate to 220 deg and reverse direction back to 0 degrees & repeat ~ 4 times.
Solenoid will be activated while stepper motors are b/w ~120-220 deg and 50-0 deg.
Each motor/solenoid will have a button to perform this process independently of the other.

I use
AccelStepper Library
setAcceleration(8000);
setMaxSpeed(600);

Will i be able to maintain these speeds if I add 2 more motors?
I, also, do not know how I would code this in order to  check if the button was pushed on each VOID loop then run the motors or solenoids without forcing a WHILE or a DELAY?
I'm sure there is a way, since i believe the accelstepper library uses the clock for delays. I just need a bit of guidance.

Code: [Select]

void loop()
{
 buttonState = digitalRead(ButPin);

   if (buttonState == HIGH) {    
     // button has been pushed
       digitalWrite(LedPin, HIGH);
       stepper.setCurrentPosition(0); //this will set the current position to 0
       stepper.enableOutputs (); //Give current to the motor
         stepper.moveTo(1);  //performs an action so motor gets some juice
         stepper.run();   //performs an action so motor gets some juice
         delay(10);//letting the motor get wild for 1 step
       for(int i=0; i<=3; i++) {
         stepper.moveTo(dist); //moves motor to dist like 220 degrees
               while (stepper.currentPosition() != dist){
                 stepper.run();
                   if (stepper.currentPosition() >= 80){
                     digitalWrite(SolPin, HIGH);
                   }else{
                     digitalWrite(SolPin, LOW);
                   }
               }
           digitalWrite(SolPin, LOW);
           delay(100); //letting the sol fall
           if(i==3)
             break;
           stepper.moveTo(-0);
                while (stepper.currentPosition() != 0){
                 stepper.run();
                   if (stepper.currentPosition() <= 50){
                     digitalWrite(SolPin, HIGH);
                   }else{
                     digitalWrite(SolPin, LOW);
                   }
                }
           digitalWrite(SolPin, LOW);
           delay(100);//letting the sol fall
       }
           delay(10);
           digitalWrite(SolPin, LOW);
           stepper.disableOutputs ();
   }
   else {
     blinkLED();
   }
   
 //Serial.print("irPin = ");
// Serial.println(val);

}

MarkT

You have provided no information on the actual motors, the power supply, the mechanical load to the motors, etc etc.
[ I won't respond to messages, use the forum please ]

GuyJustHere

INPUT
I have burnt multiple 1A H-bridges when using the same power source for all (19V  4.74A).
So, I use a 19V 4.74A for the motor & a 12V 2A for the solenoid. (This sucks)
Arduino is running of USB (Already burnt out an arduino when then other H-bridge blew, so i scared)

Parts
Motor https://www.sparkfun.com/products/9238
Solenoid https://www.sparkfun.com/products/10391
H-Bridge https://www.sparkfun.com/products/9479


PaulS

Quote
Will i be able to maintain these speeds if I add 2 more motors?

The number of motors has nothing to do with the speed that they run at.

Quote
I, also, do not know how I would code this in order to  check if the button was pushed on each VOID loop then run the motors or solenoids without forcing a WHILE or a DELAY?

What part are you needing help with? Reading the switch? Not using delay()?

The AccelStepper class takes care of making the stepper step, stopping only when it gets to the commanded position.

GuyJustHere

Quote
The number of motors has nothing to do with the speed that they run at.


False. If i am running 3 motors simultaneously using 3 separate H-bridges. I will definitely decrease the top speed that any motor can reach. 3 groups of 4 I/O pins will need to be triggered indepenently. unless accelstepper somehow groups the signals together.

PeterH


False. If i am running 3 motors simultaneously using 3 separate H-bridges. I will definitely decrease the top speed that any motor can reach.


You seem quite sure about that, which is surprising given that just yesterday you were asking whether it would make any difference. What effect is it that you think will definitely decrease the top speed?
I only provide help via the forum - please do not contact me for private consultancy.

Cue2

#7
Dec 27, 2012, 02:16 am Last Edit: Dec 27, 2012, 02:17 am by Cue2 Reason: 1


False. If i am running 3 motors simultaneously using 3 separate H-bridges. I will definitely decrease the top speed that any motor can reach.


You seem quite sure about that, which is surprising given that just yesterday you were asking whether it would make any difference. What effect is it that you think will definitely decrease the top speed?


The speed at which the atmega itself executes instructions will limit speed for a given mode.

For example this is a quote from Brian Schmalz (creator of the EasyDriver) with an accelstepper example:

Quote
If you run this code, you may find that the acceleration and deceleration are not quite as smooth as with a single motor (on an Arduino - again, this problem doesn't occur on chipKIT) - that is because our two maximum speeds (3000 and 1000) are pretty high for the ability of the processor to handle them. One solution is to make your max speeds lower, then switch from 1/8th microstepping to 1/4, half, or full step mode. If done right, you'll see the same shaft rotation speeds, but with less CPU load (because you aren't generating as many steps per second.)


As for the initial question of avoiding delays or while loops; as far as I know and I could be wrong accelstepper does one (micro)step for every stepper.run() so you can't avoid long while loops. I think there is no reason why you can't use Attachinterrupt() or an ISR function though. If there is a better way with the accelstepper library then I too would like some info on it as I'm currently doing a similar thing.

Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:

shortcuts: alt+s submit/post or alt+p preview