Skip to content

Commit 3e88bac

Browse files
committed
0.1.2 DRV8825
1 parent 7aefcd0 commit 3e88bac

File tree

7 files changed

+255
-30
lines changed

7 files changed

+255
-30
lines changed

libraries/DRV8825/DRV8825.cpp

Lines changed: 92 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: DRV8825.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.1
4+
// VERSION: 0.1.2
55
// PURPOSE: Arduino library for DRV8825 stepper motor driver
66
// DATE: 2022-07-07
77
// URL: https://github.com/RobTillaart/DRV8825
@@ -10,6 +10,9 @@
1010
// 0.1.1 2022-07-08 update readme.md
1111
// add setPosition() + getPosition();
1212
// minor optimizations
13+
// 0.1.2 2022-07-14 add support for SLP RST and EN pin
14+
// update documentation
15+
// update build-CI
1316

1417

1518
#include "DRV8825.h"
@@ -20,15 +23,35 @@ DRV8825::DRV8825()
2023
}
2124

2225

23-
bool DRV8825::begin(uint8_t dirPin, uint8_t stepPin)
26+
bool DRV8825::begin(uint8_t DIR, uint8_t STEP, uint8_t EN, uint8_t RST, uint8_t SLP)
2427
{
25-
_directionPin = dirPin;
26-
_stepPin = stepPin;
28+
_directionPin = DIR;
29+
_stepPin = STEP;
30+
2731
pinMode(_directionPin, OUTPUT);
2832
pinMode(_stepPin, OUTPUT);
33+
digitalWrite(_directionPin, LOW);
34+
digitalWrite(_stepPin, LOW);
2935

30-
digitalWrite(_directionPin, LOW); // TODO check
31-
digitalWrite(_stepPin, LOW); // TODO check
36+
// handle conditional parameters
37+
if (EN != 255)
38+
{
39+
_enablePin = EN;
40+
pinMode(_enablePin, OUTPUT);
41+
digitalWrite(_enablePin, LOW); // page 3
42+
}
43+
if (RST != 255)
44+
{
45+
_resetPin = RST;
46+
pinMode(_resetPin, OUTPUT);
47+
digitalWrite(_resetPin, LOW); // page 3
48+
}
49+
if (SLP != 255)
50+
{
51+
_sleepPin = SLP;
52+
pinMode(_sleepPin, OUTPUT);
53+
digitalWrite(_sleepPin, HIGH); // page 3
54+
}
3255
return true;
3356
}
3457

@@ -126,6 +149,69 @@ uint16_t DRV8825::getPosition()
126149
return _pos;
127150
}
128151

152+
// Table page 3
153+
void DRV8825::enable()
154+
{
155+
if (_enablePin != 255)
156+
{
157+
digitalWrite(_enablePin, LOW);
158+
}
159+
}
160+
161+
void DRV8825::disable()
162+
{
163+
if (_enablePin != 255)
164+
{
165+
digitalWrite(_enablePin, HIGH);
166+
}
167+
}
168+
169+
bool DRV8825::isEnabled()
170+
{
171+
if (_enablePin != 255)
172+
{
173+
return (digitalRead(_enablePin) == LOW);
174+
}
175+
return true;
176+
}
177+
178+
179+
void DRV8825::reset()
180+
{
181+
if (_resetPin != 255)
182+
{
183+
digitalWrite(_resetPin, HIGH);
184+
delay(1);
185+
digitalWrite(_resetPin, LOW);
186+
}
187+
}
188+
189+
190+
void DRV8825::sleep()
191+
{
192+
if (_sleepPin != 255)
193+
{
194+
digitalWrite(_sleepPin, LOW);
195+
}
196+
}
197+
198+
void DRV8825::wakeup()
199+
{
200+
if (_sleepPin != 255)
201+
{
202+
digitalWrite(_sleepPin, HIGH);
203+
}
204+
}
205+
206+
bool DRV8825::isSleeping()
207+
{
208+
if (_sleepPin != 255)
209+
{
210+
return (digitalRead(_sleepPin) == LOW);
211+
}
212+
return false;
213+
}
214+
129215

130216
// -- END OF FILE --
131217

libraries/DRV8825/DRV8825.h

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// FILE: DRV8825.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.1.1
5+
// VERSION: 0.1.2
66
// PURPOSE: Arduino library for DRV8825 stepper motor driver
77
// DATE: 2022-07-07
88
// URL: https://github.com/RobTillaart/DRV8825
@@ -23,7 +23,7 @@ class DRV8825
2323
public:
2424
DRV8825();
2525

26-
bool begin(uint8_t dirPin, uint8_t stepPin);
26+
bool begin(uint8_t DIR, uint8_t STEP, uint8_t EN = 255, uint8_t RST = 255, uint8_t SLP = 255);
2727

2828
// DIRECTION
2929
// 0 = DRV8825_CLOCK_WISE
@@ -51,15 +51,33 @@ class DRV8825
5151
void setStepPulseLength(uint16_t us = 2);
5252
uint16_t getStepPulseLength();
5353

54+
// ENABLE pin should be set.
55+
void enable();
56+
void disable();
57+
bool isEnabled();
58+
59+
// RESET pin should be set.
60+
void reset();
61+
62+
// SLEEP pin should be set.
63+
void sleep();
64+
void wakeup();
65+
bool isSleeping();
66+
5467

5568
protected:
56-
uint16_t _stepsPerRotation = 0;
5769
uint8_t _directionPin = 255;
5870
uint8_t _stepPin = 255;
71+
uint8_t _enablePin = 255;
72+
uint8_t _resetPin = 255;
73+
uint8_t _sleepPin = 255;
74+
5975
uint8_t _direction = DRV8825_CLOCK_WISE;
76+
77+
uint16_t _stepsPerRotation = 0;
6078
uint32_t _steps = 0;
61-
uint16_t _us = 2;
6279
uint16_t _pos = 0;
80+
uint16_t _us = 2;
6381
};
6482

6583

libraries/DRV8825/README.md

Lines changed: 83 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Arduino library for DRV8825 stepper motor driver.
1515

1616
**DRV8825** is a library for DRV8825 stepper motor driver.
1717

18-
**Warning: experimental**
18+
**Warning: experimental** needs testing.
1919

2020
The DRV8825 stepper motor library controls a stepper motor with
2121
a direction signal and a step pulse.
@@ -44,8 +44,10 @@ const uint8_t DRV8825_COUNTERCLOCK_WISE = 1; // HIGH
4444
### Constructor
4545

4646
- **DRV8825()** Constructor.
47-
- **bool begin(uint8_t dirPin, uint8_t stepPin)** set the direction pin and step pin.
47+
- **bool begin(uint8_t DIR, uint8_t STEP, uint8_t EN = 255, uint8_t RST = 255, uint8_t SLP = 255)** set the direction pin and step pin.
4848
Both pins are set to LOW. For direction this means DRV8825_CLOCK_WISE.
49+
Optional the enable, reset and sleep pin can be set.
50+
If these are set to 255 the related functions won't do anything.
4951

5052

5153
### Direction
@@ -109,9 +111,72 @@ Normally these need not to be changed.
109111
Default the value = 2.
110112

111113

114+
### Enable (EN)
115+
116+
- **void enable()** sets the enable line LOW.
117+
- **void disable()** sets the enable line HIGH.
118+
- **bool isEnabled()** reads back the line state.
119+
True means enabled.
120+
121+
After **enable()** the system needs 650 ns before **step()**
122+
can be called. See 7.6 Timing Requirements.
123+
124+
125+
### Reset (RST)
126+
127+
- **void reset()** sends a reset pulse to the device.
128+
129+
130+
### Sleep (SLP)
131+
132+
- **void sleep()** sets the enable line LOW.
133+
- **void wakeup()** sets the enable line HIGH.
134+
- **bool isSleeping()** reads back the line state.
135+
True means enabled.
136+
137+
After **wakeup()** the system needs **1700 us** before **step()**
138+
can be called. See 7.6 Timing Requirements.
139+
140+
141+
### MicroSteps
142+
143+
The pins M0, M1 and M2 are to be used to set micro steps.
144+
This library does not allow them to be set from code as
145+
normally these won't change in a project.
146+
147+
| STEP MODE | M2 | M1 | M0 |
148+
|:-----------:|:----:|:----:|:----:|
149+
| full | 0 | 0 | 0 |
150+
| half | 0 | 0 | 1 |
151+
| 1/4 | 0 | 1 | 0 |
152+
| 1/8 | 0 | 1 | 1 |
153+
| 1/16 | 1 | 0 | 0 |
154+
| 1/32 | 1 | 0 | 1 |
155+
| 1/32 | 1 | 1 | 0 |
156+
| 1/32 | 1 | 1 | 1 |
157+
158+
Check datasheet for details.
159+
160+
161+
### Fault (FLT)
162+
163+
The FLT pin indicates that an error has occurred.
164+
The library does not monitor this pin as that would need a background process.
165+
The user is advised to check this pin at regular intervals
166+
or connect the FLT pin to an interrupt pin of the processor.
167+
168+
- LOW == fault condition (overtemp, overcurrent)
169+
- HIGH == OK
170+
171+
The device does not provide means to interpret the type of
172+
error, but one could at least call **disable()**.
173+
174+
Check datasheet for the details.
175+
176+
112177
## Operational
113178

114-
The base functions are:
179+
The minimal code is:
115180

116181
```cpp
117182
DRV8825 stepper;
@@ -143,19 +208,12 @@ Some will only be worked on if requested and time permits.
143208

144209
#### must
145210

211+
- test test test
146212
- add examples
147213
- update documentation
148214
- investigate other pins
149-
- M0..M2 8.3.5 micro steps
150215
- decay mode 8.3.3 there are 3 modi)
151-
- fault pin FLT input to detect errors
152-
- sleep pin SLP 8.3.6
153-
- enable pin EN 8.3.6
154-
- reset pin RST 8.3.6
155216
- other?
156-
- if stepsPerRotation is set to zero, should pos be set to zero?
157-
- NB it will not be updated any more.
158-
- do we need steps counter?
159217

160218
#### should
161219

@@ -164,10 +222,8 @@ Some will only be worked on if requested and time permits.
164222
- blocking
165223
- max 1 rotation?
166224
- optimize "position admin"
167-
- gotoPosition(pos)..
168-
- needs steps(n) above.
169-
- investigate other similar STEP/DIR controllers
170-
- DRV88xx series?
225+
- should begin return bool?
226+
171227

172228
#### could
173229

@@ -176,11 +232,20 @@ Some will only be worked on if requested and time permits.
176232
- only when needed?
177233
- 8825 as derived? or as base class?
178234
- which others are similar?
179-
- investigate controlling a DRV8825 with an PCF8574
180-
- pins needed (M0..M2, SLP, RST, EN, DIR, STEP)
181-
- first need a decent basic library.
235+
- A4988, DRV8824, more?
182236

183237
#### wont
184238

185239
- left() + right();
240+
- if stepsPerRotation is set to zero, should pos be set to zero?
241+
- NB it will not be updated any more.
242+
- leaving it as is, could allow "creative calibration"
243+
- investigate controlling a DRV8825 with an PCF8574
244+
- pins needed (M0..M2, SLP, RST, EN, DIR, STEP)
245+
- first need a decent basic library.
246+
- would be a class on its own.
247+
- gotoPosition(pos)..
248+
- needs steps(n) above? for loop!
249+
- shortest angle/path or via current CW/CCW mode.
250+
- user can implement his own strategy.
186251

libraries/DRV8825/keywords.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ getSteps KEYWORD2
1919
setStepPulseLength KEYWORD2
2020
getStepPulseLength KEYWORD2
2121

22+
enable KEYWORD2
23+
disable KEYWORD2
24+
isEnabled KEYWORD2
25+
reset KEYWORD2
26+
sleep KEYWORD2
27+
wakeup KEYWORD2
28+
isSleeping KEYWORD2
29+
2230

2331
# Constants (LITERAL1)
2432
DRV8825_LIB_VERSION LITERAL1

libraries/DRV8825/library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"type": "git",
1616
"url": "https://github.com/RobTillaart/DRV8825.git"
1717
},
18-
"version": "0.1.1",
18+
"version": "0.1.2",
1919
"license": "MIT",
2020
"frameworks": "arduino",
2121
"platforms": "*",

libraries/DRV8825/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=DRV8825
2-
version=0.1.1
2+
version=0.1.2
33
author=Rob Tillaart <[email protected]>
44
maintainer=Rob Tillaart <[email protected]>
55
sentence=Arduino library for DRV8825 stepper motor driver.

0 commit comments

Comments
 (0)