Arduino to Parallel device

I have the strangest issue, I have a stepper controller based on the TB6560 chipset and all inputs are protected by an opto isolator. COnnection to the controller is via a parallel port.

Pin1 is the board Enable/Disable
Pin2 is Step
Pin3 is direction

And i'm using pin25 as a ground.

The supply to the stepper Driver is 24V.

If the stepper driver is powered up and I connect the Arduino to the USB on my computer I get device unknown and an error and the Arduino fires up but cant get serial communication to the PC.

If i pull the power out of the driver, plug the Arduino in then power up the driver everything seems to work OK.

The other issue I seem to have is that I have a POT on A4 so i can adjust the speed, speed works fine with the driver disconnected but as soon as the board is running for some reason I am getting some really random inputs on the pot especially when the pot is turned up towards the GND when its HIGH it seems kind of stable.

Only think I can think of is I am getting noise on the ground line via the interface from the driver.

Has anyone got any suggestions as to how I could decouple this or reduce the noise?

Oh, and the Arduino is powered from the USB directly, there is no separate power supply for it at this stage.

Hi,

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

Can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

A link to the specs/instructions to your stepper driver would be of help too.

Thanks .. Tom..... :slight_smile:

A link to the driver specs is here.
http://z.acralbatros.123.fr/CNC/CNC-Fraiseuse/Fraiseuse_Martin/4%20axis%20TB6560%20driver%20user%20manualV.pdf

I do not have a diagram as yet but will see if i can knock something up.

In short.

VR1 = 10K Pot that is connected to A5, Ground and 5V
Power is supplied to the board via the USB

A0 is connected to the Driver Pin1 (Enable)
A1 is connected to the Driver Pin2 (Step)
A2 is connected to the Driver Pin3 (Direction)

Ground is connected to the Driver pin 25 (Ground)

I am still working on the sketch so there is a lot of stuff there that needs to be changed, moved and consolidated. Here is what I have so far.

#include <LiquidCrystal.h>
#include <AnalogDebounce.h>
#include <AccelStepperEncoder.h>
#include <Encoder.h>
#include <Bounce2.h>

void ButtonPush(byte Button);

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
AnalogDebounce Buttons(A6,ButtonPush);  // Analog Input 6, 

// MENU CONFIG START
char menu[][4][16] = {{"BOUNCE", "FULL STROKE", "SHORT STROKE", "RANDOM"},
                     {"PROGRAM", "RECORD", "PLAY", "RESET"},
                     {"DIAGNOSTICS", "TEST ENCODER", "TEST MOTOR", "RESET SYSTEM"}};

int menuitems = sizeof(menu) / sizeof(menu[0]) - 1;                      //how many menu items do we have
int submenuitems = (sizeof(menu[0]) / sizeof(menu[0][0]) - 1);           //how many sub menu items do we have
int curmen;  //current menu selected
int cursub;  //current sub menu selected
int system_run = 0;  //menu change = 1

int selcmd = 0;
int lastcmd;
int cmdstatus = 0;

// MENU CONFIG END

const int LEDPin = 13;
const int SwitchPin = 11;
int SwitchState;
int lastSwitchState = LOW;   // the previous reading from the input pin
long int targetPossition;
long oldPosition  = -999;

int lastmove = 0;
int encdir = 0;
int lastdir = 1;
int movecnt = 0;
int cmd = 0;

// eprom start address
int addr = 0;
int loopcount = 0;
int progmem[40];

// The X Stepper pins
#define STEPPER1_DIR_PIN A2
#define STEPPER1_STEP_PIN A1
#define Enable_Pin A0
#define STOP_PIN A4
//#define SET_STROKE A2
#define SET_SPEED A5
#define DIR 1

//#define RUN_PIN 11
//#define PGM_PIN 10
//#define STP_PIN 9
//#define RST_PIN 8
//#define ESTP_PIN 7

#define arr_len( x ) ( sizeof( x ) / sizeof( *x ) )

float motorToEncoderRatio = 3.19;
int dirX = 1;
int setspeed = 3000;
int accell = 1000;

AccelStepperEncoder stepper1(AccelStepperEncoder::DRIVER, STEPPER1_STEP_PIN, STEPPER1_DIR_PIN);
Encoder encA(2, 3);             // encoder on pin 2 and 3
Bounce limit_switch = Bounce(); //limit switch
Bounce stp_button = Bounce(); //Stop Button

void setup() {
   Serial.begin(57600);
   stepper1.setMaxSpeed(6000.0);
   stepper1.setAcceleration(2000.0);
   stepper1.addEncoder(&encA, motorToEncoderRatio);
   stepper1.moveTo(0);
 
   pinMode(LEDPin, OUTPUT);
   pinMode(STEPPER1_DIR_PIN, OUTPUT);
   pinMode(STEPPER1_STEP_PIN, OUTPUT);
   pinMode(Enable_Pin, OUTPUT);
   
   pinMode(STOP_PIN, INPUT_PULLUP);
   stp_button.attach(STOP_PIN);
   stp_button.interval(5);

 pinMode(SwitchPin, INPUT_PULLUP);
 limit_switch.attach(SwitchPin);
 limit_switch.interval(5);
 
 //Control LED Backlight @ D10
 pinMode(10, OUTPUT);
 lcd.clear(); 
 lcd.begin(16, 2);
 lcd.setCursor(0,0); 
 lcd.print("Mr Stabby V1.0a");
 lcd.setCursor(0,1); 
 lcd.print(menu[0][0]);
}

void loop() {
 Buttons.loopCheck();
 stp_button.update();
 runCommand(selcmd);

if (stp_button.fell()){
 lcd.clear();
 lcd.setCursor(0,0); 
 lcd.print("Mr Stabby V1.0a");
}

switch (selcmd){
 case 0:
 break;
 
 case 1: //bounce full stroke
 lastcmd = selcmd;
 selcmd = 91;
 cmdstatus = 1;
 lcd.clear();
 lcd.setCursor(0,0); 
 lcd.print("FULL STROKE");
 lcd.setCursor(0,1); 
 lcd.print("RUNNING");
 break;
 
 case 2: //bounce short stroke
 lastcmd = selcmd;
 selcmd = 92;
 cmdstatus = 1;
 lcd.clear();
 lcd.setCursor(0,0); 
 lcd.print("SHORT STROKE");
 lcd.setCursor(0,1); 
 lcd.print("RUNNING");
 stepper1.moveTo(10);
 break;
 
 case 3: //bounce random
 lastcmd = selcmd;
 selcmd = 93;
 cmdstatus = 1;
 lcd.clear();
 lcd.setCursor(0,0); 
 lcd.print("RANDOM STROKE");
 lcd.setCursor(0,1); 
 lcd.print("RUNNING");
 break;
 
 case 11: //program record
 lastcmd = selcmd;
 selcmd = 911;
 cmdstatus = 1;
 lcd.clear();
 break;
 
 case 12: //program play
 lastcmd = selcmd;
 selcmd = 912;
 cmdstatus = 1;
 lcd.clear();
 break;
 
 case 13: //program reset
 lastcmd = selcmd;
 selcmd = 913;
 cmdstatus = 1;
 lcd.clear();
 break;
}

stepper1.run();   // runs the stepper motor commands  
}

void updatemm(int mm){
   lcd.clear();
   lcd.setCursor(0,0);
   lcd.print(menu[mm][0]);
   lcd.setCursor(0,1);
   lcd.print(menu[mm][1]);
}

void updatesm(int mm, int sm){
   lcd.clear();
   lcd.setCursor(0,0);
   lcd.print(menu[mm][0]);
   lcd.setCursor(0,1);
   lcd.print(menu[mm][sm]);
}

// Callback function
void ButtonPush(byte Button) {

 switch (Button){
   case 0: //Menu 1
   // Right Button Pressed
   // Incrament Sub Menu Value
   if(cursub == submenuitems){
     cursub = 1;
   } else {
   cursub++;
   }
   updatesm(curmen, cursub);
   break;
   
   case 1:
   // Up Button Pressed
   // Decrament Main Menu Value
   if(curmen == 0){
     curmen = menuitems;
   } else {
   curmen--;
   }
   cursub = 1;
   updatemm(curmen);
   break;
   
   case 2:
   //Down Button Presses
   // Incrament Main Menu Value

   if(curmen == menuitems){
     curmen = 0;
   } else {
   curmen++;
   }
   cursub = 1;
   updatemm(curmen);
   break;
   
   case 3:
   //Left Button Pressed
   // Decrament Sub Menu Value
   if(cursub == 1){
     cursub = submenuitems;
   } else {
   cursub--;
   }
   updatesm(curmen, cursub);
   break;
   
   case 4:
   // select button
   selcmd = curmen * 10 + cursub;
//    Serial.println(selcmd);
//    Serial.println(cmdstatus);
//    Serial.println(digitalRead(Enable_Pin));
   if(cmdstatus == 1){
   digitalWrite(Enable_Pin, HIGH);  // turn off the controler
   cmdstatus = 0;
   selcmd = 0;
   updatesm(curmen, cursub);
   }
   
   //Select Pressed
   // Select Menu Value
   break;
 }
}

void runCommand(int command){
 switch (command){
  case 91:
   //run command 1
//    Serial.println(selcmd);
 digitalWrite(Enable_Pin, LOW);  // turn on the controler
 GetSpeed();
 if((dirX == 1) && stepper1.distanceToGo() == 0){
 stepper1.moveTo((60 * 3.19)+1);
 Serial.print("Stroke Out ");
 Serial.print("Speed: ");
 Serial.println(setspeed);
 dirX = 0;
 }else if ((dirX == 0) && stepper1.distanceToGo() == 0){
 GetSpeed();
 stepper1.moveTo((10 * 3.19)+1);
 Serial.println("Stroke In");
 Serial.print("Speed: ");
 Serial.println(setspeed);
 dirX = 1;
 }
  break;
  case 2:
   //run command 2
  break;
 }
}


//Park the shaft and set the encoder and stepper to the zero point
void park() {
halt();
int lastsetspeed = setspeed;
int lastaccell = accell;
setspeed = 6000;
accell = 1000;
stepper1.setMaxSpeed(setspeed);
stepper1.setAcceleration(accell);

//cmd = 1;
targetPossition = 0;    // we want to set the park position as 0
limit_switch.update();  // read the switch state using the debouce code
                       // If the switch is high the machine is parker, if tits low the machine is not parked.

// Move the shaft until the endstop is active
while (limit_switch.read() != 0){
 limit_switch.update();
 digitalWrite(Enable_Pin, LOW);  // turn on the controler
 stepper1.moveTo(-500);
 stepper1.run();
 Serial.print("Switch State");
 Serial.println(limit_switch.read());
}

// Move the shaft off the endstop
while (limit_switch.read() != 1){
 limit_switch.update();
 digitalWrite(Enable_Pin, LOW);  // turn on the controler
 stepper1.moveTo(stepper1.currentPosition() + 10);
 stepper1.run();
 Serial.print("Switch State");
 Serial.println(limit_switch.read());
} 

// Zero the motor and the Encoder
 stepper1.stop();                // make sure the stepper is stopped. 
 stepper1.writeEnc(0);          //set encoder to zero
 stepper1.setCurrentPosition(0); //set motor ro zero
 digitalWrite(Enable_Pin, HIGH);  // turn off the controler
 cmd = 0;
 setspeed = lastsetspeed;
 accell = lastaccell;
 stepper1.setMaxSpeed(setspeed);
 stepper1.setAcceleration(accell);
}

//Machine Start/Stop
void halt() {
 cmd = 0;
 stepper1.stop();
 Serial.println("SYSTEM STOP");
}

//Extend and Retract the shaft for until stop is sent
void Cmd_BOUNCE(long int len) {
 cmd = 2;
 dirX = 1;
 digitalWrite(Enable_Pin, LOW);  // turn on the controler
 targetPossition = len;
 Serial.println("BOUNCE SHAFT");
}

void GetSpeed(){
     setspeed = analogRead(SET_SPEED);
     stepper1.setMaxSpeed(setspeed * 20);
}

Hi,

Have you written just a simple sketch, with the pot for speed and a digital input for stop/start and another for forward/reverse.
And got the driver working?

Tom.... :slight_smile:

Looks like the inputs are not protected by an opto-isolator if connecting to it over-currents
the USB socket... Opto isolated inputs typically have a + and - pin for each of enable, step, direction.

MarkT:
Looks like the inputs are not protected by an opto-isolator if connecting to it over-currents
the USB socket... Opto isolated inputs typically have a + and - pin for each of enable, step, direction.

Its definitely isolated, checked it with the meter last night.
The specs on the board state...

With optical isolation and DCDC power supply isolation, the full protection of your computer parallel port and equipment

Pinout is this.
DB25 control control control control pin (PIN) The pin of the drive board Comment Comment Comment Comment
1 EN All axes enable
2 STEPX X (First axis) pulse signal
3 DIRX X(First axis) direction direction direction direction of the signal
4 STEPY
5 DIRY Y
6 STEPZ
7 DIRZ
8 STEPA
9 DIRA
10 LIMIT-1 Limit input interface 1
11 LIMIT-2 Limit input interface 2
12 LIMIT-3 Limit input interface 3
13 LIMIT-4 Limit input interface 4
14 Relay
15 Blank
16 STEPB- B(Fifth axis) pulse signal
17 DIRB- B(Fifth axis)direction direction direction direction of the signal
18-25 GND

I simplified the code so its easier to test and still have the same issue.

//steper driver test with speed controll
#include <AccelStepperEncoder.h>
#include <Encoder.h>
#include <Bounce2.h>

// The X Stepper pins
#define STEPPER_ENABLE_PIN A0
#define STEPPER_STEP_PIN A1
#define STEPPER_DIR_PIN A2
//#define SET_STROKE A3
#define SET_SPEED_PIN A5
#define DIR 1

// Encoder Input
#define ENC_PINA 2
#define ENC_PINB 3

// SWITCH and BUTTONS
#define HOME_SWITCH 11
#define STOP_PIN A4
int stp_button_status = 0;


float motorToEncoderRatio = 3.19;
int setspeed = 3000;
int accell = 1000;
int dirX = 1;


AccelStepperEncoder stepper(AccelStepperEncoder::DRIVER, STEPPER_STEP_PIN, STEPPER_DIR_PIN);
Encoder encA(ENC_PINA, ENC_PINB);             // encoder on pin 2 and 3
Bounce home_switch = Bounce(); //limit switch
Bounce stp_button = Bounce(); //Stop Button

void setup() {
    Serial.begin(57600);

    //Setup Stepper
    stepper.setMaxSpeed(setspeed);
    stepper.setAcceleration(accell);
    stepper.addEncoder(&encA, motorToEncoderRatio);
    pinMode(STEPPER_DIR_PIN, OUTPUT);
    pinMode(STEPPER_STEP_PIN, OUTPUT);
    pinMode(STEPPER_ENABLE_PIN, OUTPUT);

    //Setup Switch
    pinMode(STOP_PIN, INPUT_PULLUP);
    stp_button.attach(STOP_PIN);
    stp_button.interval(5);

    pinMode(HOME_SWITCH, INPUT_PULLUP);
    home_switch.attach(HOME_SWITCH);
    home_switch.interval(5);
    
}

void loop() {
  // put your main code here, to run repeatedly:
    stp_button.update();
    home_switch.update();
    setspeed = analogRead(SET_SPEED_PIN);
    stepper.setMaxSpeed(setspeed);

    if (stp_button.fell()){
      //FlipFlop Status
      if (stp_button_status == 0){
        Serial.println("Start Function");
        stp_button_status = 1; //Function Running
      } else if (stp_button_status == 1){
        Serial.println("Stop Function");
        stp_button_status = 0; //Function Stopped
      }
    }
    switch(stp_button_status){
      case 1:
        bounceStepper();
        break;
      case 0:
      break;
    }
    
    stepper.run();   // runs the stepper motor commands 
}

void bounceStepper(){
  digitalWrite(STEPPER_ENABLE_PIN, LOW);  // turn on the controler
  if((dirX == 1) && stepper.distanceToGo() == 0){
    stepper.moveTo((60 * 3.19)+1);
    Serial.print("Stroke Out ");
    Serial.print("Speed: ");
    Serial.println(setspeed);
    dirX = 0;
  }else if ((dirX == 0) && stepper.distanceToGo() == 0){
    stepper.moveTo((10 * 3.19)+1);
    Serial.println("Stroke In");
    Serial.print("Speed: ");
    Serial.println(setspeed);
    dirX = 1;
  }
}

I have just put a meter across the pot and on the 5V line, its only giving me 4.3V is this normal and could this be the reason it's not working correctly?