Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions .agent/workflows/build_and_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ description: Build the project and run tests to ensure code integrity
// turbo
platformio run

2. Build using Arduino CLI (covers AVR)
3. Build using Arduino CLI (covers AVR)
// turbo
make all TARGET=arduino:avr:uno

3. Run PlatformIO Unit Tests
4. Run examples (covers all examples)
// turbo
platformio test

4. Run examples (covers one example)
// turbo
platformio ci --lib src --keep-build-dir --board esp32dev examples/BasicStepperDriver
for sketch in examples/*; do
platformio ci --lib src --keep-build-dir --board esp32dev ${sketch}
done
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Hardware currently supported:
- <a href="https://www.pololu.com/product/1182">A4988</a> Stepper Motor Driver up to 1:16
- <a href="https://www.pololu.com/product/2131">DRV8825</a> up to 1:32
- <a href="https://www.pololu.com/product/2971">DRV8880</a> up to 1:16, with current/torque control
- <a href="https://www.trinamic.com/products/integrated-circuits/details/tmc2100/">TMC2100</a> up to 1:16 native (1:256 interpolated)
- any other 2-pin stepper via DIR and STEP pins, microstepping up to 1:128 externally set

Microstepping
Expand Down Expand Up @@ -60,6 +61,9 @@ This is suggested wiring for running the examples unmodified. All the pins below
- DRV8834/DRV8880 microstep control
- M0 - D10
- M1 - D11
- TMC2100 microstep control
- CFG1 - D10
- CFG2 - D11
- ~SLEEP (optional) D13

- driver board to motor (this varies from motor to motor, check motor coils schematic).
Expand Down
57 changes: 57 additions & 0 deletions examples/TMC2100/TMC2100.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* TMC2100 Stepper Driver Verification
*
* This example uses the TMC2100 driver.
*/
#include <Arduino.h>
#include "TMC2100.h"

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

// Microstepping mode. If you hardwired it to save pins, set to the same value here.
#define MICROSTEPS 16

#define DIR 8
#define STEP 9
#define SLEEP 13 // optional (just delete SLEEP from constructor if not used)
#define CFG1 10
#define CFG2 11

/*
* Choose one of the sections below that match your hookup
*/

// Basic connection: only DIR, STEP are connected.
// TMC2100 stepper(MOTOR_STEPS, DIR, STEP);

// Fully wired: DIR, STEP, SLEEP/ENABLE, CFG1, CFG2
TMC2100 stepper(MOTOR_STEPS, DIR, STEP, SLEEP, CFG1, CFG2);

void setup() {
stepper.begin(RPM, MICROSTEPS);
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment "Fully wired: DIR, STEP, SLEEP, CFG1, CFG2" is misleading. The constructor TMC2100(MOTOR_STEPS, DIR, STEP, SLEEP, CFG1, CFG2) actually takes (steps, dir_pin, step_pin, enable_pin, cf1_pin, cf2_pin) as parameters. The 4th parameter is enable_pin (which can function as SLEEP), not a separate pin name. Consider clarifying this in the comment to match actual parameter semantics.


GLM-4.7
Z.ai

// if using enable/disable on ENABLE pin (active LOW) instead of SLEEP uncomment next line
// stepper.setEnableActiveState(LOW);
}

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

/*
* Moving motor one full revolution using the block command
*/
stepper.rotate(360);
stepper.rotate(-360);

delay(1000);

/*
* Moving motor to specific microstep levels
*/
stepper.setMicrostep(1);
stepper.rotate(360);
stepper.setMicrostep(16);
stepper.rotate(360);
}
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ DRV8825 KEYWORD1
A4988 KEYWORD1
MultiDriver KEYWORD1
SyncDriver KEYWORD1
TMC2100 KEYWORD1

setMicrostep KEYWORD2
setSpeedProfile KEYWORD2
Expand Down
5 changes: 3 additions & 2 deletions library.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "StepperDriver",
"version": "1.4.2",
"description": "Control steppers via a driver board providing STEP+DIR like the ones from Pololu. Microstepping is supported. Acceleration is supported. Supported drivers are A4988, DRV8824, DRV8825, DRV8834, DRV8880.",
"description": "Control steppers via a driver board providing STEP+DIR like the ones from Pololu. Microstepping is supported. Acceleration is supported. Supported drivers are A4988, DRV8824, DRV8825, DRV8834, DRV8880, TMC2100.",
"repository": {
"type": "git",
"url": "https://github.com/laurb9/StepperDriver"
Expand All @@ -12,7 +12,8 @@
"A4988",
"DRV8824",
"DRV8825",
"DRV8880"
"DRV8880",
"TMC2100"
],
"authors": [
{
Expand Down
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name=StepperDriver
version=1.4.2
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 like the ones from Pololu. Microstepping is supported. Acceleration is supported. Supported drivers are A4988, DRV8824, DRV8825, DRV8834, DRV8880.
sentence=A4988, DRV8825, TMC2100 and generic two-pin stepper motor driver library.
paragraph=Control steppers via a driver board providing STEP+DIR like the ones from Pololu. Microstepping is supported. Acceleration is supported. Supported drivers are A4988, DRV8824, DRV8825, DRV8834, DRV8880, TMC2100.
category=Device Control
url=https://github.com/laurb9/StepperDriver
architectures=*
2 changes: 1 addition & 1 deletion src/A4988.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class A4988 : public BasicStepperDriver {
A4988(short steps, short dir_pin, short step_pin);
A4988(short steps, short dir_pin, short step_pin, short enable_pin);

void begin(float rpm=60, short microsteps=1);
void begin(float rpm=60, short microsteps=1) override;
/*
* Fully wired. All the necessary control pins for A4988 are connected.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/BasicStepperDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class BasicStepperDriver {
/*
* Initialize pins, calculate timings etc
*/
void begin(float rpm=60, short microsteps=1);
virtual void begin(float rpm=60, short microsteps=1);
/*
* Set current microstep level, 1=full speed, 32=fine microstepping
* Returns new level or previous level if value out of range
Expand Down
2 changes: 1 addition & 1 deletion src/DRV8880.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class DRV8880 : public BasicStepperDriver {
DRV8880(short steps, short dir_pin, short step_pin, short m0, short m1, short trq0, short trq1);
DRV8880(short steps, short dir_pin, short step_pin, short enable_pin, short m0, short m1, short trq0, short trq1);

void begin(float rpm=60, short microsteps=1);
void begin(float rpm=60, short microsteps=1) override;

short setMicrostep(short microsteps) override;

Expand Down
102 changes: 102 additions & 0 deletions src/TMC2100.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* TMC2100 - SilentStepStick Stepper Motor Driver
*
* 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 "TMC2100.h"

/*
* Basic connection: only DIR, STEP are connected.
* Microstepping controls should be hardwired.
*/
TMC2100::TMC2100(short steps, short dir_pin, short step_pin)
:BasicStepperDriver(steps, dir_pin, step_pin)
{}

TMC2100::TMC2100(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 TMC2100 are connected.
*/
TMC2100::TMC2100(short steps, short dir_pin, short step_pin, short cf1_pin, short cf2_pin)
:BasicStepperDriver(steps, dir_pin, step_pin),
cf1_pin(cf1_pin), cf2_pin(cf2_pin)
{}

TMC2100::TMC2100(short steps, short dir_pin, short step_pin, short enable_pin, short cf1_pin, short cf2_pin)
:BasicStepperDriver(steps, dir_pin, step_pin, enable_pin),
cf1_pin(cf1_pin), cf2_pin(cf2_pin)
{}

void TMC2100::begin(float rpm, short microsteps){
BasicStepperDriver::begin(rpm, microsteps);

if (!IS_CONNECTED(cf1_pin) || !IS_CONNECTED(cf2_pin)){
return;
}

pinMode(cf1_pin, OUTPUT);
pinMode(cf2_pin, OUTPUT);
}

/*
* Set microstepping mode (1:divisor)
* Allowed ranges for TMC2100 are 1:1 to 1:16
* If the control pins are not connected, we recalculate the timing only
*/
short TMC2100::setMicrostep(short microsteps){
BasicStepperDriver::setMicrostep(microsteps);

if (!IS_CONNECTED(cf1_pin) || !IS_CONNECTED(cf2_pin)){
return this->microsteps;
}

// CFG1 CFG2 Microsteps Mode
// GND GND 1 SpreadCycle
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CFG pin configuration logic correctly implements the TMC2100 microstepping modes, including support for both SpreadCycle and StealthChop modes. The pin mode handling (setting pins to INPUT for float/open states) is consistent with the DRV8880 implementation pattern in this codebase.


GLM-4.7
Z.ai

// VIO GND 2 SpreadCycle
// OPEN GND 2 SpreadCycle
// GND VIO 4 SpreadCycle
// VIO VIO 16 SpreadCycle
// OPEN VIO 4 SpreadCycle
// GND OPEN 8 SpreadCycle
// VIO OPEN 16 StealthChop
// OPEN OPEN 16 StealthChop

switch(this->microsteps){
case 1:
// GND, GND
pinMode(cf1_pin, OUTPUT); digitalWrite(cf1_pin, LOW);
pinMode(cf2_pin, OUTPUT); digitalWrite(cf2_pin, LOW);
break;
case 2:
// VIO, GND
pinMode(cf1_pin, OUTPUT); digitalWrite(cf1_pin, HIGH);
pinMode(cf2_pin, OUTPUT); digitalWrite(cf2_pin, LOW);
break;
case 4:
// GND, VIO
pinMode(cf1_pin, OUTPUT); digitalWrite(cf1_pin, LOW);
pinMode(cf2_pin, OUTPUT); digitalWrite(cf2_pin, HIGH);
break;
case 8:
// GND, OPEN
pinMode(cf1_pin, OUTPUT); digitalWrite(cf1_pin, LOW);
pinMode(cf2_pin, INPUT);
break;
case 16:
// VIO, OPEN (StealthChop)
pinMode(cf1_pin, OUTPUT); digitalWrite(cf1_pin, HIGH);
pinMode(cf2_pin, INPUT);
break;
}

return this->microsteps;
}

short TMC2100::getMaxMicrostep(){
return TMC2100::MAX_MICROSTEP;
}
48 changes: 48 additions & 0 deletions src/TMC2100.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* TMC2100 - SilentStepStick Stepper Motor Driver
*
* 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.
*/
#ifndef TMC2100_H
#define TMC2100_H
#include <Arduino.h>
#include "BasicStepperDriver.h"

class TMC2100 : public BasicStepperDriver {
protected:
short cf1_pin = PIN_UNCONNECTED;
short cf2_pin = PIN_UNCONNECTED;
// tA STEP minimum, HIGH pulse width (1us)
static const int step_high_min = 1;
// tB STEP minimum, LOW pulse width (1us)
static const int step_low_min = 1;
// wakeup time, nSLEEP inactive to STEP (1000us)
static const int wakeup_time = 1000;

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

private:
// microstep range (1, 2, 4, 8, 16)
// maximum level controllable by CFG pins is 1/16, TMC2100 can interpolate to 1/256 internally
static const short MAX_MICROSTEP = 16;

public:
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The begin() method on line 31 overrides the base class implementation but is missing the override keyword. While this pattern exists in other drivers (e.g., A4988.h), adding override would improve type safety and allow the compiler to catch signature mismatches.


GLM-4.7
Z.ai

/*
* Basic connection: only DIR, STEP are connected.
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment on line 33 ("Fully wired. All the necessary control pins for TMC2100 are connected...") appears before a constructor (line 31) that only takes DIR, STEP, and SLEEP parameters. This comment should be placed after line 31 or moved to before the actual constructors that take CFG pins (lines 38 and 41).


GLM-4.7
Z.ai

* Microstepping controls should be hardwired.
*/
TMC2100(short steps, short dir_pin, short step_pin);
TMC2100(short steps, short dir_pin, short step_pin, short enable_pin);

void begin(float rpm=60, short microsteps=1) override;
/*
* Fully wired. All the necessary control pins for TMC2100 are connected.
* The CFG pins are used to set microstepping.
*/
TMC2100(short steps, short dir_pin, short step_pin, short cf1_pin, short cf2_pin);
TMC2100(short steps, short dir_pin, short step_pin, short enable_pin, short cf1_pin, short cf2_pin);
short setMicrostep(short microsteps) override;
};
#endif // TMC2100_H