0

How to run multiple steppers simultaneously?
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.

How to run multiple steppers simultaneously?

by taoxu on Mon Jul 26, 2021 11:58 pm

Hi, I have a DC+ stepper Motor Hat on Raspberry Pi. It has two steppers connected. Although I successfully ran them in a sequence, I have no idea of how to run both of them at the same time. Should I install other libraries or how can I code for that purpose? Thanks.

taoxu
 
Posts: 2
Joined: Sat Jul 03, 2021 11:37 pm

Re: How to run multiple steppers simultaneously?

by adafruit_support_bill on Tue Jul 27, 2021 5:30 am


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

Re: How to run multiple steppers simultaneously?

by taoxu on Tue Jul 27, 2021 10:27 pm

Thanks for your reply. You misunderstood my question. I tried adafruit_io_steppers.py but it ran the steppers one by one, not simultaneously. For example, I hope to run one stepper in a forward direction and meanwhile run the second stepper in a backward direction.

BTW, how should I adjust the speed for these steppers?

taoxu
 
Posts: 2
Joined: Sat Jul 03, 2021 11:37 pm

Re: How to run multiple steppers simultaneously?

by adafruit_support_bill on Wed Jul 28, 2021 7:24 am

adafruit_io_steppers.py creates a thread for each stepper, so in theory they could execute in parallel. Although it does not appear that the library synchronizes access to the i2c bus, so you would likely run into some communication issues if you tried it.

A more deterministic approach is to interleave the calls to onestep() using time.monotonic() to control the step rates for each motor. This is typically done with a state machine.

There are lots of on-line tutorials on Python state machines. Although I don't know of any that specifically address stepper motors.
https://learn.adafruit.com/circuitpytho ... e-machines

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

Please be positive and constructive with your questions and comments.