Hello!
I'm using this bonnet with a Raspberry Pi Zero W to run a NEMA 17 stepper motor.
https://www.adafruit.com/product/4280
To power the bonnet (12v) and Pi (5v), I'm using this ATX power cable from SparkFun
https://www.sparkfun.com/products/15701
The stepper motor I'm using was purchased through a distributor that does not list the specs, but based on the markings, it appears to be this:
https://www.alibaba.com/product-detail/ ... 49104.html
I've already configured the I2C bus to run at 400khz and that had no impact on the motor speed, which makes me think there may be a compatibility issue between the stepper I have and this bonnet.
To demonstrate, here is a video of the motor running in DOUBLE coil mode, 1000 steps, with a 0.00003s delay between steps. It takes 5 seconds and the stepper makes just under 5 full rotations. You can hear that it's fairly noisy as well. Other modes are slower and much more noisy.
https://photos.app.goo.gl/QSjy3CDcgABr4PRe8
Am I doing something wrong, or is the stepper incompatible? If the former, what else can I try? If the latter, how can I determine compatibility?
Thanks!
Adafruit Stepper Motor Bonnet runs a stepper slow and jerky
Moderators: adafruit_support_bill, adafruit
Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
- erichiggins
- Posts: 5
- Joined: Tue Jan 15, 2019 11:21 am
- adafruit_support_bill
- Posts: 88097
- Joined: Sat Feb 07, 2009 10:11 am
Re: Adafruit Stepper Motor Bonnet runs a stepper slow and jerky
To confirm the motor specs, please measure the resistance of the windings.
Disconnect the 2 wires from M1 and measure the resistance between them. Then do the same for the wires on M2.
Disconnect the 2 wires from M1 and measure the resistance between them. Then do the same for the wires on M2.
- erichiggins
- Posts: 5
- Joined: Tue Jan 15, 2019 11:21 am
Re: Adafruit Stepper Motor Bonnet runs a stepper slow and jerky
Resistance appears to be roughly 20.5 ohms for M1 and M2.
- adafruit_support_bill
- Posts: 88097
- Joined: Sat Feb 07, 2009 10:11 am
Re: Adafruit Stepper Motor Bonnet runs a stepper slow and jerky
OK. That motor should be compatible with drivers on the Bonnet.
Since you are using a Pi, I'm assuming that you are programming in Python. Because the bonnet uses the i2c bus to send step-by-step commands to the motor drivers, the top speed of the motor is going to be limited partly by the communication speed of the i2c bus, and partly by the overhead of the Python interpreter.
The PCA9685 chip on the Bonnet is rated for up to 1MHz. But if 400KHz did not make a noticeable difference, then Python is likely the gating factor.
The other variable is the Linux task-switching. This can introduce, irregularities in the step-to-step timing and make the stepping seem even rougher.
What is the application and what rotational speeds will it require?
Since you are using a Pi, I'm assuming that you are programming in Python. Because the bonnet uses the i2c bus to send step-by-step commands to the motor drivers, the top speed of the motor is going to be limited partly by the communication speed of the i2c bus, and partly by the overhead of the Python interpreter.
The PCA9685 chip on the Bonnet is rated for up to 1MHz. But if 400KHz did not make a noticeable difference, then Python is likely the gating factor.
The other variable is the Linux task-switching. This can introduce, irregularities in the step-to-step timing and make the stepping seem even rougher.
What is the application and what rotational speeds will it require?
- erichiggins
- Posts: 5
- Joined: Tue Jan 15, 2019 11:21 am
Re: Adafruit Stepper Motor Bonnet runs a stepper slow and jerky
Interesting! Well, I'm glad to hear that it's compatible.
Application is a little complicated to explain, but very little torque is required (just spinning a disc with no resistance). Speed is much more important. For the test script I wrote (yes, in Python), I'm simply measuring to see how many rotations I can get per step, and how many steps are needed for a full rotation of the disc.
I'm well-versed in Python and this script is about as minimal as it could be. Instantiate the stepper motor, run a loop to step the motor 1000 times with a small delay after each call to the stepper motor api to give it time to rotate.
I've added timers to confirm that most of the startup delay is induced by importing Adafruit libraries, but there is almost no runtime lag.
What else would you suggest that I try? Should I try switching the I2C bus to 1Mhz? A different Pi board (Pi 3B instead of Zero W)? Anything else?
Application is a little complicated to explain, but very little torque is required (just spinning a disc with no resistance). Speed is much more important. For the test script I wrote (yes, in Python), I'm simply measuring to see how many rotations I can get per step, and how many steps are needed for a full rotation of the disc.
I'm well-versed in Python and this script is about as minimal as it could be. Instantiate the stepper motor, run a loop to step the motor 1000 times with a small delay after each call to the stepper motor api to give it time to rotate.
I've added timers to confirm that most of the startup delay is induced by importing Adafruit libraries, but there is almost no runtime lag.
What else would you suggest that I try? Should I try switching the I2C bus to 1Mhz? A different Pi board (Pi 3B instead of Zero W)? Anything else?
- adafruit_support_bill
- Posts: 88097
- Joined: Sat Feb 07, 2009 10:11 am
Re: Adafruit Stepper Motor Bonnet runs a stepper slow and jerky
Increasing the bus speed should help some. But I suspect that Python overhead is the real bottleneck here. A faster Pi would probably help more than a bus-speed increase.
As stepper controllers go, the Bonnet is not a high-performance driver. It trades off performance for low cost, convenience and minimal pin-count. The fastest I have been able to get it to go (with optimized custom C++ code and a 400KHz i2c clock) is about 250 RPM with a 1.8 degree (200 step) motor.
If speed is a requirement, the DRV8733 would probably be a better choice (do note the lower voltage limit). Or one of the Pololu stepper drivers with a step & direction interface. Even with Python, you should be able to achieve higher step-rates due to the lower communication overhead.
As stepper controllers go, the Bonnet is not a high-performance driver. It trades off performance for low cost, convenience and minimal pin-count. The fastest I have been able to get it to go (with optimized custom C++ code and a 400KHz i2c clock) is about 250 RPM with a 1.8 degree (200 step) motor.
If speed is a requirement, the DRV8733 would probably be a better choice (do note the lower voltage limit). Or one of the Pololu stepper drivers with a step & direction interface. Even with Python, you should be able to achieve higher step-rates due to the lower communication overhead.
- erichiggins
- Posts: 5
- Joined: Tue Jan 15, 2019 11:21 am
Re: Adafruit Stepper Motor Bonnet runs a stepper slow and jerky
Switching to a Pi 3B alone didn't seem to make much of a difference, but after I boosted the I2C bus on it from 100Khz to 1Mhz, there was HUGE improvement. I optimized the python script a little, removed print statements that were inside the loop. That seems to have helped.
Now it's a matter of finding the right delay time between step. Is there any way to call stepper.onestep() asynchronously with some kind of promise or callback instead of just coming up with a static delay?
I'll order a few other driver boards to see how well they perform compared to the bonnet. Thanks again for the help thusfar!
Now it's a matter of finding the right delay time between step. Is there any way to call stepper.onestep() asynchronously with some kind of promise or callback instead of just coming up with a static delay?
I'll order a few other driver boards to see how well they perform compared to the bonnet. Thanks again for the help thusfar!
- adafruit_support_bill
- Posts: 88097
- Joined: Sat Feb 07, 2009 10:11 am
Re: Adafruit Stepper Motor Bonnet runs a stepper slow and jerky
There is a CircuitPython timer library here for the PyBoard. Not sure how applicable that would be for your Pi.
https://github.com/tuupola/circuitpytho ... /timer.rst
You might want to post over in the CircuitPython forum. The CircuitPython team may have some suggestions: viewforum.php?f=60
https://github.com/tuupola/circuitpytho ... /timer.rst
You might want to post over in the CircuitPython forum. The CircuitPython team may have some suggestions: viewforum.php?f=60
- edgjr
- Posts: 143
- Joined: Mon Jan 16, 2012 6:18 pm
Re: Adafruit Stepper Motor Bonnet runs a stepper slow and jerky
The "only" issue with async (multi-threading) is that the I2C communication is synchronous: there is the potential for one thread to stomp on another and garble the messages being sent. The bus is running at 1MHz and the Pi's CPU is running in GHz, so the code will (almost) always run faster than the serial communications. You can use threads, but you have to protect at lot of low-level resources because (afaik) there isn't blocking support for that yet.
- erichiggins
- Posts: 5
- Joined: Tue Jan 15, 2019 11:21 am
Re: Adafruit Stepper Motor Bonnet runs a stepper slow and jerky
This is really helpful to know, thank you! Sounds like the requests that need to utilize I2C would benefit a queuing system as well.
Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/