I want to test a setup for a project with nema 17 stepper motor connected to tmc2208 v3 in UART mode tmc is connected to ramps 1.4 which is mounted on a Arduino mega . I connected to the pdn_uart pin of tmc 2208 to gpio16 and gpio 17 for Rx and TX . There is a 1k resistor between TX and UART pin of tmc as tmc uses only one UART pin for both transmitting . I uploaded the code attached below but the stepper does not move when I supply around 11.2 v from Li ion battery . I checked the serial monitor which confirms that the UART connects are fine and the configurations are changing as per the code but the stepper does not move pls help me.
#include <TMCStepper.h>
// Define pins
#define EN_PIN 62 // Enable pin for Z-axis (A8 is digital pin 62 on Arduino Mega)
#define STEP_PIN 46 // Step pin for Z-axis
#define DIR_PIN 48 // Direction pin for Z-axis
#define SERIAL_PORT Serial2 // Use Serial2 for UART communication with TMC2208
// TMC2208 configuration
#define R_SENSE 0.11f // Sense resistor value in ohms
// Create a TMC2208Stepper instance
TMC2208Stepper driver(&SERIAL_PORT, R_SENSE);
void setup() {
// Initialize serial communication
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect
}
Serial.println("Starting...");
// Initialize TMC2208 serial communication
SERIAL_PORT.begin(115200);
// Enable driver
pinMode(EN_PIN, OUTPUT);
digitalWrite(EN_PIN, LOW); // Enable the driver
// Small delay to ensure the driver is enabled
delay(100);
// Configure TMC2208
driver.begin(); // Initiate pins and registers
driver.toff(5); // Enables driver in software
driver.rms_current(900); // Set RMS current to 900 mA
driver.microsteps(8); // Set microsteps to 8
driver.pdn_disable(true); // Disable using PDN pin for power down
// Debugging: Confirm settings
Serial.print("Current (mA): ");
Serial.println(driver.rms_current());
Serial.print("Microsteps: ");
Serial.println(driver.microsteps());
Serial.println("TMC2208 setup complete.");
}
void loop() {
// Ensure the driver is enabled in the loop
digitalWrite(EN_PIN, LOW);
// Basic stepper motor test loop
Serial.println("Starting motor movement...");
digitalWrite(DIR_PIN, HIGH); // Set direction
for (int i = 0; i < 200; i++) { // Move 200 steps
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(1000); // Adjust delay to control speed
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(1000); // Adjust delay to control speed
}
Serial.println("Moved 200 steps forward.");
delay(1000); // Wait a second
digitalWrite(DIR_PIN, LOW); // Change direction
for (int i = 0; i < 200; i++) { // Move 200 steps back
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(1000); // Adjust delay to control speed
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(1000); // Adjust delay to control speed
}
Serial.println("Moved 200 steps backward.");
delay(1000); // Wait a second
// Check driver status
checkDriverStatus();
}
void checkDriverStatus() {
uint32_t drv_status = driver.DRV_STATUS();
Serial.print("DRV_STATUS: ");
Serial.println(drv_status, BIN);
}
Serial monitor :
Starting...
Current (mA): 887
Microsteps: 8
TMC2208 setup complete.
Starting motor movement...
Moved 200 steps forward.
Moved 200 steps backward.
DRV_STATUS: 11000000000011100000000000000000