TCM2209 Stepper driver in XOD (stepper driver project)

Hi.
I am currently working on a hobby thing.
I have copied this code from another forum, and would like to re-create it in XOD if possible, so I can refine it myself (in XOD).

It is a stepper driver+stepper motor project.
Does this look doable, and could some kind person point me in the right direction?
I have found this library " nkrkv/stepdir@1.0.0", but don’t know if it supports tcm steppers, since they do some special magic to smooth out the waves to get super silent motor action.

I just want to be able to control the motor speed via a pot, but the real magic behind it is the tmc stepper smoothing, via the code below. (ignore the back and forth motion of the motor in the code. It’s just copy/pasted from the internet).

I think I can configure a lot of stuff in standalone mode, but it needs connection to RX and TX.
The stepper library in XOD does not have any configuration for that.

Thanks :slight_smile:

#include <TMCStepper.h> // TMCstepper - GitHub - teemuatlut/TMCStepper
#include <SoftwareSerial.h> // Software serial for the UART to TMC2209 - https://www.arduino.cc/en/Reference/softwareSerial
#include <Streaming.h> // For serial debugging output - Streaming - Arduino Reference

#define EN_PIN 2 // Enable - PURPLE
#define DIR_PIN 3 // Direction - WHITE
#define STEP_PIN 4 // Step - ORANGE
#define SW_SCK 5 // Software Slave Clock (SCK) - BLUE
#define SW_TX 6 // SoftwareSerial receive pin - BROWN
#define SW_RX 7 // SoftwareSerial transmit pin - YELLOW
#define DRIVER_ADDRESS 0b00 // TMC2209 Driver address according to MS1 and MS2
#define R_SENSE 0.11f // SilentStepStick series use 0.11 …and so does my fysetc TMC2209 (?)

SoftwareSerial SoftSerial(SW_RX, SW_TX); // Be sure to connect RX to TX and TX to RX between both devices

TMC2209Stepper TMCdriver(&SoftSerial, R_SENSE, DRIVER_ADDRESS); // Create TMC driver

int accel;
long maxSpeed;
int speedChangeDelay;
bool dir = false;

//== Setup ===============================================================================

void setup() {

Serial.begin(11520); // initialize hardware serial for debugging
SoftSerial.begin(11520); // initialize software serial for UART motor control
TMCdriver.beginSerial(11520); // Initialize UART

pinMode(EN_PIN, OUTPUT); // Set pinmodes
pinMode(STEP_PIN, OUTPUT);
pinMode(DIR_PIN, OUTPUT);
digitalWrite(EN_PIN, LOW); // Enable TMC2209 board

TMCdriver.begin(); // UART: Init SW UART (if selected) with default 115200 baudrate
TMCdriver.toff(5); // Enables driver in software
TMCdriver.rms_current(500); // Set motor RMS current
TMCdriver.microsteps(256); // Set microsteps

TMCdriver.en_spreadCycle(false);
TMCdriver.pwm_autoscale(true); // Needed for stealthChop

}

//== Loop =================================================================================

void loop() {

accel = 10000; // Speed increase/decrease amount
maxSpeed = 50000; // Maximum speed to be reached
speedChangeDelay = 100; // Delay between speed changes

for (long i = 0; i <= maxSpeed; i = i + accel){ // Speed up to maxSpeed
TMCdriver.VACTUAL(i); // Set motor speed
Serial << TMCdriver.VACTUAL() << endl;
delay(100);
}

for (long i = maxSpeed; i >=0; i = i - accel){ // Decrease speed to zero
TMCdriver.VACTUAL(i);
Serial << TMCdriver.VACTUAL() << endl;
delay(100);
}

dir = !dir; // REVERSE DIRECTION
TMCdriver.shaft(dir); // SET DIRECTION

}

Though not trivial to do, you could try wrapping the IDE code in XOD to create a new library: Wrapping Class-based Arduino Libraries — XOD

I have found out that the specific stepper I use has a stand alone mode, where you can configure it via applying voltages to selected pins. That way I don’t have to use any of the TX/RX stuff, (since that is used for configuring it via code). So I might be able to use the nkrkv stepper lib out of the box. Will test and write back.