Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Motor shield V2 and Stepper Motor
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Motor shield V2 and Stepper Motor

by bodat86 on Wed Sep 23, 2020 11:14 am

I have a Metro M4 Express and a Motor Shield V2.3. I want to use Circuitpython to drive a couple stepper motors for this little robot car I'm building. Is there a way to use 'throttle' with a stepper the way I can use it driving DC motors? Or, is there another way to control the speed of my stepper motors? I saw nothing like that in the stepper motor examples...

bodat86
 
Posts: 15
Joined: Sun Jul 01, 2018 5:10 am

Re: Motor shield V2 and Stepper Motor

by adafruit_support_bill on Wed Sep 23, 2020 11:20 am

You control the speed by controlling the step-rate. Following the example code, you would change the amount of sleep between calls to onestep(). Longer sleeps means slower stepping.
https://learn.adafruit.com/adafruit-ste ... 3010651-35

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

Re: Motor shield V2 and Stepper Motor

by bodat86 on Wed Sep 23, 2020 12:37 pm

Thanks for your quick reply, Bill!

But that means the code is busy doing this and can't do anything else. It kind of defeats the purpose (for me) of using the shield to control the motor while main code does something else - unlike controlling a DC motors doesn't it? I need the controller with HC-SR04's to stop the car before bumping into anything. I've tried DC motors to drive the wheels but they don't seem to be consistent in their speed.

I think Arduino code would work - but I chose (hoped) to use Circuitpython.

Cheers

bodat86
 
Posts: 15
Joined: Sun Jul 01, 2018 5:10 am

Re: Motor shield V2 and Stepper Motor

by adafruit_support_bill on Wed Sep 23, 2020 1:12 pm

In single-threaded environments like CircuitPython and Arduino, multitasking is best achieved by using state machines. Instead of using sleep, you can use something like the timemonotonic function to determine when it is time to take a step. And perform other functions like reading sensors in between steps.

Dave has a nice tutorial on CircuitPython state machines here: https://learn.adafruit.com/circuitpytho ... s/overview

And there is this series of guides showing examples of state machines on the Arduino:
https://learn.adafruit.com/multi-taskin ... ino-part-1
https://learn.adafruit.com/multi-taskin ... ino-part-2
https://learn.adafruit.com/multi-taskin ... ino-part-3

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

Re: Motor shield V2 and Stepper Motor

by bodat86 on Wed Sep 23, 2020 4:34 pm

Thanks Bill!

I'll try to wrap my pea brain around these suggestions!

Bo

bodat86
 
Posts: 15
Joined: Sun Jul 01, 2018 5:10 am

Re: Motor shield V2 and Stepper Motor

by slight on Mon Sep 28, 2020 10:59 am

Hi Bo,

maybe this script can inspire on some of your points....
https://github.com/s-light/cp_stepper_t ... stepper.py

it is designed to be used with SilentStepStick as driver - that one needs a Step/Dir Interface - i use PWM to do steps...

maybe sometime in the future i try to create a more general / highlevel *stepper* class that is compatible with both *backends* (Dir / Step interface and the Adafruit Motor Drivers)

sunny greetings
stefan

slight
 
Posts: 37
Joined: Wed Sep 12, 2012 2:23 am

Re: Motor shield V2 and Stepper Motor

by bodat86 on Mon Sep 28, 2020 11:27 am

Hi Slight!

I'm about to give up on using a stepper and going to DC, but I haven't pulled the trigger yet. I'll delve into this!

Thank you so much!
Bo

bodat86
 
Posts: 15
Joined: Sun Jul 01, 2018 5:10 am

Please be positive and constructive with your questions and comments.