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);
}