2014/09/21

Camera Slider / Dolly - MakerSlide + Arduino + CNC Shield + A4988 Driver + 42BYGH4417 Stepper Motor

One dimension movement is the most basic practice to position. By following the design of simple camera slider by Bart Dring from Inventables, I have made my own camera dolly and changed the pulley and belt of  gt2 specification for easy steps calculation.

The use of CNC Shield is optional, it is used just for easy extension to y-axis and z-axis.

Connection

1. Stack CNC Shield on Arduino Uno or Mega2560
2. Connect CNC Shield to power supply with voltage 8-35V
3. Connect CNC X axis to 42BYGH4417 stepper motor

Photo


Connections 



Dolly In Motion
Sketch

// simple stepper motor control 
// only x axis is used for dolly
#define EN 8 / / stepper motor enable
#define X_DIR 5/ / x axis direction control
#define Y_DIR 6/ / y axis direction control
#define Z_DIR 7/ / z axis direction control
#define X_STP 2/ / x axis step control
#define Y_STP 3/ / y axis step control
#define Z_STP 4/ / z axis step control

/*
// step(): to control direction and steps of stepper motor
// parameter: dir for direction control, 
//                   dirPin maps to DIR pin of stepper motor,
//                   stepperPin maps to STEP pin of stepper motor
// return value: none
*/

void step(boolean dir, byte dirPin, byte stepperPin, int steps)
{
  digitalWrite(dirPin, dir);
  delay(50);
  for (int i = 0; i < steps; i++) {
    digitalWrite(stepperPin, HIGH);
    delayMicroseconds(800);
    digitalWrite(stepperPin, LOW);
    delayMicroseconds(800);
  }
}

void setup (){
  // setup stepper motor I/O pin to output
  pinMode(X_DIR, OUTPUT); pinMode(X_STP, OUTPUT);
  pinMode(Y_DIR, OUTPUT); pinMode(Y_STP, OUTPUT);
  pinMode(Z_DIR, OUTPUT); pinMode(Z_STP, OUTPUT);
  pinMode(EN, OUTPUT);
  digitalWrite(EN, LOW);
}

void loop (){
  // 200 steps per turn
  step(false, X_DIR, X_STP, 1800); // run 360 mm
  step(false, Y_DIR, Y_STP, 200); 
  step(false, Z_DIR, Z_STP, 200); 
  delay(1000);
  step(true, X_DIR, X_STP, 1800);  // run 360 mm in reverse direction
  step(true, Y_DIR, Y_STP, 200); 
  step(true, Z_DIR, Z_STP, 200); 
  delay(1000);
}



14 comments:

  1. Thankyou for posting this code. I was trying to work out why my CNC-Shield v3.0 wasn't passing commands from GrblController to my motors (A4988 running NEMA11's with 12V Supply. This code works fine, therefore the problem I was having was the GRBL 0.9j running on the MEGA2560 Arduino.

    Saved me many hours of hair pulling !!!

    ReplyDelete
  2. That's why posting the code.

    ReplyDelete
  3. what is code for stopping stepperM

    ReplyDelete
  4. digitalWrite(stepperPin, LOW);

    ReplyDelete
  5. the code doesnt work by me. It shows the error: expected primary-expression befor / token. The error is in line 9.

    Thx

    ReplyDelete
  6. delete space character between "/" and "/", may be caused during copy and paste

    ReplyDelete
  7. and another question: my step motor is moving 3 rounds then stops. I think its the A4988 Driver is overheated because when i wait for a few seconds and i give agaun voltage then it moves again 3 rounds. How many Volts have you putted in the CNC shield?

    ReplyDelete
  8. Hi, thank you !
    I'm Rob, unfortunately I'm good with meccanic hardware but I do not know anything about arduino. do you think it is possible to reverse the direction by using two limit switches? I would like to make a game for my son, some targets that move right and then left.
    Thx !!

    ReplyDelete
  9. Yes, it is possible. Reprap 3D printers using limit switches are built with Arduino Mega2560.

    ReplyDelete
  10. thank you! please, have you an example of code? I unfortunately do not know anything about the programming of arduino.... sorry..

    ReplyDelete
  11. You have to download Arduino IDE, compile the code above and upload to Arduino Board (eg. UNO) to run. It's simple and there are so many tutorials about Arduino all over the internet. Arduino boards and shields are cheap.

    ReplyDelete
  12. nice, thanks you for the code
    https://papanbungabandung.net

    ReplyDelete