Gecko 203V Drivers and MEGA

Howdy folks,

I wrote a little program for a lamination CNC machine that worked properly with some cheap, fake, TB6006 drivers from China. Code is posted below. I didn't change anything in the code, but I switched over to gecko 203V drivers and switched from my breadboard to a proper PCB. The LCD is working properly, but there is no motion. The motors are NEMA 23 bipolar stepper motors and I am using a 70.5k ohm set resistor. Does anyone else here have experience using Gecko Drivers (specifically) that they can lend to me? Any help is much appreciated. I do not want to have to disassemble my setup and hello world each part again, but I will if I absolutely have to.

Uploading: IMG_1552.jpg...


#include <AccelStepper.h>
#include <LiquidCrystal.h>
#include <StateMachine.h> 

//LCD Screen Setup
const int rs = 8, en = 9, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
unsigned int lcdStatus;
bool advanceHasRun = false;
int reverseHasRun = false;
int idleingHasRun = false;

//motor decleration
AccelStepper sprayer(1, 35, 33); // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5 .   ////37 now 33, 39 now 35
AccelStepper table1(1, 43, 41);  // 1, pulse pin, direction pin
AccelStepper table2(1, 47, 45);  // 1, pulse pin, direction pin

/////////////////////////start button
int laminateButton = 52;
int laminateButtonstate = 0;

/////////////////////////boolean switches
bool sprayerOff = true;
bool tableOff = true;
bool tableHomeOff = true;
bool sprayHomeOff = true;
bool advance = false;
bool reverse = false;

/////////////////////////table1 manual control
int forwardButton = 49;
int reverseButton = 51;

int forwardButtonStatus = 0;
int reverseButtonStatus = 0;

/////////////////////////reset buttons
int sprayerResetButton = 50;
int tableResetButton = 53;

int sprayerResetStatus = 0;
int tableResetStatus = 0;

//////////////////////////table tuning
int tableSpeed = 1000;     //table overall speed // previously set to 900
int tableAccel = 5000;    //changed from 1000 to 5000 to get more table speed

int spraySpeed = 1000;  //sprayer overall speed
int sprayAccel = 2000;   //accelleration rate .   //previously set to 10000

//////////////////////////Time based longs and ints
long previousMillis = 0;
long sprayHomeTime = 1000;
long tableHomeTime = 80000;

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////     SETUP    ///////////////////////////////////////////////////////////////

void setup() {
  
  //Initalize LCD screen
  //first set the LCD's number of colums and rows:
  lcd.begin(16, 2);
  Serial.begin(9600);
  startUpScreen();
  
 //////////////////////////////////////INITALIZE STEPPERS////////////////////////////////////
  sprayer.setAcceleration(sprayAccel);
  sprayer.setMaxSpeed(spraySpeed);
  sprayer.moveTo(1800);     //sets limit on reverse distance 
  

  table1.setMaxSpeed(tableSpeed);
  table1.setAcceleration(tableAccel);

  table2.setMaxSpeed(tableSpeed);
  table2.setAcceleration(tableAccel);

  pinMode (laminateButton, INPUT);
  pinMode (forwardButton, INPUT);
  pinMode (reverseButton, INPUT);
  pinMode (sprayerResetButton, INPUT);
  pinMode (tableResetButton, INPUT);
  
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////     LOOP     ///////////////////////////////////////////////////////////////


void loop() {

///////////////////////////   MANUAL CONTROL    ////////////////////////////

  //check status of forward button, if high, advance
  forwardButtonStatus = digitalRead(forwardButton);
  if (forwardButtonStatus == HIGH) {
    advance = true;
    while (advance == true){
      table1Advance();
      table2Advance();
      if (advanceHasRun == false){
        advanceScreen();
      }
    } 
  }

  //check status of reverse button, if high, reverse
  reverseButtonStatus = digitalRead(reverseButton);
  if (reverseButtonStatus == HIGH) {
    reverse = true;
    while (reverse == true){
      table1Reverse();
      table2Reverse();
      if (reverseHasRun == false){
         reverseScreen();
      } 
    }
  }


///////////////////////////////    RESET    ////////////////////////////////

  tableResetStatus = digitalRead(tableResetButton);
  if (tableResetStatus == HIGH) {
    tableHomeOff = !tableHomeOff; 
    resetScreen();
  }
  while (tableHomeOff == false){
    tableHome();
  }

  //send the sprayer to the starting position if right left button is pressed
  sprayerResetStatus = digitalRead(sprayerResetButton);
  if (sprayerResetStatus == HIGH) {
    sprayHomeOff = !sprayHomeOff;
  }
  while (sprayHomeOff == false) {
    sprayHome();
  } 

////////////////////////    START SEQUENCE    /////////////////////////////////

  laminateButtonstate = digitalRead(laminateButton);
  if (laminateButtonstate == HIGH) {
      tableOff = false;
      sprayerOff = false;
      laminationScreen();
  }
  while (sprayerOff == false and tableOff == false) {
    spray();
    driveTable();
  }
  
  if (forwardButtonStatus == LOW and reverseButtonStatus == LOW and laminateButtonstate == LOW and tableResetStatus == LOW){
    idleScreen();
    //rebootORreset();
  }
}


//advance function, table one
void table1Advance() {
  table1.setSpeed(10000);
  table1.run();
  advance = false;
} 

//reverse function, table one
void table1Reverse() {
  table1.setSpeed(-10000);
  table1.run();
  reverse = false;
}

//advance function, table two
void table2Advance() {
  table2.setSpeed(10000);
  table2.run();
}

//reverse function, table two
void table2Reverse() {
  table2.setSpeed(-10000);
  table2.run();
}

int t2RewindDistance = -7200;
int t1RewindDistance = -8200;         ////////-25900;

int sprayHomeDistance = -500;

void tableHome() {
  //unsigned long currentTableResetTime = millis();
  table1.setMaxSpeed(tableSpeed);
  table2.setMaxSpeed(tableSpeed);
  table1.setAcceleration(tableAccel);
  table2.setAcceleration(tableAccel);
  table1.moveTo(t2RewindDistance);   //driver set to 8 microsteps // previously set to -24500
  table2.moveTo(t1RewindDistance);   //driverr set to 8 microsteps
  table1.run();
  table2.run();
  if (table1.distanceToGo() == 0){
    Serial.println(F("reset complete, material is now in its starting position"));
    tableHomeOff = true;
  } while (tableHomeOff == true){
    pleaseRebootScreen();
  }
}

void sprayHome(){
  sprayer.setMaxSpeed(spraySpeed);
  sprayer.moveTo(sprayHomeDistance);
  sprayer.run();
  Serial.println(F("sprayReset is working"));
  sprayHomeOff = true;
}


unsigned long sprayTime = 43900;   // changed from 45000 to 30000 to see if table movement distance is affected, it shortened the overall movement by roughly three feet, readjusted to 43000, very close, again to 53900
unsigned long tableTime = 80000;   // change from 90000 to 80000 did not affect distance of table movement
unsigned long sprayDelay = 4000;   //delay sprayer until table has correctly positioned materials // CHANGED TO 6000 from 7000


/////////////////build out idle state ()
int idleSpeed = 0;
int idleAccel = 0;
int idleDistance = 0;


  
//function that controls sprayer in "start" state
void spray() {
  unsigned long currentSprayMillis = millis();
  if  (currentSprayMillis - previousMillis > sprayDelay) {
    sprayer.setMaxSpeed(spraySpeed);
    sprayer.setAcceleration(sprayAccel);
    sprayer.run();
    //Serial.println("sprayer is running"); //program responded here, motors slowed down immediately
    if (sprayer.distanceToGo() == 0){
      sprayer.moveTo(-sprayer.currentPosition());
      sprayer.run();
      Serial.println(F("sprayer is running")); //program responded here, did not slow motors
    }
    if (currentSprayMillis - previousMillis > sprayTime + sprayDelay) {  //deleted "+ spray delay) from end of perentheses
      sprayerOff = true;
      Serial.println(F("sprayer is off"));
      Serial.println(F("Lamination Complete"));
      previousMillis = currentSprayMillis;
    }
  }
}



//function that controls table in "start" state
void driveTable() {
  table1.setMaxSpeed(tableSpeed);
  table1.setAcceleration(tableAccel); 
  table1.moveTo(20000);   // driver set to 8 microsteps //previously set to 16500     //table1.moveTo(33000); // driver set to 4 microsteps 
  
  table2.setMaxSpeed(tableSpeed);
  table2.setAcceleration(tableAccel);
  table2.moveTo(27000);   //driverr set to 8 microsteps // previously 24700     //table2.moveTo(48000); // driver set to 4 microsteps
  
  table1.run();
  table2.run();

  if (table1.distanceToGo() == 0 and table2.distanceToGo() == 0){
    rebootORreset();
    //idleScreen();
    tableOff = true;
  }
}


void idleScreen(){
  //lcd.clear();
  lcd.print(F("Status:"));
  lcd.setCursor(0, 2);
  lcd.print(F("Ready to proceed"));
}

void rebootORreset(){
  lcd.clear();
  lcd.print(F("Reboot b4 next"));
  lcd.setCursor(0, 2);
  lcd.print(F("run, or reset"));
}

void pleaseRebootScreen(){
  lcd.print(F("Status:"));
  lcd.setCursor(0, 2);
  lcd.print(F("Press Reboot!   "));
}

void startUpScreen(){
  lcd.print(F("SPRAY TABLE V2.0"));
  lcd.setCursor(0, 2);
  lcd.print(F("INITALIZING..."));
  Serial.println(F("Startup complete"));
  delay(500);
  idleScreen();
  Serial.println(F("Idling, ready to proceed"));
}

void advanceScreen(){
    lcd.print(F("STATUS:      "));
    lcd.setCursor(0, 2);
    lcd.print(F("Advancing       "));
    advanceHasRun = true;
    reverseHasRun = false;
    Serial.println(F("advancing"));
}

void reverseScreen(){
    lcd.clear();
    lcd.print(F("STATUS:        "));
    lcd.setCursor(0, 2);
    lcd.print(F("Reversing       "));
    reverseHasRun = true;
    advanceHasRun = false;
    Serial.println(F("reversing"));
}

void laminationScreen(){
  lcd.print(F("Status:"));
  lcd.setCursor(0,2);
  lcd.print(F("Laminating       "));
  Serial.println(F("Laminating"));
}

void resetScreen(){
  lcd.clear();
  lcd.print(F("Status:"));
  lcd.setCursor(0, 2);
  lcd.print(F("Table Resetting"));
  Serial.println(F("Table resetting"));
}


Code summary :
manual advance/reverse - two momentary pushbuttons to adjust the position of the material.
laminate functions - driveTable() and spray() happen simultaneously to pull a sheet through the machine and spray the material as it passes under the spray gantry.
reset function - brings the material back to the starting position if the spray is insufficient.

If You would post a link to the datasheet for that driver it likely helps.
Lookin at the picture I can't see what logic You have connected. There are only 3 cables per driver and no motors.
If You send schematics it would help.

Do your debug prints tell you anything?

If it's wired as shown in your picture, you need Arduino ground to Gecko common.

no, sadly. I get no errors. It ran perfectly before.

i also noticed that and added common, it didn't change anything.

I didn't mention errors, I mentioned debug prints.


also, I realize my e-stop is not correctly wired up, but that's not my issue

https://www.geckodrive.com/amfile/file/download/file_id/9/product_id/9/
(datasheet for driver)

i'm getting all of the expected prints that you see in the code

I'd be inclined to grab a spare Arduino and one of the Gecko drivers and prove to yourself that you can use it to control one of your steppers.

1 Like

I see that the Gecko is looking for a minimum of 18V, but in your diagram, I only see 12V. Do you have a separate supply for the motors?

yes. the gecko drivers are getting 36-50 VDC direct from a separate power supply. The 12vdc is to power a cooling fan and two electric solenoid valves

In most examples I see with gecko drivers, the driver's enable pin is written high. My drivers only have a disable pin. Is this the same thing? The manual says that if the enable pin is connected to controller 5v, it will stop the motors. Could this be my issue?

It looks like it I think.

I'm not currently doing anything with the disable pin. I did place a hand on the motors while running the machine, and even though there is no movement, I can feel a vibration. So something is happening, I'm just not sure how or what to adjust or play with from here. I took a driver off and tried it with an identical power supply and now it won't power up. Guess I will call gecko and report my findings back here after.

Vibration might mean you're trying to step too fast. Also, at that current you're going to need heatsinking apparently. It looks like you do, but perhaps the fan should be blowing along the vanes rather than against the side.

For sure. Everything is currently shoved into a cardboard box for the time being (same orientation as in the photo), just to get it functional and validate that it will work. Eventually I will be tig welding / water jetting an aluminum enclosure and 3d printing a faceplate for the interface (with more thoughtful placement of parts).

I'll start troubleshooting by trying everything at significantly slower speeds and whispering sweet nothings into the cardboard box. Will report back with findings.

I don't see how you have wired up the:
P1-Estop header

If you are using this in a non-hobby application, the wiring should be set up as a fail-safe.
The way your wiring is set up currently, and assuming that the E-stop is a simple 1-pole 1-throw, the disable pin is either floating or connected to ground via the E-stop.
I don't see where it is being controlled by the Mega.

If the disable pin is being controlled by the Mega, then your E-stop will not work to disable the controller unless you do some re-wiring.

"also, I realize my e-stop is not correctly wired up, but that's not my issue"

Yes, I am aware. I'm planning to sand off some solder mask on my power plane and tap into that (connected to Arduino's vcc), running a jumper from the power plane to the currently open (disconnected) pin on the e-stop header. Then I'm simply not going to use the PCB header pin that is connected to the ground plane, and connect the 1p1t e-stop latching button switch to the hacked vcc pin and the pin with all three disables connected. This way, when e-stop is pressed, all disables will get connected to arduino's 5v power, disabling the geck drives.

:+1: