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 .

Attachments

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.

//edit
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

//edit

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.

//edit

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