Stepper motor module

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
Post Reply
filipmar.mf
Posts: 3
Joined: Thu Jul 28, 2016 3:21 pm

Stepper motor module

Post by filipmar.mf » Tue Mar 07, 2017 7:24 am

Hi,
there is my module for Stepper motor driven by Adafruit Easy driver.
https://github.com/Euter2/MicroPython/b ... stepper.py

Your feedback is welcome ;)

sjp770
Posts: 7
Joined: Thu Aug 24, 2017 12:50 am

Re: Stepper motor module

Post by sjp770 » Fri Aug 25, 2017 1:42 pm

Looks good, is there doco on how to use it? I'm still new to micropython.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Stepper motor module

Post by pythoncoder » Mon Aug 28, 2017 7:29 am

That's a useful driver. For anyone puzzled (as I was) Easy Driver is this nice piece of hardware: https://www.sparkfun.com/products/12779.

An asynchronous version of the driver would be an interesting project. It could use a timer interrupt or uasyncio to achieve nonblocking behaviour. The drawback would be a substantially lower maximum step rate, especially on the ESP8266.
Peter Hinch
Index to my micropython libraries.

sjp770
Posts: 7
Joined: Thu Aug 24, 2017 12:50 am

Re: Stepper motor module

Post by sjp770 » Thu Aug 31, 2017 3:09 am

My driver is a more common Polou A4988, (https://www.pololu.com/product/1182) Any idea if it would work with this or if there is a way to control it yet?

User avatar
dbc
Posts: 89
Joined: Fri Aug 28, 2015 11:02 pm
Location: Sunnyvale, CA

Re: Stepper motor module

Post by dbc » Fri Sep 01, 2017 11:03 pm

The drawback would be a substantially lower maximum step rate, especially on the ESP826
Yes, well, say you are using a common 200 steps/rev motor, and 1/4 microstepping, and two edges per step, or 1600 edges to generate per revolution. The OP's code has a 20 uSec minimum time between edges. At 20 uSec minimum time between edges, that is 32 mSec per revolution, or 1875 RPM, which is pretty zippy. (Feel free to look for errors in my math..) So I don't think a slower step rate is a problem for many applications.

Related, since motors have real mass, you can't make them go from 0 RPM to a fast step rate all in one go. It might be nice to add some kind of acceleration ramp parameter to the API.

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: Stepper motor module

Post by OutoftheBOTS_ » Mon Dec 04, 2017 7:48 am

Usually most people will use a A4988 or a DRV8825 for controlling small to median stepper motors.
The A4988 was the classic used by most 3dprinters and smaller CNC machines until the DRV8825 came alone with better specs (smaller micro-stepping and higher current) and now is very standard. Both drivers r chopper drivers(constant current driver).

To get good acceleration torque you need to use a chopper driver (standard with all CNC machine)

To get a smooth rotation rather than a chunky stepping motion you need micro stepping the smaller the better usually.

Both these drivers have a step pin and a direction pin. U set the direction pin to high or low for direction of stepping and pulse the step pin to make it take a step. You can drive the step pin with a PWM freq to get a certain speed and you adjust the freq to adjust the speed of the stepping, you will need a counter that counts the pulses if you want to know the rotation amount.

pidou46
Posts: 101
Joined: Sat May 28, 2016 7:01 pm

Re: Stepper motor module

Post by pidou46 » Fri Jun 08, 2018 8:22 am

Hello,

My understanding is that it's impractical to drive the step pulse of a stepper driver (A4988, DRV8825, ect...) directly with an esp (8266 or 32) because of RTOS and Micropython latency.

What do you think of: https://github.com/lhartmann/esp8266_reprap

Instead of connect directly the pins from the esp to the driver, it use a register shifter (74HC595) drived through I2S.

Is this achievable with micropython, does it will allow similar stepper RPM ?
nodemcu V2 (amica)
micropython firmware Daily build 05/31/2016

User avatar
mattyt
Posts: 410
Joined: Mon Jan 23, 2017 6:39 am

Re: Stepper motor module

Post by mattyt » Fri Jun 08, 2018 12:19 pm

My understanding is that it's impractical to drive the step pulse of a stepper driver (A4988, DRV8825, ect...) directly with an esp (8266 or 32) because of RTOS and Micropython latency.
I don't believe this is true on the ESP32 as the PWM is HW-driven using the LEDC module. It should be very accurate. Relvant code is in esp32/machine_pwm.c.

Can anyone confirm? I personally haven't looked at the output on an oscilloscope...

By the way, if you're prepared to stray off mainline MicroPython, the Loboris ESP32 port offers a few other PWM features.

Post Reply