driver.begin();
driver.toff(4);
driver.setSPISpeed(speed);
driver.blank_time(24);
driver.rms_current(600); // mA
driver.microsteps(16);
driver.TCOOLTHRS(0xFFFFF); // 20bit max
driver.THIGH(0);
driver.semin(5);
driver.semax(2);
driver.sedn(0b01);
driver.sgt(STALL_VALUE);
driver.en_pwm_mode(true); // Toggle stealthChop on TMC2130/2160/5130/5160
driver.pwm_autoscale(true); // Needed for stealthChop
Serial.print("\nTesting connection...");
uint8_t result = driver.test_connection();
if (result) {
Serial.println("failed!");
Serial.print("Likely cause: ");
switch(result) {
case 1: Serial.println("loose connection"); break;
case 2: Serial.println("no power"); break;
}
Serial.println("Fix the problem and reset board.");
// We need this delay or messages above don't get fully printed out
delay(100);
abort();
I am running a 5161 on an ESP32, I am getting '0 1 292' and the motor is not moving, this is what i have wired
EN_PIN -> 14 MOSI ->MOSI SCK -> SCK CS -> SS (i have tryied Salve Select and a non-SS pin) MISO ->MISO (I assume CLK is not needed)
`#include
define STALL_VALUE 50// [0... 255]
define TOFF_VALUE 4 // [1... 15]
define EN_PIN 14 // Enable
define DIR_PIN 13 // Direction
define STEP_PIN 12 // Step
define CS_PIN SS // Chip select
define SW_MOSI 23 // Software Master Out Slave In (MOSI)
define SW_MISO 19 // Software Master In Slave Out (MISO)
define SW_SCK 18 // Software Slave Clock (SCK)
define R_SENSE 0.075f // Match to your driver
TMC5161Stepper driver(CS_PIN, R_SENSE); //TMC5161Stepper driver(CS_PIN, R_SENSE, SW_MOSI, SW_MISO, SW_SCK);
int32_t speed = 1000;
void setup() {
while(!Serial); // Wait for serial port to connect Serial.println("\nStart..."); SPI.begin(); // SPI drivers
pinMode(STEP_PIN, OUTPUT); pinMode(CS_PIN, OUTPUT); pinMode(DIR_PIN, OUTPUT); pinMode(MISO, INPUT_PULLUP);
driver.begin(); driver.toff(4); driver.setSPISpeed(speed); driver.blank_time(24); driver.rms_current(600); // mA driver.microsteps(16); driver.TCOOLTHRS(0xFFFFF); // 20bit max driver.THIGH(0); driver.semin(5); driver.semax(2); driver.sedn(0b01); driver.sgt(STALL_VALUE);
driver.en_pwm_mode(true); // Toggle stealthChop on TMC2130/2160/5130/5160 driver.pwm_autoscale(true); // Needed for stealthChop
Serial.print("\nTesting connection..."); uint8_t result = driver.test_connection();
if (result) { Serial.println("failed!"); Serial.print("Likely cause: ");
} pinMode(EN_PIN, OUTPUT); digitalWrite(EN_PIN, LOW); }
bool shaft = false;
void loop() {
static uint32_t last_time = 0;
uint32_t ms = millis();
while (Serial.available() > 0) { int8_t read_byte = Serial.read();
}
if((ms-last_time) > 100 && driver.toff() != 0 && speed != 0) { // run every 0.1s last_time = ms;
} }`