Skip to content

Commit 6182afb

Browse files
committed
0.1.0 DRV8825
1 parent 243fe8f commit 6182afb

File tree

13 files changed

+609
-0
lines changed

13 files changed

+609
-0
lines changed

libraries/DRV8825/.arduino-ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
compile:
2+
# Choosing to run compilation tests on 2 different Arduino platforms
3+
platforms:
4+
- uno
5+
# - due
6+
# - zero
7+
# - leonardo
8+
- m4
9+
- esp32
10+
- esp8266
11+
# - mega2560
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
name: Arduino-lint
3+
4+
on: [push, pull_request]
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- uses: arduino/arduino-lint-action@v1
11+
with:
12+
library-manager: update
13+
compliance: strict
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
name: Arduino CI
3+
4+
on: [push, pull_request]
5+
6+
jobs:
7+
runTest:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v2
12+
- uses: ruby/setup-ruby@v1
13+
with:
14+
ruby-version: 2.6
15+
- run: |
16+
gem install arduino_ci
17+
arduino_ci.rb
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: JSON check
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.json'
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: json-syntax-check
15+
uses: limitusus/json-syntax-check@v1
16+
with:
17+
pattern: "\\.json$"
18+

libraries/DRV8825/DRV8825.cpp

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
//
2+
// FILE: DRV8825.cpp
3+
// AUTHOR: Rob Tillaart
4+
// VERSION: 0.1.0
5+
// PURPOSE: Arduino library for DRV8825 stepper motor driver
6+
// DATE: 2022-07-07
7+
// URL: https://github.com/RobTillaart/DRV8825
8+
9+
// 0.1.0 2022-07-07 initial version.
10+
11+
12+
#include "DRV8825.h"
13+
14+
15+
DRV8825::DRV8825()
16+
{
17+
}
18+
19+
20+
bool DRV8825::begin(uint8_t dirPin, uint8_t stepPin)
21+
{
22+
_directionPin = dirPin;
23+
_stepPin = stepPin;
24+
pinMode(_directionPin, OUTPUT);
25+
pinMode(_stepPin, OUTPUT);
26+
27+
digitalWrite(_directionPin, LOW); // TODO check
28+
digitalWrite(_stepPin, LOW); // TODO check
29+
return true;
30+
}
31+
32+
33+
void DRV8825::setStepsPerRotation(uint16_t stepsPerRotation)
34+
{
35+
_stepsPerRotation = stepsPerRotation;
36+
}
37+
38+
39+
uint16_t DRV8825::getStepsPerRotation()
40+
{
41+
return _stepsPerRotation;
42+
}
43+
44+
45+
bool DRV8825::setDirection(uint8_t direction)
46+
{
47+
if (direction > 1) return false;
48+
_direction = direction;
49+
digitalWrite(_directionPin, _direction);
50+
delayMicroseconds(_us);
51+
return true;
52+
}
53+
54+
55+
uint8_t DRV8825::getDirection()
56+
{
57+
return digitalRead(_directionPin);
58+
}
59+
60+
61+
void DRV8825::step()
62+
{
63+
digitalWrite(_stepPin, HIGH);
64+
delayMicroseconds(_us);
65+
digitalWrite(_stepPin, LOW);
66+
delayMicroseconds(_us);
67+
68+
if (_stepsPerRotation > 0)
69+
{
70+
if (_direction == DRV8825_CLOCK_WISE) _steps++;
71+
else _steps--;
72+
}
73+
}
74+
75+
76+
int32_t DRV8825::resetSteps(int32_t s)
77+
{
78+
int32_t t = _steps;
79+
_steps = s;
80+
return t;
81+
}
82+
83+
84+
int32_t DRV8825::getSteps()
85+
{
86+
return _steps;
87+
}
88+
89+
90+
void DRV8825::setStepPulseLength(uint16_t us)
91+
{
92+
_us = us;
93+
}
94+
95+
96+
uint16_t DRV8825::getStepPulseLength()
97+
{
98+
return _us;
99+
}
100+
101+
102+
// -- END OF FILE --
103+
104+

libraries/DRV8825/DRV8825.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#pragma once
2+
//
3+
// FILE: DRV8825.h
4+
// AUTHOR: Rob Tillaart
5+
// VERSION: 0.1.0
6+
// PURPOSE: Arduino library for DRV8825 stepper motor driver
7+
// DATE: 2022-07-07
8+
// URL: https://github.com/RobTillaart/DRV8825
9+
10+
11+
#include "Arduino.h"
12+
13+
14+
#define DRV8825_LIB_VERSION (F("0.1.0"))
15+
16+
17+
// setDirection
18+
const uint8_t DRV8825_CLOCK_WISE = 0; // LOW
19+
const uint8_t DRV8825_COUNTERCLOCK_WISE = 1; // HIGH
20+
21+
22+
class DRV8825
23+
{
24+
public:
25+
DRV8825();
26+
27+
bool begin(uint8_t dirPin, uint8_t stepPin);
28+
29+
// DIRECTION
30+
// 0 = DRV8825_CLOCK_WISE
31+
// 1 = DRV8825_COUNTERCLOCK_WISE
32+
// returns false if parameter out of range.
33+
bool setDirection(uint8_t direction = DRV8825_CLOCK_WISE);
34+
uint8_t getDirection();
35+
36+
// STEPS
37+
void setStepsPerRotation(uint16_t stepsPerRotation);
38+
uint16_t getStepsPerRotation();
39+
void step();
40+
int32_t resetSteps(int32_t s = 0 );
41+
int32_t getSteps();
42+
43+
// CONFIGURATION
44+
// step pulse length is in microseconds
45+
// default 1.9 us
46+
void setStepPulseLength(uint16_t us = 2);
47+
uint16_t getStepPulseLength();
48+
49+
50+
private:
51+
uint16_t _stepsPerRotation = 0;
52+
uint8_t _directionPin = 255;
53+
uint8_t _stepPin = 255;
54+
uint8_t _direction = DRV8825_CLOCK_WISE;
55+
int32_t _steps = 0;
56+
uint16_t _us = 2;
57+
};
58+
59+
60+
// -- END OF FILE --
61+
62+

libraries/DRV8825/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022-2022 Rob Tillaart
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

libraries/DRV8825/README.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
2+
[![Arduino CI](https://github.com/RobTillaart/DRV8825/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
3+
[![Arduino-lint](https://github.com/RobTillaart/DRV8825/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/DRV8825/actions/workflows/arduino-lint.yml)
4+
[![JSON check](https://github.com/RobTillaart/DRV8825/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/DRV8825/actions/workflows/jsoncheck.yml)
5+
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/DRV8825/blob/master/LICENSE)
6+
[![GitHub release](https://img.shields.io/github/release/RobTillaart/DRV8825.svg?maxAge=3600)](https://github.com/RobTillaart/DRV8825/releases)
7+
8+
9+
# DRV8825
10+
11+
Arduino library for DRV8825 stepper motor driver.
12+
13+
14+
## Description
15+
16+
**DRV8825** is a library for DRV8825 stepper motor driver.
17+
18+
**Warning: experimental**
19+
20+
The 8825 stepper motor driver control a stepper motor with
21+
a direction signal and a step pulse.
22+
23+
24+
## Hardware connection
25+
26+
See datasheet.
27+
28+
29+
## Interface
30+
31+
32+
### Constants
33+
34+
```cpp
35+
// setDirection
36+
const uint8_t DRV8825_CLOCK_WISE = 0; // LOW
37+
const uint8_t DRV8825_COUNTERCLOCK_WISE = 1; // HIGH
38+
```
39+
40+
### Constructor
41+
42+
- **DRV8825()** Constructor.
43+
44+
with steps per rotation as parameter.
45+
This parameter is optional and if set to zero, steps will not be counted.
46+
- **bool begin(uint8_t dirPin, uint8_t stepPin)** set the direction and step pin.
47+
Both pins are initially set to LOW.
48+
49+
50+
### Direction
51+
52+
To define in which way the motor will turn.
53+
54+
- **void setDirection(uint8_t direction = DRV8825_CLOCK_WISE)** idem.
55+
- **uint8_t getDirection()** returns DRV8825_CLOCK_WISE (0) or
56+
DRV8825_COUNTERCLOCK_WISE (1).
57+
58+
59+
### Steps
60+
61+
- **void setStepsPerRotation(uint16_t stepsPerRotation)** specifies the steps per rotation for the specific stepper motor.
62+
If set to zero, the steps will not be counted.
63+
- **uint16_t getStepsPerRotation()** returns the value set before
64+
or zero default.
65+
- **void step()** The workhorse, will give a pulse on the STEP pin.
66+
- **int32_t resetSteps(int32_t s = 0; )**
67+
- **int32_t getSteps()** returns the sum of the steps made.
68+
CW = + and CWW = - so one can go back to a relative position.
69+
70+
The combination getSteps with stepsPerRotation indicates the position of the motor.
71+
72+
73+
## Operational
74+
75+
The base functions are:
76+
77+
```cpp
78+
DRV8825 stpr;
79+
80+
void setup()
81+
{
82+
Serial.begin(115200);
83+
...
84+
stpr.begin(4, 5); // direction + step pin
85+
stpr.setDirection(DRV8825_CLOCK_WISE);
86+
...
87+
}
88+
89+
void loop()
90+
{
91+
...
92+
stpr.step;
93+
...
94+
}
95+
```
96+
97+
See examples.
98+
99+
100+
## Future
101+
102+
Ideas are kept here so they won't get lost.
103+
104+
- redo interface
105+
- stepCW() + stepCCW(); or just CW(); and CCW();
106+
- left() + right();
107+
- step(nr of steps) blocking!!
108+
- add position
109+
- = steps % steps/rotation
110+
- base class DIRSTEP
111+
- 8825 as derived?
112+
- other too

0 commit comments

Comments
 (0)