0

Arduino Motor Shield v2.3 and Stepper Motor Speed
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Arduino Motor Shield v2.3 and Stepper Motor Speed

by bkidd73 on Sat Feb 06, 2021 9:28 pm

Code: Select all | TOGGLE FULL SIZE
[code][/code]
Hi - I'm learning how to use the Arduino Motor Shield (v2.3) and am playing with the standard Stepper Test sketch (with only single coil steps; the others are commented out) and the stepper motor speed doesn't match the setSpeed(rpm) value in the sketch. I'm using a 5V, 4A power supply and the following NEMA 17 Stepper:

https://www.omc-stepperonline.com/nema- ... ector.html

The motor seems to be operating fine, just not at the expected speed. There actually appears to be an initial dip in motor speed when I increase the setSpeed value.

What am I missing or not understanding?

Here's the code:


Code: Select all | TOGGLE FULL SIZE
/*
This is a test sketch for the Adafruit assembled Motor Shield for Arduino v2
It won't work with v1.x motor shields! Only for the v2's with built in PWM
control

For use with the Adafruit Motor Shield v2
---->   http://www.adafruit.com/products/1438
*/


#include <Wire.h>
#include <Adafruit_MotorShield.h>

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);

// Connect a stepper motor with 200 steps per revolution (1.8 degree)
// to motor port #2 (M3 and M4)
Adafruit_StepperMotor *myMotorA = AFMS.getStepper(200, 2);


void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Stepper test!");

  AFMS.begin();  // create with the default frequency 1.6KHz
 // AFMS.begin(1000);  // OR with a different frequency, say 1KHz
 
  myMotorA->setSpeed(5);  // 10 rpm   
}

void loop() {
  Serial.println("Single coil steps");
 myMotorA->step(2000, FORWARD, SINGLE);
 delay(2000);
 //myMotorA->release();
  delay(2000);
 myMotorA->step(2000, BACKWARD, SINGLE);
 delay(2000);
 //myMotorA->release();
 delay(2000);
 
 //Serial.println("Double coil steps");
 //myMotorA->step(100, FORWARD, DOUBLE);
 //delay(1000);
 //myMotorA->step(100, BACKWARD, DOUBLE);
 //delay(1000);
 
// Serial.println("Interleave coil steps");
// myMotorA->step(100, FORWARD, INTERLEAVE);
// myMotorA->step(100, BACKWARD, INTERLEAVE);
// delay(1000);
 
// Serial.println("Microstep steps");
// myMotorA->step(50, FORWARD, MICROSTEP);
// delay(2000);
// myMotorA->release();
// delay(2000);
// myMotorA->step(50, BACKWARD, MICROSTEP);
// delay(2000);
// myMotorA->release();
//  delay(2000);
}
Attachments
Capture.JPG
Capture.JPG (50.63 KiB) Viewed 164 times

bkidd73
 
Posts: 4
Joined: Thu Jan 28, 2021 10:54 pm

Re: Arduino Motor Shield v2.3 and Stepper Motor Speed

by adafruit_support_bill on Sat Feb 06, 2021 9:36 pm

That motor is not compatible with the shield. Based on the specs (the 1.1 ohm phase resistance in particular) it appears to have been designed for use with a current-limiting 'chopper' type driver. For more detail see this guide: https://learn.adafruit.com/all-about-st ... he-stepper

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

Re: Arduino Motor Shield v2.3 and Stepper Motor Speed

by bkidd73 on Sat Feb 06, 2021 10:46 pm

Thanks for the quick reply! Is the problem that because the stepper has such a low resistance and the supply voltage is 5 V (~4.5V actually measured at the terminals) then it would need I = V/R = 4.5V/1.1 ohm = 4A and the shield can only supply 1.2A? I assume I should use a stepper with at least 4 ohm resistance in the windings?

bkidd73
 
Posts: 4
Joined: Thu Jan 28, 2021 10:54 pm

Re: Arduino Motor Shield v2.3 and Stepper Motor Speed

by adafruit_support_bill on Sun Feb 07, 2021 7:46 am

Yes. That is correct. The driver chips on the shield are most likely overloading and shutting down. This is especially true at slower step rates.

Interestingly, at higher step rates, the inductance of the coils increases the effective impedance. That accounts for the improved performance at higher step rates.

The reason that the actual RPM lags behind the programmed RPM is because the step timing in the library does not account for the i2c communication time. And the maximum step rate is ultimately governed by the processing and communication overhead. For more information on the topic see this thread: viewtopic.php?f=31&t=57041&p=292119

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

Re: Arduino Motor Shield v2.3 and Stepper Motor Speed

by bkidd73 on Wed Feb 17, 2021 3:10 pm

OK - So I bought another stepper motor which should be compatible: (https://smile.amazon.com/gp/product/B01 ... UTF8&psc=1)

The output speed still does not match the speed set in the code with the 'setspeed' command. Given the limitations of the i2C, with it ever match, or will I always have to do a little trial-and-error testing to figure out what value to set for 'setspeed' in order to get the desired output speed?

bkidd73
 
Posts: 4
Joined: Thu Jan 28, 2021 10:54 pm

Re: Arduino Motor Shield v2.3 and Stepper Motor Speed

by adafruit_support_bill on Wed Feb 17, 2021 3:18 pm

The Adafruit stepper library will always have some error - since it does not have compensation for the communication & execution overhead. The AccelStepper library will give you accurate speeds - at least up to the point where you reach the limits of the i2c bus speed. https://github.com/adafruit/AccelStepper

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

Re: Arduino Motor Shield v2.3 and Stepper Motor Speed

by bkidd73 on Wed Feb 17, 2021 3:55 pm

Dumb question, but to use the accellstepper library I assume I have to add #include <AccellStepper.h> library along with the #include <Adafruit_MotorShield.h>, or would I use the AccellStepper library instead of the Adafruit library?

bkidd73
 
Posts: 4
Joined: Thu Jan 28, 2021 10:54 pm

Re: Arduino Motor Shield v2.3 and Stepper Motor Speed

by adafruit_support_bill on Wed Feb 17, 2021 4:04 pm

There are AccelStepper examples included with the Adafruit_Motor_Shield_V2_Library:

https://github.com/adafruit/Adafruit_Mo ... r/examples

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

Please be positive and constructive with your questions and comments.