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/
Locked
User avatar
taoxu
 
Posts: 2
Joined: Sat Jul 03, 2021 11:37 pm

How to run multiple steppers simultaneously?

Post by taoxu »

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.

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: How to run multiple steppers simultaneously?

Post by adafruit_support_bill »


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

Re: How to run multiple steppers simultaneously?

Post by taoxu »

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?

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: How to run multiple steppers simultaneously?

Post by adafruit_support_bill »

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

Locked
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/

Return to “Adafruit Raspberry Pi® accessories”