Need help with getting nema 17 to work

image
Here is a schematic diagram of how the wiring is done.

Hello, i am relatively new to arduino and stepper motors. I am using Arduino nano and a tmc2208 stepper driver to control a nema 17 motor. But the motor does not seem to run at all. This is the code that i have found online:

const int dirPin = 3; // Direction
const int stepPin = 4; // Step

// Motor steps per rotation
const int STEPS_PER_REV = 200;

void setup() {

// Setup the pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
}
void loop() {

// Set motor direction clockwise
digitalWrite(dirPin,HIGH);

// Spin motor one rotation slowly
for(int x = 0; x < STEPS_PER_REV; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin,LOW);
delayMicroseconds(2000);
}

// Pause for one second
delay(1000);

// Set motor direction counterclockwise
digitalWrite(dirPin,LOW);

// Spin motor two rotations quickly
for(int x = 0; x < (STEPS_PER_REV * 2); x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin,LOW);
delayMicroseconds(1000);
}

// Pause for one second
delay(1000);
}

Any advice or help would be very much appreciated !!

Why do you only give us the size of the mounting plate (1.7 inch).
Not very useful info.
Leo..

Put on the hard hat. Here we go.

No, that's not schematics, it's a coloured picture showing the physical shape of the circuits. Magnifying the picture, pin designations are blurred out.

?? Is it running or not?

12 volt power supply.... Capable of what? What's the setting for current in the driver?

That tells that M3 screws can be used and what the hole pattern for mounting should be like. Tells nothing about the electric parameters.

Try stepper basics from the IDE. Lots of crap out on the Internet.
Format the code in the IDE. You have supplied text, in code tags (thanks), but not code.

delay(1000) between steps make movements look like the speed of a snail.
A pulse for a step should be some 10 micro seconds, time between pulses some 10 mS.
The enable pin look like connected but no I/O giving it a value.

Adjust the delays to reasonable figures, autoformat the code and post it in Your next post.

i apologise for the lack of information. I am using a HANPOSE 17HS42-23 motor !

What is that? Datasheet please.

One piece of the puzzle.

1.6volt, 2.6ohm, 0.6Amp.
Did you set the driver to 600mA.
Leo..

I have just tested with this program here simple stepper program and an accelstepper example from random

< #include <AccelStepper.h>
 
// Define a stepper and the pins it will use
#define MOTOR_STEPS 200
#define DIR 3
#define STEP 4

//AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
AccelStepper stepper(AccelStepper::DRIVER, STEP, DIR ); 

void setup()
{  
}
 
void loop()
{
    if (stepper.distanceToGo() == 0)
    {
        // Random change to speed, position and acceleration
        // Make sure we dont get 0 speed or accelerations
        delay(500);
        stepper.moveTo(rand() % 200);
        stepper.setMaxSpeed((rand() % 200) + 1);
        stepper.setAcceleration((rand() % 200) + 1);
    }
    stepper.run();
}

The stepper motor does not move at all.
I'm not very sure if the enable pins are used at all, the example codes does not make use of the enable pins.

Try grounding the enable pin on the stepper driver or pulling it low.

In other works, in setup add:

digitalWrite(2,LOW);

Hi,
Do you have a DMM?
Can you please post some images of your project, so we can see your component layout?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

Just going to add this.

The tmc2208 does not have an internal pull-down resister attached to the enable pin. So it is disabled by default. Therefore the enable pin must be brought to ground to enable it.
There are two options:

A. Connect the driver enable pin directly to ground. If you don’t need to disable the driver this is the simplest.

B. Connect the driver enable pin to a logic pin on the arduino and pull it low. This is why I suggest that the original poster add digitalWrite(2.LOW) to the setup function on their sketch.

I just completed a project using a tmc 2209 driver which is almost identical to the 2208 and ran into the same problem.

Hello phoont, i have pulled the enable to low but it still didnt work !

Hello tom ! I do not have DMM with me right now, but i have checked the coils with DMM, so in the image attached, the red-yellow and green-blue wires are a pair each.
Connection is as followed :
VIO - 5V nano pin (powered by arduino nano when USB is connected)
GND - GND
DIR - Nano pin 3
STER - Nano pin 4
EN - Nano pin 2
VM - (+ve side) 11.1V power supply
Gnd - (-ve side) 11.1V power supply

Stepper wire pairs : red/yellow , green/blue
M2B - Stepper green wire
M2A - Stepper red wire
M1A - Stepper yellow wire
M1B - Stepper blue wire

and this is the code that i used :

#include <AccelStepper.h>
#define MOTOR_STEPS 200
#define DIR 3
#define STEP 4

//AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
AccelStepper stepper(AccelStepper::DRIVER, STEP, DIR ); 

void setup()
{  
  digitalWrite(2,LOW);
}
 
void loop()
{
    if (stepper.distanceToGo() == 0)
    {
        // Random change to speed, position and acceleration
        // Make sure we dont get 0 speed or accelerations
        delay(500);
        stepper.moveTo(rand() % 200);
        stepper.setMaxSpeed((rand() % 200) + 1);
        stepper.setAcceleration((rand() % 200) + 1);
    }
    stepper.run();
}

An image of a hand drawn schematic will be fine, include ALL power supplies, component names and pin labels.
Would be so much better.

Is that gnd connected to the UNO gnd?

I see more wires than are necessary, can you remove the other hardware and wires and get back to basics and get the stepper to work first?

Please consider getting a DMM, a $20 special is all you need.

Tom... :smiley: :+1: :coffee: :australia:

OK, I don't know the accelStepper, but after a quick look, it looks like it drives steppers directly. It does look like it can also run drivers. And it looks like you're creating it correctly.

Just to see if it all works, try this:

#define STEP_PIN 4
#define DIR_PIN 3
#define EN_PIN 2

void setup() {
  pinMode(STEP_PIN, OUTPUT);
  pinMode(DIR_PIN, OUTPUT);
  pinMode(EN_PIN, OUTPUT);

  digitalWrite(EN_PIN,LOW);
  digitalWrite(DIR_PIN, LOW);

}

void loop() {

  digitalWrite(STEP_PIN, HIGH));
  delayMicroseconds(200);
  digitalWrite(STEP_PIN, LOW));
  delay(10);


}

I tried the code you provided and it works for me. It's possible that you driver may be caput. Also, looking at your set up you should have a 75 to 100 mf capacitor on your motor voltage. Going between the positive and negative leads on vm and gnd

what does caput mean ?

will it not work without a capacitor ?