Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/larsks/micropython-stepper-motor
https://github.com/larsks/micropython-stepper-motor
Last synced: 24 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/larsks/micropython-stepper-motor
- Owner: larsks
- Created: 2020-12-21T18:54:05.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2020-12-24T04:29:09.000Z (almost 4 years ago)
- Last Synced: 2024-04-22T12:35:31.966Z (8 months ago)
- Language: Python
- Size: 7.81 KB
- Stars: 8
- Watchers: 4
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-micropython - micropython-stepper-motor - Drive a 28BYJ-48 motor attached to a ULN2003 driver. (Libraries / Motion)
README
# MicroPython Stepper Motor Driver
Code to drive a 28BYJ-48 motor attached to a ULN2003 driver.
## Overview
The module `motor.py` implements the following classes:
- `FullStepMotor` -- This class drives a stepper motor using full steps, which
with the 28BYJ-48 means 2048 steps for a single rotation.- `HalfStepMotor` -- This class drives a stepper motor using half steps, so
4096 steps for a single rotation.## API
Motor objects support the following methods:
- `zero()` -- set the current position as position 0.
- `step(n)` -- move forward (positive `n`) or backwards (negative `n`) the given number of steps
- `step_until(position)` -- move motor to the given position. By default the motor will move in the shortest direction, but you can force a direction with the optional `dir` keyword argument (`1` for forward, `-1` for reverse).
- `step_until_angle(angle)` -- move motor to the given angle.## Examples
If you have a ULN2003 connected to a Wemos D1 on pins D5, D6, D7, D8,
like this ([pinout][]):[pinout]: https://escapequotes.net/esp8266-wemos-d1-mini-pins-and-diagram/
| Wemos pin | ULN2003 pin |
| ----------- | ----------- |
| D5 (GPIO14) | IN1 |
| D6 (GPIO12) | IN2 |
| D7 (GPIO13) | IN3 |
| D8 (GPIO15) | IN4 |Then you could create a `HalfStepMotor` object like this:
```
import motor
m = motor.HalfStepMotor.frompins(14,12,13,15)
```Once you have a motor object, you can run it forward:
```
m.step(500)
```Or backwards:
```
m.step(-500)
```You can run it to a specific position:
```
m.step_until(2000)
```Or to a specific angle:
```
m.step_until_angle(270)
```When using the `step_until*` methods, the motor will by default move
in the direction of shortest distance. You can force a direction with
the optional `dir` keyword argument:```
m.step_until(2000, dir=-1)
```