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/
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/
- taoxu
- Posts: 2
- Joined: Sat Jul 03, 2021 11:37 pm
How to run multiple steppers simultaneously?
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.
- adafruit_support_bill
- Posts: 88154
- Joined: Sat Feb 07, 2009 10:11 am
Re: How to run multiple steppers simultaneously?
There is an example for that here: https://learn.adafruit.com/wireless-ste ... ython-code
- taoxu
- Posts: 2
- Joined: Sat Jul 03, 2021 11:37 pm
Re: How to run multiple steppers simultaneously?
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?
BTW, how should I adjust the speed for these steppers?
- adafruit_support_bill
- Posts: 88154
- Joined: Sat Feb 07, 2009 10:11 am
Re: How to run multiple steppers simultaneously?
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
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
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/