Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
laurb9 committed Jun 26, 2017
2 parents dee87aa + 21959c7 commit 7aa0b40
Show file tree
Hide file tree
Showing 19 changed files with 743 additions and 138 deletions.
54 changes: 54 additions & 0 deletions examples/AccelTest/AccelTest.ino
@@ -0,0 +1,54 @@
/*
* Demo / test acceleration parameters
*
* Copyright (C)2015-2017 Laurentiu Badea
*
* This file may be redistributed under the terms of the MIT license.
* A copy of this license has been included with this distribution in the file LICENSE.
*/
#include <Arduino.h>
#include "BasicStepperDriver.h"

// Motor steps per revolution. Most steppers are 200 steps or 1.8 degrees/step
#define MOTOR_STEPS 200

// Since microstepping is set externally, make sure this matches the selected mode
// 1=full step, 2=half step etc.
#define MICROSTEPS 16

#define DIR 5
#define STEP 9

// 2-wire basic config, microstepping is hardwired on the driver
BasicStepperDriver stepper(MOTOR_STEPS, DIR, STEP, 10);

void setup() {
Serial.begin(115200);

stepper.begin(120, MICROSTEPS);

/*
* LINEAR_SPEED profile needs the acceleration and deceleration values
* in full steps / s^2.
*/
stepper.setSpeedProfile(LINEAR_SPEED, 1000, 1000);

Serial.println("START");
stepper.startRotate(360);
}

void loop() {
static int step = 0;
unsigned wait_time = stepper.nextAction();
if (wait_time){
Serial.print(" step="); Serial.print(step++/2);
Serial.print(" dt="); Serial.print(wait_time);
Serial.print(" rpm="); Serial.print(stepper.getCurrentRPM());
Serial.println();
microWaitUntil(micros() + wait_time);
} else {
stepper.disable();
Serial.println("END");
delay(3600000);
}
}
11 changes: 4 additions & 7 deletions examples/BasicStepperDriver/BasicStepperDriver.ino
Expand Up @@ -35,21 +35,18 @@ void setup() {
* Set target motor RPM.
* These motors can do up to about 200rpm.
* Too high will result in a high pitched whine and the motor does not move.
*
* Also tell the driver the microstep level we selected.
* If mismatched, the motor will move at a different RPM than chosen.
*/
stepper.setRPM(120);
stepper.begin(120, MICROSTEPS);
}

void loop() {

// energize coils - the motor will hold position
// stepper.enable();

/*
* Tell the driver the microstep level we selected.
* If mismatched, the motor will move at a different RPM than chosen.
*/
stepper.setMicrostep(MICROSTEPS);

/*
* Moving motor one full revolution using the degree notation
*/
Expand Down
5 changes: 2 additions & 3 deletions examples/ClockStepper/ClockStepper.ino
Expand Up @@ -43,10 +43,9 @@ DRV8834 stepper(MOTOR_STEPS, DIR, STEP, M0, M1);

void setup() {
/*
* Set target motor RPM.
* Set target motor RPM=1 and microstepping=1
*/
stepper.setRPM(1);
stepper.setMicrostep(1); // make sure we are in full speed mode
stepper.begin(1, 1);
}

void loop() {
Expand Down
2 changes: 1 addition & 1 deletion examples/MicroStepping/MicroStepping.ino
Expand Up @@ -49,7 +49,7 @@ void setup() {
* These motors can do up to about 200rpm.
* Too high will result in a high pitched whine and the motor does not move.
*/
stepper.setRPM(120);
stepper.begin(120);
}

void loop() {
Expand Down
53 changes: 53 additions & 0 deletions examples/MultiAxis/MultiAxis.ino
@@ -0,0 +1,53 @@
/*
* Multi-motor control
*
* Move two or three motors at the same time.
*
* Copyright (C)2017 Laurentiu Badea
*
* This file may be redistributed under the terms of the MIT license.
* A copy of this license has been included with this distribution in the file LICENSE.
*/
#include <Arduino.h>
#include "BasicStepperDriver.h"
#include "SyncDriver.h"

// Motor steps per revolution. Most steppers are 200 steps or 1.8 degrees/step
#define MOTOR_STEPS 200

// X motor
#define DIR_X 5
#define STEP_X 9

// Y motor
#define DIR_Y 8
#define STEP_Y 6

// If microstepping is set externally, make sure this matches the selected mode
// 1=full step, 2=half step etc.
#define MICROSTEPS 32

// 2-wire basic config, microstepping is hardwired on the driver
// Other drivers can be mixed and matched but must be configured individually
BasicStepperDriver stepperX(MOTOR_STEPS, DIR_X, STEP_X);
BasicStepperDriver stepperY(MOTOR_STEPS, DIR_Y, STEP_Y);

SyncDriver controller(stepperX, stepperY);

void setup() {
/*
* Set target motors RPM.
*/
stepperX.begin(30, MICROSTEPS);
stepperY.begin(90, MICROSTEPS);
}

void loop() {

controller.rotate(90*5, 60*15);
delay(1000);
controller.rotate(-90*5, -30*15);
delay(1000);
controller.rotate(0, -30*15);
delay(30000);
}
12 changes: 12 additions & 0 deletions keywords.txt
Expand Up @@ -5,8 +5,20 @@ DRV8834 KEYWORD1
DRV8824 KEYWORD1
DRV8825 KEYWORD1
A4988 KEYWORD1
MultiDriver KEYWORD1
SyncDriver KEYWORD1

setMicrostep KEYWORD2
setSpeedProfile KEYWORD2
move KEYWORD2
rotate KEYWORD2
setRPM KEYWORD2
getRPM KEYWORD2
enable KEYWORD2
disable KEYWORD2
startMove KEYWORD2
startRotate KEYWORD2
nextAction KEYWORD2

CONSTANT_SPEED LITERAL1
LINEAR_SPEED LITERAL1
4 changes: 2 additions & 2 deletions library.properties
@@ -1,9 +1,9 @@
name=StepperDriver
version=1.0.6
version=1.1.0
author=Laurentiu Badea
maintainer=Laurentiu Badea
sentence=A4988, DRV8825 and generic two-pin stepper motor driver library.
paragraph=Control steppers via a driver board providing STEP+DIR. Microstepping is supported. Supported drivers are A4988, DRV8824, DRV8825, DRV8834.
paragraph=Control steppers via a driver board providing STEP+DIR. Microstepping is supported. Acceleration is supported. Supported drivers are A4988, DRV8824, DRV8825, DRV8834.
category=Device Control
url=https://github.com/laurb9/StepperDriver
architectures=*
22 changes: 11 additions & 11 deletions src/A4988.cpp
Expand Up @@ -19,30 +19,30 @@ const uint8_t A4988::MS_TABLE[] = {0b000, 0b001, 0b010, 0b011, 0b111};
* Basic connection: only DIR, STEP are connected.
* Microstepping controls should be hardwired.
*/
A4988::A4988(int steps, int dir_pin, int step_pin)
A4988::A4988(short steps, short dir_pin, short step_pin)
:BasicStepperDriver(steps, dir_pin, step_pin)
{}

A4988::A4988(int steps, int dir_pin, int step_pin, int enable_pin)
A4988::A4988(short steps, short dir_pin, short step_pin, short enable_pin)
:BasicStepperDriver(steps, dir_pin, step_pin, enable_pin)
{}

/*
* Fully wired.
* All the necessary control pins for A4988 are connected.
*/
A4988::A4988(int steps, int dir_pin, int step_pin, int ms1_pin, int ms2_pin, int ms3_pin)
A4988::A4988(short steps, short dir_pin, short step_pin, short ms1_pin, short ms2_pin, short ms3_pin)
:BasicStepperDriver(steps, dir_pin, step_pin),
ms1_pin(ms1_pin), ms2_pin(ms2_pin), ms3_pin(ms3_pin)
{}

A4988::A4988(int steps, int dir_pin, int step_pin, int enable_pin, int ms1_pin, int ms2_pin, int ms3_pin)
A4988::A4988(short steps, short dir_pin, short step_pin, short enable_pin, short ms1_pin, short ms2_pin, short ms3_pin)
:BasicStepperDriver(steps, dir_pin, step_pin, enable_pin),
ms1_pin(ms1_pin), ms2_pin(ms2_pin), ms3_pin(ms3_pin)
{}

void A4988::init(void){
BasicStepperDriver::init();
void A4988::begin(short rpm, short microsteps){
BasicStepperDriver::begin(rpm, microsteps);

if (!IS_CONNECTED(ms1_pin) || !IS_CONNECTED(ms2_pin) || !IS_CONNECTED(ms3_pin)){
return;
Expand All @@ -58,17 +58,17 @@ void A4988::init(void){
* Allowed ranges for A4988 are 1:1 to 1:16
* If the control pins are not connected, we recalculate the timing only
*/
unsigned A4988::setMicrostep(unsigned microsteps){
short A4988::setMicrostep(short microsteps){
BasicStepperDriver::setMicrostep(microsteps);

if (!IS_CONNECTED(ms1_pin) || !IS_CONNECTED(ms2_pin) || !IS_CONNECTED(ms3_pin)){
return this->microsteps;
}

const uint8_t* ms_table = this->getMicrostepTable();
size_t ms_table_size = this->getMicrostepTableSize();
const uint8_t* ms_table = getMicrostepTable();
size_t ms_table_size = getMicrostepTableSize();

int i = 0;
unsigned short i = 0;
while (i < ms_table_size){
if (this->microsteps & (1<<i)){
uint8_t mask = ms_table[i];
Expand All @@ -90,6 +90,6 @@ size_t A4988::getMicrostepTableSize(){
return sizeof(A4988::MS_TABLE);
}

unsigned A4988::getMaxMicrostep(){
short A4988::getMaxMicrostep(){
return A4988::MAX_MICROSTEP;
}
22 changes: 11 additions & 11 deletions src/A4988.h
Expand Up @@ -15,10 +15,9 @@
class A4988 : public BasicStepperDriver {
protected:
static const uint8_t MS_TABLE[];
int ms1_pin = PIN_UNCONNECTED;
int ms2_pin = PIN_UNCONNECTED;
int ms3_pin = PIN_UNCONNECTED;
void init(void);
short ms1_pin = PIN_UNCONNECTED;
short ms2_pin = PIN_UNCONNECTED;
short ms3_pin = PIN_UNCONNECTED;
// tA STEP minimum, HIGH pulse width (1us)
static const int step_high_min = 1;
// tB STEP minimum, LOW pulse width (1us)
Expand All @@ -32,25 +31,26 @@ class A4988 : public BasicStepperDriver {
virtual size_t getMicrostepTableSize();

// Get max microsteps supported by the device
unsigned getMaxMicrostep() override;
short getMaxMicrostep() override;

private:
// microstep range (1, 16, 32 etc)
static const unsigned MAX_MICROSTEP = 16;
static const short MAX_MICROSTEP = 16;

public:
/*
* Basic connection: only DIR, STEP are connected.
* Microstepping controls should be hardwired.
*/
A4988(int steps, int dir_pin, int step_pin);
A4988(int steps, int dir_pin, int step_pin, int enable_pin);
A4988(short steps, short dir_pin, short step_pin);
A4988(short steps, short dir_pin, short step_pin, short enable_pin);

void begin(short rpm=60, short microsteps=1);
/*
* Fully wired. All the necessary control pins for A4988 are connected.
*/
A4988(int steps, int dir_pin, int step_pin, int ms1_pin, int ms2_pin, int ms3_pin);
A4988(int steps, int dir_pin, int step_pin, int enable_pin, int ms1_pin, int ms2_pin, int ms3_pin);
unsigned setMicrostep(unsigned microsteps);
A4988(short steps, short dir_pin, short step_pin, short ms1_pin, short ms2_pin, short ms3_pin);
A4988(short steps, short dir_pin, short step_pin, short enable_pin, short ms1_pin, short ms2_pin, short ms3_pin);
short setMicrostep(short microsteps) override;
};
#endif // A4988_H

0 comments on commit 7aa0b40

Please sign in to comment.