Skip to main content

Arduino CNC shield control Stepper motor with DRV8825



CNC shield is quite useful for stepper motor driving. Here, I demonstrated how to use simple arduino code to drive stepper motor with DRV8825.



First, just simply mount CNC shield onto Arduino Uno.














Make sure the direction of the shield was right, where both the USB port and power supply wire was on your left hand site.

The blue wire is my power supply which can be connect to 12-36V of power source.

Next step you can mount the DRV8825 chip onto the CNC shield. Make sure the DRV8825 chip goes like this direction. If you put the chip in the wrong direction, you will probably damage it.



By adjusting the jumber underneath the DRV8825 chip, motors can be driven with different kind of microstepping mode.


I put three number here so it means that I set it into 1/32 step driving mode. Which is the most precise  one of DRV8825.


The motor can connect to the right site of the DRV8825.



Plug in the usb to your computer and upload these coded which will generate steps moving in both direction sequentially.
#define EN        8  

//Direction pin
#define X_DIR     5 
#define Y_DIR     6
#define Z_DIR     7

//Step pin
#define X_STP     2
#define Y_STP     3 
#define Z_STP     4 


//DRV8825
int delayTime=30; //Delay between each pause (uS)
int stps=6400;// Steps to move


void step(boolean dir, byte dirPin, byte stepperPin, int steps)

{

  digitalWrite(dirPin, dir);

  delay(100);

  for (int i = 0; i < steps; i++) {

    digitalWrite(stepperPin, HIGH);

    delayMicroseconds(delayTime); 

    digitalWrite(stepperPin, LOW);

    delayMicroseconds(delayTime); 

  }

}

void setup(){

  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(){

  step(false, X_DIR, X_STP, stps); //X, Clockwise
  step(false, Y_DIR, Y_STP, stps); //Y, Clockwise
  step(false, Z_DIR, Z_STP, stps); //Z, Clockwise

  delay(100);

  step(true, X_DIR, X_STP, stps); //X, Counterclockwise
  step(true, Y_DIR, Y_STP, stps); //Y, Counterclockwise
  step(true, Z_DIR, Z_STP, stps); //X, Counterclockwise

  delay(100);

}

And you can started to see the stepper motor moving in both directions.


Have a look of this video :-)




Comments

  1. Hi I'm new to the Arduino. I have messed around with a little bit of the basic code. However; I have yet to try this type of motor in the since that I would need a separate power source. If you could would you please send me a picture of what you use to connect to the CNC shield. Or possibly a amazon link? My e-mail is danielmilam2000@yahoo.com thanks for any help.

    ReplyDelete
    Replies
    1. Hello Daniel
      I think this picture will do the job!
      It's a separate power source(the black and red wire)
      https://courses.ideate.cmu.edu/60-428/s2017/ref/text/resrc/cnc-shield.html
      Sorry for the late response

      Delete
  2. Hi, could you tell what the blue wire connects to on the CNC shield board? I can see the connection on the top of the board but not the one underneath.
    Really good demonstration.
    Many thanks,
    Colin

    ReplyDelete
    Replies
    1. The CNC shield has some open circuit when I got is(probably because of the quality of manufacture). That's why I use the blue wire to connect the open circuit. You don't have to do that actually :-)

      Delete
  3. can someone please give me the code to program this in a counterclockwise direction only?

    ReplyDelete
    Replies
    1. Just remove one part of code and it will only go one direction
      You can try to do that and find which part of code is directing the motor to move clockwise!


      /*
      clockwise
      This part of code will not run
      step(false, X_DIR, X_STP, stps); //X, Clockwise
      step(false, Y_DIR, Y_STP, stps); //Y, Clockwise
      step(false, Z_DIR, Z_STP, stps); //Z, Clockwise
      */
      delay(100);


      //counterclockwise
      step(true, X_DIR, X_STP, stps); //X, Counterclockwise
      step(true, Y_DIR, Y_STP, stps); //Y, Counterclockwise
      step(true, Z_DIR, Z_STP, stps); //X, Counterclockwise

      Delete
    2. I tried you solution, but I'm still getting the same problem. I'm wanting it to go counterclockwise. I'll post below the code and see if you see anything that I'm missing to remove. I'm still learning code as much as I can from online. Thank you for your help and the design of the project. Once I get this fixed I'll be able to use it to transfer super 8 film to digital. That's the idea anyway.

      Here's the code:

      #define EN 8

      //Direction pin
      #define X_DIR 5
      #define Y_DIR 6
      #define Z_DIR 7

      //Step pin
      #define X_STP 2
      #define Y_STP 3
      #define Z_STP 4


      //DRV8825
      int delayTime=30; //Delay between each pause (uS)
      int stps=6400;// Steps to move


      void step(boolean dir, byte dirPin, byte stepperPin, int steps)

      {

      digitalWrite(dirPin, dir);

      delay(100);

      for (int i = 0; i < steps; i++) {

      digitalWrite(stepperPin, HIGH);

      delayMicroseconds(delayTime);

      digitalWrite(stepperPin, LOW);

      delayMicroseconds(delayTime);

      }

      }

      void setup(){

      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(){


      step(true, X_DIR, X_STP, stps); //X, Counterclockwise
      step(true, Y_DIR, Y_STP, stps); //Y, Counterclockwise
      step(true, Z_DIR, Z_STP, stps); //X, Counterclockwise

      delay(100);

      }

      Delete
    3. I think the code you are using is right. Did you upload it successfully? Hope you solve it soon!

      Delete
    4. Unfortunantly the code doesn't seem to want to work. It still goes both ways. If you find a code that work let me know. Or at least were I could find one that would be helpful.

      Delete
  4. how would it look without microstepping?

    ReplyDelete
  5. salve come posso fare se uso ARDUINO MEGA E RAMPS 1.4?

    ReplyDelete
  6. Thank you very much for this. I have been looking for a solution like this for a long time since I'm not a programmer, I struggle to understand what I need and what not. Is it possible to show me how to control the speed of the stepper in a chosen direction using a Rotary Encoder like this one: https://www.robotics.org.za/ROT-MOD and or controlling two extra steppers using this: Analog Joystick https://www.robotics.org.za/KY-023

    I'm trying to build my own camera slider as a learning project, but I just don't seem to get started properly.

    ReplyDelete
  7. Hello,
    Just curious, how would I get two motors running in the same direction at the same time for the same distance? Also, how in the code would I add end stop limit switches to "home" the rack and pinion setup I am using?
    I have coded some vex robots with c+ around 3 years ago. So I am pretty rusty at coding but I have a pretty decent understanding of what is happening.
    Any little bit will help. Thanks.

    ReplyDelete
  8. Your code works and is great for further learning. There is only one small problem ... The DRV8825 heatsink is hot after 2 minutes of operation. This is normal?

    ReplyDelete
  9. I have the same problem with you"how would it look without microstepping?"
    i just buy a stepper motor from https://www.oyodental.com.

    ReplyDelete
  10. I have the same problem with you"how would it look without microstepping?"
    i just buy a stepper motor from https://www.oyostepper.com.

    ReplyDelete
  11. Could someone please help me add a simple click button to this code and help me with what pins to use on the CNC Shield ? Thank you

    ReplyDelete
  12. excuse me, someone tell me if this code also works with the drivers a4988 please, or what should i do?... thanks

    ReplyDelete
  13. How can I use more than one stepper motor ??

    ReplyDelete
  14. Uploaded codes no response from stepper motor

    ReplyDelete
  15. This comment has been removed by the author.

    ReplyDelete
  16. What would the code look like if i had three stepper motors?

    ReplyDelete
  17. Hi
    I did all what in this tutorial but got no stepper movement only pulses and hammer voice.
    how can i solve this problem

    ReplyDelete
  18. Thank you for sharing such great information very useful to us.
    CNC Training in Gurgaon

    ReplyDelete
  19. AppTechno Services best training center in delhi provides placement solution to the participants. Training courses in Delhi with placement assistance. Computer Software Training Institutes For Java, Software Testing Institutes. Training and skills development have become essential ingredients in ensuring the efficiency of service staff.

    r language course in Delhi, Dwarka
    best machine learning course
    python course in Delhi, Dwarka
    Ruby on Rails Training in Delhi

    ReplyDelete
  20. I did the same but my stepper motor only produce noise it won't turn what is the reason .Please reply faster

    ReplyDelete
  21. Kamubet adalah Bandar judi online terpercaya yang menyediakan permainan sportbook, casino, slots, togel, sabung ayam, dan poker juga banyak bonus-bonus menariknya..

    mau tau bonus apa saja yang kita sediakan?

    berikut promo kamubet :
    - BONUS DEPOSIT NEW MEMBER SLOT GAMES 50%
    - BONUS NEXT DEPOSIT 20% SLOT GAMES
    - WELCOME BONUS DEPOSIT SPORTBOOK 100%
    - WELCOME BONUS DEPOSIT SABUNG AYAM 100%
    - BONUS CASHBACK MIXPARLAY 100%
    - BONUS ROLLINGAN LIVE CASINO 1%
    - BONUS CASHBACK SPORTBOOK 10%
    - BONUS DISKON TOGEL UP TO 66%
    - BONUS CASHBACK SLOT GAMES 5%
    - BONUS DEPOSIT SETIAP HARI UP TO 20.000
    - BONUS REFERRAL SEUMUR HIDUP

    Jangan lupa daftar sekarang juga di kamubet.info

    ReplyDelete
  22. Thanks a lot for sharing this amazing knowledge with us. This site is fantastic. I always find great knowledge from it.
    Cnc controller

    ReplyDelete
  23. Thank you for a very interesting article. I greatly appreciate the time you take to do all the research to put together your posts. I especially enjoyed this one!!
    Cnc retrofit

    ReplyDelete
  24. Ok..im from indinesia (im sorry for my english language bad)

    Thanks ...this trick 100% working....
    God bless u

    ReplyDelete
  25. Ok I come to play, but if I become addicted to this game I will report you to the competent authorities. If you have no problems and you are sure that this addiction will not happen to me, I will send you an email that you will have to sign me taking this risk. Let me know if you agree....

    ReplyDelete
  26. Hi, this tutorial sure helped me alot!
    Do you know where I could find a code with just a constant speed setting?

    ReplyDelete
  27. hello Im trying to run this code using web ide but its not working.
    its giving the following message
    avrdude: 4540 bytes of flash verified

    avrdude: safemode: lfuse reads as 0

    avrdude: safemode: hfuse reads as 0

    avrdude: safemode: efuse reads as 0

    avrdude: safemode: Fuses OK (E:00, H:00, L:00)

    avrdude done. Thank you.

    ReplyDelete
  28. Nice articles and your informatin valuable and good artices thank for the sharing information Brake Oil Plant

    ReplyDelete
  29. Very interesting details you have mentioned , thanks for posting . cnc machining parts

    ReplyDelete
  30. Very interesting details you have mentioned , thanks for posting . ivetsupply

    ReplyDelete
  31. Thanks for sharing an informative blog on Arduino CNC shield control Stepper motor with DRV8825.


    Automatic Batch Blending (ABB)

    ReplyDelete

Post a Comment

Popular posts from this blog

Connect Arduino Wemos D1 ESP8266 to Internet/Wi-Fi Router

Connect ESP8266 to Wi-Fi Router Upload these code to your Arduino WeMos D1 ESP8266 W-Fi board. #include <ESP8266WiFi.h> //SSID of your network char ssid[] = " myRouter"; //SSID of your Wi-Fi router char pass[] = " myPassWord"; //Password of your Wi-Fi router void setup() {   Serial.begin(115200);   delay(10);   // Connect to Wi-Fi network   Serial.println();   Serial.println();   Serial.print("Connecting to...");   Serial.println(ssid);   WiFi.begin(ssid, pass);   while ( WiFi.status() != WL_CONNECTED) {     delay(500);     Serial.print(".");   }   Serial.println("");   Serial.println("Wi-Fi connected successfully"); } void loop ( ) {} Using ESP8266 to connect to Wi-Fi need to use the function of: WiFi.begin(ssid, pass); // connect to target Wi-Fi SSID is the name of the Wi-Fi you want to connect to.  while ( ...

Setting up CUDA 10.0 for mxnet on Google Colaboratory

Preface Recently, I was trying to train model on Google Colaboratory with mxnet. However, I found the CUDA version pre-installed on the Colab. is 10.2. Till now, mxnet only support to CUDA 10.1 Therefore, I started to think about if it is possible to setup the environment that mxnet has support. Till now CUDA 10.1 doesn’t work for me. But I do successfully installed CUDA 10.0. Also tried to trained a LeNet on Colaboratory. Since I am a mac user, NVIDIA GPU is always what we are jealous and envy. Until I found Google Colaboratory…. I’d like to share my journey with you, if you also encounter some problem on setting up environment. Google Colaboratory provide free access to the NVIDIA Tesla K80 GPU (24GB RAM, 4992 CUDA core) . It is a great gift for most of people who is eager to learn deep learning but doesn’t have good hardware systems to train deeper models. NVIDIA Tesla K80 GPU I assume that you already have background knowledge of Python and familiar with tools like jup...