Arduino Projects

Arduino CNC Shield V3.0 and A4988 Hybrid Stepper Motor Driver + Joystick

Description:

 

Arduino CNC Shield V3.0 and A4988 Hybrid Stepper Motor Driver– This is a basic getting started tutorial in which you will learn how to use the Arduino CNC Shield V3.0 and A4988 Stepper Motor Driver to control a Hybrid Stepper Motor. I will start with the very basics explaining how to control the direction of the Stepper Motor using a very simple Arduino program, and then I will make it a little bit complex by adding a Joystick which can be used to control the stepper Motor. I will also explain how to use the CNC Shield male headers in custom made projects.

In this tutorial, we will cover,

allpcb circuit
  1. A4988 Stepper Motor Driver Pinout and technical specifications
  2. Arduino CNC Shield V3.0 Pinout and technical specifications
  3. Hybrid Stepper Motor wires and technical specifications
  4. Interfacing and finally
  5. Arduino programming

Without any further delay, let’s get started!!!


Amazon Links:

Arduino Uno

12v Adaptor:

2-Axis Analog Joystick

Arduino CNC Shield V3.0

A4988 Stepper Motor Driver

Hybrid Stepper Motor Nema17:

12v UniPolar stepper motor:

CD ROM bipolar stepper motor:

24BYJ48 5V DC unipolar stepper motor:

*Disclosure: These are affiliate links. As an Amazon Associate I earn from qualifying purchases.



A4988 Stepper Motor Driver Pinout and technical specifications

Arduino CNC Shield

The A4988 is a complete microstepping motor driver with built-in translator for easy operation. It is designed to operate bipolar stepper motors in full-, half-, quarter-, eighth-, and sixteenth-step modes, with an output drive capacity of up to 35V and ±2A as per the datasheet. The A4988 includes a fixed off-time current regulator which has the ability to operate in Slow or Mixed decay modes.

The translator is the key to the easy implementation of the A4988. Simply inputting one pulse on the STEP input drives the motor one microstep. There are no phase sequence tables, high-frequency control lines, or complex interfaces to program. The A4988 interface is an ideal fit for applications where a complex microprocessor is unavailable or is overburdened.

Arduino CNC Shield

As you can the A4988 stepper motor driver has a total of 16 male headers which are clearly labeled as GND, VDD, 1B, 1A, 2B, 2A, GND, VMOT, DIR, STEP, SLP, RST, MS3, MS2, MS1, and EN.

Let’s start with the GND and VDD pins, these two pins are connected with a power supply of 3 to 5.5V to power up the driver. You can connect these two pins with the Arduino’s GND and 5V pins.

The next 4 pins 1A, 1B, 2A, and 2B are connected with the Bipolar stepper motor. As you know a Bipolar stepper motor has 4 wires which are internally connected with the two coils. So the pins 1A and 1B will be connected to one coil of the stepper motor and the pins 2A and 2B will be connected to the other coil of the Bipolar Stepper Motor.

The next two pins GND and VMOT are used to power the Bipolar Stepper Motor, the GND and VMOT pins are connected to a power supply from 8 to 35 Volts. If you are not using the CNC shield then I highly recommend to use a decoupling capacitor across these two pins, the capacitor value should be at least 47uF. This capacitor is used for protecting the A4988 driver from voltage spikes.


The next two 2 pins, Step and Direction are the pins that we actually use for controlling the motor movements. The Direction pin controls the rotation direction of the motor and we need to connect it to one of the digital pins on our microcontroller.

With the Step pin, we control the mirosteps of the motor and with each pulse sent to this pin the motor moves one step. So that means that we don’t need any complex programming, phase sequence tables, frequency control lines and so on because the built-in translator of the A4988 Driver takes care of everything. Here we also need to mention that these 2 pins are not pulled to any voltage internally, so we should not leave them floating in our program.

The sleep pin can be used to minimize power consumption when the motor is not in use. A logic low input on this pin puts the A4988 Stepper Motor driver in sleep mode.

The next pin is the RESET pin that sets the translator to a predefined Home state. If you want to study more about this you can download the A4988 driver datasheet by clicking on the download button given below.

Download A4988 Datasheet: A4988 DATASHEET

The next 3 pins (MS1, MS2, and MS3) are used for selecting one of the five step resolutions as per the truth table available in the datasheet.

Arduino CNC Shield

These pins have internal pull-down resistors so if we leave them disconnected, the board will operate in full step mode.

The last pin is the ENABLE pin which is used for turning on or turning off the FET outputs. So logic high will keep the outputs disabled.


CNC Shield V3.0 Pinout and Technical Specifications:

Arduino CNC Shield

This is the Arduino CNC Shield V3.0 which I got from Digitspace.

If you have this CNC shield then using the A4988 Stepper Motor driver is very simple. You don’t need a breadboard for the connections. You can easily plug-in the A4988 drivers. You can plug-in 4 drivers. But in this tutorial, I will use only two drivers. First I will explain everything for only one driver and then later, in the end, I will use two drivers to control two stepper motors.  This CNC Shield sits nicely on top of the Arduino Uno board, without any external jumper wires.

Arduino CNC Shield

The  Arduino  CNC  Shield makes it easy to get your  CNC  projects up and running in a  few hours.  It uses open-source firmware on Arduino to control 4 stepper motors using 4 pieces of A4988 Stepper Motor driver breakout board,  with this shield and  Arduino Uno/Mega, you can build all kinds of robotics,  linear motion projects or projects including CNC routers, laser cutters and even pick & place machines.

You can use the open-source firmware like the GRBL that turns G-code commands into stepper signals. Which I will explain in one of my upcoming videos while making a CNC machine. But for now, in this tutorial my only goal is to help you understand how you can write your own code and how to use these male headers in custom made projects.


Arduino CNC Shield

As you can see this CNC shield is provided with too many male headers. In order to use this CNC shield is custom made projects you should know about these male headers.

Arduino CNC Shield

Let’s start with the male headers labeled with M0, M1, and M2. As you can see each driver is provided with jumpers that can be set to configure the microstepping for the A4988. These are connected with the driver MS1, MS2, and MS3 pins. As per the truth table, I already explained “High” indicates that a jumper is inserted and “Low” indicates that no jumper is inserted. As currently, no jumpers are inserted, so all the drivers are configured in the Full Step.

The letters X, Y, Z, and A represents the 4 stepper motors.

Arduino CNC Shield

On the right side of each driver, you can see 4 male headers which are connected with the A4988 driver pins 1B, 1A, 2B, and 2A. This is where we connect the 4 wires of the Bipolar Stepper Motor.

A Blue color terminal block is labeled with the + and – signs and this is where we connect our external power supply. Make sure you connect the wires in the correct way otherwise you will damage the drivers.

On the left side, you can see these Blue and Yellow color male headers. You will need to short the two pins labeled as EN/GND to enable the board. You can use a jumper cap or you can use female to female type jumper wire.

The X.STEP, Y.STEP, Z.STEP, and A.STEP male headers are connected with the step pins of the A4988 drivers and are also connected with the Arduino Pins which you can find by using the digital Multiplemeter. Set the multimeter on continuity or beep, when you hear the beep sound it means the two points are connected.



Arduino CNC Shield

I checked all these pins and I found out that the

X.STEP is connected with the Arduino’s pin number 2.

Y.STEP is connected with the Arduino’s pin number 3.

Z.STEP is connected with the Arduino’s pin number 4.

X.DIR is connected with the Arduino’s pin number 5

Y.DIR is connected with the Arduino’s pin number 6

Z.DIR is connected with the Arduino’s pin number 7

Pin number 8 is not connected.

Pin number 9 of the Arduino is connected with the X- and X+ pins of the CNC Shield.

Pin number 10 of the Arduino is connected with the Y- and Y+ pins of the CNC Shield.

Pin number 11 of the Arduino is connected with the Z- and Z+ pins of the CNC Shield.

Pin number 12 of the Arduino is connected with the SpnEn pin of the CNC Shield.

Pin number 13 of the Arduino is connected with the SpnDir pin of the CNC Shield.

A0 analog pin of the Arduino is connected with the Abort pin of the CNC shield.

A1 analog pin of the Arduino is connected with the Hold pin of the CNC shield.

A2 analog pin of the Arduino is connected with the Resume pin of the CNC shield.

A3 analog pin of the Arduino is connected with the CoolEn pin of the CNC shield.

A4 analog pin of the Arduino is connected with the SDA pin of the CNC shield.

A5 analog pin of the Arduino is connected with the SCL pin of the CNC shield.

Bipolar Stepper Motors from DFrobot:

Arduino CNC Shield

These are the two Bipolar Stepper Motors from the DFrobot. Each stepper motor has 4 wires, Black, Red, Green, and Blue. The Black and Green wires are connected with one coil, while the Red and Blue wires are connected with the other coil.

It is a simple 2 phases hybrid stepper motor. It features 3.5kg high torque output. It is applied in most CNC machines or 3D printers such as makerbot and ultimaker. If you want to make your own CNC or 3D printer, this motor is the most suitable one.

The Model number of this Bipolar stepper motor is 42BYGH40-1.8-22A. 1.8 is the Step Angle in degrees. The rated voltage is 3.4V and the current per phase is 1.7 Amps.

Arduino CNC Shield


The four wires of the stepper motor are provided with pins which I am going to cut and I will solder female headers so that I can easily interface the stepper motors with the CNC Shield.

Arduino CNC Shield

So now as you can see I am done with the soldering, female headers are connected. Now we will start the interfacing.

I started off by connecting the DC female power jack for connecting the external 12 volts power supply. Be very careful while connecting the wires, wrong connections may lead to the permanent damage of the A4988 Stepper motor drivers.

Arduino CNC Shield

Next, plug-in the A4988 Stepper motor driver. To enable the CNC Shield short the EN and GND pins, you can use a jumper cap or you can use a female to female type jumper wire. If you find it difficult to follow, watch the video tutorial given at the end of this article.

Now before you connect the stepper motor you need to adjust the current limiting of the driver, so that we are sure that the current is within the current limits of the motor. This is done by adjusting the reference voltage using the variable resistor or potentiometer.

We have a formula for this

Current Limit = VRef x 2

As we know the Stepper motor per phase current is 1.7 Amps. So

1.7 = VRef X 2

VRef = 1.7 / 2

So

VRef = .85 Volts

After adjusting the current limit, now we can connect the stepper motor. Now the final step is to start the programming.


Arduino CNC Shield Stepper Motor Programming:

This is a very basic program that controls the steps and direction of the stepper motor. As the stepper motor, I am using has a step angle of 1.8 degrees and as I am using the A4988 stepper motor driver in the full step configuration so, for 1 complete revolution I will need 200 steps as 1.8 x 200 = 360.

For the practical demonstration watch video given at the end of this article.

Now, let’s control the same stepper motor using a Joystick.

Arduino CNC Shield


I have a very detailed tutorial on how to use this joystick.

Arduino CNC Shield

This time I added the +5v and GND pins of the Joystick with the CNC Shield 5v and ground pin and connected the VRx and VRy pins with the CNC Shield Abort and Hold pins which are connected with the Arduino’s Analog pins A0 and A1.

Arduino CNC Shield and Joystick programming:



I modified the code and defined pins for the VRx and VRy pins of the Joystick and defined two variables vrx_data and vry_data of the type integer for storing the values.

This time I defined a variable to control the stepper motor speed. I set the two pins of the joystick as the input.

Joystick() is a user-defined function. the purpose of this function is to check if the joystick is moved in the forward direction or in the reverse direction. So that’s all about the programming.

In the end, I successfully controlled the stepper motor using the Arduino CNC Shield V3.0. For the step by step explanation and demonstration, watch the video tutorial given below.

Watch Video Tutorial:

 

Related Projects:

CD ROM Stepper motor Arduino L298n + Joystick controlled speed and Direction Control

UniPolar and Bipolar Stepper Motors Speed and Position Control

2-Axis Joystick Arduino Project, Joystick Button & Joystick Library Arduino

Salvage Stepper Motors and other useful parts from LaserJet Printer

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Related Articles

6 Comments

  1. I am getting problem in making a cnc 2D plotter my steppers are not moving even I have followed all the instructions.
    How can I fix this??

  2. Hello, could you explain me how i can adjust voltage of vref? in the article you said what we have to do but I dont’t know how can i do it. thaks for your time!

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button