TMCStepper and Arduino for precise movement

Hello All,
I am trying to build a telescope GOTO system. I am new to using microcontrollers and need to figure out how to get my stepper motors working. I am using the TMC2209 drivers - for silent operation - with an Arduino Mega Board. The GitHub documentation was not as helpful for me: I am very new new to this.
I have posted my code so far (Mostly copy-pasted from examples), but I need a way to get the stepper motor to move a precise amount so I know the position at all time, similar to how 3D printers work. Can someone please point me in the right direction.

#include <Arduino.h>
#include <TMCStepper.h>     // TMCstepper - https://github.com/teemuatlut/TMCStepper
#include <SoftwareSerial.h> // Software serial for the UART to TMC2209 - https://www.arduino.cc/en/Reference/softwareSerial
#include <Streaming.h>      // for the << operator I think

#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

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);
  pinMode(STEP_PIN, OUTPUT);
  pinMode(DIR_PIN, OUTPUT);
  digitalWrite(EN_PIN, LOW); // Enable driver in hardware

  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
}

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
}

Double check your numbers and usage here - and Software serial won’t go anywhere near that speed.

If that’s what you need, find a board with multiple hardware UARTS like the Mega2560

What makes You ask for "point me in the right direction"?
What works and what doesn´t do what You want?
Reading other posting here You would likely see a number like 115200...
Makes any difference?

This code is still mostly copy pasted.

#include <Arduino.h>
#include <TMCStepper.h> // TMCstepper - https://github.com/teemuatlut/TMCStepper

#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 SERIAL_PORT Serial1 // TMC2208/TMC2224 HardwareSerial port
#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 (?)

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

void setup()
{
    pinMode(EN_PIN, OUTPUT);
    pinMode(STEP_PIN, OUTPUT);
    pinMode(DIR_PIN, OUTPUT);
    digitalWrite(EN_PIN, LOW); // Enable driver in hardware

    driver.begin();          //  SPI: Init CS pins and possible SW SPI pins
    driver.toff(5);          // Enables driver in software
    driver.rms_current(600); // Set motor RMS current
    driver.microsteps(2);    // Set microsteps to 1/16th

    driver.pwm_autoscale(true); // Needed for stealthChop
}

bool shaft = false;

void loop()
{
    // Run 5000 steps and switch direction in software
    for (uint16_t i = 0; i < 10000; i++)
    {
        digitalWrite(STEP_PIN, HIGH);
        delayMicroseconds(160);
        digitalWrite(STEP_PIN, LOW);
        delayMicroseconds(160);
    }
    shaft = !shaft;
    driver.shaft(shaft);
}

What I still need is a way to move to a specific position at a specific speed. I have seen VACTUAL() used, but that seems to lack any position tracking. Would changing delayMicroseconds(160); here change the speed?

Look at the TMC_AccelStepper.ino example in the TMCStepper libarary for how to use the TMCStepper library with the AccelStepper library. AccelStepper takes care of counting steps (keeping track of position) and moving the motor with acceleration.

My experience is with the TMC2208. I have used in in the simple step dir mode without any of the serial configuration. The stepper motor is very quite with the driver as is in its basic configuration. I would not try to implement the serial interface and the advance features unless you are certain you need them.

It works well with AccelStepper in step/dir mode.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.