{"id":26011245,"url":"https://github.com/cnadler86/MicroPython_Motor","last_synced_at":"2025-03-05T23:01:33.820Z","repository":{"id":247327202,"uuid":"825552392","full_name":"cnadler86/MicroPython_Motor","owner":"cnadler86","description":"Control PWM based motors in MicroPython the easy way","archived":false,"fork":false,"pushed_at":"2025-03-01T08:41:11.000Z","size":59,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-01T09:26:00.372Z","etag":null,"topics":["dcmotor","micropython","motor-control","servo","stepper"],"latest_commit_sha":null,"homepage":"","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/cnadler86.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":"2024-07-08T04:16:21.000Z","updated_at":"2025-03-01T08:41:15.000Z","dependencies_parsed_at":"2024-07-08T05:32:28.329Z","dependency_job_id":"db52702a-2bc4-4d6f-ac5c-9cce0063f239","html_url":"https://github.com/cnadler86/MicroPython_Motor","commit_stats":null,"previous_names":["cnadler86/micropython_motor"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnadler86%2FMicroPython_Motor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnadler86%2FMicroPython_Motor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnadler86%2FMicroPython_Motor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnadler86%2FMicroPython_Motor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cnadler86","download_url":"https://codeload.github.com/cnadler86/MicroPython_Motor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241955041,"owners_count":20048405,"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":["dcmotor","micropython","motor-control","servo","stepper"],"created_at":"2025-03-05T23:01:32.957Z","updated_at":"2025-03-05T23:01:33.775Z","avatar_url":"https://github.com/cnadler86.png","language":"Python","readme":"# Motor Control Libraries\r\n\r\nLibraries for controlling DC motors, servomotors, and stepper motors with MicroPython on various microcontroller platforms.\r\n\r\nMost libraries out there only support basic movements, but here you will find more advance functionalities such as controlling the speed of the servo or moving the motors with the ability to perform other stuff (async-movement).\r\n\r\n- [Overview](#overview)\r\n- [DCMotor Library](#dcmotor-library)\r\n- [Servo Library](#servo-library)\r\n- [Stepper Library](#stepper-library)\r\n- [Installation](#installation)\r\n- [Usage](#usage)\r\n- [Importing the Libraries](#importing-the-libraries)\r\n- [DCMotor Library](#dcmotor-library-1)\r\n    - [Initialization](#initialization)\r\n    - [Controlling the Motor](#controlling-the-motor)\r\n- [Servo Library](#servo-library-1)\r\n    - [Initialization](#initialization-1)\r\n    - [Moving the Servomotor](#moving-the-servomotor)\r\n    - [Synchronous Movement](#synchronous-movement)\r\n    - [Asynchronous Movement](#asynchronous-movement)\r\n    - [Checking if the Target is Reached](#checking-if-the-target-is-reached)\r\n    - [Stopping the Servomotor](#stopping-the-servomotor)\r\n    - [Detaching the Servomotor](#detaching-the-servomotor)\r\n- [Stepper Library](#stepper-library-1)\r\n    - [Initialization](#initialization-2)\r\n    - [Single Step](#single-step)\r\n    - [Performing Steps](#performing-steps)\r\n    - [Angle-Based Steps](#angle-based-steps)\r\n    - [Continuous Movement](#continuous-movement)\r\n    - [Stop Movement](#stop-movement)\r\n    - [Release Coils](#release-coils)\r\n- [Examples](#examples)\r\n  - [DCMotor Example](#dcmotor-example)\r\n  - [Servo Example](#servo-example)\r\n  - [Stepper Example](#stepper-example)\r\n\r\n## Overview\r\n\r\n### DCMotor Library\r\n\r\nThe dcmotor library provides a simple interface to control a DC motor using PWM signals, with support for  synchronous and asynchronous movement.\r\n\r\n**Fearures:**\r\n- Control motor speed and direction using two PWM pins.\r\n- Fast and slow decay modes.\r\n\r\n### Servo Library\r\n\r\nThe servo library offers an easy way to control servomotors, with support for synchronous and asynchronous movement.\r\n\r\n**Fearures:**\r\n- Control servomotor angles with optional speed and asynchronous movement.\r\n\r\n### Stepper Library\r\n\r\nThe stepper library allows precise control of stepper motors, with support for synchronous and asynchronous movement.\r\n\r\n**Features:**\r\n- Control stepper motors using digital or PWM pins.\r\n- Support for various stepping methods: `SINGLE`, `DOUBLE`, `INTERLEAVE`, `MICROSTEP`.\r\n- Ability to perform continuous movements.\r\n\r\n## Installation\r\n\r\nEnsure you have MicroPython installed on your microcontroller. Upload the relevant Python files (`dcmotor.py`, `servo.py`, `stepper.py`) to your microcontroller.\r\n\r\n## Usage\r\n\r\n### Importing the Libraries\r\n\r\nFirst, import the required libraries:\r\n\r\n```python\r\nfrom dcmotor import DCMotor\r\nfrom servo import Servo\r\nfrom stepper import Stepper\r\n```\r\n\r\n### DCMotor Library\r\n\r\n#### Initialization\r\n\r\nCreate an instance of the `DCMotor` class by specifying the pins for speed and direction control, the PWM frequency, and the decay mode.\r\n\r\n```python\r\n# Initialize the motor with fast decay mode\r\nmotor = DCMotor(pina=0, pinb=1, freq=50, fast=True)\r\n```\r\n\r\n#### Controlling the Motor\r\n\r\nSet the motor speed and direction:\r\n\r\n```python\r\nmotor.speed(-50)  # Set speed (range: -100 to 100)\r\n```\r\n\r\nStop the motor:\r\n\r\n```python\r\nmotor.stop()\r\n```\r\n\r\n### Servo Library\r\n\r\n#### Initialization\r\n\r\nCreate a Servo object by specifying the pin to which the servomotor is connected. Optional parameters include the start angle, minimum and maximum angles, PWM frequency, and minimum and maximum pulse widths.\r\n\r\n```python\r\nservo = Servo(pin=2, start=0)\r\n```\r\n\r\n#### Moving the Servomotor\r\n\r\nUse the `move` method to move the servomotor to a specific angle. Optionally, you can specify the movement speed and asynchronous mode.\r\n\r\n##### Synchronous Movement\r\n\r\n```python\r\nservo.move(90)\r\n```\r\n\r\n##### Asynchronous Movement\r\n\r\n```python\r\nservo.move(90, speed=30, async_mode=True)\r\n```\r\n\r\n#### Checking if the Target is Reached\r\n\r\nUse the `goal_reached` method to check if the servomotor has reached the target angle.\r\n\r\n```python\r\nif servo.goal_reached():\r\n    print(\"The servo has reached the target.\")\r\n```\r\n\r\n#### Stopping the Servomotor\r\n\r\nUse the `stop` method to stop the servomotor's movement.\r\n\r\n```python\r\nservo.stop()\r\n```\r\n\r\n#### Detaching the Servomotor\r\n\r\nUse the `detach` method to detach the servomotor.\r\n\r\n```python\r\nservo.release()\r\n```\r\n\r\n### Stepper Library\r\n\r\n#### Initialization\r\n\r\nCreate a `Stepper` object by specifying the pins for the coils and, optionally, the number of microsteps.\r\n\r\n```python\r\nmotor = Stepper(ain1=12, ain2=13, bin1=14, bin2=15)\r\n```\r\n\r\n- `ain1`, `ain2`, `bin1`, `bin2`: Pin numbers for coil connections\r\n- `microsteps`: Number of microsteps (optional, default is None for digital outputs)\r\n\r\n#### Single Step\r\n\r\n```python\r\nmotor.onestep(direction=FORWARD, style=SINGLE)\r\n```\r\n\r\n- `direction`: Either `FORWARD` or `BACKWARD`\r\n- `style`: One of the stepping methods (`SINGLE`, `DOUBLE`, `INTERLEAVE`, `MICROSTEP`)\r\n\r\n#### Performing Steps\r\n\r\n```python\r\nmotor.step(200, direction=FORWARD, style=SINGLE, rpm=60)\r\n```\r\n\r\n- `steps`: Number of steps to perform\r\n- `direction`: Either `FORWARD` or `BACKWARD`\r\n- `style`: One of the stepping methods (`SINGLE`, `DOUBLE`, `INTERLEAVE`, `MICROSTEP`)\r\n- `rpm`: Revolutions per minute\r\n\r\n#### Angle-Based Steps\r\n\r\n```python\r\nmotor.angle(90, direction=FORWARD, style=SINGLE, rpm=60)\r\n```\r\n\r\n- `angle`: Angle in degrees\r\n\r\n#### Continuous Movement\r\n\r\n```python\r\nmotor.continuous(direction=FORWARD, style=SINGLE, rpm=60)\r\n```\r\n\r\n- `direction`: Either `FORWARD` or `BACKWARD`\r\n- `style`: One of the stepping methods (`SINGLE`, `DOUBLE`, `INTERLEAVE`, `MICROSTEP`)\r\n- `rpm`: Revolutions per minute\r\n\r\n#### Stop Movement\r\n\r\n```python\r\nmotor.stop()\r\n```\r\n\r\n#### Release Coils\r\n\r\n```python\r\nmotor.release()\r\n```\r\n\r\n## Examples\r\n\r\n### DCMotor Example\r\n\r\n```python\r\nfrom DCMotor import DCMotor\r\nimport time\r\n\r\nmotor = DCMotor(pina=0, pinb=1, freq=50, fast=True)\r\nmotor.speed(100)  # Set speed\r\ntime.sleep(5)  # Run for 5 seconds\r\nmotor.stop()  # Stop the motor\r\n```\r\n\r\n### Servo Example\r\n\r\n```python\r\nfrom servo import Servo\r\nimport time\r\n\r\nservo = Servo(pin=2, start=0)\r\nservo.move(90, speed=30, async_mode=True)  # 30 degrees per second\r\ntime.sleep(5)  # Wait for 5 seconds to let the servo move\r\nservo.stop()\r\n```\r\n\r\n### Stepper Example\r\n\r\n```python\r\nfrom Stepper import Stepper\r\nimport time\r\n\r\nmotor = Stepper(ain1=12, ain2=13, bin1=14, bin2=15, microsteps=16)\r\nmotor.step(steps=200, direction=FORWARD, style=SINGLE, rpm=60)  # Move 200 steps\r\ntime.sleep(5)  # Wait for 5 seconds\r\nmotor.stop()  # Stop the motor\r\n```\r\n","funding_links":[],"categories":["Libraries"],"sub_categories":["Motion"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcnadler86%2FMicroPython_Motor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcnadler86%2FMicroPython_Motor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcnadler86%2FMicroPython_Motor/lists"}