Name | micropython-stepper JSON |
Version |
1.0.3
JSON |
| download |
home_page | |
Summary | Library to use stepper drivers in micropython in a tidy way |
upload_time | 2023-02-01 08:08:31 |
maintainer | |
docs_url | None |
author | |
requires_python | |
license | MIT License Copyright (c) 2023 redoxcode Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
stepper
motor
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
[![pypi version shield](https://img.shields.io/pypi/v/micropython-stepper)](https://pypi.org/project/micropython-stepper/) [![pypi downloads per month shield](https://img.shields.io/pypi/dm/micropython-stepper?color=brightgreen)](https://pypi.org/project/micropython-stepper/)
## Description
A micropython library to use stepper motors in a tidy way.
Your steppers should be connected to a stepper driver that is controlled using a step, a dir and optional an enable pin.
This library uses one timer per stepper to achive controlled speeds for multiple steppers in a non blocking way.
The steppers can be controlled by angle if the number of steps per rotation is supplied.
Multiple steppers can share a common dir pin, allowing for N steppers controlled by N+1 output pins.
## Examples
### Two steppers
```Python
from stepper import Stepper
import time
s1 = Stepper(18,19,steps_per_rev=200,speed_sps=50)
s2 = Stepper(20,21,steps_per_rev=200,speed_sps=50)
s1.target_deg(90)
s2.target_deg(45)
time.sleep(5.0)
s1.target_deg(0)
s2.target_deg(5)
time.sleep(5.0)
```
### Calibrate absolute position using an endswitch
```Python
import machine
import time
from stepper import Stepper
s1 = Stepper(18,19,steps_per_rev=200)
#create an input pin for the end switch (switch connects pin to GND)
endswitch = machine.Pin(2, machine.Pin.IN, machine.Pin.PULL_UP)
s1.speed(20) #use low speed for the calibration
s1.free_run(-1) #move backwards
while endswitch.value(): #wait till the switch is triggered
pass
s1.stop() #stop as soon as the switch is triggered
s1.overwrite_pos(0) #set position as 0 point
s1.target(0) #set the target to the same value to avoid unwanted movement
s1.speed(100) #return to default speed
s1.track_target() #start stepper again
#calibration finished. Do something else below.
s1.target_deg(45)
time.sleep(5.0)
```
### Two steppers sharing a common dir pin
```Python
import machine
from stepper import Stepper
dir_pin = machine.Pin(19,machine.Pin.OUT)
s1 = Stepper(18,dir_pin,steps_per_rev=200,speed_sps=50)
s2 = Stepper(20,dir_pin,steps_per_rev=200,speed_sps=50)
```
## API
### class Stepper(step_pin,dir_pin,en_pin=None,steps_per_rev=200,speed_sps=10,invert_dir=False,timer_id=-1)
- step_pin: Pin id or machine.Pin object for the pin connected to the step input of the stepper driver
- dir_pin: Pin id or machine.Pin object for the pin connected to the direction select input of the stepper driver
- en_pin: (Optional) None or pin id or machine.Pin object for the pin connected to the enable input of the stepper driver
- steps_per_rev: Amount of stepper steps that would result in a 360° rotation
- speed_sps: Speed in steps per secound (= step frequency in Hz)
- invert_dir: True if the direction of the stepper should be inverted
- timer_id: Id of the timer that should be used. On most boards -1 will construct a new virtual timer (https://docs.micropython.org/en/latest/library/machine.Timer.html)
```speed(sps)```
- set the speed of the stepper
- sps: Speed in steps per secound (= step frequency in Hz)
```speed_rps(rps)```
- set the speed of the stepper
- rps: Speed in rotations per secound
```target(t)```
- set a target position. The stepper will move towards that position
- t: Target in steps
```target_deg(deg)```
- set a target position. The stepper will move towards that position
- deg: Target in degrees
```target_rad(rad)```
- set a target position. The stepper will move towards that position
- rad: Target in radians
```get_pos()```
- returns the current position in steps
```get_pos_deg()```
- returns the current position in degrees
```get_pos_rad()```
- returns the current position in radians
```overwrite_pos(p)```
- overwrites the current position. Used to calibrate the absolute position
- p: Current position in steps
```overwrite_pos_deg(deg)```
- overwrites the current position. Used to calibrate the absolute position
- deg: Current position in degree
```overwrite_pos_rad(rad)```
- overwrites the current position. Used to calibrate the absolute position
- rad: Current position in radians
```step(d)```
- instantly moves the stepper by a single step
- d: Direction of the step (d>0: Forwards, d<0: Backwards, d==0: No movement)
```free_run(d)```
- moves the stepper continuously until stopped
- d: Direction of movement (d>0: Forwards, d<0: Backwards, d==0: Stop)
```track_target()```
- puts the stepper back in the default mode, where it follows the target position after free_run(d) or stop() was used.
```stop()```
- stops the timer and all movement (single steps using the step() function are still possible)
```enable(e)```
- enable or disable the stepper driver using the enable pin. While this stops the movement of the actual hardware, the Stepper class will still act as if the stepper is moving. This can be used for testing. Recalibration of the absolute position might be needed if the stepper was disabled.
-e: True or False
```is_enabled()```
- returns the last status (True or False) of the enable(e) function
Raw data
{
"_id": null,
"home_page": "",
"name": "micropython-stepper",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "stepper,motor",
"author": "",
"author_email": "redoxcode <redoxcode@github.com>",
"download_url": "https://files.pythonhosted.org/packages/61/c1/40888b0cceedcefa79ac65d48df2d40d7956884a6bb579a984ec3a5a1972/micropython-stepper-1.0.3.tar.gz",
"platform": null,
"description": "[![pypi version shield](https://img.shields.io/pypi/v/micropython-stepper)](https://pypi.org/project/micropython-stepper/) [![pypi downloads per month shield](https://img.shields.io/pypi/dm/micropython-stepper?color=brightgreen)](https://pypi.org/project/micropython-stepper/)\n## Description\nA micropython library to use stepper motors in a tidy way.\n\nYour steppers should be connected to a stepper driver that is controlled using a step, a dir and optional an enable pin.\n\nThis library uses one timer per stepper to achive controlled speeds for multiple steppers in a non blocking way.\n\nThe steppers can be controlled by angle if the number of steps per rotation is supplied.\n\nMultiple steppers can share a common dir pin, allowing for N steppers controlled by N+1 output pins.\n\n## Examples\n### Two steppers\n```Python\nfrom stepper import Stepper\nimport time\n\ns1 = Stepper(18,19,steps_per_rev=200,speed_sps=50)\ns2 = Stepper(20,21,steps_per_rev=200,speed_sps=50)\n\ns1.target_deg(90)\ns2.target_deg(45)\ntime.sleep(5.0)\ns1.target_deg(0)\ns2.target_deg(5)\ntime.sleep(5.0)\n```\n\n### Calibrate absolute position using an endswitch\n```Python\nimport machine\nimport time\nfrom stepper import Stepper\n\ns1 = Stepper(18,19,steps_per_rev=200)\n#create an input pin for the end switch (switch connects pin to GND)\nendswitch = machine.Pin(2, machine.Pin.IN, machine.Pin.PULL_UP)\n\ns1.speed(20) #use low speed for the calibration\ns1.free_run(-1) #move backwards\nwhile endswitch.value(): #wait till the switch is triggered\n pass\ns1.stop() #stop as soon as the switch is triggered\ns1.overwrite_pos(0) #set position as 0 point\ns1.target(0) #set the target to the same value to avoid unwanted movement\ns1.speed(100) #return to default speed\ns1.track_target() #start stepper again\n\n#calibration finished. Do something else below.\ns1.target_deg(45)\ntime.sleep(5.0)\n```\n\n### Two steppers sharing a common dir pin\n```Python\nimport machine\nfrom stepper import Stepper\n\ndir_pin = machine.Pin(19,machine.Pin.OUT)\ns1 = Stepper(18,dir_pin,steps_per_rev=200,speed_sps=50)\ns2 = Stepper(20,dir_pin,steps_per_rev=200,speed_sps=50)\n```\n\n## API\n### class Stepper(step_pin,dir_pin,en_pin=None,steps_per_rev=200,speed_sps=10,invert_dir=False,timer_id=-1)\n- step_pin: Pin id or machine.Pin object for the pin connected to the step input of the stepper driver\n- dir_pin: Pin id or machine.Pin object for the pin connected to the direction select input of the stepper driver\n- en_pin: (Optional) None or pin id or machine.Pin object for the pin connected to the enable input of the stepper driver\n- steps_per_rev: Amount of stepper steps that would result in a 360\u00b0 rotation\n- speed_sps: Speed in steps per secound (= step frequency in Hz)\n- invert_dir: True if the direction of the stepper should be inverted\n- timer_id: Id of the timer that should be used. On most boards -1 will construct a new virtual timer (https://docs.micropython.org/en/latest/library/machine.Timer.html)\n\n\n```speed(sps)```\n- set the speed of the stepper\n- sps: Speed in steps per secound (= step frequency in Hz)\n\n```speed_rps(rps)```\n- set the speed of the stepper\n- rps: Speed in rotations per secound\n\n```target(t)```\n- set a target position. The stepper will move towards that position\n- t: Target in steps\n\n```target_deg(deg)```\n- set a target position. The stepper will move towards that position\n- deg: Target in degrees\n\n```target_rad(rad)```\n- set a target position. The stepper will move towards that position\n- rad: Target in radians\n\n```get_pos()```\n- returns the current position in steps\n\n```get_pos_deg()```\n- returns the current position in degrees\n\n```get_pos_rad()```\n- returns the current position in radians\n\n```overwrite_pos(p)```\n- overwrites the current position. Used to calibrate the absolute position\n- p: Current position in steps\n\n```overwrite_pos_deg(deg)```\n- overwrites the current position. Used to calibrate the absolute position\n- deg: Current position in degree\n\n```overwrite_pos_rad(rad)```\n- overwrites the current position. Used to calibrate the absolute position\n- rad: Current position in radians\n\n```step(d)```\n- instantly moves the stepper by a single step\n- d: Direction of the step (d>0: Forwards, d<0: Backwards, d==0: No movement)\n\n```free_run(d)```\n- moves the stepper continuously until stopped\n- d: Direction of movement (d>0: Forwards, d<0: Backwards, d==0: Stop)\n\n```track_target()```\n- puts the stepper back in the default mode, where it follows the target position after free_run(d) or stop() was used.\n\n```stop()```\n- stops the timer and all movement (single steps using the step() function are still possible)\n\n```enable(e)```\n- enable or disable the stepper driver using the enable pin. While this stops the movement of the actual hardware, the Stepper class will still act as if the stepper is moving. This can be used for testing. Recalibration of the absolute position might be needed if the stepper was disabled.\n-e: True or False\n\n```is_enabled()```\n- returns the last status (True or False) of the enable(e) function\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2023 redoxcode Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
"summary": "Library to use stepper drivers in micropython in a tidy way",
"version": "1.0.3",
"split_keywords": [
"stepper",
"motor"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b03038d1f34e7f23d488b508a49092556402e245d22679f3899e38133f92b40c",
"md5": "6dd5f6264da1d0d8869802d4ab521944",
"sha256": "585829a23ea66a5592a87d75a1a1048c96e068cd7669625896845ccbe452f2f4"
},
"downloads": -1,
"filename": "micropython_stepper-1.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6dd5f6264da1d0d8869802d4ab521944",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 5500,
"upload_time": "2023-02-01T08:08:29",
"upload_time_iso_8601": "2023-02-01T08:08:29.924694Z",
"url": "https://files.pythonhosted.org/packages/b0/30/38d1f34e7f23d488b508a49092556402e245d22679f3899e38133f92b40c/micropython_stepper-1.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "61c140888b0cceedcefa79ac65d48df2d40d7956884a6bb579a984ec3a5a1972",
"md5": "89ec002b3d88e67842949191ee712a47",
"sha256": "32725cbb455a030ba03a854805793a7ca3c5727d0723c3d8c015b99428ce845b"
},
"downloads": -1,
"filename": "micropython-stepper-1.0.3.tar.gz",
"has_sig": false,
"md5_digest": "89ec002b3d88e67842949191ee712a47",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4644,
"upload_time": "2023-02-01T08:08:31",
"upload_time_iso_8601": "2023-02-01T08:08:31.970335Z",
"url": "https://files.pythonhosted.org/packages/61/c1/40888b0cceedcefa79ac65d48df2d40d7956884a6bb579a984ec3a5a1972/micropython-stepper-1.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-02-01 08:08:31",
"github": false,
"gitlab": false,
"bitbucket": false,
"lcname": "micropython-stepper"
}