3D Tech Works
Custom Benchtop CNC Machines and Supplies
Technology for a 3D World 
My Blog Page
Blog the First
Well, this is my first attempt at blogging.  Not sure why I am doing this, other than it adds content to my website.  Being an unemployed Electronic Designer, it gives me something to do to keep me off the streets.  I was laid off from a career of 25 years earlier this year, another casualty of low oil prices. However, I'm not dead yet, nor am I quite ready to retire, so we'll see what shakes out of all this.  There is a link on the site to my online bio/resume if you have the slightest interest in what makes me tick, at least career-wise.  Or if you have a burning desire to have the benefit of my impressive intellect and experience working for you (for an substantial stipend, of course).

3D Tech Works is my second attempt at creating a WebPage.  I have absolutely no idea what I am doing, but like Darwin, I have a theory that it will evolve with time, hopefully in the direction of survival of the fittest.  Surely, the weak and lame content will die out, leaving only the shining beacon of excellence behind.  Yeah, right.

Since I am trying to sell benchtop CNC equipment to potential beginners in the art, I thought adding a technical blog to the site was a good idea.  I will try to cover the basics of CNC machines, the deep dark secrets of how they work, and the work flow that goes into creating a design, generating a g-code program, and feeding it to a machine, taking ideas to reality.  There is something fundamentally satisfying about creating things by your own hand, even though you use a large dose of technology to assist.

In any case, I have decided to start this blog as my entry point into freelance writing.  Maybe someone will notice. I  have always enjoyed writing, although up to this point it has been limited to technical manuals and instructional tomes.  This blog will serve to give me practical experience, and as an example of my talents that I can show to prospective clients.  Besides, I need the money.

So, onward and upward.  I am learning how to use a program designed to do WYSIWYG websites to help me in setting up the pages you are currently perusing.  Although I know nothing of HTML, or scripts, or any of this stuff, I am yet not too old a dog to learn these new tricks.  We shall also see how that goes.  I may review the program as I get a bit more familiar with it. 

Blog the Second

Hi, and welcome back.  This is the start of a new series of Blog episodes based on an OpenBuilds CNC router.  I am going to attempt to tutor you on the basics of CNC routing from the ground up, using concepts from the OpenBuilds Community.  

OpenBuilds is a community based on Creative Commons licensing where guys like you and me create projects like routers, plasma and laser cutters, and 3D printers based on a set of predefined parts.  This modular parts system centers on aluminum extrusions called linear rails, which have been designed and made reality by a crowdfunding effort.  The extrusions are now manufactured by the community for use by all the participants.  Participants design their own parts as well, and contribute the designs to the community.  It's a really great concept for sharing knowledge and fostering creativity.  It also allows thousands of people to share their knowledge and help out the community by designing and sharing their own nifty stuff with all members.

I stumbled across the website watching some interesting YouTube videos on CNC machining.  I was looking at some stuff from a well known CNC guy, "NYC CNC".  He does video blogs based on his own CNC shop, which was in New York, but has since moved somewhere north.  One of the related videos on the YouTube sidebar was a build video for the OpenBuilds OX CNC router.  I was fascinated by the way the system was put together, from modular parts that are easily available and can even be purchased as a kit.  The video was well put together, and shows the construction in great detail.

I was hooked.  I joined the forums, looked around, and was impressed by the literally hundreds of user submitted designs for all types of CNC equipment.  I was also impressed by the willingness of the Forum participants to help out and answer dumb Newbie questions about the builds, software, hardware, and CAD systems.

I found that most of the guys there use SketchUp for their 3D CAD designs, and SketchUp models were available all over the site for the various parts and assemblies used in the projects.  There is also a Web Store that stocks all of the available parts you can use to build stock designs, or invent a new design tailored to your requirements.  It's like Lego for CNC, you can mix and match parts to get your own creation up and running.  Then you can use your newly built CNC machine to make parts for the next generation of Custom Made CNC designs.

So, I downloaded SketchUp, and proceeded to try to learn it.  This was my first foray into 3D CAD, I have been a 2D CAD user for many years, and like to think that I am pretty proficient.  Let me tell you SketchUp is a completely different animal.  It appears to be simple, but I actually found it very difficult to learn.  To be fair, I think that was mainly because I am used to doing things in a 2D CAD world, and SketchUp is nothing like 2D CAD.  To paraphrase Steve Martin "It's like they have a different word for everything".  After talking to some users on the forums who started out with SketchUp, they couldn't understand why I was having such a hard time.  The old guard guys who grew up on 2D CAD sympathized with me completely.  Seems the preconceptions are a pretty big barrier to learning SketchUp, new users seem to pick it up much faster.

In my opinion, Sketchup seems to be missing a lot of the tools that 2D drafters take for granted, like snaps and things like mirroring, step and repeat, etc.  To be fair, there are a lot of extension plugins available to do most of these things, but the very fact that extensions are necessary says something in itself, I think. Also, to be fair, a lot of the stuff is just called a different name, but seems to have similar functionality to the 2D world.  Suffice to say, it took me a couple of months to get proficient enough that I felt comfortable creating my own CNC router design using various parts cut and pasted from other designs, along with designing a few custom parts on my own using Sketchup.  I won't bore you with the details.  That's a topic for another blog in itself.

Note that Sketchup is the tool of choice among the OpenBuilds crowd, but you are not limited to using it if you have a preferred software package that you are comfortable with.  Most of the parts on OpenBuilds have some alternative CAD format, such as STP or IGES, along with 2D DXF files.  There are lots of alternatives out there, some of them free.  Even Autocad offers Autocad Fusion 360 with a free license for hobbyists and lite commercial users with revenue under $100,000.

The ultimate goal of the 3D CAD package is to provide a means of converting your drawings to G-Code. Those of you familiar with CNC machining will recognize G-Code as the universal language of CNC machines everywhere.  The CNC machine uses G-code to tell it where to go, what to do, and when to do it.  G-Code is typically generated on a PC, and then sent serially (or via USB or parallel port) to the electronics on the router itself.  The computer on the CNC machine interprets the G-Code, and converts it into step and direction information for the (typically) 3 axes of control motors on the CNC machine.

G-code is a pretty simple thing.  It has a command symbol representing what type of operation the machine is to do, and a set of X, Y, and Z co-ordinates needed to do that operation.  G-code is plain old ASCII text, and is readable by the user.  Only one command is allowed on a line.  Each command is executed one at a time, sequentially as the machine scans through the file.  One just needs to get familiar with the commands, and you can easily read and modify G-code on the fly.

It is not strictly necessary to be able to use 3D CAD to do CNC designs.  2D cad can be converted to G-Code as well.  This is generally known as 2.5D CAD.  The third dimension is added by the g-code generation program, by the user entering in the Z Axis (height) information such as hole depth, changes in elevation of the part, etc. manually.

But, that is sufficient to absorb for now.  I'll include some links below so you can take a look around.  Next time, we'll dive into the hardware and how the mechanical parts of the system work.  

Happy Creating!

Intro to CNC
OpenBuilds OX
Blog the Third

Today I thought I would take a closer look at the mechanical hardware of the CNC Router, using an example from the OpenBuilds website.  We''ll take a look at the OpenBuilds OX CNC Router, (named after the beast of burden for it's strength and robustness), and see how it ticks.  Below is a picture generated from the Sketchup model of the Ox that shows some of its major components and construction.

As you can see, it's a pretty robust looking machine.  The flat bed is an MDF sheet which is replaceable if it becomes too chewed up.  This base sheet is called the Spoil Board.  The Y-axis consists of the two side linear extrusions, and two gantry plates (Black plates with OX inscribed on them).  These gantry plates roll on V shaped wheels, which ride in the V-shaped track on the top and bottom of the extrusion.  I'll show a closer view in a minute. 

If you look closely, you can see the two stepper motors for the Y-axis, one on each side of the gantry plates.  These have a toothed pulley attached, with a toothed belt stretched over the top of the pulley.  The belt is held in the track by the gantry wheels, and attached at each end of the track.  Thus, as the motor rotates, it pulls the gantry along the toothed belt and provides predictable linear motion.

You can see that connected between the two Y-axis gantry plates is another pair of linear extrusion cross beams.  These beams serve to connect the two Y-axis gantries into a single solid assembly, as well as providing the track that the X-axis carriage moves on.  In the center of the X-axis gantry rides the Z-axis assembly.  You can see that on the back of the Z carriage there is another stepper motor and belt arrangement that moves the gantry back and forth on the track in the X-axis direction.

In the front of the X-Z axis carriage is the Z-axis itself, which has the spindle motor attached.  At the very top of the carriage is another stepper motor which powers the Z-axis up and down motion.  The Z-axis uses a linear screw drive instead of a toothed belt.  The Z-axis extrusion moves up and down on the wheels visible on the sides of the extrusion.

Here is another photo focusing on the X-Z carriage, and one of the Y-axis gantry plates.  It shows a bit more detail on how the belt and stepper combination moves the axes, as well as a closer look at the carriage itself.

Zooming in on the inside of the Y-axis gantry plate, you can see how the belt is hidden in the V-groove of the track until it gets past the inner two guide wheels.  It is then stretched up and over the stepper motor pulley, and back down under the rear guide wheel.  This is a rather ingenious drive system, the belt remains hidden and protected, and the guide wheels hold it in the track except for the section that goes over the pulley.  The belt is tensioned by pulling it taught after installation and held by two locking screws at each end of the track.  Note that there are guide wheels on the bottom of the gantry plate as well, (not visible) so the the whole Y gantry plate is held firmly onto the track to eliminate any play or twisting motion.

Turning our attention to the Z-axis carriage, you can see the same drive arrangement for the x-axis (left and right) with the motor at the back.  A double set of guide wheels for the X-axis top and bottom ensure that the Z carriage rides straight and true.  You can also see that the Z-axis consists of another piece of the linear extrusion, held in place by the vertical rows of guide wheels, and driven by a lead screw (not visible) down the back of the extrusion.  The spindle motor is mounted on the front of the extrusion and provides the power to the cutting bit.

So, as you can see, this is a simple design, yet robust and stiff enough to get the job done.  It is capable of machining a wide range of materials, from wood to plastic and even aluminum.  It all bolts together with metric fasteners, angle brackets, and tee nuts.  Assembly is simple and straightforward, and can be easily done in a weekend.  This particular machine is available as a kit of parts from a couple of different suppliers, and there are extensive assembly videos on YouTube. (be warned that these videos are over an hour each, so make popcorn)

The main thing to note about this build is that it uses a plethora of stock parts, such as the wheels, extrusions, fasteners, and brackets.  These parts are all included in the kit, but the main thing to note is that they are also all available separately.  The gantry plates for this build are custom made, but there is nothing stopping you from customizing the build by making your own plates or having them made.  There are also other axis drive options such as rack and pinion, belt loop, lead screw, and others that you can choose at will.  You can virtually mix and match parts and assemblies to create pretty much any size and kind of CNC machine you want to build.  SketchUp, Iges, Step, and DXF models of all the parts are available, so you can design your own virtual machine in 3D CAD, all  without spending a dime or physically turning a screw.

A lot of examples of builds by the OpenBuilds members are shown on the website link I provided last time.  People have made plasma cutters, laser cutters, foam cutters, cloth cutters, just about any kind of machine you can think of, just by replacing the spindle unit on the Z-axis with whatever hardware you desire.  Members regularly make machines up to 4' x 8'.  In addition, it is very popular to make 3D printers using this hardware system, I have seen 3D printers in the Builds section of the site that will print objects up to 800x800x800mm.  You'd better buy your filament by the truckload for that one, and be prepared to wait days for the finished product!

Parts and kits are avilable from several sources, including but not limited to:

Next time we'll take a look at Stepper Motors, how they work, and how to drive them.
Hasta la vista!

Intro to Stepper Motors and Drivers
Blog the Fourth

For CNC work, we'll need to review a bit about stepper motors and how they work.  Generally, an electric motor has a rotor and a stator, and some means of introducing electrical power to force the rotor to turn by using a changing magnetic field acting on the rotor.  DC motors tend to be fixed speed of rotation devices, speed based on the voltage and current applied to them.  Stepper motors are kind of a special breed of motor, in which the rotor is made to advance a specific portion of a revolution as two phased coils are alternately energised and de-energised in a set sequence.  Thus, it is not really a smooth running motor as we normally think of them, but it can be moved a specific portion of a turn with great accuracy and repeatability.  This is why stepper motors are used for precise positioning of things like CNC machines and the like.

Stepper motors are generally classified by size.  The National Electrical Manufacturer's Association (NEMA) has a classification system for stepper motors based on size.  For instance, a NEMA 11 stepper motor is 1.1" in diameter, a NEMA 23 motor is 2.3" in diameter, and so on.  Each size classification can have several different motors in it, which vary by the length of the housing and thus the maximum torque that they can generate.  They may also have different coil voltage and current ratings, which also affect power and torque.  

Stepper motors fall into 3 main types, the variable reluctance motor, the permanent magnet motor, and a hybrid of the two.  The variable reluctance is not used much any more, the hybrid has pretty much taken over for positioning use as it combines all the advantages of the other two, having high resolution, good torque, and being generally pretty easy to drive.  Stepper motors are well suited to being computer controlled. Since they are open loop devices that do not generally require positional feedback from an encoder or other device, they are simple to interface.  Also, the computer is tailor made for keeping track of the position of the motor internally.

Stepper motors in their simplest form have two stator coils wound with a phase relationship of 90 degrees to each other, with a set number of N and S magnetic poles arranged in a circle.  The poles are arranged to have a series of "teeth" on the pole faces, and the rotor is magnetized and has a few less "teeth" than the stator.  Thus, as the windings are energised in a set pattern, the teeth on the rotor tend to move into alignment with the teeth on the stator that are energised to the opposing magnetic polarity.  The excitation for the coils is then rotated around the stator, drawing the teeth on the rotor into alignment with the next set of stator teeth, and the rotor rotates.  Looking at the figure below, as the coils A thru D are energised in sequence ADCB, the rotor will turn clockwise one step at a time.  If the sequencing stops, and the current in the stator windings is maintained, the rotor "locks" in position and is prevented from rotating.  Thus, the motor can be locked in any position simply by maintaining the coil drivers in the last state.

Stepper motors are also specified based on the number of complete motor steps it takes to go one revolution.  This "angular resolution" is usually specified as rotational degrees per step, or total steps per revolution.  Note that a "motor step" as defined here is actually made up of a complete cycle of electrical signals required for the motor to move the defined portion of a revolution.  So, a motor with a resolution of 200 steps/revolution with full step drive still requires 4 stages of coil excitation to move 1/200th of a rev.  If the motor had half step drive, it would require 8 stages to move the same amount, or, conversly, 4 stages of coil drive would only move it half of its nominal resolution.  So, it can be seen that making the drive steps smaller effectively increases the apparent angular resolution of the motor.  Again, as always with stepper motors, there is a tradeoff.  Increasing the overall angular resolution will reduce the torque and maximum rotational speed of the motor. 

One more item I want to check off is the electrical arrangement of the drive coils on a stepper. There are 3 basic types of coil construction used, 4 wire, 6 wire, and 8 wire, further broadly separated into 2 types, unipolar and bipolar.  Unipolar coils have center tapped coils, where the power supply is tied into the center tap of the coil, and the ends of the coil are grounded based on whether you want a N or S polarity of the winding.  These require only a simple pair of low side drivers to energise each coil.  Unipolar coils are either 6 wire or 8 wire, based on whether each winding is center tapped or split, (consisting of 2 separate coils).  Power is fed in through either the center tap, or if 2 separate coils, the inner wires from each coil are tied together to create an artificial center tap.  Motors with split windings can also use Bipolar drive by simply parallel connecting the two windings in each phase.

Bipolar coils are a single winding, and in order to reverse polarity of the magnetic field, you need to physically reverse the polarity of the applied voltage.  This requires an H Bridge driver arrangement, which uses four transistors in a classic Wheatstone Bridge configuration.  This allows you to switch the transistors to allow current flow through the single coil in either direction, reversing the magnetic polarity.  Bipolar wound motors typically have better torque than unipolar motors, simply because bipolar motors energise the whole winding, whereas unipolar motors only energize half the winding at a time.

I don't want to get too much further into stepper motor theory and construction.  It just pays to have a basic knowledge of what you are working on to help understand how and why it works, and assist if you need to troubleshoot something.  If you want to know more about it, one of my favorite mnemonics is FGIY, in polite company this means "Frakking Google It Yourself"!

Stepper motor drivers formerly were fairly simple DC circuits consisting of several current switching devices (transistors), series reistors to limit coil current, and the inductance characteristics of the winding itself.  The circuitry being rather simple, the mathematics to determine currents, voltages, etc. was fairly complex.  With the advent of microprocessor and DSP integrated circuits, most of the hard jobs are now done in the chips, which require only basic instructions of "which way" and "how much" and pretty much take care of the rest.
Modern Stepper Drivers take care of all the processing required to move the motor by progressively energising the coils in the proper sequence.  They typically have some jumper or switch settings which select the drive mode, whether it be single step, half, quarter, eighth, on up to 64 or more steps per motor step.  The higher numbers indicate what is generally known as Microstepping, and actually supply an analog voltage similar to a sine wave in the proper phase to each of the the coils, moving the rotor incrementally with each change in voltage.  This makes the movement much smoother and quieter, at the expense of speed and torque.  Full and half step settings are more common for workhorse applications, since they provide the highest torque and speed, at the expense of smoothness and noise.

Below are illustrated some of the typical drive waveforms for a stepper motor.  Beginning on the left, is the single step drive, where the waveforms shown represent the necessary drive for 1 motor step.  The second image is for half step drive, note that at some times during the revolution the drive to one or the other phases is off completely.  Finally, the third waveform shows a motor step with microstep drive.  Note that the waveform appears to be a sinusoidal wave.  Also note that in all 3 cases, the waveforms have a phase relationship of 90 degrees to one another.
Early stepper motors operated from fairly low voltages, in the range of 2-5V, and relied on physically large current limiting resistors to keep the current in line.  This, however, was very wasteful in terms of energy, generated a lot of heat and took up a lot of space.     Stepper motors operate on current.  You must limit the current in the windings to prevent overheating the motor and burning out the windings.    Most modern stepper drivers use PWM (Pulse Width Modulation) to limit the winding current in the motor to a safe or specified value. They change the Duty Cycle (On time/Off time) of the incoming power to reduce the current into the motor to a safe value. 
How this works is that typically, a power supply will have a fixed voltage. The stepper motor controller circuit turns this voltage on and off at a very high rate, on the order of hundreds or even thousands of times per second. It can vary the on time/off time ratio, which then reduces the apparent voltage of the power supply by this ratio. So, if you have a power supply of 24v, and you PWM it's output by a 50% ratio, you will have an apparent output voltage of 12v (only under load). In the case of Stepper Drivers, the PWM ratio is actually reducing the power output of the supply and not the voltage. You still get the full supply voltage, but only for half the time, therefore half the average current. 
Stepper motors are inherently rather low voltage/low impedance/high current devices. As an example with easy math, f you have a stepper motor that requires a current of 2.4A at a voltage of 2.4V, using Ohm's Law it has a winding resistance of 1 ohm. 
Now, suppose you are using a 24V supply, and want to use PWM to limit the current into this motor, you would initially calculate that the motor current would be 24v/1 ohm or 24A. This is obviously way too high for the motor, so you would use the PWM to limit the current to 2.4A. The required PWM percentage to achieve this would be 2.4/24 or 0.1 or 10%. So, your stepper driver would be set to provide a 10% on and 90% off duty cycle. This would limit the average current into the stepper windings to 10% * (24V/1 ohm) = 2.4A, which is what you want. 
Where the advantage comes in, is that the power supply voltage is still 24v. So, when the stepper driver turns on the coil, it will apply 24v to the coil for the first 10% of the cycle, and then turn off for the remaining 90% of the cycle. Since the stepper motor is actually an inductor, not just a straight resistor, it will take some time for the current to build up in the coil, and when the voltage is removed, it will take time for the current to fall back to zero. I don't want to get into inductive theory at this point, so you'll just have to take my word for it. 
This means that the stepper driver can deliver more energy to the coil initially, since the voltage is higher. The average current will still be the specified current for the motor winding, but the instantaneous current when the PWM is on will be much higher because of the higher voltage. This instantaneous application of high power causes the motor to accelerate faster and have more torque, while still keeping it within its specifications. 
So, the theory is that the higher the voltage you use to drive the motor, (while still limiting its current to specified levels via PWM), the more torque the motor will have and the faster it will accelerate.  This gives much higher torques for the same size motor, because of the higher voltage drive, and yet limits dissipation and heat in the motor and drive circuitry for better efficiency.  They also have settings for driver waveform selection, run and hold current, and compensation for motor resonances and inefficiencies.  Of course, there are limits to this as to everything, so you will eventually hit a point of diminishing returns for one reason or another.   Stepper motors are a very complicated bit of kit, and there are a lot of issues I simply left out for clarity.

Shown below are 3 types of single channel stepper controllers.  The one on the left is a postage stamp sized module that is made for smaller motors such as those used in 3D printers and the like. It plugs into a "motherboard" with several others of its ilk to form a multi axis control system.  The center unit is a bit larger, for medium sized steppers, with an integral heatsink for the driver chip.  The one on the right is a fully configurable multistep driver for medium to large motors.  Each of these has its place, and of course with the infinite variety of electronics designs, other configurations and combinations, as well as multichannel systems are always available.

The Stepper Drive does all the legwork as far as taking care of the motor's voltage and current needs.  As mentioned earlier, the current through the windings is controlled by PWM'ing the input voltage duty cycle down until the correct current is fed to the coil.  The Stepper Drive typically requires only minimal signals from the controller chip to activate the drive.  These signals consist of a Direction bit, which is high for one direction of motor rotation, and low for the other, and a step bit, which is a pulse that the driver interprets as instruction to move 1/N steps.  N is the driver setting for step size as shown above.  If the motor driver is set to half step, it will take two input step pulses to move one motor step.  In addition, there is usually a third signal, which is optional, called the Enable signal.  When it is active, the motor is allowed to move, and when it is inactive, motor movement is inhibited.  Most drives default this signal to the enabled mode, and allow the microcontroller to use it or not as required.

Most Stepper Drives have a power input for the motor supply, and a separate power input for the drive electronics.  This separates the noisy motor supply from the sensitive microcontroller inputs to the Drive.  Also, most Drives have the control inputs isolated from the Drive electronics by high speed optocouplers, which prevent damaging spikes or faults from feeding back and damaging the microcontroller or control computer.

Well, that's it for this edition, next we will scrutinize the options for electronics and software for the CNC enthusiast, including my personal favorite, the Arduino.  Prices for the hardware range from downright cheap to reasonable, and software prices range from free to almost free.  The free stuff is very popular and works very well.

Blog the Fifth

Finally time for some hardcore electronics!  The amount of hardware and software available for CNC controllers is pretty extensive.  Several companies offer integrates packages that will do all the necessary functions.  There seems to be a couple of main camps,  the LPT port powered systems which use a Breakout Board connected to a PC via old fashioned Parallel Port, and the Arduino powered systems.  There are a few others, but these seem to be the most popular.

The LPT connected systems use the PC software to interpret G-code and send stepper driver ready digital signals via the port to a BOB as mentioned earlier.  The BOB has optoisolators to isolate the PC from the motor drive signals, and essentially just provides a place to connect the stepper driver boards to the PC.  Thus the name Breakout Board.  Separate stepper driver boards either individual or multichannel are then used to actually drive the motors for each axis.  Small CNC systems typically use 3 axes, X, Y, and Z.  Other axes can be added to the system which include a rotary axis to do machining of objects by rotating them, and tilt axes that can tilt the Z axis to either side to provide ability to do angular cuts.  These are beyond the scope of this project.

Some examples of LPT based systems are the LinuxCNC software, which is open source, and the MK3 and MK4 software which is not free, but reasonably priced at a few hundred dollars.   PlanetCNC software is also free, and uses a USB based BOB and separate stepper drivers.  Finally, Arduino based CNC using the GRBL g-code interpreter is the system I have chosen to use.  It can run up to 4 axes by using the onboard digital I/O of the Arduino to control stepper drivers, interface limit switches, and even control the spindle motor.  Arduino based systems are very cheap, the entire controller can be built for less than $100, and all the software is free.

I want to take a close look at the Arduino platform for a CNC controller, at least the hardware that I ended up using.   and look at the GRBL software for converting g-code to X-Y-Z positioning.  I will touch on loader software for the Arduino, and loading the Arduino from Windows in a later blog.  With much oration and hand waving, let's get started!

The Arduino series of microcontroller boards has turned out to be a fantastically popular small open source computing platform for just about any project you can think of.  From robots to IOT devices, to sensor platforms, drones, whatever application you have can pretty much be done on an Arduino.  This has also led to a plethora of add on boards that plug into the I/O headers on the Arduino mainboard, known as "shields".   Motor drivers, network interfaces, sensor interfaces, displays, LED panels, audio players, GPS, GSM cellphone, you name it, somebody has a shield to do it.  

The first and still very popular Arduino was the Uno.  It uses an ATMega328 microcontroller chip.  The board integrates a power supply, USB connector for power and communications, and an integral FTDI USB-serial converter.  It can be programmed via hex downloads from the USB port, or using an external programmer.  A free IDE programming environment is avalable which allows you to use canned libraries of software, or write your own "sketches" as they are called to do whatever task is required.  

There are 14 programmable digital I/O lines and 6 analog inputs, along with another half dozen power pins brought out to 2 rows of single row female headers that form the interface connectors.  Arduino  "Shields" can be plugged into these stacking connectors, most shields have stackthrough connectors so boards can be stacked several layers deep.  

A 6 pin ICSP programming header is also provided.  The ATMega can be programmed through this header, but it also has a preprogrammed boot loader burned into the internal ROM which allows programs to be downloaded from a PC using the USB port.  We'll get into that a bit later when we install the GRBL software.  Another free program is available to download hex files into the Uno.

Shown below is one of the many clone Arduino boards available.

Intro to the CNC Electronic Hardware 
There are several shields and driver boards specifically made for CNC systems such as the TinyG, the CNC Shield, and the GRBL shield.  I will just go over some of the most popular systems out there, there are a plethora of boards out there.  

The first board we will look at is the CNC shield.  This is an open source board manufactured by dozens of different manufacturers both here and abroad.  It consists of an Arduino shield board with a bit of interfacing hardware and sockets for plugin style motor controllers.  These are postage stamp style stepper drivers that plug into headers on the CNC Shield.  Up to 4 motors can be controlled using this shield, and the controllers can handle in the range of 1-2 amps per phase, typically.  

These drivers can be Allegro Microsystems A4988 chip drivers, which handle up to 1A typically, or a bit more with a heatsink and forced air cooling.  They can do 1-1/16 step drive with built in thermal limiting and an adjustable current limit.  They are also short circuit protected, and run at up to 35V input.  The Texas Instruments DRV8825 drivers are similar, but can handle an input of up to 45V, 1.5A without heatsink and 2.2A with heatsink and forced air cooling.  They also have adjustable current limit, short circuit and thermal protection, and can go to 1/32 step microstepping.

This board was my first choice, but in general it cannot handle enough current for the larger 2.8A NEMA23 stepper motors that the CNC uses, so I decided not to use them.  They are very popular, however, for use with 3D printers, as they are more than sufficient to drive the NEMA17 motors used in those systems.  The 3D printers also require the fourth axis for filament feed systems, so these are ideal.  The CNC Shield in one of its many incarnations, with an DRV8825 driver shown beside it:

Now let's take a look at the GRBL Shield.  This is manufactured by Synthetos, the same company that makes the TinyG.  It is a smaller shield type board with 3 motor drivers installed.  It can drive 2.5A at 30v, up to 1/8 microstepping, with independent current control for each channel.  It uses the TI DRV8818 stepper driver chips.  This is a nice board, but again, did not quite meet my requirements.  It is shown here:
After a lot of reading and looking around, I found that the smaller systems such as the CNC shield and the GRBL shield were a bit lightweight for the system I had in mind.  Both of these boards have multi channels of stepper drives, but can only handle stepper motors up to about 2 amps.  This is more than adequate for a NEMA 17 stepper motor used in typical 3D printers, but I needed a bit more sputz to drive the 2.8A NEMA 23 motors that I had in mind.  All of the single board systems are a bit light weight for a serious CNC machine.  I also don't like the fact that if one driver or some minor component on the board burns out, the whole multi-hundred-dollar board is garbage.  Much better to have a modular approach where it's easy and cheap to replace individual components.

So, I went with a screw terminal shield for my Arduino which is a passive shield that simply brings out all the arduino I/O connections to screw terminals so that I can easily connect them to individual stepper drivers.  I chose  a Single Axis TB6560 3.5A Stepper Stepping Motor Driver Board.  This is a small board about 2.5" square, utilizing the Toshiba TB 6560 stepper driver chip.  It has a heatsink on the back, and is capable of driving a single motor of up to 3.5A@24V.  It has optoisolated inputs, and settings on board for current, step size, hold current and decay mode.  One board is needed for each stepper motor.

The Arduino with Screw Terminal Shield is on the left, the Stepper Driver board is shown below right:

The board has simple connections for Motor supply, motor windings, and Step, Direction, and Enable inputs with an isolated 5V supply input for the optos.  This made wiring the system a snap.  Each stepper driver is simply wired to its associated axis motor, and to the Arduino as shown below.  2 wires per axis, and a common power connection and Enable signal daisy chained to each board.  The wiring will be a bit more complex when I add the limit switches, for now I will rely on the soft limits built into the GRBL controller.  I also added a couple of push button switches for the Feed Hold and Resume circuits, and a reset button.  These are on the top of the enclosure that holds the Arduino board. I'm not using the coolant output nor the PWM spindle speed output yet.  I have to come up with a way to control a universal motor (the spindle router) with the PWM signal before that gets added.

Note that the pin layout showm is for GRBL firmware version 0.9 and above.  It is slightly different on earlier versions.  Make sure you have the right diagram for your software.
The only thing left was a power supply.  I had Mean Well LRS-30-24 supply kicking around which was ideal.  With 4 motors running, the current draw would max out at just under 12A, so a 350W supply was needed.  I mounted all of the electronics on a simple aluminum panel.. 

So, that's it for this edition.    Next edition, we'll look at loading the GRBL software into the Arduino, and some of the options for outputting G-code from the PC.  Then, we'll fire it all up and see if we contain the magic smoke or not!

[You do, of course, know that all electronic components work because they contain Magic Smoke.  If you cause the Magic Smoke to leave the component, by whatever means, it does not work any more!]

Blog the Sixth

The arduino is now wired up to the stepper drivers and the power supply is connected.  I ended up doing a mounting plate to hold all the components as shown below.  The plate is long enough to hold everything (500mm x 80mm), and has mounting holes that line up with the v-slot outside dimensions and slot spacing so it can bolt onto any v-slot based build.  I increased the size of the power supply a bit so it can handle 4 motors with ease, and put the ability to mount 4 stepper drivers.  This gives me the capability to build a larger machine with 2 Y Axis motors like the OX if I want to upgrade, without having to rebuild the whole electronics section.  This is a Sketchup rendering of the panel, the stepper drivers are a bit different than the ones mentioned in the previous blog, but you get the idea.

Final Wiring and Programming the Arduino 
The wiring for the stepper drivers is pretty straightforward.   As you saw in the last installment, the axis Step and Direction outputs for each axis are shown on the bottom left of the Arduino pinout.  Each axis driver has step, direction, enable, and a common power connection between it and the relevant axis connections on the Arduino.  Each input to the stepper driver is actually the LED side of an optocoupler, and the Arduino output signal simply drives the LED.   If you have two motors on one axis, like some of the larger machines, simply add another driver in parallel with the existing driver, and connect the motors to the individual motor outputs.  This way both motors receive exactly the same signals.  

Keep in mind that if one motor is mounted on the left side, and the other is mounted on the right side,  one of the motors must turn in the reverse direction of the other so the carriage will move properly.  In order to reverse rotation of a stepper motor (or any multiphase motor), simply reverse the connections on one of the phases.  It doesn't matter which one.  I have included a rudimentary pic of how the stepper drivers are wired up below.  Note that these drivers have a common +5v going to the arduino, depending on the type of driver it may have common ground instead.  (This would require reversing the polarity of the drive signal in the Arduino, we'll get to that in a later installment)  Also note that this image does not show the stepper motor enable connections, they are similar to the step and direction connections, but a single enable line is tied to all the stepper drivers.   Some systems do not use the enable lines.     In my case, the 5V is supplied by the Arduino USB connection.  Again, the stepper drivers are a bit different thatn the ones I am using, but it gets the concept across.

As you can see, this diagram includes limit switches and control switches for Start, Stop, and Resume.  However, it does not show the stepper Enable connections which I think are quite useful.  If you leave the connection out, the stepper driver stays in the enabled state by itself.   Probably would be more correctly called Disable.  If you don't have the enable hooked up, your motors may overheat becasue the are always on.

It is possible to add fixed limit/homing switches to each axis to physically stop the machine if the switch is tripped.  Typically these limit switches are placed so that some part of the machine trips them when it comes into contact with the switch.  They are typically placed at the extreme limits of axis travel just before the axis crashes into the end stops.  The Arduino halts all movement of the machine and goes into an error state if any of these switches are tripped.  This prevents damage to the machine if an axis were run hard into the end stops.  The limit switches for each end of one axis are simply wired in parallel.  The Ardino cannot tell which of the two switches was activated,  There are then 2 limit switches for each axis, or 6 in total.  There are only 3 input lines to the arduino, the other lines to the switches are tied to ground common.  Limit switches can be either normally open or normally closed.  The inputs in GRBL can be programmed to accept either type.  Again, more on this later.

The limit switches at the end of each axis can also be used as a home indicator.  Homing is a process where the machine moves each axis in a particular direction until it hits the limit switch at that end of the axis.  The machine then stops at that position and waits for further commands.  Homing is very useful to place the machine at a known position before beginning a g-code program run.  The machine can always be returned to a known position using the home command, so it is particularly useful in case of a power interruption or other issue during a program run.  The homing cycle usually begins with the Z axis, which is moved to the top of its travel.  This gets the tool out of the way and prevents it from hitting anything during the rest of the cycle.  The X axis usually homes next, followed by the y axis.  Homing axis directions and behaviour can be set in the Settings for the GRBL program, which we will get into in a later installment.  Note that you can hoe to either end of an axis, since GRBL cannot tell which switch is tripped.  The home position is set by telling GRBL which direction to move to home each axis.  So, by changing this direction, one can home to either end of any axis.

Important Note:  With the Arduino Nano, and to a lesser extent with the Uno, false triggering of the limit inputs is sometimes a problem.  Since the Arduino just uses its internal programmable pullups on the input pins, and these are on the order of 20K to 50K ohms, noise can easily be coupled into the limit switch input pins.  This can be solved by pputting 0.1uF Caps from each limit input to ground, and/or adding harder pullups (5k or 1K ohms) to each input pin.  This is particularly a problem with the Nano board.  Using shielded wire and hiding it in the v-slots of the machine rails helps as well.  If shielded wire is used, make sure to only ground the shield at one end, preferrably the Arduino end.  Leave the other end unconnected.

Apart from Homing inputs, there are a few more optional I/O lines used by GRBL.  There are 2 control lines for the spindle motor, one of which can be used to change direction of rotation of the spindle, and the other can be used to enable the motor and control its speed via PWM.  External control circuitry is needed to use these signals.  Additionally, there is a coolant enable output which can be used to turn on a coolant valve for the bit.  This is generally used only for machining metals, and on larger milling machines.  There are Reset, Hold, and Cycle Start/Resume inputs that can have pushbutton switches wired in for manual controls.  These are seldom necessary since the software has control over these functions as well.  

The last input is called Probe.  This is an extremely useful input, used to calibrtate the Z axis height.  It allows a metal pad electrically connected to the input to obtain the zero position of the Z axis.  It is used to zero out the Z axis at the point of contact with the work.  The pad is wired to the input of the Arduino, and ground is connected to the machine bit with an alligator clip.  A small g-code program is then run which slowly lowers the Z axis until the bit just contacts the pad and the Arduino detects the electrical contact.  The Arduino immediately halts the movement of the Z axis.  The Z axis position is then set to the height of the pad, and the axis is now calibrated to the exact height of the workpiece in the machine.  There are manual ways to do this, but using the probe input is fast and accurate. 

Arduino Programming

Now that we have the system all wired up, it's time to consider downloading the GRBL program into the Arduino.  This can be accomplished in a few different ways.  One is by using the Arduino Software IDE program available from:

This program is an Integrated Development Environment specifically designed to be used with all of the Arduino controllers.  Upon installation, it loads drivers which may be needed to communicate with the Arduino on your Windows PC.  Installation is recommended for this reason, although I am not a programmer so I don't use 90% of its functionality.  It is useful for talking to the arduino to make sure it is connected, detecting and setting the port number, and as mentioned, installing the necessary USB drivers.

Now that your Arduino is up and running, we can download GRBL itself.  As of this writing, the current version is 0.9j, and can be found here:

The general page for GRBL is on Github here:

The other program I use to actually load the software into the Arduino is called Xloader.  It's pretty simple and basic and easy to use.  Once you have the GRBL hex file, use Xloader to download it to the Arduino.  It couldn't be simpler.  Just point at the file, set your baud rate and COM Port, and go.  On that note, GRBL 0.9 and up use a Baud Rate of 115,200.  Earlier versions were 9600.  The program should auto detect the processor type, but if not it is an Uno ATMega 328, or you can use a Nano AtMega328.  Note that GRBL only runs on the ATMega 328, not the 168, 1280, or 2560.

Once the Xloader program indicates success, you can open the Arduino IDE and see if you can talk to the Arduino.  Click on Tools, then on Board, it should be set to Arduino/Genuino Uno.  Then click Port, and it should show a Com port with the board connected there.  Now click on Serial Monitor and it should open a small terminal window.  Press enter, and you should get the GRBL power up message.  Note that you have to have the baud rate set at 115,200 for the UNO and GRBL 0.9j

Well, that covers installation of the stepper drive system, programming the Arduino, and getting everything wired up.  Next time, we'll go over the GRBL settings, and see if we can make something move!

GRBL Settings and Calibration 

Blog the Seventh 

Now that we have GRBL up and running, it’s time to get the settings for GRBL lined up with our machine. GRBL has a list of internal variables which must be customized for the machinery connected to the controller. These internal settings consist of things like customizing the steps/mm of the stepper motor/driver/axis type and setting up the directions and enabling optional features. We’ll start out with a list of the settings used by GRBL, note that these are settings for a Big Ox type machine with belt drive and 4 axis motors. Each is followed by a quick reference of what it does.

Factory GRBL Settings Reference  
$0=10 (step pulse, usec) – This is the width of the step pulse in microseconds sent to the stepper drive 
$1=255(step idle delay, msec) – This is the delay in milliseconds after a move instruction before the stepper motors are disabled. Setting this to 255 keeps motors always enabled. 
$2=1 (step port invert mask: 00000000) – These are binary mask bits that set the polarity of the step pulse. 0 = normally low, high pulse, 1 = normally high, low pulse. Only the last 3 bits (LS) are used. 
$3=3 (dir. port invert mask: 00000011) - Binary mask bits for the direction signal to the stepper driver. 0 = normally low, 1 = normally high. Again, only the last 3 LSB are used, ZYX. If you motor goes the wrong direction, reverse the setting of the relevant bit. 
$4=1 (step enable invert, bool) – direction of the enable line. 0 = normally low, positive direction, 1 = normally high, negative direction. 
$5=0 (limit pins invert, bool) - inverts the polarity of the limit switch inputs (normally high, active low) 
$6=0 (probe pin invert, bool) – inverts the polarity of the Probe input (normally high, active low) 
$10=3 (status report mask: 00000011) - This setting determines what Grbl real-time data it reports back to the user when a '?' status report is sent. 
$11=0.020 (junction deviation, mm) – This setting determines the speed algorithm when GRBL approaches a corner. Usually not altered 
$12=0.002 (arc tolerance, mm) - This setting has to do with how GRBL does arcs by breaking them into many small line segments. Not usually required to be altered. 
$13=0 (report inches, bool) – Changes the units reporting from mm to inches 
$20=0 (soft limits, bool) – enable/disable soft limits (numerical entry) 
$21=0 (hard limits, bool) – enable/disable hard limits (switches) 
$22=1 (homing cycle, bool) – enable/disable homing cycle 
$23=3 (homing dir. invert mask: 00000011) – sets direction of travel for homing cycle for each axis. Last 3 bits set direction for ZYX respectively 
$24=200.000 (homing feed, mm/min) – speed of movement for last part of homing cycle 
$25=1000.000 (homing seek, mm/min) – speed of movement for first part of homing cycle 
$26=50 (homing debounce, msec) – debounce time in milliseconds for homing switches 
$27=1.0 (homing pull-off, mm) – amount of pullback when homing routine hits a switch. Ensures that switches are not still activated after homing cycle if limit switches are enabled. 
$100=26.730 (x, step/mm) – Steps per mm for X axis 
$101=26.730 (y, step/mm) – Steps/mm for Y axis 
$102=200.000 (z, step/mm) – Steps/mm for Z axis. - These 3 are the calibration values for the 3 axes, and compensate for the leadscrew pitch or belt teeth/mm, microstepping, and stepper motor resolution. 
$110=3500.00 (x max rate, mm/min) - maximum speed for the X axis 
$111=3500.00 (y max rate, mm/min) – Maximum speed for the Y axis 
$112=2000.00 (z max rate, mm/min) – Maximum speed for the Z axis 
$120=50.000 (x accel, mm/sec^2) – acceleration constant for the X axis 
$121=50.000 (y accel, mm/sec^2) - acceleration constant for the Y axis 
$122=50.000 (z accel, mm/sec^2) - acceleration constant for the Z axis 
$130=564.000 (x max travel, mm) – Maximum axis travel for the X axis. Used for soft limits 
$131=750.000 (y max travel, mm) – Maximum axis travel for the Y axis. Used for soft limits 
$132=55.000 (z max travel, mm) – Maximum axis travel for the Z axis. Used for soft limits 
These are minimal descriptions of what each setting does. For more information and detailed explanations of each setting, see the Settings Reference Section of the GRBL documentation at: 


Setting up Your Machine 
The above settings normally have to be gone through with a fine tooth comb when setting up your machine for the first time. After that, they can usually be forgotten about since nothing on your machine should change after initial setup. The values above are stored in the Arduino in non-volatile memory, so they remain set even through power cycles. Note that setting these is different depending on what G-Code sender program you use. Refer to the documentation for the program to see how to modify these values. 

Normally the first thing to set is the stepper driver parameters. Leave the stepper pulse width setting at the default unless the stepper drivers you have require a different setting. In any case, do not set this to less than 10uS. The Step Idle Delay I usually set to 255mS. This makes sure the motors are always energized after a move is finished. This locks the axes positions in place so you don’t accidentally move the axis and lose it’s position in the software. Having said this, you need to have stepper drivers that reduce the current to the motors automatically when they are not moving, or the motors will overheat very quickly. If you apply full holding current to the motor, it may destroy itself. Make sure that your drivers have this reduced current feature before setting this parameter to 255. Otherwise, set it to 254 or less to protect your motors. 
The next group of settings is the step port invert and direction port invert settings. Test your system out by firing up your G-Code sender program of choice and trying out the jog buttons. Direction bits need to be set first. Each axis needs to be tested to make sure it is going in the right direction. The usual defaults are: 

X axis: Right is +, Left is – 
Y axis: Back is +, forward is – 
Z axis: Up is +, down is – 

Set the bits to high on any axis that is moving in reverse. Note that the setting is in Decimal, even though the bit mask is binary. So, 00000001 would be entered as a 1, 00000111 would be entered as a 7. The pulse bits usually do not require changing, since almost all drivers require a positive going pulse to step. Check your driver documentation to see if these need to be changed. Another reason to change these would be a stepper driver module that uses a common ground on its inputs rather than a common positive. 

The next 3 settings just invert the polarity of the relevant signals if required. Again, check your documentation for the stepper drivers to see what they require for an enable polarity. It is usually high = disabled, low = enabled. The Limit Switch and Probe settings depend on how you wire these up as to what polarity is required. 

The next pair of settings, Junction Deviation and Arc Tolerance rarely require change. See GRBL detailed documentation on what these do. 

The next setting, Report Inches, is pretty self-explanatory. If you are a dinosaur that likes your settings in inches, by all means feel free to change this from the default mm. However, keep in mind that the native units for the system are in mm, so changing to inches may introduce slight conversion errors, and your values are almost never going to be even, whole numbers. Also, keep in mind that your other software like g-code senders and CAD programs will need to be set to inches as well. No mixing of units allowed. 

The next 3 settings are simply enable signals. Usually you would only set soft limits if you did not have electrical limit switches on your axes. I highly recommend homing switches, they do make life easier for machine setup. The homing direction invert settings set the direction that the axes move in when you hit the homing button. They should be set so that the direction of movement is toward your homing switches wherever you decide to place them. You can home to any quadrant of the machine simply by placing the homing switches in that quadrant. There are a lot of opinions about homing and where the homing point should be, but ultimately it is your decision as to where you like home to be. 

The Homing Seek and Feed Speed settings need to be set as well. I like to have the Seek speed fairly fast so it doesn’t take all day to do a homing cycle, but you need to be careful that it is not set too fast so the machine can’t stop in time when it hits a homing switch and crashes into the end stops on the axis. The Feed speed setting should be, as a rule of thumb, about ¼ of the Seek speed. This allows the system to accurately find the switch point and repeatably home to the same place each time. If your homing does not seem consistent, try lowering the speeds. 

Homing Debounce is, as the description says, a small time delay to allow a mechanical switches contact to stop bouncing. Almost all mechanical switches bounce, or make multiple contacts when activated. This can confuse software, so a delay is added to ignore any changes until the delay period elapses. This allows enough time for the switch contacts to reach a stable state before the software tries to read them. 50 mS is a reasonable guess for this value. If your homing seems flakey, try increasing the delay. 

Homing pull off is a small movement that moves the axis away from the switch after it finds it. This is so the same switch can be used for Homing and Limit. If the homing switch did not back off until the switch opened again, as soon as the homing cycle finished, the system would get a limit switch error and lock up in Alarm Mode. It would be impossible to reset this alarm if the switch remained activated, without physically moving the axis back. Since this scenario has a high PITA value, we don’t want to do this. The pulloff should be set to the smallest distance that reliably ensures the switch is deactivated before the homing cycle finishes. 

Movement Calibration 
Now that we have most of the settings out of the way, it is time to calibrate the movement of each of the axes. This is done with the Steps/mm settings for each axis. This will require a bit of calculation. 

With a lead or ball screw type axis, you will need some information about the pitch of the screw. This is the distance travelled for each revolution of the screw. So, a TR8*8/2 pitch lead screw will travel 2mm for each revolution of the screw. You also need to know the angular resolution of your stepper motors. Most modern motors are 1.8per step, or 200 steps per revolution. In addition, if your stepper drivers are capable of microstepping, you need to know the microstep setting. So, for a C-Beam type lead screw axis actuator, we would have: 

200 steps/rev  
---------------------- = 100 steps/mm 
If you add microstepping into the equation, if you have your motor set for 4 microsteps per step, 
200 x 4 steps/rev 
----------------------- = 400 steps/mm 
The calculation is similar for a belt drive: 

Motor steps/rev X microsteps  
------------------------------------------ = steps/mm  
Pulley teeth x belt pitch 
Now that you have the correct value for the axis in question, go ahead and calculate the values for all of your Axes and enter them into the settings above. This will give you a starting point for your calibration. 
Now you need to check your calibration against the machine to see if it needs adjustment. Start with an axis near one end, and an accurate stainless steel ruler, a small machinists square, and a 0.5mm mechanical pencil. Use the square against the axis rail and the edge of the carriage somewhere where it gives a fixed value. Place the square against the rail, and against some part of the axis that protrudes the farthest, and carefully make a pencil mark across the rail on the edge of the square. Then move the axis using your jog controls by the length of the ruler, and make another pencil mark across the rail in the same way as the first one. Now jog the axis back to its starting position, and use the ruler to measure the distance between the two marks. It should be exactly as indicated on your screen. If it is not, it will be necessary to adjust the calculated values above until the calculated and actual values exactly agree. 
As an example, suppose I move the axis 200mm according to the jog program screen, but my pencil lines are 205mm apart. This means I have to reduce the steps/mm calibration value to compensate. I would reduce it by: 
Cal constant             200 
-------------------  =  -----  = 0.976.    Multiply this by my existing cal constant, 200 X 0.976 = 195 steps/mm 
Actual value             205 
So, I would go back and enter 195 steps/mm as my new calibration constant and repeat the test above. Keep doing this until your axis movement is bang on. Note that you may have to do a reset on the Arduino to get GRBL to use the new constants each time you change them. 
Lather, rinse, and repeat for each axis on your machine. You will now have everything perfectly calibrated. 
The last group of settings are the maximum speeds, accelerations, and travels for each axis. Maximum speed will depend on your motor torque, mass of the gantries, and a gazillion other factors. Very difficult to calculate. Generally just set it or 2000-3000 mm/minute and live with it.   If you lose steps when moving fast, reduce the value.

Acceleration is an trial and error thing. GRBL will accelerate each axis up to full speed over a certain distance. If the torque of the motors is not sufficient to accelerate the mass of the gantry to this speed in this amount of time, the motors will lose steps. So, the best way to set these is also trial and error. Set the acceleration up a bit, and run the axis back and forth several times, checking how far it moves each time using the pencil line method above. If the axis loses distance at any time, the acceleration value is probably too high. Keep increasing the acceleration until the machine starts to lose position, then back it off by about 25% to get a safe value. This will need to be done separately for each axis, since they all have different masses. Or, just set it to a median value and forget about it. Optimizing the acceleration curves will gain you a bit of speed in your overall machining time, but it may be such a small difference as to not make it worth the effort. 

Well, I’ve been plenty verbose for this blog post. Kind of dry and no sexy pictures. But. It’s an important subject and well worth understanding. Ta Ra for now. 

GRBL Panel Operation

Blog the Eighth 

Now that we've got our machine running, calibrated, and ready to go, we need to take a look at the software used to control the machine, the G-Code Sender.  This program is typically a Windows or Linux based program that communicates with the GRBL controller on the machine, and takes care of several functions:
  • Communicates with the GRBL controller, and set communication parameters
  • Displays and sets machine position
  • Has buttons for commonly used GRBL controls like alarm reset, GRBL reset, program hold/resume, etc
  • Status Window shows machine status, current operations, and alarm conditions
  • Provides jog controls for manually moving the machine
  • Usually has an interface to the GRBL Settings parameters
  • Able to load, display, and run G-Code programs, and display the running code in a window
  • Has settings for things like units, jog size, jog speeds, modes, etc.
  • Has a manual command entry window that allows the user to execute manual g-codes
  • Provides control and setup of Work Offsets
  • May have the capability to program Macros to automate commonly used tasks such as Z Axis zero, etc
So, as you can see from the above list, its a pretty comprehensive little program.  This is the interface that you will use to do all of your machine control functiona, as well as to load and execute G-code that you have generated from your CAM program.  There are many of these programs out there, and most are free to use.  Some, like MACH 3 have a license requirement and must be purchased.  MACH 3 is closer to a professional machine control program, and does not run with GRBL, so we will not go into it here.  There are also several Linux based systems out there, but I am not a Linux kind of guy so we will leave those for someone else to deal with.

You are free to choose whatever program you like for machine control.  Some of the more common ones are:

  • GRBL Panel -  Thsi is the one I prefer to use and the one I will go into some depth about its operation and uses.
  • GRBLControl
  • Universal G-Code Sender
  • 109JB's GRBL Interface
  • CNC G-Code Sender
There are many others out there as well, these are only a few ovf the avilable ones.  There are also lots of programs avilable for purchase, some of which have more than 1 function.

  • EstlCAM - a full function CAM program as well as having machine controller functionality
  • MACH 3 / MACH 4
For our purposes, I will concentrate on GRBL Panel.  It was written by the same people that wrote the GRBL firmware, so it should be compatible.  It's the one I usually use and so the one I am most familiar with.  It's features are pretty much the same as the other programs of its ilk, so knowledge of the interface can translate well to other programs.

GRBL Panel Control Functions

Note that some of this content was shamelessly lifted from the GitHub GRBL Panel Wiki, written by Garret Visser.  This information is used under the Open Source Licence.

The GRBL Panel Main Screen is shown in this screen capture: (note that this is not from the latest version.  The Macro tab is not shown)

The main tab of GrblPanel is Interface. This tab has everything you need for typical operation of a CNC controlled device attached to Grbl. Many of the buttons etc. have ToolTips that show if you hover over them for a moment.  GrblPanel helps you stay out of trouble by locking access to its various controls depending on the state of operation.

Connection to Grbl is initiated in the "Grbl grouping". The drop-down will show the last port that you connected to successfully. If you happen to start the app before connecting to Grbl, use Rescan to find the new port. Once you press Connect, the app opens the serial port, blips DTR to hard reset Grbl and then waits 1.5 seconds for the controller to wake up from its slumber.  Windows assigns USB COM ports based on when they were connected.  The assigned COM port for a given device may change.  Occasionally, the COM port handler will lose its tiny little mind and GrblPanel will not be able to find the Grbl controller.  This may necessitate rebooting the computer to get the COM port reassigned.

Also, the Connect/Disconnect button is useful for zeroing Machine Position.  If the disconnect button is pressed when the machine is in some arbitrary position, then the connect button is pressed just after, the machine position and all of the position displays are reset to zero.  This is handy for zeroing out your machine position at the start of your g-code.  Note that any offsets stored in G54 or the currently selected Active Offset will be loaded when the Machine Position is zeroed.

The "Status view" box generally has nothing in it unless you get errors, Alarms or enable Verbose. The Q and RX progress bars reflect the status of those 2 queues in Grbl. The Status display box will show the current status being reported in the poll ('?') responses. 
The "Position display" shows the current Work Offset position in large font and the absolute machine position in smaller font. The 0 buttons to the right of each axis display is used to Zero that axis' position in the Active Work Offset. The Zero XYZ button sets all 3 axes to 0 in the Active WorkOffset. Typically this is G54, the default but it could be one of the others supported by Grbl. You can change to a different offset in the State panel on the RH of the screen. The units displayed are from Grbl's Report Inches settings. 
The "Jogging grouping" is for doing just that, jogging. You can set the increment and feed rate using checkboxes as well as the Units, Metric or Inches. These settings are independent from/do not alter Grbl's Report option. Note that the Jog speeds and increments are local variables only and are only used for jog button operations.  They are overridden by the values contained in any g-code you run.  The Jog buttons autorepeat based on fields on the Settings tab. The default is 2.5/sec. On the Settings tab you can also enable Keyboard arrows for jogging that way. (The keyboard repeat rate is not alterable, that rate applies to all Windows apps.) 
The "State grouping" reflects Grbl's response to $G initially. It subsequently follows gcode from a gcode file. The dropdown boxes allow you to send the relevant setting to Grbl, e.g. useful when testing your Coolant mister. These parameters are usually found at the start of a Gcode file so they may change once you start a run. (FeedRate, Spindle RPM and Tool Number are presently settable via the MDI or Gcode file, not from these text boxes.) 
The "Gcode grouping" provides controls to open a file, Run, Pause, or Stop a file. The # of lines is shown and each gcode line is numbered in the view. As a command is responded to by Grbl, the Sts field reflects that. The column can be resized to show the full error text. Gcode file execution stops on Alarm, and Pauses on errors (there is an option on the Settings tab for the latter case). A comment line in the file will populate the Message box, useful to give you feedback on what MOP you are presently cutting. 
Lastly, the "MDI grouping" provides a means of manually entering and sending commands. You can use Return key to send or the Send button. Gcode entered here is reflected in the State grouping as well as in the Gcode view below.  This area also contains your Macro buttons.  If you program a Macro using the Macros Tab, a button will show up here so you can execute the macro.  Be sure to use a good name for the macro so you can remember what it does.

This section reflects Grbl's settings. GrblPanel populates this automatically after a successful connection to Grbl. You can change settings by clicking on a Value, altering the value and then double-click to send the value to Grbl. 
For future proofing, there is a Last Grbl Param which should be set to the last Parameter value you expect to get from Grbl. This might change in the future with Grbl enhancements, hence the configuration option.

On the left, in the "GRBL Settings" pane, are the current non volatile memory settings from the connected microcontroller running GRBL.  See a previous Blog post for information on GRBL settings.  These can be edited by clicking on the value you want to edit.  A small pencil icon will apear on the left.  The new value can be entered in the box, and then you must double click on the number to force it to change.  Note that your mouse has to be right on top of the number for this to work.  The cursor will relocate to the top of the window if the update was successful.  Otherwise, the number may appear to change, but when the screen is refreshed the old value may reappear.  This takes a bit of practice to get right.

Position Pane - This section provides you with settings that alter what commands are used for the various Position related actions.   You might want to modify the G28 and G30 commands by adding X, Y and/or Z parameters to indicate where you want the Controlled Point to move to before going to the final destination.   Be careful using Z0 for G28/G30 as it is often the point where the tip of the tool touches your work surface. 

Misc Pane -  This section provides various settings to control GrblPanel's behaviour.  The default Poll Interval provides decent visual tracking of the work position changes while running a program. Setting this too small might interfere with Grbl's operation, slowing down the Controlled Point's motion.  Left Handed GUI swaps the 2 main groups of controls on the Interface tab. 

Jogging Pane - The 4 feed increment and rate values available on the Interface tab are set from here. The defaults were chosen to give good control while positioning the Controlled Point relative to a work piece.   The Repeat rate is set to a reasonable value to avoid overrunning your desired end position but still proving a repeat. Too fast and you will crash into limits (or wish you had limit switches :-)   The Enable Keyboard arrows option enables the use of the usual arrow keys as well as Pg Up and Pg Dn. These repeat at the standard Windows repeat rate, not affected by the repeat rate settings here.

Offsets(2) Pane  -  G28 and G30 are 2 very useful location settings . Typically G28 should be set after you Home Cycle and back off from the Limit switches. Click Set and the absolute machine positions at the time are recorded in EEProm. In other words you don't need to do this every time you power up your machine.   G30 is similar, but it is typically used to set an absolute location for Tool Changes. Jog to that location, go back to Settings tab and click Set for G30.   

Both G28 and G30 are executed from the Interface tab using Goto Spcl Posn1/2. These operations take place at high speed, unlike Homing Cycle. Think of Spcl Posn1 as a soft home operation. Please do consider carefully with both these commands that you need to send Z axis to somewhere safe, i.e. above your work piece and clamps. If you want, that value can be set in the Position block on this Settings page.

The last section is the Macro Tab.   This allows user programmable macros to be entered to automate various processes that would normally require entering g-code manually.    In the Editor pane, you can give the macro a name, and enter in a mini g-code program to perform a function.  A commonly used macro would be to zero out the Z axis using a probe.  One would enter 

G38.2 Z-10 F10
G92 Z20.0

This macro would lower the Z axis a maximum distance of -10mm, at a speed of 10 mm/min, until the bit touches the probe pad.  It would then set the Z axis position to the height of the pad, in this case 20.0 mm.  Clicking the Add button after this g-code has been entered will cause the macro to appear in the list.  Existing macros can be edited by double clicking the name in the list, or deleted by highliting and pressing the Delete Selected button.   All macros in the list will have a button appear in the Interface tab in the Command Pane under the manual entry box.  Just click on the named button to execute the macro.

Well, that's been a basic introduction to controlling your machine using GRBL Panel.  Next time, we'll look at common tasks using GRBL panel, such as zeroing and positioning.  Then we will look at loading and executing G-code.

Stay Tuned!


Blog the Ninth

So the machine is now up and running, and ready to make some shavings. There are still a few things you need to know about machine operation. You need to learn about homing and what the purpose of it is, and you need to know a bit about co-ordinate work systems. 


Homing is an automated process that returns your machine to a known position, hopefully repeatable and accurate. I find it indispensable for getting your machine into a known state. Homing requires a bit of hardware added to your machine, namely homing switches or sensors. If you have limit switches installed on your machine, you can simply use those. If you do not have limit switches, you will need to add homing switches and enable the homing cycle in GRBL settings. Programs like GRBL Panel will show a homing button if the homing function is enabled. 

Most CNC’ers, including the OpenBuilds crowd, use the front left corner of the machine as the home point. The homing switches are set to bring the Y Axis full forward, The X Axis full left, and the Z Axis to full height. This is X and Y axes to their full negative value, and the Z axis to its full positive value. Thus, all work will be in a positive direction for both the X and Y axes. Most CAM programs for gantry type CNC’s work this way.  

Some CNC users set their homing point at the right rear of the machine, and all work is in the negative X and Y planes. This is less common, but it’s out there. You can find any number of arguments on the forums about which is best. Users of large CNC milling machines typically also use a different format. Ultimately it depends on your CAM program and how it lays out the work space. I typically use SketchUp and Sketch-U-Cam, which defaults to the lower left corner as zero. Of course, when you do your toolpath generations, typically the CAM program will let you put your Zero Reference Point anywhere you want. 

In any case, you need to set the machine up to home properly to the selected homing position. When the machine is first powered up, it loads the machine position from the GRBL Settings X, Y, and Z Max Travel parameters (the last 3 settings in the GRBL Setup Menu) into the Machine position register. Actually, it subtracts the Homing Offset from these values before loading. I don’t know why it does this, it’s kind of annoying. The Machine Position is usually displayed somewhere in whatever G-Code sender program you use. I typically use GRBL Panel; it seems to be pretty robust and is made to work with GRBL Arduino code. In GRBL Panel, the small numbers below the X, Y, and Z position bars on the upper left of the main screen Work tab are the Machine position, as well as being displayed in the Offsets Tab. GRBL panel may also load this information into the G54 fields. 

With the machine powered up, make sure all your axes are working and going in the right direction using the jog buttons: 

• Y + is to the rear, Y- is to the front 
• X + is to the right, X – is to the left 
• Z + is up, Z – is down 

Manually move the carriages to their home positions using the jog buttons, and check to see that the homing sensors LED’s light up before the machine hits the bumpers. Adjust either the bumpers or the proximity sensors as needed until they work right. Adjust all the axes away from home for the next step (if they are already at home position, nothing will happen): 

  • Press the Home Cycle key on the GP main page. The machine should home and stop in the front left corner with the Z axis fully raised. 
  • If it does not, check your homing switches and adjust if necessary.  
  • Now you need to zero the X and Y axes positions and the machine position displays. This is most easily accomplished by simply disconnecting GRBL panel from the machine and reconnecting. GRBL will automatically zero the machine position and all axis indicators when this is done. Just hit the Disconnect button in the GRBL box (top center where the COM port setup is). The button then changes to Connect, press it again. 
  • Now you need to set the Z axis. Run the Z axis down as far as it will go before hitting the stop. Press the zero button next to the Z position. 
  • Now press the Home Cycle key again, and the z Axis will raise to its full height and stop after a little wiggle. 
  • Note the indicated height of the Z axis.  
  • Switch to the Offsets tab and enter the negative of this number in the Z axis box of the G54 Work Offsets. I.E. if the number is 60, enter -60 in the Z cell. This will ensure that your Z axis goes to this max value every time you do a Home Cycle. To enter this number, click on the Z cell, type in the number, and double click in the cell. (the cursor must be right on top of the numbers for this to work) 
  • Do not zero the Z axis. 
  • Now you should have all zeros in your position display, with the exception of the Z axis. This is good; your machine is now fully zeroed. 
Don’t move your machine yet! I like to set G28, or Special Position 1 to this zero point for later. If something were to happen, I can always return to the home position without doing a home cycle. To do this: 

  • Go to the Settings Tab 
  • About the center of the page, at the bottom, you will see Machine Locations G28 and G30. 
  • Press the Set button beside the G28 values 
  • You should see the current position (0,0,0) in the G28 display 
  • You have now set G28 to your Home position 
You can also set the G30 position using the same steps as above, but pressing Set beside the G30 location instead. Follow the instructions above, but set this position to the G30 key instead. You can use G30 to be any important position on the table. I usually use this to move the carriage to the back of the machine so I can easily position the work on the table without the gantry being in the way. Of course, this is entirely my way of doing things; you have several other options for setting work offsets. This is a whole subject in and of itself, and there are other offsets you can use including G54-G60 which can store work offsets. Again, Google is your friend if you want to find out more. 

Now you can return to the main screen, and press the Special Position 1 button, and your machine should return to the home position. Press User Position 2, and your machine will return to your other set point. Of course you can set your G28 and G30 points to anywhere on your machine that you find convenient. You can also zero your position anywhere you like and call it your work zero position. 

Note that once the workpiece is positioned on the table, you can manually move the machine to the corner of the workpiece and zero out the machine at this point (press disconnect/reconnect). This will zero the machine at the start of your work, and wherever the machine ends up if you press the User Position 1 button the machine will return to this zero point, no matter where it is. This is a very handy function. 

Note: Hitting the E-Stop while the machine is running will cause it to get stupid and lose its position information. Run a Home Cycle and set up as above if this happens. You should not have to reset G28 and G30, they are remembered by the Arduino, and once the machine is homed, they will work properly again. Remember to zero the machine position by hitting the disconnect/reconnect buttons immediately after doing a homing cycle. 

Installing Homing Switches 

I have been using the small electronic proximity sensors for homing switches on machines that I build for quite some time. They are economical, reliable, and work pretty well. They are available from many sources on eBay, Amazon, and others for almost less than what it costs for a micro switch type limit. They do require a bit more wiring than limits, simply because they require a power source to function. Let's take a look: 

This is one of the more common units available, Chinese made and branded Fotek. It has a sensing distance of about 5mm for steel (hence the -05 in the part number), and a 3 wire connection. This unit is an NPN transistor output, which means it has an NPN transistor which pulls the output line to ground when the sensor is activated. These are available in PNP output as well, which has a PNP transistor which pulls the output to VCC when the output is active. This type is not really useful for our application. The -N suffix on the part number shown on the unit indicates that this is an NPN output type. The PL prefix in the part number indicates that this is a long body type sensor, there are long and short bodied sensors. There is actually only a couple of millimeters difference in length so this is not really important. 
These sensors require a power input of 10-30 VDC to operate. Since the Arduino on a CNC machine is 5V, it is not capable of operating these sensors. You might think that you could just hook it up to your 24V motor supply, but there are a couple of problems with this. Typically, stepper driver modules have optically isolated control inputs to maintain isolation from the machine motor power supply and the Arduino. This is a Good Thing, as MS would say. If you used the motor power to run the sensors, you would be compromising this isolation since the ground from the sensors and the ground on the Arduino would have to be connected together. In addition, it may cause noise and ground loop problems if you tied motor ground and Arduino ground together. I don't recommend doing this no matter how convenient it may seem. 
I usually just use a separate 12V wall wart power supply to run the sensors. You can connect the ground from this supply to the Arduino without problems since it is an isolated supply. I have done up a diagram shown below:  

There is a lot going on in the diagram that we will talk about now. As you can see, the prox sensors just have their power and ground wires tied together to the incoming 12v supply + and -. This is pretty self-explanatory. Note that the ground from the power supply/sensors is tied to the Arduino board ground as well. 
Now we get into the purpose of the components shown on the diagram associated with the prox sensor outputs. The Arduino board digital inputs D9, D10, and D12 have internal pullup resistors to 5v inside the PIC chip. These are the dedicated GRBL inputs for X, Y, and Z Limits respectively. These inputs are also used for the homing function. Unfortunately, these are very high value resistors and make weak pullups. This means that it is quite easy to induce noise onto these signal lines which can cause false triggering of the digital inputs, and hence either false limit switch alarms or false homing signals. This can be a real pain in a machine, because limit switch alarms cause you to have to reset the processor and then reset the alarm. In the case of the homing switches, it can cause problems with the homing cycle. Since this is not a Good Thing, (thanks Martha) we need to take steps to avoid problems. 
It seems for some reason that the Arduino Uno is a bit more immune to this noise than the Arduino Nano. I have increasingly been using Nano's since they are much smaller, have a cool little screw terminal wiring board that makes wiring a snap, and don't require enclosures or shields. In either case, I find it prudent to at least put a 0.1uF capacitor from each digital in terminal to ground. This bypasses noise coupling into the digital inputs and vastly improves the noise immunity of the input. You don't need much of a capacitance to make a drastic improvement. I highly recommend this mod, especially with Nanos. Just solder the caps onto the back of the board and tie the common terminals to ground. 
If this does not do the trick, you need to take more drastic measures. This is where the external pullup resistors come in. They are kind of optional, if the caps do the trick for you, you may not need them. If you are still getting false limit alarms, you may have to add additional pullup resistors. I usually use either 4.7K ohm or 2.7K ohm resistors. Smaller value resistors will be more effective, but don't go lower than 1K or so. 
Note that these modifications are just as relevant with plain old microswitch limit switches as they are with the proximity types. Noise can haunt your limit switches just as easily as your prox sensors. 
Now we get to the diodes. These are necessary with the prox sensors that I have seen because of a problem with the output NPN transistor in the unit. Normally, this should not be pulled up inside the prox sensor because this means that the NPN output will float at the power supply voltage, which in this case is 12V. Obviously, it is not good for your 5V Arduino to have 12V on its digital input pins, this could destroy the inputs, making the Arduino a paperweight. The manufacturer should not have put these pullups into the device, but they did anyway. It would have worked properly if they had not included this pullup. To avoid problems, it is necessary to add a diode to each input in series with the line from the prox sensor. The diode cathode (the end of the diode with the paint stripe on it) should be towards the sensor. This prevents 12v from the sensor from reaching the Arduino input, but allows the NPN transistor to pull the input low when active. I usually just solder these diodes in series with the lead from the sensor where it goes into the screw terminal on the Arduino. Be sure to put a bit of heat shrink over the diode to prevent shorts. 
Just about any diode will work. A 1N400X, where x=1-7, is about the most common. This is just a standard 1A rectifier diode, with a forward drop of about 0.7v. A 1N5819 or equivalent Schottky diode would be better; Schottky’s only have a forward voltage drop of about 0.4V, which would help in this circuit. Since the diode only conducts a few mA, a small signal diode like a 1N914 would also work. 
For homing switch applications, I usually try to standardize mounting of the prox sensors. The Z axis prox is usually mounted on one of the X axis wheel screws, or sometimes on the top of the carriage gantry plate. A screw and tee nut on the Z axis v-slot is usually sufficient for a target. You can see a mounting example here on a Big Ox HD Z axis. I mounted a 2 hole angle bracket on the wheel screw, and then used a limit switch mounting plate from the OB store to mount the prox sensor. Conveniently, the hole pattern on a microswitch is the same distance apart as the mounting holes on the prox senor, so the limit switch plate is a convenient way to mount the prox sensor. 


These proximity sensors, although they say they have a sensing distance of 5mm, this applies only to steel targets. If you use aluminum targets, their sensing distance is only about 2mm. This is not a big deal; they will still reliably detect an aluminum object, the just have to be mounted closer. 
Below is shown a mounting for the X axis. You can see I put an 2 hole angle bracket on one of the screws on the side of the gantry plate, and then put a 1/8" aluminum spacer to lift up the prox senor to clear the top of the gantry plate. I also bent the limit switch mount a bit to angle the sensor down. It just picks up the edge of the X axis plate when it gets close to the end of its travel at X- or the left side of the gantry. This shows the switch mounting, and also shows the gantry being detected. 


For the Y axis, I again put an angle bracket on the front wheel screw on the gantry plate. The prox sensor goes on a limit switch mount, and faces forward. I then put another angle bracket on the side of the 20x80 rail to act as a target. Spacers are used to get everything to line up. Couple of notes here, if you want a bit more sensing distance, you can put a screw and tee nut in the target angle bracket, the steel will increase distance. I also like to put a piece of heat shrink over the angle bracket target, its a real ripper if you accidentally scrape your arm or hand on the sharp edge sticking out.  

 Of course, your machine may have different gantries, different construction, and different spots to conveniently mount the sensors. Also, all of these principles also apply to mounting microswitch type homing sensors, but they do not need diodes. 

Limit switches are just mounted at the opposite ends of the axes, so each axis has a pair of switches, one at each end. The switches for each axis are wired in parallel and connected to a single Arduino input. 
There are specific settings in the GRBL Settings page for your machine to enable both homing switches and Limit switches. There are a couple of other settings associated with these that define how the Limit and Homing switches function. See the Blog Entry on GRBL settings for more information.  

Once all the switches are installed and tested, you need to calibrate them. The best way to do this is to manually move the gantry until it is just about to touch the end stop bumper. Then adjust the switch until it just activates at this position. That should be all there is to it. Repeat this for all 3 axes. Double check that the switches activate before the gantry hits the bumper. If it does hit the bumper, it may cause the gantry to bounce back and not activate the sensor properly. 

There are other types of sensors that can be used for homing/limit switches as well. I have seen Hall Effect logic sensors used, which will sense small magnets mounted on the moving parts. These seem to work well. Of course, the old standby microswitch works for this application too.