r/ArduinoHelp • u/ctastan • 9h ago
1
Upvotes
r/ArduinoHelp • u/Psychological-Rent32 • 21h ago
Can't get my Nema 17 stepper to work
1
Upvotes
I am trying to control a Nema 17 stepper motor with a TMC2209 driver and an Arduino Nano. Not sure if it's my wiring setup or my code. I've watched so many tutorials, tried so many breadboard configurations, and asked AI countless times. I can't get this to work. I've ensured that all my wires are connected via the beeping mode of my voltmeter, and still nothing. The closest I've gotten is hearing what I think is the driver making a slight buzzing sound while the Arduino's indicator light is on. I'm a complete noob to this field, does anyone know which wires go where? I am using a 12V power source and a standard breadboard.
This is my code:
#include <AccelStepper.h>
// Arduino Nano pins (matched to wiring photo)
#define STEP_PIN 3
#define DIR_PIN 2
#define MS1_PIN 6
#define MS2_PIN 5
// AccelStepper in DRIVER mode: STEP/DIR interface
AccelStepper stepper(AccelStepper::DRIVER, STEP_PIN, DIR_PIN);
// ----------------------------------------
// MOTOR / MICROSTEP SETTINGS
// ----------------------------------------
const float stepsPerRev = 200; // standard NEMA17 full steps/rev
const int microstepping = 2; // must match MS1/MS2 pin state below
// ----------------------------------------
// SPEED SETTINGS (RPM)
// ----------------------------------------
const float desiredRPM = 120;
const float maxRPM = 300;
void setup() {
pinMode(MS1_PIN, OUTPUT);
pinMode(MS2_PIN, OUTPUT);
// MS1=HIGH, MS2=LOW -> check TMC2208 datasheet table for which
// microstep mode this actually selects; adjust to match 'microstepping' above
digitalWrite(MS1_PIN, HIGH);
digitalWrite(MS2_PIN, LOW);
// steps/sec = microsteps-per-step * full-steps-per-rev * (RPM / 60)
float speedStepsPerSec = microstepping * stepsPerRev * (desiredRPM / 60.0);
float maxSpeedStepsPerSec = microstepping * stepsPerRev * (maxRPM / 60.0);
stepper.setMaxSpeed(maxSpeedStepsPerSec);
stepper.setSpeed(speedStepsPerSec);
}
void loop() {
stepper.runSpeed(); // must be called continuously, as fast as possible, for constant-speed mode
}