{"id":13802379,"url":"https://github.com/redoxcode/micropython-stepper","last_synced_at":"2025-04-24T05:30:53.916Z","repository":{"id":65607253,"uuid":"595602356","full_name":"redoxcode/micropython-stepper","owner":"redoxcode","description":"Library to use stepper drivers in micropython in a tidy way","archived":false,"fork":false,"pushed_at":"2025-03-30T09:27:47.000Z","size":22,"stargazers_count":19,"open_issues_count":2,"forks_count":7,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-30T10:26:28.845Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/redoxcode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-31T12:32:02.000Z","updated_at":"2025-03-30T09:27:50.000Z","dependencies_parsed_at":"2024-08-07T11:21:22.170Z","dependency_job_id":"8c58c501-ebff-4526-9bc3-098cc0e52f2e","html_url":"https://github.com/redoxcode/micropython-stepper","commit_stats":{"total_commits":4,"total_committers":1,"mean_commits":4.0,"dds":0.0,"last_synced_commit":"3c1e07ebe250083a2b7638b1366b4fa2de244a62"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redoxcode%2Fmicropython-stepper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redoxcode%2Fmicropython-stepper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redoxcode%2Fmicropython-stepper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redoxcode%2Fmicropython-stepper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/redoxcode","download_url":"https://codeload.github.com/redoxcode/micropython-stepper/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250572177,"owners_count":21452326,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T00:01:43.117Z","updated_at":"2025-04-24T05:30:53.902Z","avatar_url":"https://github.com/redoxcode.png","language":"Python","readme":"[![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# some boards might require a different timer_id for each stepper:\n# s1 = Stepper(18,19,steps_per_rev=200,speed_sps=50,timer_id=0)\n# s2 = Stepper(20,21,steps_per_rev=200,speed_sps=50,timer_id=1)\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,invert_enable=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° 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- invert_enable: True if the stepper driver needs an inverted enable signal\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\u003e0: Forwards, d\u003c0: Backwards, d==0: No movement)\n\n```free_run(d)```\n- moves the stepper continuously until stopped\n- d: Direction of movement (d\u003e0: Forwards, d\u003c0: 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","funding_links":[],"categories":["Libraries"],"sub_categories":["Motion"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredoxcode%2Fmicropython-stepper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fredoxcode%2Fmicropython-stepper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredoxcode%2Fmicropython-stepper/lists"}