CNC
Working with GRBL (Custom CNC Part 4)

Working with GRBL (Custom CNC Part 4)

If you are just joining us,

Introduction

Grbl is a no-compromise, high performance, low cost alternative to parallel-port-based motion control for CNC milling. This version of Grbl runs on an Arduino Mega2560 only.
The controller is written in highly optimized C utilizing every clever feature of the AVR-chips to achieve precise timing and asynchronous operation. It is able to maintain up to 30kHz of stable, jitter free control pulses.
It accepts standards-compliant g-code and has been tested with the output of several CAM tools with no problems. Arcs, circles and helical motion are fully supported, as well as, all other primary g-code commands. Macro functions, variables, and most canned cycles are not supported, but we think GUIs can do a much better job at translating them into straight g-code anyhow.
Grbl includes full acceleration management with look ahead. That means the controller will look up to 24 motions into the future and plan its velocities ahead to deliver smooth acceleration and jerk-free cornering.

https://github.com/fra589/grbl-Mega-5X

I really couldn’t say it better. GRBL is to CNCs as Marlin is to 3D printers. Its the brains of the whole thing. GRBL interprets GCODE and controls all of the logic, pulses and timing needed to drive the stepper motors as the code commands.

For my purposes I decided to use FRA5589’s GRBL-MEGA-5X which can control up to 6 axis simultaneously. It is an offshoot of the GRBL MEGA branch which is still limited to 3 axis, with a 4th clone. I also found that the 5X version had been updated more recently.

Installation

You will need to head over to https://github.com/fra589/grbl-Mega-5X to download the most recent version. Then, you will need to go back to the original GRBL site and follow the directions for compiling and burning the image onto the Mega. These instructions are found here: https://github.com/gnea/grbl/wiki/Compiling-Grbl

NOTE: When you install a Library in Arduino, it will copy it to your Arduino directory. Mine was in the my documents folder. You have to go to that directory and edit that version of the code for your changes to take effect. It took me a few hours before I realized the code had been copied to a different directory and that I had been editing a different file than I thought.

Configuring

If you didn’t see it, I talk about setting up my homing cycle and axis back https://replicantfx.com/cncpart3. The big take away from it was that to clone an axis, you simply rename the axis you wish to become the clone to the same name as the axis it is cloning, like below.

  #define AXIS_4_NAME 'A' // Letter of axis number 4

To:

  #define AXIS_4_NAME 'Y' // Letter of axis number 4

The rest of the configuration was pretty straight forward and if you are coming from Marlin it will be reminiscent.

GRBL takes care of most of its user setting via EEPROM. The settings are as follows:

Settings and sample values Description
$0=10 Step pulse, microseconds
$1=25 Step idle delay, milliseconds
$2=0 Step port invert, mask
$3=0 Direction port invert, mask
$4=0 Step enable invert, boolean
$5=0 Limit pins invert, boolean
$6=0 Probe pin invert, boolean
$10=1 Status report, mask
$11=0.010 Junction deviation, mm
$12=0.002 Arc tolerance, mm
$13=0 Report inches, boolean
$20=0 Soft limits, boolean
$21=0 Hard limits, boolean
$22=1 Homing cycle, boolean
$23=0 Homing dir invert, mask
$24=25.000 Homing feed, mm/min
$25=500.000 Homing seek, mm/min
$26=250 Homing debounce, milliseconds
$27=1.000 Homing pull-off, mm
$30=1000. Max spindle speed, RPM
$31=0. Min spindle speed, RPM
$32=0 Laser mode, boolean
$100=250.000 X steps/mm
$101=250.000 Y steps/mm
$102=250.000 Z steps/mm
$103=250.000 A steps/mm
$104=250.000 B steps/mm
$105=250.000 C steps/mm
$110=500.000 X Max rate, mm/min
$111=500.000 Y Max rate, mm/min
$112=500.000 Z Max rate, mm/min
$111=500.000 A Max rate, mm/min
$112=500.000 B Max rate, mm/min
$113=500.000 C Max rate, mm/min
$120=10.000 X Acceleration, mm/sec^2
$121=10.000 Y Acceleration, mm/sec^2
$122=10.000 Z Acceleration, mm/sec^2
$123=10.000 A Acceleration, mm/sec^2
$124=10.000 B Acceleration, mm/sec^2
$125=10.000 C Acceleration, mm/sec^2
$130=200.000 X Max travel, mm
$131=200.000 Y Max travel, mm
$132=200.000 Z Max travel, mm
$133=200.000 A Max travel, mm
$134=200.000 B Max travel, mm
$135=200.000 C Max travel, mm

To manipulate these settings, you will use a console. You can use the console in the Arduino editor (Serial Monitor) or in your GCode Sender (I’ll show you one soon). To get a print out of your current settings, use “$$”. To change a setting use “$130=100.0” which will set the X Max Travel to 100.0mm. For more details about configuring GRBL via EEPROM, check out their site at:

https://github.com/gnea/grbl/wiki/Grbl-v1.1-Configuration

Note, they will not list the A, B and C axis settings, I had to discover these on my own. I think that is it for what I wanted to point out about GRBL. Their Wiki is actually pretty great, so head over there for more details.