Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

AccelStepper used with stepper shield 1438
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

AccelStepper used with stepper shield 1438

by efrank03gps on Tue Jun 27, 2017 4:48 pm

what is MaxSpeed and Acceleration? Units? Adafruit's description of 1438 is it works with 5 wire unisteppers, but AccelStepper says only 4 and 6. Should I choose step0, step1, step2, or step4 for a 5 wire stepper? To move each wheel a specific number of steps should I use moveto() or just put run() in a FOR loop? The two wheels (steppers) will be running for exactly the same time but at different rates. Can runSpeedToPosition() be used simultaneously for the two steppers (running at different speeds but for the same length of time, so going to different positions) or is that command a blocking one (so using that command for motor1 would block execution of the same command for motor2)? Is there an example file that would do this? Thanks for your input!

efrank03gps
 
Posts: 22
Joined: Tue Oct 23, 2012 10:56 am

Re: AccelStepper used with stepper shield 1438

by adafruit_support_bill on Tue Jun 27, 2017 4:58 pm

A 6 wire steppers can be wired as either 4-wire bipolar (leaving the center taps unconnected) or as 5-wire unipolar (connecting both center taps to ground).

A 5 wire steppers can only be wired unipolar (common center-tap to ground).

A 4-wire steppers can only be wired as bipolar.

For details on the AccelStepper library, check the Airspayce site: http://www.airspayce.com/mikem/arduino/AccelStepper/

adafruit_support_bill
 
Posts: 78748
Joined: Sat Feb 07, 2009 10:11 am

Re: AccelStepper used with stepper shield 1438

by efrank03gps on Wed Jun 28, 2017 4:29 pm

Is this stepper shield (1438) available without the connectors, headers, etc already soldered onto the board? I am using this shield in making many robots for teaching, and it is a nuisance to have to unsolder all these connectors and headers on each board to make it suitable for the robots. Please advise. Thanks! Eric

efrank03gps
 
Posts: 22
Joined: Tue Oct 23, 2012 10:56 am

Re: AccelStepper used with stepper shield 1438

by adafruit_support_bill on Wed Jun 28, 2017 4:46 pm

There are a few options:
The shield comes with the terminal blocks installed, but the headers separate.
Image

We have a "Feather Wing" version of the same circuit which has no headers or terminal blocks installed.
https://www.adafruit.com/product/2927
Image


There are also breakouts for just the TB6612 H-bridge chips. These have no terminals or headers installed:
https://www.adafruit.com/product/2448
Image

adafruit_support_bill
 
Posts: 78748
Joined: Sat Feb 07, 2009 10:11 am

Re: AccelStepper used with stepper shield 1438

by efrank03gps on Tue Jul 11, 2017 4:44 pm

The 1438 shield is working well, thanks to your previous help. But is there a way of turning off the power to the shield with an I2C command when stepping is not needed? The AccelStepper.cpp has a disableOutputs() command that kills power to the steppers themselves (and that works fine), but the shield is still drawing the same current from the Power connection right next to the green LED. When a program is first uploaded to the Arduino to run the shield, no power is drawn, even after executing all the commands up to running the steppers (ie the commands in setup), but after the steppers are activated, the shield continues to draw the same current after the steppers stop that it does when the steppers are running. Is there a command I have not found yet that cuts the power to the board? Obviously I still need to power the board itself with the 5V output from the Arduino but it would be very helpful if the shield didn't draw much power when the steppers are off.
Thanks for your help with this.
Eric

efrank03gps
 
Posts: 22
Joined: Tue Oct 23, 2012 10:56 am

Re: AccelStepper used with stepper shield 1438

by adafruit_support_bill on Tue Jul 11, 2017 4:58 pm

The Adafruit stepper motor object that AccelStepper is using to actually move the motor has a "release()" function. You need to call that to cut power to the motor.

adafruit_support_bill
 
Posts: 78748
Joined: Sat Feb 07, 2009 10:11 am

Re: AccelStepper used with stepper shield 1438

by efrank03gps on Tue Jul 11, 2017 5:16 pm

The release function cuts power to the motors, but that leaves power still being consumed by the shield. I measured the current going into the Power contacts, and it stays the same even when the steppers are not powered. I measured the voltage on the motor connectors, and indeed it is 0 when the Release command is issued. But the current supplied to the Power contacts stays the same. Maybe something is wrong with my board? Here is the release command:
void Adafruit_StepperMotor::release(void) {
MC->setPin(AIN1pin, LOW);
MC->setPin(AIN2pin, LOW);
MC->setPin(BIN1pin, LOW);
MC->setPin(BIN2pin, LOW);
MC->setPWM(PWMApin, 0);
MC->setPWM(PWMBpin, 0);
}
That turns off power to the motors, as you say, but for my shield at lease, not to the Power contacts.

efrank03gps
 
Posts: 22
Joined: Tue Oct 23, 2012 10:56 am

Re: AccelStepper used with stepper shield 1438

by adafruit_support_bill on Tue Jul 11, 2017 5:24 pm

You will still have a small amount of power consumed by the LED. Other than that, there should be nothing on the board that consumes motor power - unless you have the VIN jumper installed - in which case it will be supplying power to the Arduino as well.

adafruit_support_bill
 
Posts: 78748
Joined: Sat Feb 07, 2009 10:11 am

Re: AccelStepper used with stepper shield 1438

by efrank03gps on Tue Jul 11, 2017 5:54 pm

Must be that I did something bad to my board. I was supplying jumper connections from Vin, 5V, 3V and Gnd because I have not stacked the shield on the Arduino. But I just unplugged all the connections except 5V and GND (and of course A4 and A5) and made sure the jumper on the shield was off, and still get the same result. Zero power to the Power Motor connection on the shield when I first turn it on, but then stays at 0.5 amps after the steppers are run once. I'll try a new shield.

efrank03gps
 
Posts: 22
Joined: Tue Oct 23, 2012 10:56 am

Re: AccelStepper used with stepper shield 1438

by adafruit_support_bill on Tue Jul 11, 2017 6:02 pm

Please post the code you are using.

adafruit_support_bill
 
Posts: 78748
Joined: Sat Feb 07, 2009 10:11 am

Re: AccelStepper used with stepper shield 1438

by efrank03gps on Tue Jul 11, 2017 7:54 pm

Here is the code. I have taken out the comments that Adafruit added at the top:

Code: Select all | TOGGLE FULL SIZE
#include <AccelStepper.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"

Adafruit_MotorShield AFMS(0x60); // Default address, no jumpers

// Connect two steppers with 513 steps per revolution (0.7 degree)

Adafruit_StepperMotor *myStepper1 = AFMS.getStepper(513, 1);
Adafruit_StepperMotor *myStepper2 = AFMS.getStepper(513, 2);

void forwardstep1() { 
  myStepper1->onestep(FORWARD, SINGLE);
}
void backwardstep1() { 
  myStepper1->onestep(BACKWARD, SINGLE);
}
// wrappers for the second motor!
void forwardstep2() { 
  myStepper2->onestep(BACKWARD, SINGLE);
}
void backwardstep2() { 
  myStepper2->onestep(FORWARD, SINGLE);
}

// Now we'll wrap the 2 steppers in an AccelStepper object
AccelStepper stepper1(forwardstep1, backwardstep1);
AccelStepper stepper2(forwardstep2, backwardstep2);

void setup()

  AFMS.begin(); // Start I2C
  }

void loop(){
  stepper1.setSpeed(900);
  stepper1.move(450);  //relative to current position
  stepper2.setSpeed(100);
  stepper2.move(500);  //relative to current position
   
  while (stepper1.distanceToGo() > 0){
    stepper1.runSpeed();
    stepper2.runSpeed();  //should stop when stepper1 finishes
                          //even if not done for stepper2
    }
  stepper1.disableOutputs();  //these don't disconnect the power to the shield
  stepper2.disableOutputs();
  delay(2000);  //was power removed?  yes from motors, not from shield.


Thanks for taking the time to look at this.
Eric
Last edited by adafruit_support_bill on Tue Jul 11, 2017 8:02 pm, edited 1 time in total.
Reason: please use [code] tags when posting code to the forums

efrank03gps
 
Posts: 22
Joined: Tue Oct 23, 2012 10:56 am

Re: AccelStepper used with stepper shield 1438

by efrank03gps on Tue Jul 11, 2017 7:55 pm

Here is the code. I have taken out the comments that Adafruit added at the top:

Code: Select all | TOGGLE FULL SIZE
#include <AccelStepper.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"

Adafruit_MotorShield AFMS(0x60); // Default address, no jumpers

// Connect two steppers with 513 steps per revolution (0.7 degree)

Adafruit_StepperMotor *myStepper1 = AFMS.getStepper(513, 1);
Adafruit_StepperMotor *myStepper2 = AFMS.getStepper(513, 2);

void forwardstep1() { 
  myStepper1->onestep(FORWARD, SINGLE);
}
void backwardstep1() { 
  myStepper1->onestep(BACKWARD, SINGLE);
}
// wrappers for the second motor!
void forwardstep2() { 
  myStepper2->onestep(BACKWARD, SINGLE);
}
void backwardstep2() { 
  myStepper2->onestep(FORWARD, SINGLE);
}

// Now we'll wrap the 2 steppers in an AccelStepper object
AccelStepper stepper1(forwardstep1, backwardstep1);
AccelStepper stepper2(forwardstep2, backwardstep2);

void setup()

  AFMS.begin(); // Start I2C
  }

void loop(){
  stepper1.setSpeed(900);
  stepper1.move(450);  //relative to current position
  stepper2.setSpeed(100);
  stepper2.move(500);  //relative to current position
   
  while (stepper1.distanceToGo() > 0){
    stepper1.runSpeed();
    stepper2.runSpeed();  //should stop when stepper1 finishes
                          //even if not done for stepper2
    }
  stepper1.disableOutputs();  //these don't disconnect the power to the shield
  stepper2.disableOutputs();
  delay(2000);  //was power removed?  yes from motors, not from shield.


Thanks for taking the time to look at this.
Eric
Last edited by adafruit_support_bill on Tue Jul 11, 2017 8:03 pm, edited 1 time in total.
Reason: please use [code] tags when posting code to the forums

efrank03gps
 
Posts: 22
Joined: Tue Oct 23, 2012 10:56 am

Re: AccelStepper used with stepper shield 1438

by adafruit_support_bill on Tue Jul 11, 2017 8:06 pm

Where is the release() function being called? I don't see it in the code posted above.

The AccelStepper disableOutputs() function does not really do anything when used with the shield. You need to call release() to cut power to the motor.

adafruit_support_bill
 
Posts: 78748
Joined: Sat Feb 07, 2009 10:11 am

Re: AccelStepper used with stepper shield 1438

by efrank03gps on Wed Jul 12, 2017 3:52 pm

None of the example files in Adafruit_MotorShield illustrate the use of release(). The example MotorParty does use release(), but only to do something for a DC motor, not a stepper.

// turn on motor M1
myMotor->setSpeed(200);
myMotor->run(RELEASE);

Older example files in this folder (from 2011) did have two examples claiming to use release for steppers, but I couldn’t get them to work. The first one didn’t even use the word “release” in the file, and the 2nd one (“Try2”) had an error and would not compile. The current version I just downloaded (from December, 2016) eliminated these two examples.

The release() command in Adafruit_MotorShield.cpp makes all 4 pins LOW, which it does, but current is still drawn from the Power contacts on the board. And it’s not clear how this command should be called. As
myStepper1->onestep(RELEASE, SINGLE); ? (that’s how it is listed in the old “Try2” example)

void Adafruit_StepperMotor::release(void) {
MC->setPin(AIN1pin, LOW);
MC->setPin(AIN2pin, LOW);
MC->setPin(BIN1pin, LOW);
MC->setPin(BIN2pin, LOW);
MC->setPWM(PWMApin, 0);
MC->setPWM(PWMBpin, 0);
}

The disableOutputs command in AccelStepper.cpp appears to do exactly the same thing. So why isn’t one of these commands the “same” as the other? And neither one reduces the current being supplied to the Power contacts on the board.

// Prevents power consumption on the outputs
void AccelStepper::disableOutputs()
{
if (! _pins) return;

digitalWrite(_pin1, LOW);
digitalWrite(_pin2, LOW);
if (_pins == 4)
{
digitalWrite(_pin3, LOW);
digitalWrite(_pin4, LOW);
}
}

Can you provide an example file that shows how release() or disableOutputs() is used to turn off stepper power to the board?

Thanks,
Eric

efrank03gps
 
Posts: 22
Joined: Tue Oct 23, 2012 10:56 am

Re: AccelStepper used with stepper shield 1438

by adafruit_support_bill on Wed Jul 12, 2017 4:45 pm

Release() is a function of the Adafruit_StepperMotor class. AS such, you need to call it on an instance of Adafruit_StepperMotor. You have two instances declared in your code:

Code: Select all | TOGGLE FULL SIZE
Adafruit_StepperMotor *myStepper1 = AFMS.getStepper(513, 1);
Adafruit_StepperMotor *myStepper2 = AFMS.getStepper(513, 2);


So when you want to call release(), you call it on the ones you have declared:

Code: Select all | TOGGLE FULL SIZE
myStepper1->release();
myStepper2->release();

adafruit_support_bill
 
Posts: 78748
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.