Controlling a Nema23 Stepper Motor with a TB6560 driver and Arduino UNO R3?

Hello!
With the following materials:
Nema23 Stepper Motor
TB6560 driver (3A)
Arduino UNO R3

I am attempting to rotate a stepper motor in one direction at the click of a button, and then in the reverse direction at the click of another button.

The problem is that the motor will not rotate at all. It will hum when I supply current to it, but it does not run in my current configuration or with my current code (both shown below). My hypotheses are that I am incorrectly utilizing the arduino stepper library, OR I have wired the project incorrectly. If you notice any glaring mistakes in my failed approach, please let me know where I went wrong! Thanks so much!

/*
 Stepper Motor Control

 by Grahame MacKugler, 7/18/2016

 */

#include <Stepper.h>

const int stepsPerRevolution = 200;  // the number of steps per revolution for stepper motor.
const int numberRevolution = 5; // the number of revolutions required to move the stage the desired
// linear distance. There are roughly 5 revolutions per inch of linear travel.
const int rpm=20; // revolutions per minute of the stepper motor. Modify to achieve desired linear speed of stage.
const int steps=stepsPerRevolution*numberRevolution; // total number of steps in one direction.

const int ButtonOnePin = 2;
const int ButtonTwoPin = 3;
const int ledPin = 13;

// variables will change:
int ButtonOneStatus = 0;         // variable for reading the pushbutton status
int ButtonTwoStatus = 0;         // variable for reading the pushbutton status

// initialize the stepper library on pins 8 and 9
Stepper myStepper(stepsPerRevolution, 8, 9);

void setup() {
  // set the speed. 
  myStepper.setSpeed(rpm);
  // initialize the serial port:
  Serial.begin(9600);
  pinMode(ButtonOnePin, INPUT);
  pinMode(ButtonTwoPin, INPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(ButtonOnePin, HIGH);
  digitalWrite(ButtonTwoPin, HIGH);
}

void loop() {
  ButtonOneStatus = digitalRead(ButtonOnePin);
  if (ButtonOneStatus == LOW){ // If the Button #1 is pressed, perform the following:
  // step in one direction.
  digitalWrite(ledPin, HIGH);   // turn the LED on (HIGH is the voltage level)
  Serial.println("clockwise");
  myStepper.step(steps);
  delay(500);
  }
  ButtonTwoStatus = digitalRead(ButtonTwoPin);
  if (ButtonTwoStatus == LOW){ // If the Button #2 is pressed, perform the following:
  // step in the other direction:
  digitalWrite(ledPin, HIGH);   // turn the LED on (HIGH is the voltage level)
  Serial.println("counterclockwise");
  myStepper.step(-1*steps);
  delay(500);
  }
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}





With that stepper driver you should use the AccelStepper library with the DRIVER option. The standard stepper library is not really intended for drivers that take step and direction signals.

Post a link to the datasheet for your motor.

What power supply are you using for the motor (volts and amps)?

Have you properly adjusted the current limit on the driver to match the requirements of the motor?

This Simple Stepper Code should be good for testing. It does not need any library.

...R Stepper Motor Basics

Hi, Your pictures did not stick.

Can you post a link to the stepper data/spec. "Nema23 Stepper Motor" tells us what physical size it is but not its electrical specifications.

Likewise for the TB6560 driver (3A).

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thank you. Tom..... :)

Hello! With the following materials: Nema23 Stepper Motor (24V 3A) (link) TB6560 driver (link) Arduino UNO R3

I am attempting to rotate a stepper motor in one direction at the click of a button, and then in the reverse direction at the click of another button.

I've copied code from this simple stepper program, to test functionality.

I've also attached the wiring diagram (can't seem to upload correctly, right-click to open in new tab). I am pretty sure the wiring configuration from the motor is correct, as I've supplied current to the red&blue pair, and then the green&black pair sequentially to make the motor step forward, but that was isolated from the rest of the circuitry.

Per the tb6560 configuration table, I have switched SW1, SW2, and SW3 to the ON position, to supply 3A to the motor. S1 through S6 are all OFF.

// testing a stepper motor with a Pololu A4988 driver board or equivalent

// this version uses millis() to manage timing rather than delay()
// and the movement is determined by a pair of momentary push switches
// press one and it turns CW, press the other and it turns CCW

byte directionPin = 9;
byte stepPin = 8;

byte buttonCWpin = 2;
byte buttonCCWpin = 3;

boolean buttonCWpressed = false;
boolean buttonCCWpressed = false;

byte ledPin = 13;

unsigned long curMillis;
unsigned long prevStepMillis = 0;
unsigned long millisBetweenSteps = 25; // milliseconds

void setup() { 

  Serial.begin(9600);
  Serial.println("Starting Stepper Demo with millis()");

  pinMode(directionPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  
  pinMode(buttonCWpin, INPUT_PULLUP);
  pinMode(buttonCCWpin, INPUT_PULLUP);
  
}

void loop() { 

 curMillis = millis();
 readButtons();
 actOnButtons();

}

void readButtons() {

 buttonCCWpressed = false;
 buttonCWpressed = false;

 if (digitalRead(buttonCWpin) == LOW) {
 buttonCWpressed = true;
 }
 if (digitalRead(buttonCCWpin) == LOW) {
 buttonCCWpressed = true;
 }
}

void actOnButtons() {
 if (buttonCWpressed == true) {
 digitalWrite(directionPin, LOW);
 singleStep();
 }
 if (buttonCCWpressed == true) {
 digitalWrite(directionPin, HIGH);
 singleStep();
 }
}

void singleStep() {
 if (curMillis - prevStepMillis >= millisBetweenSteps) {
 prevStepMillis += millisBetweenSteps;
 digitalWrite(stepPin, HIGH);
 digitalWrite(stepPin, LOW);
 }
}

I can’t see your wiring diagram.

It would be wise to use your multimeter to measure the resistance of the coils and thus identify which pairs of wires belong to each coil. I would not rely on the colours.

I presume you have the CLK, CW and EN negative wires connected to Arduino GND. I never know whether en should be high or low to make the motor work - but it is easy to test both.

Use the simpler program until you are satisfied that things are working.

…R

Hmm. Here is a link to my wiring diagram. I tried the simpler code (no buttons) and still have no response from the motor. I have also tested the resistance between each combination of the motor wires. Red and Blue together results in no resistance, same with Blue and Green together. Otherwise there is resistance. That means that those are the pairs, correct?

I used my button set up to turn Off and On some leds, so I know that circuit works. Also, I have stepped the motor by applying current directly to the pairs of wires, so I know the motor functions. The part I don’t understand is the tb6560 driver. Is there some way to test with a multimeter that the driver is functioning properly?

Thanks.

Okay, so I have updated my wiring as follows:
EN-, CW-, CLK- to ground.
EN+ to pin 13
CW+ to pin 9
CLK+ to pin 8

Now, when I run the simple stepper code below, I get something new! My motor makes a stuttering noise, almost what I expect it would sound like if it was actually stepping. But I still see no movement. Maybe I am not supplying enough voltage to the motor? How do I tell if I am supplying enough voltage to the motor coils?

// testing a stepper motor with a Pololu A4988 driver board or equivalent
// on an Uno the onboard led will flash with each step
// this version uses delay() to manage timing

byte directionPin = 9;
byte stepPin = 8;
int numberOfSteps = 100;
byte ledPin = 13;
int pulseWidthMicros = 20;  // microseconds
int millisbetweenSteps = 25; // milliseconds


void setup() { 

  Serial.begin(9600);
  Serial.println("Starting StepperTest");
  digitalWrite(ledPin, LOW);
  
  delay(2000);

  pinMode(directionPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  
 
  digitalWrite(directionPin, HIGH);
  for(int n = 0; n < numberOfSteps; n++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(pulseWidthMicros); // this line is probably unnecessary
    digitalWrite(stepPin, LOW);
    
    delay(millisbetweenSteps);
    
    digitalWrite(ledPin, !digitalRead(ledPin));
  }
  
  delay(3000);
  

  digitalWrite(directionPin, LOW);
  for(int n = 0; n < numberOfSteps; n++) {
    digitalWrite(stepPin, HIGH);
    // delayMicroseconds(pulseWidthMicros); // probably not needed
    digitalWrite(stepPin, LOW);
    
    delay(millisbetweenSteps);
    
    digitalWrite(ledPin, !digitalRead(ledPin));
  }
}

void loop() { 
}

[EDIT] After adjusting the pulse width to 800, the motor is now turning. Unfortunately, I can not decrease the time between steps to anything that will allow faster RPM. When I try, the motor skips back&forth between steps. This also occurs when I switch S4 to go 1/16th steps. Any suggestions to change the code to get more fluid and faster revolutions?

Give the AccelStepper library a try.
This library makes it easier for you instead of fiddling with the right parameters like pulse widths etc.
Benefits:

  • easy setup (your current wiring should do 1:1)
  • acceleration, deceleration included

Drawback:

  • max. Pulsrate around 4000 steps/sec = 1200 RPM at fullstep-mode

Generally speaking:
If you want to increase the speed, you have to go to lower microstepping.

Today you have 1/16 set.
That means you need to send 16 pulses to have one fullstep.
One fullstep gives you 1.8 degree movement for a stepper which needs 200 (FULLSTEPS) to make a full turn.

So, if you want to stay with your current code, modify the driver microstepping to e.g. 1/4 and the stepper will turn 4 times faster.

The fastest, but also most noisiest mode, is Fullstep which needs 200 steps as said above to make one turn.

With, say 4000 pulses = steps / sec you will get 4000/200 = 20 turns/ sec = 20 * 60 = 1200 RPM.
If you need acceleration/deceleration, use the AccelStepper lib as said above and as already recommended by Robin.

If it does not work with my simple code it won't work with a more complex program. Stick with the simple program until it works.

Don't use pin 13 because that is for the onboard LED and has slightly different electrical properties.

Don't increase the pulse width. Increase the interval between steps - the variable millisBetweenSteps Try changing that to 250 or 1000 and see what happens. (I think I will change the value in my demo).

Don't explore anything complicated until you get steady running - even if only at low speed.

...R

Hello Anybody and Everybody

I need help.... I would like to know if anybody out there can help. I have designed a bottle filler and I would like to use a Heavy duty nema 23 stepper motor , a T6560 driver and a Arduino Mega. The rotations will be every 22.5 degrees which gives me 16 turns to complete a complete 360 degrees.

My idea is to have the motor rotate 22.5 degrees every 5 seconds and to have the ability to change # of degrees and /or delay time between turns.

Any help will be appreciated.

The first essential is to make sure that the driver can comfortably handle the current required by the motor. As you have not posted a link to the datasheet for either I cannot tell.

Most stepper motors do 200 steps per revolution so a precise 22.5 degrees (which would need 12.5 steps) is impossible without gearing. Maybe alternate moves of 12 steps and 13 steps would be OK.

Having said all that, what you want to do should be straightforward.

I presume you have read all of the earlier parts of this Thread carefully.

...R

If your driver allows for using it in microstepping mode, this might do the trick with 22.5 degrees as follows: As @robin2 pointed out, most steppers need 200 steps/ turn -> 12.5 steps for getting a 22.5 degree turn, which is not possible in the real world. But if you would choose 1/2 microstepping, you need 2x steps to get the same moving distance. Means: you need 25 steps for 22.5 degrees and 25 steps is possible.

Alternatively you can go for - 50 steps and 1/4 microstepping - 100 steps and 1/8 microstepping etc.

rpt007: But if you would choose 1/2 microstepping, you need 2x steps to get the same moving distance.

OOPs - I missed that. I had it in my mind that @RAMONFT needed something that was not a simple multiple of 2.

And that could happen if he chooses other angles

...R

Hi everyone. I have a problem to drive nema 17(17HS4401) with tb6560(green one). I give my wiring below.

+12V-- +24v
-12V-- gnd
black wire-- A+
blue wire-- A-
green wire-- B+
red wire-- B-

Enable + and enable - are not connected.

clk- and cw- ------ arduino gnd.

clk+ — pin9
cw+ — pin8

and I tried to use stepper library my code is given below:

#include <Stepper.h>

Stepper mystepper(200,8,9);

void setup(){

pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
mystepper.setSpeed(60);

}

void loop(){

mystepper.step(200);

}

but it did not work. Can you help me? I don’t know may be I have a problem about wiring or coding. Or, there are sw and s switches. I did not touch them. All of them are off. I tried some but I could not get my step motor to work. I m waiting your help it s my dissertation.

kaanertugrl: but it did not work.

That does not provide any useful information. What actually happened? What did you want to happen?

It seems to me you have tacked your question at the end of this Thread without reading all the existing stuff in the Thread - particularly the code in Reply #6

Have a careful look at these links Stepper Motor Basics Simple Stepper Code

...R

That means my step motor did not rotate. Nothing happened. I just wanted to get it rotate 200 step based on my code. Maybe stepper library does not work with this driver. Is there anyone who used stepper library with tb6560?

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :)

kaanertugrl: Maybe stepper library does not work with this driver. Is there anyone who used stepper library with tb6560?

Did you read the links I gave or try the code in them?

...R

Lets do this way. Here is my wiring:

+12V------>+24(input of tb6560) -12V------->gnd(input of tb6560) black wire of nema17------>A+(input of tb6560) blue wire of nema17------->A-(input of tb6560) red wire of nema17-------->B+(input of tb6560) green wire of nema17----->B-(input of tb6560)

pin9(arduino)-------->CLK+(input of tb6560) pin8(arduino)-------->CW+(input of tb6560) gnd(arduino)--------->CW- and CLK-(inputs of tb6560) not connected-------->EN+ and EN- (inputs of tb6560)

Nema17(17HS4401) Arduino mega tb6560 12V power supply

so, how should I code to just make nema17 to rotate?

I run this code JUST NOW (I have CLK+ and CW+ to 5V, and negativ to arduino_pins)
(google translate norwegian comments)

My powersuply is a HP-laptop 19V / 4.7A

/* EKSEMPEL  
 * Stepper-styring for hevebro
 ' Merk hvordan bryterne står..
 * strømmen sette 'så lav' som mulig, Men likevel så stor at
 * den klarer å dra broa greit.
 * motoren satt til 16-dels step => betyr 3200 steps pr. turn
 * hvis motoren må gå 5 runder, betyr det 5*3200= 16000 pulser
 * OPPKOPLING
 * 5V til pinnene CW+ og CLK+  (enable er ikke nødv.-da er den alltid 'på')
 * CW- og 
*/
#define stp_pin 8 // step-pinne (valgfri pin)
#define dir_pin 7 // retning (valgfri pin)
#define opp 1     // kan hende bytter du verdiene på opp og ned
#define ned 0
#define antallSteg 16000 // bestemmer hvor lagt motren skal rotere. Her 5 turn

void setup()
{
  pinMode(stp_pin, OUTPUT);
  pinMode(dir_pin, OUTPUT);
}

void loop()
{
  // hvis brua skal opp
  // sett rødt lys
  kjqr_bro(opp);   // q=ø (ikke tillat å bruke norske tegn)
  // så venter vi til 'noe' har passert
  delay(3000); // denne er for testing
  kjqr_bro(ned);
  //sett grønt lys ??
  //annen styring
  delay(2000); // denne er for testing
}
void kjqr_bro(byte retning)
{
  digitalWrite(dir_pin, retning);
  // så skal du trekke i tråden..
  for (int i=0; i < antallSteg; i++)
  {
    digitalWrite(stp_pin, LOW);   
    delayMicroseconds(5);    // noen mikrosekunder lav puls
    digitalWrite(stp_pin, HIGH);
    delayMicroseconds(295);   // ikke lavere enn 80 us, max: verdien du finner passer
    // databladet sier "opptil 20000 pulser/sek" (sikkert overdrevet)
  }
}