Cnc Grbl With Adafruit Motot Shield V2




Introduction: Cnc Grbl With Adafruit Motot Shield V2

This is not an instructables is most for sharing the grbl software that I modified to work with Adafruit Motor Shied V2.

I had some Adafruit motor shield v2 and some stepper motors saved from some old printers and i sad i can make cnc or 3d printer. For the mechanical part it was quite easy , is a simple design and i think is one of the most reliable design, is the one where you don't move the spindle on x axis, you just move the hole board, it has minuses at the space you need when you use it. The hard part was the part when i cut the aluminium bars and other stuff because i had to cut them manual.

When all was finish I start searching for software to interpret the gcode on arduino but everything i found was not for my stepper drivers or a bit dumb. So i took an old version of grbl (v7d) and i start modifying and it was not as simple as I thought :))

Step 1: Building the Machine

At this part is not to much to say, there are a lot of good instructables about cnc's and i have nothing new :p

I decided to make the Z axis a bit higher so I can attach a extruder and transform the cnc to 3dPrinter, so the working area is 500 mm on X, 400 mm on Y and 300 mm on Z.

The motors are not the best for this but they do the job. Two of them are PM55-L and one is PM35-L all having 48 steps/rotation I power them with 12 v from a atx power supply, the small one is connected to Y axis because it doesn't need so much torque.

The frame for Z and Y axis is made from 20/20 mm aluminium square bars, the X axis frame is made from pal and some aluminium.

Instead of linear bearings I used ball drawer sliders, you can find them at furniture stores, also not the best choice but cheap and stable enough.

I used standard M8 threaded rod with 1.25 mm/step.

To couple the motor shaft with the threaded rod i used cable glands , I put some picture of it, you can find it on electrical store, there are used to tightening cables that are going in or out from a panel or some other boxes. I saw a lot of diy cnc couplers but this is very efficient. For the M8 rod you can use M12 x 1.5 cable glands, the rod is fixing good enough inside of it but you can still use some glue.

For the "control unit" I used a big junction box made by Gewise and the cables for motors and limit switches are going trough aluminium pipes

I will attach a SketchUp file so you can take a better look at the cnc and make some measurement .

Step 2: Electrical Connection

The power supply is a atx pc power supply, to use it you need to put a switch on ground(black wire) and PS_ON(green wire) and also a dummy resistor (10k) between +5v(red wire) and ground, you also can look for a instructables on how to convert a atx to a regular power supply. I used 12 v to power the motor drivers and 5 v for arduino and also for a big fan used to cool down the drivers.

Motor drivers are Adafruit motor shield v2, you need 2 pcs . The shields can be stacked so you can easily use them. The driver support up to 12v. The shields connects to arduino through I2C so it came with a default address (0x60) and it have some pads to change the address from 0x60 to 0x61 ... up to 0x65 depending on what pads you solder, you can find more about this here on Adafruit page.

The limit switches are normal microswitch connected to arduino with a 10k resistor to ground, and connected to a digital pin. Each switch are defined in config.h, I used 2,3,4,5,6,7 digital pin from arduino. Keep in mind that you need serial connection with the pc so do not use pins 0 and 1.

//limit swtch pins    <br><br>    #define X_LIMIT_START_PIN 2<br>    #define X_LIMIT_END_PIN 3<br>    #define Y_LIMIT_START_PIN 4<br>    #define Y_LIMIT_END_PIN 5<br>    #define Z_LIMIT_START_PIN 6<br>    #define Z_LIMIT_END_PIN 7


I've made a usb extension cable and glued on the control unit so i can easily connect the cnc to pc.
I think this is all here :P

Step 3: Grbl Firmware

The initial grbl is using Easy driver to control stepper motors. The Easy driver use 2 pins to control the motor, one pin control the direction and the other one for step.

To implement the Adafruit driver i had to rewrite the motor control and the motion control files, to remake the line and arc algorithms. Also I remade the limit switch functions so now the software knows which limit switch is pressed and throw the exact error. The firmware can be configured to work with limit switch or without them.

At the Gcode level I added some other M functions:

M100 - go to mechanical zero - the machine moves every axis until it hit the mechanical zero position (min limit switch)

M101 - go to mechanical zero without Z axis - the same with M100 but does not move the z axis, because sometimes the tool on z axis is not mounted exact on the min limit switch so you don't wanna hit the working plate with your tool.

M102 -go to park position :P - this move your axis to one end so the machine can be easily stored, this function needs to be modified according to your design, you can find it on stepper_control.cpp file.

Also the settings are remade so you can set on every motor the number of steps/rev, the threaded rod steps, the default feed rate, the length of arc segments, and a lot of stuffs and also a calibrate function that goes from one limit switch to the other, on each axis, count the steps and calculate the exact working area then store it in eeprom.

As a g code sender you can use about any sender, I use the Grbl Controller, you can find it on GitHub here, but is a bit slow so i use it for the settings window, and manual control and for sending bigger gcodes I use JCNC, you can find it here, it is a cool tool, you can edit the g code, you can preview the image and also play a animation, it has manual control but it does not have a command line.

For Gcode generator, or cam software:

2.5D I use Easel by Inventables, is a free browser tool that let you upload a vector file(svg or whatever) or create a design and normaly it should connect to a Carver (a cnc produced by Inventables) but you also can export the g code by going to Machine tab / Advanced.

For 3D milling Vectric Cut 3D, is not free, i think is about 300$, but is super cool.

I will implement a option in settings to configure if you use limit switch or not because now is just defined in config.h

I attached two 7zip files, one of them have inside a .ino file so you can just open it with arduino and the other one contain a NetBeans project and you just need to rename the file grbl_"Adafruit_motor_driverV2.ino.cpp" too "grbl_Adafruit_motor_driverV2.ino"

If you have any suggestion on how to improve or if you wanna improve it by your self please share.


Update: Added Limit switch enable and Release after move to setttings so you do not need to modify the config file, but the pin number definition is still in config.

//edit//edit :)

Sorry that the code is not working, i didn't used since I made the instructable and i used it with GRBL v 0.9 also I don,t have an arduino to test it but I guess i found the bug :)

Soo... if you go on the serial with '$' or '$$' and you are using GRBL_VERSION == "0.7" then it will give you Bad format number, if your serial command start with '$' the serial data will go to settings.cpp - settings_execute_line(char *line) and how the GRBL_VERSION (defined in settings.h) is 0.7, you have that if:

if(GRBL_VERSION == "0.7") {
  if(line[char_counter] == 0) {
     settings_dump(); return(STATUS_OK);  

as your line was '$' or '$$' and char_counter = 1 then line[char_counter] is never 0, it won't dump_settings and will go and try to build the params and values to store in settings and that is not possible because you just entered only '$'

so that if should be :

if (GRBL_VERSION == "0.7") {
    if(line[char_counter] == NULL) {
        settings_dump(); return(STATUS_OK);

The change is in settings.cpp at line 188 ( if(line[char_counter] == NULL) {)

I would suggest to go with GRBL_VERSION 0.9, change it in settings.h

Step 4: Cnc Working



  • Tiny Home Contest

    Tiny Home Contest
  • Water Contest

    Water Contest
  • Creative Misuse Contest

    Creative Misuse Contest

48 Discussions


2 years ago

Version 0.9j

Thanks a lot for the work. I used it for my XY-Plotter. But i need to say: The documentation is a little bit poor. One only need the umpackend files to be copied into the Library-folder. Do not rename it because of the *.ino file.

After uploading a wrong message shows up: Type '$' for settings. The present Grpl syntax is '$$'. A '$' means I am asking for help. You implementier already '$$'.???

I am confused about the GRBL controller. I get no values for the axis.


2 years ago

Hi ppl, i just build my own xy plotter with arduino grbl, adafruit motorshield v1 as driver stepper, now, i need to lift the cutter with a servo/solenoid when the cutter is travelling, what can i use in the grbl firmware? couldn't find anything where i can wire a servo or realy for a solenoid.. thanks ppl! maybe the servo output on adafruit as Z axis?

1 reply

I guess you could do a class where you implement the shield functionality for the servo motor, methods like one-step() and other methods that are used from the adafruit library and make all your calculation for your z axis so it match the original implementation .In the end you should be able to define the motor[Z_axis] as your custom class and use my software as it is...this wold be nice.

ok we have GRBL! I'm not sure if you updated the files or not, but rather than the standard zip, I tried the Net Beans project zip and It is working!

Alrighty! Motors etc. are up and steppin'! Most standard g codes are operating perfectly, but the grbl system commands aren't working( like "Home" and "Zero")

These are the commands that in grbl usually start with a "$" that normal? (e.g. they were not programmed due to available space) or am I still missing something?

Id also like to add an extruder capability which will require an additional stepper, and in the future I might like to add additional axises...

5 replies

i don't know about grbl system commands but you have g 28 and g 30 for home and also I implemented 3 M codes, M 100 (machine zero), M 101 (machine zero except z axis), M 102 (machine park-puts the machine in a position for storage). The commands with "$" are for settings - in grbl controller you go to advance/grbl settings . there are also some custom stuff like motor step configuration for each motor, rod step in mm, limit switch enable/disable, working area for each axes, recalibrate working area ( this will move all axis from start to end and count the steps between limit switches). I hope this helps you.

Thanks! I haven't installed limit switches yet. Those commands will definitely help.Thus far I've simply moved the x and y axis from one end to the other. So far I have about x12000 and y4500 work area( still not sure if grbl is seeing these requests as mm or step)I did set the mm per step, and steps per revolution.(200 steps per rev, using 18 threads per 254mm or 1inch) I need to check out grbl controller currently I'm working with gcode teleporter.

I may also need to simply use a plain serial connection to see if the $ commands issue isnt in the interface software im using

18 threads per 254mm means 1.41 threads pem mm, that is the value to put in settings. I don't understand what is not working for you you said that you set the motor step per rev and some other setting so I understand that the settings command is working and all the commantd that starts with $ are for settings only. I use grbl controller only for settings window for sending g codes i use jcnc.

Those settings I manually configured in the Arduino IDE under the "config.h"

Still haven't got the grbl settings to show by simply typing$$. The settings tab in grbl controller may be just the ticket.Ill try a few things when back home tonight and let ya know.

Vasiliuc, Excellent work on interfacing this shield to GRBL.

Could the eeprom errors below mentioned by Gurpreet may be that the Arduino wasn't flashed with the GRBL hex file.

Could you go through a bit on exactly the process you used to get your hex file, libraries and sketch all loaded correctly and communicating, or did you even have to load the GRBL hex?

Again thanks for your work on this, the stackable configuation of the adafruit would allow a person to do tons of stuff just using simple gcode.

3 replies

Also, what versions of the Arduino are you using and which IDE revision?

I tested on arduino uno and arduino nano, and about ide version I will come back later... That error that Gurpreet had it is not about eeprom, is on every file from the software, compiler find duplicates files in a temp folder from one older build, I have no ideea why.
To use my custom grbl you need a arduino board with atmega 328 processor, a arduino Ide with the adafruit motor shield v2 library instaled. Open the .ino file from my software with arduino ide and upload it to the board, and start use it. To connect the gcode sender(jcnc or grbl sender or whatever you like) you have to set the port where the board is connected to pc and set the bound rate at 115200 and you're good to go.

Thanks Vasiliuc! Just wanted to clarify those few points. Im still getting those duplicates and will continue working on clearing those. I may need to do a complete reinstall on my CnC computer with upgraded IDE( currently running 1.06 and have had other issues with the serial coms with ot)her sketches). Still building on the Hardware portions and will be back to testing motors etc. as soon as I get my Power supply.I'll keep you posted.

Has anyone figured out the problem that was posted by Gurpreets21 down below. I am also having the same problem every time i try to compile it throws that error.

I know that i have the ada fruit motor sheild drivers installed.

I had i working before and loaded it into my uno and now need to make some adjustments but i cannot get the program to compile now. I need some help Thank you form your time

1 reply

Hy, you can try to put the adafruit lib files in the project root, also try to run an example from adafruit and see if is running.

Vasiliuc you made a great project, just please tell me is that project runs on motor shield v1 or it can work with only v2?

2 replies

Have you made work GRBL, with motor shield v1 and two stepper?

Hy, I don't think it is working with v1(I don't know how it's v1working) but I think it shouldn't be to hard to make it. You will need to modify the shield_begin() function and to make sure that you have a onestep() method in your library

it says grbl_Adafruit_motor_driverV2.ino:25:34: fatal error: Adafruit_MotorShield.h: No such file or directory

compilation terminated.

Error compiling.