GY-63_MS5611/libraries/DRV8825/DRV8825.h

87 lines
2.0 KiB
C
Raw Normal View History

2022-07-08 10:11:40 -04:00
#pragma once
//
// FILE: DRV8825.h
// AUTHOR: Rob Tillaart
2023-09-17 04:17:04 -04:00
// VERSION: 0.2.0
2022-07-08 10:11:40 -04:00
// PURPOSE: Arduino library for DRV8825 stepper motor driver
// DATE: 2022-07-07
// URL: https://github.com/RobTillaart/DRV8825
#include "Arduino.h"
2023-09-17 04:17:04 -04:00
#define DRV8825_LIB_VERSION (F("0.2.0"))
2022-07-08 10:11:40 -04:00
// setDirection
2022-07-09 03:39:01 -04:00
const uint8_t DRV8825_CLOCK_WISE = 0; // LOW
const uint8_t DRV8825_COUNTERCLOCK_WISE = 1; // HIGHT
2022-07-08 10:11:40 -04:00
class DRV8825
{
public:
DRV8825();
2022-07-15 04:22:42 -04:00
bool begin(uint8_t DIR, uint8_t STEP, uint8_t EN = 255, uint8_t RST = 255, uint8_t SLP = 255);
2022-07-08 10:11:40 -04:00
// DIRECTION
// 0 = DRV8825_CLOCK_WISE
// 1 = DRV8825_COUNTERCLOCK_WISE
// returns false if parameter out of range.
bool setDirection(uint8_t direction = DRV8825_CLOCK_WISE);
uint8_t getDirection();
// STEPS
void setStepsPerRotation(uint16_t stepsPerRotation);
uint16_t getStepsPerRotation();
void step();
2022-07-09 03:39:01 -04:00
uint32_t resetSteps(uint32_t s = 0 );
uint32_t getSteps();
// POSITION
// only works if stepsPerRotation > 0
2023-09-17 04:17:04 -04:00
// returns false if position > stepsPerRotation.
bool setPosition(uint16_t position = 0);
2022-07-09 03:39:01 -04:00
uint16_t getPosition();
2022-07-08 10:11:40 -04:00
// CONFIGURATION
// step pulse length is in microseconds
2022-07-13 06:40:22 -04:00
// datasheet default = 1.9 us
2023-09-17 04:17:04 -04:00
void setStepPulseLength(uint16_t stepPulseLength = 2);
2022-07-08 10:11:40 -04:00
uint16_t getStepPulseLength();
2022-07-15 04:22:42 -04:00
// ENABLE pin should be set.
2023-02-19 08:16:16 -05:00
bool enable();
bool disable();
2022-07-15 04:22:42 -04:00
bool isEnabled();
// RESET pin should be set.
2023-02-19 08:16:16 -05:00
bool reset();
2022-07-15 04:22:42 -04:00
// SLEEP pin should be set.
2023-02-19 08:16:16 -05:00
bool sleep();
bool wakeup();
2022-07-15 04:22:42 -04:00
bool isSleeping();
2022-07-08 10:11:40 -04:00
2022-07-09 03:39:01 -04:00
protected:
2022-07-08 10:11:40 -04:00
uint8_t _directionPin = 255;
uint8_t _stepPin = 255;
2022-07-15 04:22:42 -04:00
uint8_t _enablePin = 255;
uint8_t _resetPin = 255;
uint8_t _sleepPin = 255;
2022-07-08 10:11:40 -04:00
uint8_t _direction = DRV8825_CLOCK_WISE;
2022-07-15 04:22:42 -04:00
uint16_t _stepsPerRotation = 0;
2022-07-09 03:39:01 -04:00
uint32_t _steps = 0;
2023-09-17 04:17:04 -04:00
uint16_t _position = 0;
uint16_t _stepPulseLength = 2;
2022-07-08 10:11:40 -04:00
};
// -- END OF FILE --