vertical plotter -wiring the tb6600

Hello

I am doing a vertical plotter with two tb6600 drivers. It's using the serial to pass the coordinates. I hope i am not overwhelming with so many questions.

I tried to do this project with raspberry and at the end i saw that it will be much better with Arduino. I am newbie.

In the arduino uno code the pins for the tb6600 are defined

#define DirY 7
#define StepY 4
#define EnableY 8

#define DirX 12 
#define StepX 9 
#define EnableX 6

Enable and Dir are for ENA and DIR, Does Step goes to PUL?

in that case is that right?
ENA- pin 8, PUL- pin 4 ,DIR- pin 7

ENA+,PUL+ and DIR+ go to 5v pin, no?

I am confuse because of this funcion?

digitalWrite(DirX, HIGH);digitalWrite(StepX, LOW);digitalWrite(EnableX,HIGH);

Is the servo motor connected to pin 3?

#include <Servo.h>
...
Servo servoPen;
.....

servoPen.attach(3);

I am attaching a png file with how i am guessing the schematics are.

and the whole code. Thanks in advantage for any help.

#include <Servo.h>
long i=0;
Servo servoPen;
int PosServoUp = 66;//105
int PosServoDown = 54; // 30
float curX,curY,curZ;
float tarX,tarY,tarZ; // target xyz position
float delayy=80;

float AB=635;
float CO=490;
float L0=sqrt((AB/2)*(AB/2)+CO*CO);

float LA_precedente=L0;
float LB_precedente=L0;
float LA,LB,dlA,dlB;
long StepsA,StepsB;
long CbStepsA,CbStepsB;

/******** mapping xy position to steps ******/
float STEPS_PER_CIRCLE = 3200;
float DIAMETER = 13.50;
//float STEPS_PER_MM = (STEPS_PER_CIRCLE/PI/DIAMETER);





#define DirY 7
#define StepY 4
#define EnableY 8

#define DirX 12 
#define StepX 9 
#define EnableX 6


void setup(){


Serial.begin(115200);

servoPen.attach(3);
pinMode(DirX, OUTPUT);pinMode(StepX,OUTPUT);pinMode(EnableX, OUTPUT);
pinMode(DirY, OUTPUT);pinMode(StepY,OUTPUT);pinMode(EnableY, OUTPUT);


digitalWrite(DirX, HIGH);digitalWrite(StepX, LOW);digitalWrite(EnableX,HIGH);

digitalWrite(DirY, HIGH);digitalWrite(StepY, LOW);digitalWrite(EnableY,HIGH);
servoPen.write(PosServoUp); 

digitalWrite(EnableX,HIGH);

digitalWrite(EnableY,HIGH);

}
void prepareMove()
{
  //float dx = tarX - curX;
  //float dy = tarY - curY;
  //float distance = sqrt(dx*dx+dy*dy);
  
  // map xy to string length

    LA=sqrt((AB/2+tarX)*(AB/2+tarX)+(CO-tarY)*(CO-tarY));
    LB=sqrt((AB/2-tarX)*(AB/2-tarX)+(CO-tarY)*(CO-tarY));

    dlA=LA-LA_precedente;
    dlB=LB-LB_precedente; //en mm
    
    ActivDir(dlA,dlB);
    StepsA=(3200.00*dlA)/(PI*DIAMETER);
    StepsB=(3200.00*dlB)/(PI*DIAMETER);
    Rotation(StepsA,StepsB);
    //Serial.print((3200*dlA)/(PI*DIAMETER));Serial.print(";");Serial.println((3200*dlB)/(PI*DIAMETER));
    
    LA_precedente=LA_precedente+(PI*DIAMETER*float(CbStepsA))/3200.00;
    LB_precedente=LB_precedente+(PI*DIAMETER*float(CbStepsB))/3200.00;
    CbStepsA=0;
    CbStepsB=0;


  //curX = tarX;
  //curY = tarY;
  //Serial.print(curX);Serial.print(";");Serial.println(curY);
}


void parseCordinate(char * cmd)
{
  char * tmp;
  char * str;
  str = strtok_r(cmd, " ", &tmp);
  while(str!=NULL){
    str = strtok_r(0, " ", &tmp);
    //Serial.printf("%s;",str);
    if(str[0]=='X'){
      tarX = atof(str+1);
    }else if(str[0]=='Y'){
      tarY = atof(str+1);
    }else if(str[0]=='Z'){
      tarZ = atof(str+1);
    }else if(str[0]=='F'){
      //float speed = atof(str+1);
      //tarSpd = speed/60; // mm/min -> mm/s
    }else if(str[0]=='A'){
      //stepAuxDelay = atol(str+1);
    }
  }
  prepareMove();
}

void parsePen(char * cmd)
{
  char * tmp;
  char * str;
  str = strtok_r(cmd, " ", &tmp);
  int pos = atoi(tmp);
  servoPen.write(pos);
}


void parseMcode(char * cmd)
{
  int code;
  code = atoi(cmd);
  switch(code){
    case 1:
      parsePen(cmd);
      break;
  }
}
void parseGcode(char * cmd)
{
  int code;
  code = atoi(cmd);
  switch(code){
    case 1: // xyz move
      parseCordinate(cmd);
      break;
    case 28: // home
      tarX=0; tarY=0;
      prepareMove();
      break; 
  }
}


void parseCmd(char * cmd)
{
  if(cmd[0]=='G'){ // gcode
    parseGcode(cmd+1); 
    Serial.println("OK");
  }else if(cmd[0]=='M'){ // mcode
    parseMcode(cmd+1);
    Serial.println("OK");
  }
}

char buf[64];
char bufindex;

void loop(){

 if(Serial.available()){
    char c = Serial.read();
    //Serial.print(c);
    buf[bufindex++]=c;
    if(c=='\n'){
      parseCmd(buf);
      memset(buf,0,64);
      bufindex = 0;
    }
  }


}

void Rotation(long x,long y)
{


float rx,ry,ax,ay;
long m=max(abs(x),abs(y));

 ax=0;
 ay=0;


rx=abs(float(x))/float(m);
ry=abs(float(y))/float(m);


i=0;

do{
 ax=ax+rx;
 ay=ay+ry;
if(ax>=1){ax--;digitalWrite(StepX,HIGH);digitalWrite(StepX,LOW);if(digitalRead(DirX)==1){CbStepsA=CbStepsA-1;}else{CbStepsA=CbStepsA+1;}} 

if(ay>=1){ay--;digitalWrite(StepY,HIGH);digitalWrite(StepY,LOW);if(digitalRead(DirY)==1){CbStepsB=CbStepsB+1;}else{CbStepsB=CbStepsB-1;}} 




i++; 
 delayMicroseconds(delayy);


}while(i<m); // StopCond

  /*Serial.print("Steps A : ");
  Serial.println(CbStepsA);
  Serial.print("Steps B : ");
  Serial.println(CbStepsB);*/

}


void ActivDir(float x,float y)
{

  if (x<0)digitalWrite(DirX, HIGH);
   else digitalWrite(DirX, LOW);
  if (y<0)digitalWrite(DirY, LOW);
   else digitalWrite(DirY, HIGH);

}

Enable turns on the driver stage in the tb6600. Dir == direction, forward or backward.
Step is then pulsed to make the stepper move one step.
The red line, tied to +5 volt and using active low as signals probably works. I tied them to GND and used positive as active.

If You supply the entire code it will be better.

thanks Railroader,

The entire code is at the end.

Railroader:
I tied them to GND and used positive as active.

do you mean that you did it opposite? plugin ENA+, DIR+,PUL+ to the corespondent pins?

Railroader:
The red line, tied to +5 volt and using active low as signals probably works.

then, i will try tomorrow that setting.

what about the servo? do you think my guess was right?

(:

Sorry, my mistake. It must have been EN-, DIR- and PUL- I tied to GND and using "HIGH" as active. Your wiring is good using "LOW" as the active signal.
Please, attache the entire code, if possible, in code tags. Some helpers use tablets or mobiles and can't download code from included files.

hope it helps

#include <Servo.h>
long i=0;
Servo servoPen;
int PosServoUp = 66;//105
int PosServoDown = 54; // 30
float curX,curY,curZ;
float tarX,tarY,tarZ; // target xyz position
float delayy=80;

float AB=635;
float CO=490;
float L0=sqrt((AB/2)*(AB/2)+CO*CO);

float LA_precedente=L0;
float LB_precedente=L0;
float LA,LB,dlA,dlB;
long StepsA,StepsB;
long CbStepsA,CbStepsB;

/******** mapping xy position to steps ******/
float STEPS_PER_CIRCLE = 3200;
float DIAMETER = 13.50;
//float STEPS_PER_MM = (STEPS_PER_CIRCLE/PI/DIAMETER);





#define DirY 7
#define StepY 4
#define EnableY 8

#define DirX 12 
#define StepX 9 
#define EnableX 6


void setup(){


Serial.begin(115200);

servoPen.attach(3);
pinMode(DirX, OUTPUT);pinMode(StepX,OUTPUT);pinMode(EnableX, OUTPUT);
pinMode(DirY, OUTPUT);pinMode(StepY,OUTPUT);pinMode(EnableY, OUTPUT);


digitalWrite(DirX, HIGH);digitalWrite(StepX, LOW);digitalWrite(EnableX,HIGH);

digitalWrite(DirY, HIGH);digitalWrite(StepY, LOW);digitalWrite(EnableY,HIGH);
servoPen.write(PosServoUp); 

digitalWrite(EnableX,HIGH);

digitalWrite(EnableY,HIGH);

}
void prepareMove()
{
  //float dx = tarX - curX;
  //float dy = tarY - curY;
  //float distance = sqrt(dx*dx+dy*dy);
  
  // map xy to string length

    LA=sqrt((AB/2+tarX)*(AB/2+tarX)+(CO-tarY)*(CO-tarY));
    LB=sqrt((AB/2-tarX)*(AB/2-tarX)+(CO-tarY)*(CO-tarY));

    dlA=LA-LA_precedente;
    dlB=LB-LB_precedente; //en mm
    
    ActivDir(dlA,dlB);
    StepsA=(3200.00*dlA)/(PI*DIAMETER);
    StepsB=(3200.00*dlB)/(PI*DIAMETER);
    Rotation(StepsA,StepsB);
    //Serial.print((3200*dlA)/(PI*DIAMETER));Serial.print(";");Serial.println((3200*dlB)/(PI*DIAMETER));
    
    LA_precedente=LA_precedente+(PI*DIAMETER*float(CbStepsA))/3200.00;
    LB_precedente=LB_precedente+(PI*DIAMETER*float(CbStepsB))/3200.00;
    CbStepsA=0;
    CbStepsB=0;


  //curX = tarX;
  //curY = tarY;
  //Serial.print(curX);Serial.print(";");Serial.println(curY);
}


void parseCordinate(char * cmd)
{
  char * tmp;
  char * str;
  str = strtok_r(cmd, " ", &tmp);
  while(str!=NULL){
    str = strtok_r(0, " ", &tmp);
    //Serial.printf("%s;",str);
    if(str[0]=='X'){
      tarX = atof(str+1);
    }else if(str[0]=='Y'){
      tarY = atof(str+1);
    }else if(str[0]=='Z'){
      tarZ = atof(str+1);
    }else if(str[0]=='F'){
      //float speed = atof(str+1);
      //tarSpd = speed/60; // mm/min -> mm/s
    }else if(str[0]=='A'){
      //stepAuxDelay = atol(str+1);
    }
  }
  prepareMove();
}

void parsePen(char * cmd)
{
  char * tmp;
  char * str;
  str = strtok_r(cmd, " ", &tmp);
  int pos = atoi(tmp);
  servoPen.write(pos);
}


void parseMcode(char * cmd)
{
  int code;
  code = atoi(cmd);
  switch(code){
    case 1:
      parsePen(cmd);
      break;
  }
}
void parseGcode(char * cmd)
{
  int code;
  code = atoi(cmd);
  switch(code){
    case 1: // xyz move
      parseCordinate(cmd);
      break;
    case 28: // home
      tarX=0; tarY=0;
      prepareMove();
      break; 
  }
}


void parseCmd(char * cmd)
{
  if(cmd[0]=='G'){ // gcode
    parseGcode(cmd+1); 
    Serial.println("OK");
  }else if(cmd[0]=='M'){ // mcode
    parseMcode(cmd+1);
    Serial.println("OK");
  }
}

char buf[64];
char bufindex;

void loop(){

 if(Serial.available()){
    char c = Serial.read();
    //Serial.print(c);
    buf[bufindex++]=c;
    if(c=='\n'){
      parseCmd(buf);
      memset(buf,0,64);
      bufindex = 0;
    }
  }


}

void Rotation(long x,long y)
{


float rx,ry,ax,ay;
long m=max(abs(x),abs(y));

 ax=0;
 ay=0;


rx=abs(float(x))/float(m);
ry=abs(float(y))/float(m);


i=0;

do{
 ax=ax+rx;
 ay=ay+ry;
if(ax>=1){ax--;digitalWrite(StepX,HIGH);digitalWrite(StepX,LOW);if(digitalRead(DirX)==1){CbStepsA=CbStepsA-1;}else{CbStepsA=CbStepsA+1;}} 

if(ay>=1){ay--;digitalWrite(StepY,HIGH);digitalWrite(StepY,LOW);if(digitalRead(DirY)==1){CbStepsB=CbStepsB+1;}else{CbStepsB=CbStepsB-1;}} 




i++; 
 delayMicroseconds(delayy);


}while(i<m); // StopCond

  /*Serial.print("Steps A : ");
  Serial.println(CbStepsA);
  Serial.print("Steps B : ");
  Serial.println(CbStepsB);*/

}


void ActivDir(float x,float y)
{

  if (x<0)digitalWrite(DirX, HIGH);
   else digitalWrite(DirX, LOW);
  if (y<0)digitalWrite(DirY, LOW);
   else digitalWrite(DirY, HIGH);

}

Thanks.
I think You can tie all Enables toghether. Why disable power for only one stepper?
What is the actual problem?

Write a limited code that exercises one stepper motor and make that work.

You write about servo? Where does that one come up in the project?

the servo is moving the pen up and down to draw or not to draw.

Yes, i will start only with one driver/motor and see if its work. I found the project on internet and this is the code. it uses Makelangelo to convert the files and mdraw to tell arduino what to draw through the serial. I got little knowledge about c and arduino, that´s why i was hopping it work justconnecting the pins right to the arduino.

I will research how to debug in arduino, it might take longer but i will learn something

Railroader:
Why disable power for only one stepper?
What is the actual problem?

i don't want to disable power for one stepper, i just send the diagram of one because i think that the other is very similar

my question was if my assumptions were right and about the pin for the stepper. i didn't connect it yet so there is no actual problem with the machine, just some questions
:slight_smile:

Make the same small sketch for the servo to get comfortable with it.
One way to debug I've used a lot during 25 years is that I put test prints, serial.print, in the code telling "I am here", or telling the values of a strategic variable. Use Serial Monitor int the IDE to receive those test prints.

Then tie all enables to GND, or, to one controlling output.

I've not compared Your picture and Your code. You'll manage that.

Why start a new thread for the same question as vertical plotter -wiring the tb6600 - #7 by pedante - Programming Questions - Arduino Forum?

in the other thread i thought i asked too many questions and i made this post to clarify the first question i had. I also thought it is more about programming the help i need. I also wanted to ask the other question about the servo in other post

can the other threat be moved here?

should i delete this one?

The ENA+,PUL+ and DIR+ go to GND pin instead of the 5V

looking at the project comments of the project i found out that the tb6560 driver is similar to the tb6600. I was successful finding some help about arduino and the tb6560.

The ENA+,PUL+ and DIR+ go to GND pin instead of the 5V, witch i s probably what Railroader was saying but i didn't understand.

i will make the connections and see if it works, also the servo

can the other threat be moved here?

Topics about the same code merged

The ENA+,PUL+ and DIR+ go to GND pin instead of the 5V

No. The + sides of the inputs go to Vcc (+5V). The Arduino outputs go to the - sides (common anode).
Or, like Railroader says, the - sides go to ground and the + sides go to Arduino outputs (common cathode).

The inputs to the TB6600 are optoisolators. Polarity is critical. See the common cathode and common anode connection diagrams on this page pages 4 and 5.

thank you groundFungus that pdf was really usefull.
Now finally i got all motors working. Still the machine didn't draw the input i gave to it. i will try to change some parameters and the location of the motors and see if the problem continues...