Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tfeldmann/arduino-motordriver
Generic Arduino interface for various motor drivers.
https://github.com/tfeldmann/arduino-motordriver
arduino controller motor pwm
Last synced: 3 months ago
JSON representation
Generic Arduino interface for various motor drivers.
- Host: GitHub
- URL: https://github.com/tfeldmann/arduino-motordriver
- Owner: tfeldmann
- License: mit
- Created: 2021-11-02T14:36:30.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-10-01T04:39:28.000Z (over 1 year ago)
- Last Synced: 2024-05-01T20:40:46.436Z (8 months ago)
- Topics: arduino, controller, motor, pwm
- Language: C++
- Homepage:
- Size: 37.1 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Arduino MotorDriver Library
[![tests](https://github.com/tfeldmann/Arduino-MotorDriver/actions/workflows/tests.yaml/badge.svg)](https://github.com/tfeldmann/Arduino-MotorDriver/actions/workflows/tests.yaml)
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/tfeldmann/library/MotorDriver.svg)](https://registry.platformio.org/libraries/tfeldmann/MotorDriver)This library let's you easily switch between different methods of controlling motors.
Assume you have the following code which controls a DC motor via an PWM and direction pin:
```c
// code without MotorDriver libraryconst int MOTOR_DIR_PIN = 5;
const int MOTOR_PWM_PIN = 6;void setup() {
pinMode(MOTOR_DIR_PIN, OUTPUT);
pinMode(MOTOR_PWM_PIN, OUTPUT);
}void loop() {
// forward
digitalWrite(MOTOR_DIR_PIN, HIGH);
analogWrite(MOTOR_PWM_PIN, 255);
delay(1000);// stop
analogWrite(MOTOR_PWM_PIN, 0);
delay(1000);// backward
digitalWrite(MOTOR_DIR_PIN, LOW);
analogWrite(MOTOR_PWM_PIN, 255);
delay(1000);// stop
analogWrite(MOTOR_PWM_PIN, 0);
delay(1000);
}
```With this library this can be simplified to:
```c
#includeDirPwmMotor motor(5, 6);
void setup() {}
void loop() {
motor.setSpeed(255);
delay(1000);motor.stop();
delay(1000);motor.setSpeed(-255);
delay(1000);motor.stop();
delay(1000);
}
```Now imagine you change the motor control circuit and now have two
separate direction pins FWD and BWD and a PWM pin for speed.
With this library you only need to change the `DirPwmMotor` to `FwdBwdPwmMotor`:```diff
-DirPwmMotor motor(5, 6);
+FwdBwdPwmMotor motor(4, 5, 6);
```A `MotorDriver` has a super simple api:
```c
int speed();
void setSpeed(int speed);
bool reversed();
void setReversed(bool reversed);
void stop(bool brake = false);
```The following implementations are available:
| Classname | Pins | Comment |
| -------------------------- | ------------------------------ | -------------------------------------------------------- |
| `MotorDriver` | \* | Generic base class, define your own interface |
| `PwmMotor` | `Pwm` | A single direction pwm motor controller |
| `DirPwmMotor` | `Dir`, `Pwm` | A direction / pwm motor controller |
| `FwdBwdPwmMotor` | `Dir FWD`, `Dir BWD`, `Pwm` | Uses two pins to set the direction |
| `HBridgeHighLowMotor` | `H1`, `L1`, `H2`, `L2` | A H-bridge motor controller with high / low pwm controls |
| `HBridgeSelectPwmMotor` | `Sel1`, `Pwm1`, `Sel2`, `Pwm2` | A H-bridge controller with select / pwm controls |
| `HBridgeSoftDeadtimeMotor` | `H1`, `L1`, `H2`, `L2` | A H-bridge motor controller with software deadtime |PRs / issues welcome!