Stepper motor controller and arduino

I have bought 4 stepper motors and with them a 4 axis tb6560 stepper motor driver.


I am wanting to make a small circuit to control the stepper motor speed with a potentiometer just to test the interfacing between the controller, stepper motors and arduino.
However, I found that the tb6560 only has a parallel port, manual interface port(looks to fit a VGA cable) and another smaller port. Does anyone know how to connect arduino to this driver to be able to take values from the potentiometer through arduino to the driver then the motors.
I saw someone managed to manual insert pins into the port and allow an arduino to send values to the driver.

And also found someone managed to make what looks like a DIY parallel shield converter shield to do the same thing.

Also how would I interface/code to the arduino in the above youtube link there is something about gbrl and there is also mach3? any hard code that would work?
I am specifically looking to know how it would be wired manually through the parallel port and make simple pin outputs from the arduino to driver and work.

Anyone have any idea? I'm really stuck!

You don't say whether the stepper driver board has a male or female D connector. You should have no trouble buying a matching connector that you can connect wires to to make a simple interface to your Arduino.

You will need a pin wiring diagram for the D connector so you know what connects to what.

I'm guessing there is a ground connection and a step and direction connection for each stepper motor. That would amount to 9 pins. There may also be connections for other functions - maybe an enable for each motor, and maybe connections to choose whether microstepping is used.

Have you a link to the specifications for the driver board?

...R

Thank you for you help, Here are the specifications of the driver https://www.machsupport.com/forum/index.php?action=dlattach;topic=15903.0;attach=23971.
Also I was perhaps hoping for a more specific solution as I am still not quite sure on what to do.
Also the board has a male d connector and I do have a female to female d connector.

Can you help?
Or anyone else have input?

You need a female connector to connect to a male connector. I'm guessing what you have is "gender bender" intended to be a bridge between two identical connectors. Just buy the right part, they aren't expensive.

As I suspected the 25pin D connector takes signals for 4 stepper and the spindle drive. Lets just focus on Pins 4, 1 and 16 which are Enable, Direction and Step for the X axis motor.

I don't know whether its essential to connect Enable - some driver boards allow the motor to run without it being connected in which case you would just use it to disable the motor. It will have to be either HIGH or LOW so it will only take a few moments to test.

The following code should make the motor move if you connect Arduino pin 9 to the direction pin and Arduino pin 8 to the step pin in the D Connector. My code doesn't use enable. For testing you could just manually connect it to 5v or 0v.

The spec sheet doesn't say which pins in the D connector are for Ground. It's essential to connect the Ground to the Arduino ground. Assuming it is designed to connect to a standard PC parallel port D connector then you should be able to find a full pinout diagram on the web.

// testing a stepper motor with a Pololu A4988 driver board
// on an Uno the onboard led will flash with each step
// as posted on Arduino Forum at http://forum.arduino.cc/index.php?topic=208905.0

byte directionPin = 9;
byte stepPin = 8;
int numberOfSteps = 50;
byte ledPin = 13;
int pulseWidthMicros = 50;  // microseconds
int millisbetweenSteps = 50; // 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);
    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);
    digitalWrite(stepPin, LOW);
    
    delay(millisbetweenSteps);
    
    digitalWrite(ledPin, !digitalRead(ledPin));
  }
  
}

void loop() 
{ 

}

Hope this helps

...R

Thankyou for this help and information.

I tried it with female to male connecter wired without a converter just to test it and nothing happened.
It is most likely my wiring (those wires for direction and step were meant to connect to the PWM pins on the arduino right?)
Could it also be because there are not enough pulses.
I am using a geared stepper motor which makes it slower.

Thanks

The code I posted is very simple so that you can easily change parts of it - for example the number of steps. It should be obvious, but my code only runs once every time the Arduino is reset.

The Arduino PWM has NOTHING to do with driving stepper motors. Any of the Arduino pins can be used as long as they are programmed to produce the appropriate step pulses.

How have you connected the enable pin?

How have you connected Arduino ground to the driver board ground?

Best thing would be for you to post a diagram of exactly how you have things wired up - both to the Arduino and to the motor. A photo of a clear pencil sketch will be fine.

Also, how have you set the DIP switches on the driver board for microstepping and whatever else they do? For testing its best to use single (full) steps.

...R

I believe it is my wiring, I tried testing just the steppers and tb6560 board with the Mach3 software it came with and could not get the motors to move at all, there wasn't even any juttering. I believe either my polarity of either pairs of the 4 wires of the geared steppers may be wrong or, the sheet/table with which pins are which on the D25 port may be wrong.
(I could not find a complete table with all 25 pins of the D25 port)

As I suggested, show us a diagram of how it is wired and we may be able to help.

Google "parallel port pinout"

...R

hahah, it works, finally, thankyou so much for your help.
I'm just editing the code now to decrease the juttee when turning and increase to find out what one rotation is. It is a geared stepper motor so it will require a lot more turning to get one rotation.
Just quickly, what would you increase or decrease in the code to make the stepper faster or slower?

I have attached a diagram of the arduino and tb6560 driver wiring I have done.
Also, thought I'd let you know, the enable pin DOES need to be connected to 5v or the stepper will not move.
Still can't get it to move with the Mach3 software though, probably the pin set up.

Any other information you could give me?
Thank you so much for your help you have given me,

thanks
Alexis

In my code the speed is governed by the value in the variable millisbetweenSteps.

I'm afraid I have no experience of Mach3. I think its a Windows program and I don't do Windows. Isn't there a Mach3 forum?

...R

Ok.
The motor is running, but there is a problem.

It is not changing direction now. I'm pretty sure it was yesterday but it is not today.
I copy and pasted the code that you posted for me.
What could be wrong?

haha, never mind, I made an absolutely dumb mistake.
The wire I was connecting to the arduino had slipped out
It now changes direction fine

Thankyou

Alexis

Alexisa:
I made an absolutely dumb mistake.

Welcome to the club :slight_smile:

Glad its working.

...R

Good evening, Robin2 and others!

I ran into a problem trying to implement the code you suggested to Alexisa above for the TB6560 Driver, and I can't seem to get it to make my stepper move. I had it running fine on my original code, but with your even simpler code it will only "enable" the stepper with holding power, but it won't actually step during either of the movement blocks. The grounds are tied together between the driver and the arduino, and I've double and triple checked my connections. Since I'm getting half of it to work (holding torque), I'm kind of confused as to why it's not abiding by your code.

My DIP switches are set to the current of the Stepper motor (2 amps) with 20% stop current, set back to no microstepping (1=1), and 0% decay. I have the serial monitor open with some minor changes to the code telling me that it can't be the board or the code itself since it's working as it should... what could be wrong?

// testing a stepper motor with a Pololu A4988 driver board
// on an Uno the onboard led will flash with each step
// as posted on Arduino Forum at http://forum.arduino.cc/index.php?topic=208905.0
byte StepperStart = 12;
byte directionPin = 11;
byte stepPin = 10;
int numberOfSteps = 50;
byte ledPin = 13;
int pulseWidthMicros = 100;  // microseconds
int millisbetweenSteps = 100; // milliseconds

void setup() 
{ 

  Serial.begin(9600);
  Serial.println("Starting StepperTest");
  digitalWrite(ledPin, LOW);
  
  delay(2000);
  pinMode(StepperStart, OUTPUT);
  pinMode(directionPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  
  delay(100);
  
  digitalWrite(StepperStart, HIGH);
  Serial.println("Stepper Online");
  delay(1000);
  

  digitalWrite(directionPin, HIGH);
  Serial.println("Stepper Direction Set Positive");
  for(int n = 0; n < numberOfSteps; n++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(pulseWidthMicros);
    digitalWrite(stepPin, LOW);
    Serial.println("Stepped");
    delay(millisbetweenSteps);
    
    digitalWrite(ledPin, !digitalRead(ledPin));
  }
  
  delay(3000);
  

  digitalWrite(directionPin, LOW);
  Serial.println("Stepper Direction Set Negative");
  for(int n = 0; n < numberOfSteps; n++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(pulseWidthMicros);
    digitalWrite(stepPin, LOW);
    Serial.println("Stepped");
    delay(millisbetweenSteps);
    
    digitalWrite(ledPin, !digitalRead(ledPin));
  }
  
}

void loop() 
{ 

}

ACrespin124:
I had it running fine on my original code, but with your even simpler code it will only "enable" the stepper with holding power, but it won't actually step during either of the movement blocks.

I'm tempted to ask why you bother with my code if your own code works ? :slight_smile:

I think you need to make a pencil drawing showing ALL the connections and post a photo of the drawing.

It may also be useful to post the working code.

...R

Hahaha my code was kind of a test for the motor and the driver, but your code easily separates variables for adjustment in a way that I've been wondering how to do myself. Just learned a little something new in the process :slight_smile:

I've come across an even worse problem now, I tried Verifying my old code that worked from before and now it's giving me this error which I know others have had before but I can't find the answer to it.

at java.util.regex.Pattern$GroupTail.match(Pattern.java:4717)
at java.util.regex.Pattern$BranchConn.match(Pattern.java:4568)
at java.util.regex.Pattern$CharProperty.match(Pattern.java:3777)
at java.util.regex.Pattern$Branch.match(Pattern.java:4604)
at java.util.regex.Pattern$GroupHead.match(Pattern.java:4658)
at java.util.regex.Pattern$Loop.match(Pattern.java:4785)

The previous "working" code is actually below (next post, won't let me post in this one) but I removed the second motor block since it was giving me trouble with the move back and forth.

That Java problem is because whoever wrote the Arduino IDE did not trap all possible errors correctly. There is some mistake in your code that Java is choking on. You will need to read through your code very carefully. Perhaps make a copy of your code and then delete chunks to isolate where the choke point is.

...R

WOOT! I found the error after reading all lines of code that I had modified...

So now I'm back to square one: my code worked and yours didn't on the board, but I'll make a diagram to show my wiring exactly how I have it.

Here's my code:

#include <Keypad.h>
#include <Adafruit_NeoPixel.h>


// Define the states for the lock state machine
#define LOCKED 2
#define UNLOCKED 0

// State Variables:   Initialize to the locked state
int LockState = LOCKED;
long StartTime = 0;
int position = 0;
int Distance = 0; //Record steps

// Define your password key sequence here
char* secretCode = "2301000";

// Keypad key matrix:
const byte rows = 4;
const byte cols = 3;
char keys[rows][cols] =
{
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};

// Keypad pin definitions
byte rowPins[rows] = {5, 6, 7, 8};
byte colPins[cols] = {2, 3, 4};

// Instantiate the keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);

int transistorPin = 9; //LED Transistor Pin Definition

int StepperDistance = 10; //Stepper Distance Pin Definiton
int StepperDirection = 11; //Stepper Direction Pin Definition
int StepperStart = 12; //Stepper Engage Pin Definition

int ColorLED = 13; //Color LED Definition

Adafruit_NeoPixel IndicatorLED = Adafruit_NeoPixel(2, ColorLED, NEO_RGB + NEO_KHZ800);
//400 IS FOR WS2811 and 800 IS FOR WS2812


void setup()
{
  //Set stepper and Light Parts as Outputs)
  pinMode(transistorPin, OUTPUT);
  pinMode(StepperDistance, OUTPUT);
  pinMode(StepperDirection, OUTPUT);
  pinMode(StepperStart, OUTPUT);



  //Set stepper settings off and Clockwise
  digitalWrite(StepperStart, LOW);
  digitalWrite(StepperDistance, LOW);
  digitalWrite(StepperDirection, LOW);


  // Initialize state of lock and communications.
  setLockState(LOCKED);
  IndicatorLED.begin();
  IndicatorLED.show(); //Initialize LEDs to 'off'
  Serial.begin(9600);
}


void loop()
{
  // Run the state machine:

  // Locked State - Monitor keypad for valid Password code entry
  if (LockState == LOCKED)
  {
    char key = keypad.getKey();

    if (key == '*' || key == '#')
    {
      position = 0;
    }
    if (key != 0)
    {
      if (key == secretCode[position])  // Valid key in Password sequence
      {
        Serial.print("Matched ");
        Serial.print(key);
        Serial.print("-at-");
        Serial.println(position);
        position ++;

        IndicatorLED.setPixelColor(0, 255, 0, 0);
        IndicatorLED.setPixelColor(1, 255, 0, 0);
        IndicatorLED.show();
        delay(10);
        IndicatorLED.setPixelColor(0, 0, 0, 0);
        IndicatorLED.setPixelColor(1, 0, 0, 0);
        IndicatorLED.show();
        //Green LED flash
      }
      else  // Invalid key - start all over again
      {
        Serial.println("Invalid Code!");
        position = 0;

        IndicatorLED.setPixelColor(0, 0, 255, 0);
        IndicatorLED.setPixelColor(1, 0, 255, 0);
        IndicatorLED.show();
        delay(100);
        IndicatorLED.setPixelColor(0, 0, 0, 0);
        IndicatorLED.setPixelColor(1, 0, 0, 0);
        IndicatorLED.show();
        //Red LED on for 2 seconds
      }
    }


    if (position == 7)  // Password successfully entered - advance state
    {
      setLockState(UNLOCKED);

      position = 0;
    }
    delay(100);
  }

}

// Set the state and the time of the state change
void setLockState(int state)
{
  LockState = state;
  StartTime = millis ();
  if (state == LOCKED)
  {
    Serial.println("Locked!");
  }

  else if (state == UNLOCKED)
  {
    Serial.println("Unlocked!");


    //MyStepper.step(STEPS);
    digitalWrite(StepperStart, HIGH);
    delay(25);
    digitalWrite(StepperDirection, LOW);
    digitalWrite(StepperDistance, HIGH);
    delay(100);
    digitalWrite(StepperDistance, LOW);
    digitalWrite(StepperStart, LOW);
    
    //Code for 90 degree clockwise turn below... 1:1 stepping ratio, no chopping
    if(Distance < 90);
    {
      digitalWrite(StepperDirection, LOW);
      digitalWrite(StepperDistance, HIGH);
      delayMicroseconds(100);
      digitalWrite(StepperDistance, LOW);
      delayMicroseconds(100);
      Distance = Distance + 1; //Record this Step
      Serial.println("Stepped!");
    }
    
      
      
      
    for (int brightness = 0; brightness < 255; brightness++) {
      analogWrite(transistorPin, brightness);
      delay(12);
    }

    rainbow(12); //Start flashing Rainbow LEDs
    

    IndicatorLED.setPixelColor(0, 0, 0, 0);
    IndicatorLED.setPixelColor(1, 0, 0, 0);  //0, Begin Rainbow Countdown to Close ROYGBP
    IndicatorLED.show();
    delay(1000);
    IndicatorLED.setPixelColor(0, 0, 255, 0);
    IndicatorLED.setPixelColor(1, 0, 255, 0);  //RED
    IndicatorLED.show();
    delay(1000);
    IndicatorLED.setPixelColor(0, 0, 0, 0);
    IndicatorLED.setPixelColor(1, 0, 0, 0);
    IndicatorLED.show();
    delay(100);
    IndicatorLED.setPixelColor(0, 100, 255, 0);
    IndicatorLED.setPixelColor(1, 100, 255, 0);  //ORANGE
    IndicatorLED.show();
    delay(1000);
    IndicatorLED.setPixelColor(0, 0, 0, 0);
    IndicatorLED.setPixelColor(1, 0, 0, 0);
    IndicatorLED.show();
    delay(100);
    IndicatorLED.setPixelColor(0, 255, 255, 0);
    IndicatorLED.setPixelColor(1, 255, 255, 0);  //YELLOW
    IndicatorLED.show();
    delay(1000);
    IndicatorLED.setPixelColor(0, 0, 0, 0);
    IndicatorLED.setPixelColor(1, 0, 0, 0);
    IndicatorLED.show();
    delay(100);
    IndicatorLED.setPixelColor(0, 255, 0, 0);
    IndicatorLED.setPixelColor(1, 255, 0, 0);  //GREEN
    IndicatorLED.show();
    delay(1000);
    IndicatorLED.setPixelColor(0, 0, 0, 0);
    IndicatorLED.setPixelColor(1, 0, 0, 0);
    IndicatorLED.show();
    delay(100);
    IndicatorLED.setPixelColor(0, 0, 0, 255);
    IndicatorLED.setPixelColor(1, 0, 0, 255);  //BLUE
    IndicatorLED.show();
    delay(1000);
    IndicatorLED.setPixelColor(0, 0, 0, 0);
    IndicatorLED.setPixelColor(1, 0, 0, 0);
    IndicatorLED.show();
    delay(100);
    IndicatorLED.setPixelColor(0, 0, 255, 255);
    IndicatorLED.setPixelColor(1, 0, 255, 255);  //PURPLE
    IndicatorLED.show();
    
    

    //Fade off the Light
    for (int brightness = 255; brightness >= 0; brightness--) {
      analogWrite(transistorPin, brightness);
      delay(20);
    }
    //Close Cabinet
    
    //Code for 90 degree clockwise turn below...
    
    
    //Indicate the code will return to locked state
    IndicatorLED.setPixelColor(0, 0, 0, 0);
    IndicatorLED.setPixelColor(1, 0, 0, 0);
    IndicatorLED.show();
    delay(500);
    IndicatorLED.setPixelColor(0, 0, 255, 0);
    IndicatorLED.setPixelColor(1, 0, 255, 0);  //RED
    IndicatorLED.show();
    delay(500);
    IndicatorLED.setPixelColor(0, 0, 0, 0);
    IndicatorLED.setPixelColor(1, 0, 0, 0);
    IndicatorLED.show();
    delay(500);
    IndicatorLED.setPixelColor(0, 0, 255, 0);
    IndicatorLED.setPixelColor(1, 0, 255, 0);  //RED
    IndicatorLED.show();
    delay(500);
    IndicatorLED.setPixelColor(0, 0, 0, 0);
    IndicatorLED.setPixelColor(1, 0, 0, 0);
    IndicatorLED.show();
    setLockState(LOCKED);


  }
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for (j = 0; j < 256; j++) {
    for (i = 0; i < IndicatorLED.numPixels(); i++) {
      IndicatorLED.setPixelColor(i, Wheel((i + j) & 255));
    }
    IndicatorLED.show();
    delay(wait);
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if (WheelPos < 85) {
    return IndicatorLED.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if (WheelPos < 170) {
    WheelPos -= 85;
    return IndicatorLED.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
    WheelPos -= 170;
    return IndicatorLED.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

ACrespin124:
Here's my code:

That is very long compared to mine :slight_smile:

If this code makes your stepper move more than one step then your driver must be very different from the type my code is intended for

    digitalWrite(StepperStart, HIGH);
    delay(25);
    digitalWrite(StepperDirection, LOW);
    digitalWrite(StepperDistance, HIGH);
    delay(100);
    digitalWrite(StepperDistance, LOW);
    digitalWrite(StepperStart, LOW);

If this code does make you stepper move multiple steps please post a link to the datasheet for your stepper driver.

...R