Grbl (pronounced “gerbil”) is a standard G-code interpreter that runs on the Arduino platform. G-code is a standard used to control 3D printers and other CNC machines, just like your drawing programs. By using a G-code interpreter, wired up correctly to a stepper driver board (the big read boards that we connect stepper motors to) we can send very simple commands to an Arduino such as “G1 X10.6 Y5.2 Z-1.0”, which means “move to the position (10.6, 5.2, -1.0)” and the Arduino will take care of the rest.
You can learn more about Grbl on it’s web site and follow the installation instructions on the [GitHub wiki page](https://github.com/grbl/grbl/wiki/Flashing-Grbl-to-an-Arduino), it’s a bit more complicated than installing a normal Arduino sketch because it has to be written directly to the board rather than use the Arduino IDE. (I’m happy to help with this process.)
Wiring up an Arduino to the Stepper Driver Board, as we saw in my previous post on using stepper motors means using the black parallel port driver board and this means that we need to know which pins on the Arduino should be connected to which pins on the breakout board in order to speak to the correct pins on the stepper driver board.
The standard Grbl installation uses the following output pins on an Arduino:
- Pin 2: A pulse triggers one step in the x-direction
- Pin 3: A pulse triggers one step in the y-direction
- Pin 4: A pulse triggers one step in the z-direction
- Pin 5: Controls the direction of movement on the x-axis
- Pin 6: Controls the direction of movement on the y-axis
- Pin 7: Controls the direction of movement on the z-axis
- Pin 8: Controls whether the motors are enabled or not
The breakout board uses the following input pins:
- Pin B0: Controls whether the motors are enabled or not
- Pin B1: A pulse triggers one step of the A motor
- Pin B2: Controls the direction of movement of the A motor
- Pin B3: A pulse triggers one step in the B motor
- Pin B4: Controls the direction of movement of the B motor
- Pin B5: A pulse triggers one step in the C motor
- Pin B6: Controls the direction of movement on the C motor
- Pin B7: A pulse triggers one step in the D motor
- Pin C0: Controls the direction of movement on the D motor
REMEMBER: It’s important to also connect one of the ground (GND) pins on the breakout board to the ground on the Arduino.
NOTE: Grbl can only control up to 3 axes (X, Y, Z) but our stepper driver board can control 4 motors (A, B, C, D). In practice, this may not be a problem because the signals for one axes may be sent to two different motors by splitting the signal coming out of the step and direction pins on the Arduino for one axis so that two motors can work in unison. For example, this is commonly the case for controlling the X axis in many machine designs because it often needs two motors to handle the load.
The only thing remaining to do is to attach the stepper motors, which you should do in the same way as the previous post on controlling stepper motors directly from Arduino. Once we’ve got Grbl loaded on an Arduino and the necessary wires connected we can then test to see if Grbl is working properly and able to control the motors. Open Arduino on your computer and check that it is connected to the right serial port. Open
Tools > Serial Monitor and you should see a greeting from Grbl printed into the console area. You can now send G-code commands to Grbl and it will move the motors. There’s much more to say about this, but to test you motors simply type the following:
G1 X10 Y10 Z10
By default, this will move your motors to the position (10mm, 10mm, 10mm) based on the current settings in Grbl. You can view these settings by sending Grbl
$$ and you can change settings (such as the number of steps per millimeter) by sending commands such as
$0=200. This says that it takes 200 steps to move 1mm along the x-axis, this is based the current configuration of the motor driver and physical aspects of the machine such as the belt pitch and pulley size.