Thursday, March 31, 2016

Review: tiny Arduino Nano-based CNC shield

"Keyes_CNC" Arduino Nano shield for 4 axes CNC machines

The Keyes_CNC controller embarks an Arduino Nano
This little board is an "inverse" shield, on which an Arduino Nano must be plugged to provide functionality. It offers the same functionality as a regular Arduino Uno or Duemilanove CNC shield, with the same power.

But the result is both extremely compact and cheap: less than 7€ for the naked shield (or here), and about 22€/$25 for a complete setup: the shield plus an Arduino Nano and basic Pololu stepper drivers (here or there if you want ebay -- but the latter seems to be a reseller). And for once, it seems to come from a Chinese seller who designs and makes its own boards, which I tend to like.

Add a few Dupont wires (well, Jump wire is the generic name) and you are ready to go!
Fifteen years ago it would have cost thousands of euros!

A regular Arduino CNC shield has 4 axes
Important note 1: Even though 4 general purpose input/outputs are left to the user, this shield is not meant for 3D printing. It lacks a fourth axis (for the extruder). It has no support to read temperature inputs and has no power MOSFET or relays to drive the heaters. It is meant for 3-axis machines like CNCs, plotters and laser engravers.

Important note 2: the connectors are not meant to be abused. This is no industrial stuff, and there is no secure way to attach the steppers for example. As usual when a motor is disconnected while it is powered, back emf will generate a high current back into the board, which definitely can kill it. You do not want this to happen! This applies to all boards and all motors, but special care must be taken without better locking connectors.

Also, there is no documentation and GRBL does not come pre-installed. Hence this post.

Board pinout

I had to revert to my multimeter in order to double check the pin attributions.

Place the board in landscape view, with the power plug to the top left. You should be reading "Control by GRBL" in the center of the board in the correct orientation. Also, plug the arduino nano into the board so its USB plug goes to the right side of the board, as in the top picture in this post.

The silkscreen properly shows most of the signals, ground and power lines.

Here are the Arduino pins that control the outputs and the inputs of the board;

Note that the DIR signals are permuted with the STEP signals with respect to regular Uno CNC shields!

EN D8 (shared X,Y,Z)

EN D8 (shared X,Y,Z)

EN D8 (shared X,Y,Z)

CoolEN A3 (bottom row) and GND (top)
Resume A2 (bottom row) and GND (top)
Hold A1 (bottom row) and GND (top)
Abort A0 (bottom row) and GND (top)

E-STOP RST (bottom pin) and GND (top pin)

Generic extensions:

A7 From top to bottom: GND, 5V, A7
A6 From top to bottom: GND, 5V, A6

The SDA and SCL are part of so called I2C bus. These are very interesting for fast serial communication, where you talk to one or many slaves by referring to their "address" (use and I2C scanner to know the addresses if you need to). When you need many more input/output, you can use I2C "expander" chips like the MCP23017 (gives 32 more I/O) or PCF8574 (only 8 more I/O but with interrupt for when a slave wants to talk!).

Reciprocal view: here are the Arduino Nano pin attributions
RX0 $serial$
TX0 $serial$
D9 X- and X+ (endstops)
D10 Y- and Y+ (endstops)
D11 Z- and Z+ (endstops)
D12 [gpio]
D13 [gpio] / onboard LED
A0 Abort
A1 Hold
A2 Resume
A3 CoolEN
A4 $SDA$
A5 $SCL$
A6 [gpio]
A7 [gpio]

Power line for the stepper motors: a drawback!

The main power plug accepts up to 12V, but it always powers the Arduino Nano.

When the nearby jumper (named ''Mot_VOL_Sel'') is put in place, this power plug also powers the stepper motors. So there is no way to send 24V to the motor with the jack as you would burn the Arduino.

Reciprocally, without the jumper in place, the stepper can only be powered by the ''Mot_VCC'' and ''Mot_GND'' (common ground). These are unpopulated vias on the PCB, and located strangely far from each other on the top of the board.

The spacing between the two pairs of pins is 4 mm, and I found no connector to fit these pins and drill diameters. The best solution I found out is to solder thick wire directly to the board and add some gun glue to relief the cable. Not good.

Another solution could be to cut the trace between the power jack and the nano board, so as to leave the jumper in place and power the steppers from the jack (and the nano board from the USB plug, or from one of the many ''+5'' pins available on the board).

This is a pity as the remaining of the board is pretty nicely done. Some more routing and a footprint for a usual 2-pin screw terminal would have been easy to do in the first place, leaving a much better way to power the steppers independently of the Arduino board.

Flashing the GRBL software on the Keyes_CNC controller board

GRBL is a software initially designed for the Arduino ecosystem. It will run on this board exactly as on an Arduino Uno, since they have the same microcontroller inside. The pinout is slightly different though.

GRBL really is dedicated to efficient G-CODE interpretation. These are the data sent to 3D printers and CNCs alike. GRBL will convert the commands to stepper impulsions, and it will optimize the paths to take inertia into account.

Why use GRBL instead of the regular Arduino stepper library?

Indeed, you can also use this shield with the default Arduino stepper controller examples when you do not need to interpret G-CODES. This may happen also when you need more room for your own programming, as GRBL does not leave much memory!

The Arduino stepper libraries are quite inefficient compared to the dynamics of GRBL, which takes care of inertia and path optimization in your place. But they do the job and they are way easier to use if you just need to control small stepper motors, slightly loaded, or at slow speed.

Back to GRBL

Now that we know how to wire the board, we can tweak the GRBL configuration file. Note that even though GRBL can be uploaded very easily to your board, thanks to their little Arduino library that only uploads the binary to the board, it will not be possible here as it does not give the chance to depart from the default pinout!
You have to build it from source... This is slightly more complicated than a regular Arduino program because GRBL does not use the slow and bulky Arduino software ecosystem. Check the doc.