mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-09-19 16:46:11 -04:00
0.2.0 DRV8825
This commit is contained in:
parent
be6be3572f
commit
d7f33eb32c
@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.1.5] - 2023-09-14
|
||||
- fix #9
|
||||
- add example**DRV8825_reset_sleep.ino**
|
||||
- update readme.md badges
|
||||
- minor edits (internal variables)
|
||||
|
||||
|
||||
## [0.1.4] - 2023-02-19
|
||||
- fix keywords.txt
|
||||
- add bool return value to enable, reset and sleep functions.
|
||||
@ -15,7 +22,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
- update license 2023
|
||||
- minor edits
|
||||
|
||||
|
||||
## [0.1.3] - 2022-11-02
|
||||
- add changelog.md
|
||||
- add rp2040 to build-CI
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: DRV8825.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.4
|
||||
// VERSION: 0.2.0
|
||||
// PURPOSE: Arduino library for DRV8825 stepper motor driver
|
||||
// DATE: 2022-07-07
|
||||
// URL: https://github.com/RobTillaart/DRV8825
|
||||
@ -36,7 +36,7 @@ bool DRV8825::begin(uint8_t DIR, uint8_t STEP, uint8_t EN, uint8_t RST, uint8_t
|
||||
{
|
||||
_resetPin = RST;
|
||||
pinMode(_resetPin, OUTPUT);
|
||||
digitalWrite(_resetPin, LOW); // page 3
|
||||
digitalWrite(_resetPin, HIGH); // page 3
|
||||
}
|
||||
if (SLP != 255)
|
||||
{
|
||||
@ -81,22 +81,22 @@ uint8_t DRV8825::getDirection()
|
||||
void DRV8825::step()
|
||||
{
|
||||
digitalWrite(_stepPin, HIGH);
|
||||
if (_us > 0) delayMicroseconds(_us);
|
||||
if (_stepPulseLength > 0) delayMicroseconds(_stepPulseLength);
|
||||
digitalWrite(_stepPin, LOW);
|
||||
if (_us > 0) delayMicroseconds(_us);
|
||||
if (_stepPulseLength > 0) delayMicroseconds(_stepPulseLength);
|
||||
|
||||
_steps++;
|
||||
if (_stepsPerRotation > 0)
|
||||
{
|
||||
if (_direction == DRV8825_CLOCK_WISE)
|
||||
{
|
||||
_pos++;
|
||||
if (_pos >= _stepsPerRotation) _pos = 0;
|
||||
_position++;
|
||||
if (_position >= _stepsPerRotation) _position = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_pos == 0) _pos = _stepsPerRotation;
|
||||
_pos--;
|
||||
if (_position == 0) _position = _stepsPerRotation;
|
||||
_position--;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -116,29 +116,29 @@ uint32_t DRV8825::getSteps()
|
||||
}
|
||||
|
||||
|
||||
void DRV8825::setStepPulseLength(uint16_t us)
|
||||
void DRV8825::setStepPulseLength(uint16_t stepPulseLength)
|
||||
{
|
||||
_us = us;
|
||||
_stepPulseLength = stepPulseLength;
|
||||
}
|
||||
|
||||
|
||||
uint16_t DRV8825::getStepPulseLength()
|
||||
{
|
||||
return _us;
|
||||
return _stepPulseLength;
|
||||
}
|
||||
|
||||
|
||||
bool DRV8825::setPosition(uint16_t pos)
|
||||
bool DRV8825::setPosition(uint16_t position)
|
||||
{
|
||||
if (pos >= _stepsPerRotation) return false;
|
||||
_pos = pos;
|
||||
if (position >= _stepsPerRotation) return false;
|
||||
_position = position;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
uint16_t DRV8825::getPosition()
|
||||
{
|
||||
return _pos;
|
||||
return _position;
|
||||
}
|
||||
|
||||
// Table page 3
|
||||
@ -169,9 +169,9 @@ bool DRV8825::isEnabled()
|
||||
bool DRV8825::reset()
|
||||
{
|
||||
if (_resetPin == 255) return false;
|
||||
digitalWrite(_resetPin, HIGH);
|
||||
delay(1);
|
||||
digitalWrite(_resetPin, LOW);
|
||||
delay(1);
|
||||
digitalWrite(_resetPin, HIGH);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: DRV8825.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.4
|
||||
// VERSION: 0.2.0
|
||||
// PURPOSE: Arduino library for DRV8825 stepper motor driver
|
||||
// DATE: 2022-07-07
|
||||
// URL: https://github.com/RobTillaart/DRV8825
|
||||
@ -11,7 +11,7 @@
|
||||
#include "Arduino.h"
|
||||
|
||||
|
||||
#define DRV8825_LIB_VERSION (F("0.1.4"))
|
||||
#define DRV8825_LIB_VERSION (F("0.2.0"))
|
||||
|
||||
|
||||
// setDirection
|
||||
@ -41,14 +41,14 @@ public:
|
||||
|
||||
// POSITION
|
||||
// only works if stepsPerRotation > 0
|
||||
// returns false if pos > stepsPerRotation.
|
||||
bool setPosition(uint16_t pos = 0);
|
||||
// returns false if position > stepsPerRotation.
|
||||
bool setPosition(uint16_t position = 0);
|
||||
uint16_t getPosition();
|
||||
|
||||
// CONFIGURATION
|
||||
// step pulse length is in microseconds
|
||||
// datasheet default = 1.9 us
|
||||
void setStepPulseLength(uint16_t us = 2);
|
||||
void setStepPulseLength(uint16_t stepPulseLength = 2);
|
||||
uint16_t getStepPulseLength();
|
||||
|
||||
// ENABLE pin should be set.
|
||||
@ -76,8 +76,8 @@ protected:
|
||||
|
||||
uint16_t _stepsPerRotation = 0;
|
||||
uint32_t _steps = 0;
|
||||
uint16_t _pos = 0;
|
||||
uint16_t _us = 2;
|
||||
uint16_t _position = 0;
|
||||
uint16_t _stepPulseLength = 2;
|
||||
};
|
||||
|
||||
|
||||
|
@ -2,8 +2,11 @@
|
||||
[![Arduino CI](https://github.com/RobTillaart/DRV8825/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
||||
[![Arduino-lint](https://github.com/RobTillaart/DRV8825/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/DRV8825/actions/workflows/arduino-lint.yml)
|
||||
[![JSON check](https://github.com/RobTillaart/DRV8825/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/DRV8825/actions/workflows/jsoncheck.yml)
|
||||
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/DRV8825.svg)](https://github.com/RobTillaart/DRV8825/issues)
|
||||
|
||||
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/DRV8825/blob/master/LICENSE)
|
||||
[![GitHub release](https://img.shields.io/github/release/RobTillaart/DRV8825.svg?maxAge=3600)](https://github.com/RobTillaart/DRV8825/releases)
|
||||
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/DRV8825.svg)](https://registry.platformio.org/libraries/robtillaart/DRV8825)
|
||||
|
||||
|
||||
# DRV8825
|
||||
@ -19,7 +22,8 @@ Arduino library for DRV8825 stepper motor driver.
|
||||
|
||||
The DRV8825 stepper motor library controls a stepper motor with
|
||||
a direction signal and a step pulse.
|
||||
The library has a default pulse length of 2 us however this can be adjusted to the specific requirements of the motor.
|
||||
The library has a default pulse length of 2 us however this can be
|
||||
adjusted to the specific requirements of the motor.
|
||||
|
||||
The library will probably work for similar controllers.
|
||||
This is not tested. If you have some working, please let me know.
|
||||
@ -80,9 +84,9 @@ default to zero.
|
||||
Returns the last value of internal steps counter.
|
||||
- **uint32_t getSteps()** returns the steps made since start of the program or the last **resetSteps()**.
|
||||
Its purpose is to have an indication of usage (wear and tear).
|
||||
- **bool setPosition(uint16_t pos = 0)** to calibrate the position of the motor. Default value is zero.
|
||||
- **bool setPosition(uint16_t position = 0)** to calibrate the position of the motor. Default value is zero.
|
||||
Works only if stepsPerRotation > 0.
|
||||
Returns false if pos > stepsPerRotation.
|
||||
Returns false if position > stepsPerRotation.
|
||||
Note: it does not rotate the motor to a position.
|
||||
Note: there is no relation between position and steps.
|
||||
- **uint16_t getPosition()** returns the position which is kin the range 0 .. stepsPerRotation - 1.
|
||||
@ -108,7 +112,7 @@ This is done as the library added the position functions.
|
||||
|
||||
### Configuration
|
||||
|
||||
- **void setStepPulseLength(uint16_t us = 2)** configures the pulse length of one step.
|
||||
- **void setStepPulseLength(uint16_t pulseLength = 2)** configures the pulse length of one step.
|
||||
This is defined in microseconds, default is 2 which is almost the 1.9 from the datasheet.
|
||||
Normally these need not to be changed.
|
||||
- **uint16_t getStepPulseLength()** returns the set value in microseconds.
|
||||
@ -234,7 +238,6 @@ Some will only be worked on if requested and time permits.
|
||||
- optimize "position admin"
|
||||
- should begin return bool?
|
||||
|
||||
|
||||
#### Could
|
||||
|
||||
- stepCW() + stepCCW()
|
||||
@ -259,3 +262,12 @@ Some will only be worked on if requested and time permits.
|
||||
- shortest angle/path or via current CW/CCW mode.
|
||||
- user can implement his own strategy.
|
||||
|
||||
|
||||
## Support
|
||||
|
||||
If you appreciate my libraries, you can support the development and maintenance.
|
||||
Improve the quality of the libraries by providing issues and Pull Requests, or
|
||||
donate through PayPal or GitHub sponsors.
|
||||
|
||||
Thank you,
|
||||
|
||||
|
@ -0,0 +1,89 @@
|
||||
//
|
||||
// FILE: DRV8825_reset_sleep.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo
|
||||
// DATE: 2022-11-14
|
||||
|
||||
#include "DRV8825.h"
|
||||
|
||||
DRV8825 stepper;
|
||||
const int DIRECTION_PIN = 4;
|
||||
const int STEP_PIN = 5;
|
||||
|
||||
|
||||
// connect to ground if pushed
|
||||
const int FORWARD_PIN = 8;
|
||||
const int BACKWARD_PIN = 9;
|
||||
const int ENABLE_PIN = 10;
|
||||
const int RESET_PIN = 11;
|
||||
const int SLEEP_PIN = 12;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("DRV8825_LIB_VERSION: ");
|
||||
Serial.println(DRV8825_LIB_VERSION);
|
||||
|
||||
stepper.begin(DIRECTION_PIN, STEP_PIN, ENABLE_PIN, RESET_PIN, SLEEP_PIN);
|
||||
|
||||
pinMode(FORWARD_PIN, INPUT_PULLUP);
|
||||
pinMode(BACKWARD_PIN, INPUT_PULLUP);
|
||||
pinMode(ENABLE_PIN, INPUT_PULLUP);
|
||||
pinMode(RESET_PIN, INPUT_PULLUP);
|
||||
pinMode(SLEEP_PIN, INPUT_PULLUP);
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// read both buttons
|
||||
bool fw = digitalRead(FORWARD_PIN) == LOW;
|
||||
bool bw = digitalRead(BACKWARD_PIN) == LOW;
|
||||
|
||||
// process the button state
|
||||
if (fw && bw) // both buttons pressed
|
||||
{
|
||||
Serial.println("not allowed, please release both buttons.");
|
||||
delay(1000); // block
|
||||
}
|
||||
else if (fw)
|
||||
{
|
||||
stepper.setDirection(DRV8825_CLOCK_WISE);
|
||||
delay(50);
|
||||
stepper.step();
|
||||
delay(50);
|
||||
}
|
||||
else if (bw)
|
||||
{
|
||||
stepper.setDirection(DRV8825_COUNTERCLOCK_WISE);
|
||||
delay(50);
|
||||
stepper.step();
|
||||
delay(50);
|
||||
}
|
||||
|
||||
// handle RESET and SLEEP
|
||||
if (digitalRead(RESET_PIN))
|
||||
{
|
||||
stepper.reset();
|
||||
delay(100); // debounce
|
||||
}
|
||||
|
||||
if (digitalRead(SLEEP_PIN))
|
||||
{
|
||||
if (stepper.isSleeping())
|
||||
{
|
||||
stepper.wakeup();
|
||||
}
|
||||
else
|
||||
{
|
||||
stepper.sleep();
|
||||
}
|
||||
delay(100); // debounce
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
@ -15,9 +15,9 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/DRV8825.git"
|
||||
},
|
||||
"version": "0.1.4",
|
||||
"version": "0.2.0",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"frameworks": "*",
|
||||
"platforms": "*",
|
||||
"headers": "DRV8825.h"
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=DRV8825
|
||||
version=0.1.4
|
||||
version=0.2.0
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for DRV8825 stepper motor driver.
|
||||
|
Loading…
Reference in New Issue
Block a user