Pages: [1]   Go Down
Author Topic: multiple motors solenoids _ 1 arduino _ accelstepper  (Read 912 times)
0 Members and 1 Guest are viewing this topic.
Miami
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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);

}
« Last Edit: December 10, 2012, 02:16:56 pm by GuyJustHere » Logged

0
Offline Offline
Shannon Member
****
Karma: 200
Posts: 11694
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You have provided no information on the actual motors, the power supply, the mechanical load to the motors, etc etc.
Logged

[ I won't respond to messages, use the forum please ]

Miami
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Miami
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

bumps
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Miami
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12568
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 1
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: December 26, 2012, 08:17:48 pm by Cue2 » Logged

Pages: [1]   Go Up
Jump to: