0

oneStep is not a good option for Stepper Motors
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/
Please be positive and constructive with your questions and comments.

oneStep is not a good option for Stepper Motors

by rickseiden on Tue May 11, 2021 7:55 am

Hello,

I have the motor bonnet for the Raspberry Pi, and I've installed the Python library and my motor works and turns. My problem is that the oneStep function is not good when you need to do multiple steps. Say I need to do 10 steps. I have to call oneStep in a loop 10 times. No big deal from a programming point of view, but it's not a smooth turn of the shaft equivalent to 10 steps, but a jerky 10 "step stop" cycles.

I've been through the code, but there's so much overhead to use the various library to support a lot of products in one solution that I can't find the part where the code is actually sent to the PCA9685. I've been through the data sheets of both the PCA9685 and the TB6612, and have an understanding of what needs to be sent based one registers on the PCA9685 and how it's connected to the TB6612, but I'm having trouble figuring out how to ensure that exactly the number of steps I want are taken. I can set all the registers to set the appropriate PWMs on the PCA9685 on and off at the right time (I think), but I don't see how the Python library is sending information for just one step.

I guess I'd like to know if anyone has found a way to turn their stepper x number of steps without sending x oneSteps so that the stepper motor moves in just one continuous motion instead of in little jerks.

Thanks

rickseiden
 
Posts: 51
Joined: Thu Oct 06, 2016 2:48 pm

Re: oneStep is not a good option for Stepper Motors

by adafruit_support_bill on Tue May 11, 2021 9:36 am

The Motor Bonnet (as well as the HAT, Shield & WIng versions of the board) is a fairly simple general purpose motor driver. To keep it general purpose, most of the low-level motor control is performed in software. This approach has its limitations.

Python is not optimized for speed, so your maximum step rate is somewhat limited by the software overhead.

And Linux uses time-slicing for multitasking. So precise timing is difficult to achieve.

One of the Arduino compatible processors programmed in C++ would improve performance on both of those fronts.

A different approach would be to use a more sophisticated stepper controller with built-in timing and a high level interface. https://www.pololu.com/category/212/tic ... ontrollers
I believe that Pololu has a Ras-Pi library for the Tic also.

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

Re: oneStep is not a good option for Stepper Motors

by rickseiden on Tue May 11, 2021 6:05 pm

It actually turns out that my code had a sleep(0.1) in the for loop to run the steps. I don't know if I put that in there or if it was part of the example code, but that's what was causing the problem. Took that out and now it runs smooth.

Entirely on me, I think.

rickseiden
 
Posts: 51
Joined: Thu Oct 06, 2016 2:48 pm

Re: oneStep is not a good option for Stepper Motors

by adafruit_support_bill on Tue May 11, 2021 6:23 pm

Yes, a sleep will slow things even further. And it would most likely result in your program relinquishing it's time-slice, so 1ms might turn into 10 or 20 depending on what else is running on the board.

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

Re: oneStep is not a good option for Stepper Motors

by rickseiden on Thu May 13, 2021 10:26 pm

Is there anyway to control the speed of the stepper motor?

I have a stepper motor turning a platter, and if I do 200 steps (one full revolution on the stepper motor) in a for loop, it goes right past the full revolution mark due to inertia. (If I take the platter off, it doesn't have this problem.)

If I put any kind of sleep statement in my code, it will sometimes skip steps (I'm assuming because of the threading issue you mention). I tried putting a sleep(0.1) in the _update_coils code, and that slowed it down to an absolute crawl.

At this point I'm wondering if it might be better to use the TP6612 or DRV8833 breakouts instead of this one.

Rick

rickseiden
 
Posts: 51
Joined: Thu Oct 06, 2016 2:48 pm

Re: oneStep is not a good option for Stepper Motors

by adafruit_support_bill on Fri May 14, 2021 5:34 am

With any of those drivers, the step timing needs to be controlled by the software - which means adding delays of some sort. A 'busy-wait' (looping while actively checking the time) would reduce the chance of losing your time-slice and may work better for you than a sleep.

The TB6612 and DRV8833 are controlled directly by GPIO pins (as compared to i2c for the bonnet), so there is less overhead per step.

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

Re: oneStep is not a good option for Stepper Motors

by rickseiden on Fri May 14, 2021 6:58 am

adafruit_support_bill wrote:With any of those drivers, the step timing needs to be controlled by the software - which means adding delays of some sort. A 'busy-wait' (looping while actively checking the time) would reduce the chance of losing your time-slice and may work better for you than a sleep.

The TB6612 and DRV8833 are controlled directly by GPIO pins (as compared to i2c for the bonnet), so there is less overhead per step.


Thanks. I'll give the busy-wait a try. I'm going to order the two breakout boards, too and see how that works out for me.

rickseiden
 
Posts: 51
Joined: Thu Oct 06, 2016 2:48 pm

Please be positive and constructive with your questions and comments.