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 !!
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.
< #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.
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 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();
}
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.
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