0

Stepper Speed limitations with MotorShield v2?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: Stepper Speed limitations with MotorShield v2?

by edwinlimlx on Mon Sep 25, 2017 11:52 pm

scottferg wrote:Bill pointed me to this thread and I thought I'd share my experiences here as well.

I've hacked the Adafruit_StepperMotor class to cache the 'latch' and 'pwm' values in the 'onestep' function so that they are transmitted by i2c only when they change. This eliminates a significant number of 12c transmissions rather than just speeding them up. This is essentially the contribution of the 'quickstep' hack, but caching makes the optimization available to ALL stepping styles, not just DOUBLE, and without a separate function. This caching resulted, for my case, in about a 25% improvement in calls/sec to loop(), yielding higher possible stepping frequencies. I tried increasing i2c speed to 400kHz and even 500kHz (verified by printing TWBR within loop()) but did not notice any further significant improvements.

I also applied a trivial hack to the AccelStepper library to use microsecond timing rather than millisecond timing, which significantly improved it's calculations and thus the correlation between it's report of stepper speed with the values I see empirically. I.e. without this hack I was observing actual speeds less than those being requested!


Hi scorrferg, I'm having difficulty adjusting the i2c speed in the first place. not sure if your solution will help me. Would appreciate if you could share the code?
edwinlimlx
 
Posts: 12
Joined: Thu Nov 17, 2011 1:59 am

Re: Stepper Speed limitations with MotorShield v2?

by scottferg on Wed Sep 27, 2017 12:22 am

edwinlimlx wrote:Hi scorrferg, I'm having difficulty adjusting the i2c speed in the first place. not sure if your solution will help me. Would appreciate if you could share the code?

I've placed my version of the code on my website at: http://www.forestmoon.com/drop/Adafruit ... ld_opt.zip
It's been a while, so I hope this contains all my changes.

I really do NOT recommend driving a stepper with a MotorShield. For steppers it only acts as an output pin multiplexer over I2C and the main processor does all the work to drive all the stepper pins. You save a couple of IO pins but at a terrible performance cost. If they had put some actual stepper intelligence on the shield, it would be worthwhile!

scottferg
 
Posts: 10
Joined: Tue Apr 05, 2016 6:29 pm

Re: Stepper Speed limitations with MotorShield v2?

by edwinlimlx on Thu Sep 28, 2017 5:27 am

scottferg wrote:
edwinlimlx wrote:Hi scorrferg, I'm having difficulty adjusting the i2c speed in the first place. not sure if your solution will help me. Would appreciate if you could share the code?

I've placed my version of the code on my website at: http://www.forestmoon.com/drop/Adafruit ... ld_opt.zip
It's been a while, so I hope this contains all my changes.

I really do NOT recommend driving a stepper with a MotorShield. For steppers it only acts as an output pin multiplexer over I2C and the main processor does all the work to drive all the stepper pins. You save a couple of IO pins but at a terrible performance cost. If they had put some actual stepper intelligence on the shield, it would be worthwhile!


Thanks scottferg! i'm actually using the adafruit Stepper Motor HAT, not sure if it's as intelligent as you mentioned.
is there a way to proper test that i2c has changed to 400khz on a pi3 running pixel? I've try all method mentioned online, however i'm not sure if the bottlenet is on the shield or the configuration on rpi.
edwinlimlx
 
Posts: 12
Joined: Thu Nov 17, 2011 1:59 am

Re: Stepper Speed limitations with MotorShield v2?

by scottferg on Thu Sep 28, 2017 6:05 am

edwinlimlx wrote:Thanks scottferg! i'm actually using the adafruit Stepper Motor HAT, not sure if it's as intelligent as you mentioned.
is there a way to proper test that i2c has changed to 400khz on a pi3 running pixel? I've try all method mentioned online, however i'm not sure if the bottlenet is on the shield or the configuration on rpi.


The code I used is like this. You can print the TWBR value somewhere in your loop() to make sure it was set properly.

Code: Select all | TOGGLE FULL SIZE
   // must come AFTER the AFMS.begin()...
   TWBR = ((F_CPU / 500000l) - 16) / 2; // Change the i2c clock to 500KHz

By "intelligent stepper code" I mean, ideally, that you could send I2C commands to start a stepper toward a goal position with speed and acceleration. At the very least, it would do what's in the onestep() function and reduce the processor and I2C comm burden. I'm fairly certain there's no Adafruit library or shield that does that.

scottferg
 
Posts: 10
Joined: Tue Apr 05, 2016 6:29 pm

Re: Stepper Speed limitations with MotorShield v2?

by adafruit_support_bill on Thu Sep 28, 2017 6:18 am

By "intelligent stepper code" I mean, ideally, that you could send I2C commands to start a stepper toward a goal position with speed and acceleration.

The Synthetos TinyG board has an embedded GCode interpreter. https://www.adafruit.com/product/1749
As you would expect, that high-level intelligence makes it a bit more expensive than a basic shield.

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

Re: Stepper Speed limitations with MotorShield v2?

by adafruit_support_bill on Thu Sep 28, 2017 6:21 am

@edwinlimlx - Make sure that your clock speed changing code is *after* the call to AFMS.begin(). Otherwise, it will just get reset back to the default speed.

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

Re: Stepper Speed limitations with MotorShield v2?

by edwinlimlx on Thu Sep 28, 2017 6:37 am

adafruit_support_bill wrote:@edwinlimlx - Make sure that your clock speed changing code is *after* the call to AFMS.begin(). Otherwise, it will just get reset back to the default speed.


I'm actually using the raspberry pi motor hat library
https://github.com/adafruit/Adafruit-Mo ... on-Library
edwinlimlx
 
Posts: 12
Joined: Thu Nov 17, 2011 1:59 am

Re: Stepper Speed limitations with MotorShield v2?

by edwinlimlx on Thu Sep 28, 2017 6:42 am

adafruit_support_bill wrote:@edwinlimlx - Make sure that your clock speed changing code is *after* the call to AFMS.begin(). Otherwise, it will just get reset back to the default speed.



Speaking of which, when i dig into the source code,
https://github.com/adafruit/Adafruit-Mo ... rs.py#L227

Is there some params that I should pass in, as neither any of the examples states any.
edwinlimlx
 
Posts: 12
Joined: Thu Nov 17, 2011 1:59 am

Re: Stepper Speed limitations with MotorShield v2?

by adafruit_support_bill on Thu Sep 28, 2017 6:56 am

Is there some params that I should pass in, as neither any of the examples states any.

I don't believe so. All of the parameters to the _init_ have default assignments. I don't believe any of them pertain to clock speed.
But the Pi is not my area of expertise. You might want to post your question on the Pi forum here: viewforum.php?f=50

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

Re: Stepper Speed limitations with MotorShield v2?

by theITguyfromNY on Thu Jan 24, 2019 12:39 pm

I know this post is years old. I'm looking to do the same thing and just wondering the product(s) I need to buy...

Right now I have a small 28BYJ-48 (5v) and a ULN 2003 controller with RPi 3+. This is not as fast as I need it to be. While I do not need speeds you all are talking about above, I would like at least 1 RPS (60 RPM), maybe double that at-most.

I can obviously tweak software/files (am trying to use C), but the first question is, what motor and controller? Oh, yeah, biopolar control, too. (Ultimately turning a dial around about 720 degrees really fast clockwise and then, maybe even only a second later, back off...then on, off in 3 seconds, etc.

Possible? Hardware reqs?

theITguyfromNY
 
Posts: 12
Joined: Thu Jan 24, 2019 12:33 pm

Re: Stepper Speed limitations with MotorShield v2?

by adafruit_support_bill on Thu Jan 24, 2019 1:38 pm

@theITguyfromNY - The 28BYJ-48 is a geared stepper. It is designed for high-torque and low-speed. If you are just turning a dial, you are probably better off with just a plain stepper motor directly driving the dial. The #324 motor is a pretty good match for the Pi Motor HAT if you want to use a Pi:
https://www.adafruit.com/product/324
https://www.adafruit.com/product/2348

To go higher than 60 RPM with the HAT, you will need increase the i2c clock rate (referred to as 'baud-rate' in the land of Pi). The Pi forums should be able to help you with that.

If you only have one motor to drive, you can avoid the i2c speed limitations of the HAT and use one of the TB6612 breakouts:
https://www.adafruit.com/product/2448
These can be driven directly via GPIO pins and are capable of higher step-rates than the HAT.

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

Re: Stepper Speed limitations with MotorShield v2?

by theITguyfromNY on Thu Jan 24, 2019 2:36 pm

I'm still a newbie and sorry to not know if I would need the controller (2348 WITH the HAT versus 324 w/o the HAT). I do need to use the RPi to control another motor at the same time (independently), so the TB6612 isn't for me this time.

I am familiar with changing the I2c baud rate, so that's not a concern. I guess my only q is the exact diff. between the 2348 v. 324 (motor only). Thanks a million!

theITguyfromNY
 
Posts: 12
Joined: Thu Jan 24, 2019 12:33 pm

Re: Stepper Speed limitations with MotorShield v2?

by adafruit_support_bill on Thu Jan 24, 2019 2:59 pm

I guess my only q is the exact diff. between the 2348 v. 324 (motor only).

The 28BYJ-48 is a small geared stepper motor with (approximately) 512 steps per revolution. It is commonly used in home air conditioners and automotive climate control systems. It is designed for high-torque at a relatively low speed. There are many variations on this motor, but the ones we carry are all unipolar wiring only.

The #324 motor is a NEMA-17 sized bipolar stepper with (exactly) 200 steps per revolution. It capable of moderate torque and higher speeds compared to the 28BYJ-48.

I do need to use the RPi to control another motor at the same time (independently), so the TB6612 isn't for me this time.

How precise does the motor control need to be? The Pi is not an ideal platform for applications requiring critical timing.

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

Re: Stepper Speed limitations with MotorShield v2?

by theITguyfromNY on Thu Jan 24, 2019 4:17 pm

I don't need precision at all for this project...Not at all. :-)

I just am not sure if I need the HAT/controller or I can use the NEMA 17 directly connected to GPIO ports. Or...I have a ULN2003; Can that work with this motor?

theITguyfromNY
 
Posts: 12
Joined: Thu Jan 24, 2019 12:33 pm

Re: Stepper Speed limitations with MotorShield v2?

by adafruit_support_bill on Thu Jan 24, 2019 5:52 pm

I just am not sure if I need the HAT/controller or I can use the NEMA 17 directly connected to GPIO ports. Or...I have a ULN2003; Can that work with this motor?

No. GPIO pins cannot supply enough current to drive a motor directly. And a ULN2003 cannot handle a bipolar motor. You need a motor driver with 2 full H-Bridges per stepper like the HAT.

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

Please be positive and constructive with your questions and comments.