Skip to main content

The Software Stack for The Arduino CNC Controller

 

Computer Numerical Control (CNC) is very much software driven. Yet, the architecture of the CNC software is obscured from the general software world. It has evolved separately with its own paradigm and nomenclature.

At the heart of a CNC is the G-Code which is an old programming language that resembles an assembly language. A G-Code keyword is a combination of a letter and digits such as G0, G2, M2, M30, etc. All letters in the alphabet are fully used in G-Code. It is all about moving a tool onto a certain path in a work coordinate system with certain speed, duration, distance, and anything related to it. They call it jogging and inching the tool. It may involves multiple tools simultaneously. The tools need to move accordingly to make, to assemble or to move products. Understanding how G-Code works is the precursor to understand how CNC works.

In a CNC controller as depicted above, the Arduino Nano becomes the G-Code interpreter to control 3 stepper motors simultaneously. G-Code is not just for stepper motors. It can deal with various actuators. However, this particular Arduino CNC controller is designed for controlling 3-axis movement using stepper motors. Arduino Nano is a small micro-controller. A powerful computer is needed to deal with more complex and high performance CNC requirements. The computer may run LinuxCNC which is a dedicated operating system for CNC. 

Since the Arduino Nano has a very small processing resources so it requires a separate driver module for each stepper motor. The A4988 module simplifies Arduino interfacing with stepper motor. More details can be found in the article Control Stepper Motor with A4988 Driver Module & Arduino and in the video on How to Set Vref for A4988 and DRV8825 Stepper Motor Drivers.

The Arduino CNC controller will receive G-Codes from a master computer. Hence, it needs some sort of a handler that awaits for G-Codes and at the same time executes them. Grbl was designed for Arduino to serve that purpose. Usually an Arduino CNC controller is loaded with Grbl. What does Grbl stand for? The answer is nothing.

On the master computer side there are many software that can send G-Codes to Grbl-based controllers. One of it is bCNC. The word 'send' is highlighted in the earlier sentence because there are many G-Code sender software out there. It is a part of the nomenclature. The computer sends G-Codes to the machine so that the machine reacts accordingly.

The bCNC is a G-Code sender for 3-axis CNC machine. It has other features such as X-Y planar autoleveller, digitizer, and G-Code editor. First time user of bCNC will immediately notice some buttons of G54 to G59, and will wonder what are they for. The bCNC has dedicated G54-G59 user interfaces for configuring multiple workspaces. The G54-G59 are G-Codes that handle the work coordinate system for 6 tuples or workspaces. The bCNC is very much G-Code oriented.

Working with G-Codes directly can be very tedious. Hence, most software like bCNC will auto-generate G-Codes from a given Computer Aided Design (CAD) drawing which was previously conditioned for specific machining. However, fine-tuning G-Codes manually can improve performance and reduce the cost of production.

The Arduino CNC controller has nothing to do with Arduino programming. The only Arduino related coding is the Grbl which is maintained by a strong community. It has Arduino in the name because it uses an Arduino module. However, nothing is stopping anyone from writing his own Arduino code. But then he will be on his own, and he may have to write his own software on the master computer to communicate with his Arduino code.

There are many types of Arduino CNC controllers. The one in the picture above can control three 12V stepper motors. There are controllers that handles different types of stepper motors, servos, or linear actuators. There are controllers that handles spindles or lasers. A close-loop controller will handle feedback such as from limit sensors, rotary encoders, or gauges. There are general purpose controllers and there are single purpose controllers. As long as they use G-Codes then controlling them will be similar from the software point of view.

The diagram above summarizes the software stack for the Ardunino CNC controller. The bCNC software can work with various drawing types prepared using some CAD software. The bCNC will convert a drawing into a series of paths which will then be converted into G-Codes. The bCNC can also load G-Codes directly from files. The bCNC will then send the G-Codes to Grbl which will parse and run it. The Grbl will control the stepper motors attached to the Arduino according to the given G-Codes. The stepper motors are expected to move some sort of tooling such as engraving or cutting. The movement should follow the drawing.

The Arduino CNC controller cannot work on its own. It always await for a G-Code from a master. It is event driven. It is like a vehicle which requires a driver. A G-Code is like an instruction from a driver such as move forward, turn left, stop, etc.

The bCNC and Grbl can be replaced with any software with similar functionality. The G-Code, however, must be there to qualify for the CNC standard.

Comments

Popular posts from this blog

Setting Up PyScripter for Quantum GIS

PyScripter is a general purpose Python Integrated Development Environment (IDE). Quantum GIS (QGIS) is a desktop GIS application that can be extended with Python plugins. Both are open source softwares. We intend to use PyScripter as an IDE to build QGIS Python plugin. We are using PyScripter 2.4.1.0 and QGIS 1.6.0 in Windows. PyScripter does not come with Python. On the other hand, QGIS is built in with Python. Thus, we will setup up PyScripter to use the build in Python in QGIS. We assume both PyScripter and QGIS are already installed. Preparing PyScripter batch file We assume that QGIS is installed in C:\OSGeo4W\ folder and PyScripter is installed in C:\Program Files\PyScripter\ . 1. Copy qgis.bat in C:\OSGeo4W\ bin to pyscripter.bat 2. Edit pyscripter.bat to remove the last line that read something like this start "Quantum GIS" /B "%OSGEO4W_ROOT%"\apps\qgis\bin\qgis.exe %* and replace it with this in one line Start "PyScripter" /B "C:\Progr...

Using React in Foundation for Sites

This post was the precursor to the Foundation-React Template . React and Foundation are two different web UI frameworks addressing different needs. They evolve differently. Both of them are powerful on their own accord. Fusing them together may create superpower. We will walk through the process of adding React into Foundation. We will start by installing both Foundation and React through command line interface (CLI). Then we will create a simple Todo web app. Along the way we will highlight the development process. But before all that, let us summarize React and Foundation. The details can be found at their respective websites. Both of them are well documented. React is a run-time UI rendering engine. It renders dynamic UI elements in its own fast virtual DOM, and only update necessary changes to the slow browser DOM. This behaves like a  double buffering DOM which makes any UI update feels fast. React wraps a UI rendering script in a component. A React component can ...

Debugging PHP using Apache Error Log

PHP runs on the server side and behaves like a function that return a value against the given arguments. A remote client may call this function and expect a specified return value and nothing else. So how do we debug this function ? It must not return debugging messages since the client is never designed to handle them. We must never burden any client to handle debugging messages. If we run PHP through Apache server then we can use the error log to keep our debugging messages. It may not be the best way to do it. But we only want to talk about this approach now. Error Logs The Apache error log files generally can be found in the following directory: var/log/apache2 We issue the following command from within the directory to read the latest error messages: # tail error.log The tail command reads the last few lines from the error.log file and prints them on the terminal. If we need to read a specific number of lines from the end of the file then we can specify the -n opti...