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

Sending Emails via SMTP

msmtp  requires a minimal setup for sending emails via SMTP compared to sendmail. Here is a configuration for you to send emails from a web host to an external SMTP server. Prior to doing that, you must check whether there is a clear communication channel between your web host and the SMTP server. You can use Telnet . Set up msmtp You are going to set msmtp as an MTA . Hence, you need to remove all other MTAs such as postfix and sendmail: $ sudo apt-get --purge autoremove postfix sendmail Install msmtp and related utilities: $ sudo apt-get install msmtp msmtp-mta mailutils Configure msmtp: $ sudo nano /etc/msmtprc # Set default values for all following accounts. defaults # Use the mail submission port 587 instead of the SMTP port 25. port 587 # Always use TLS. tls on # Set a list of trusted CAs for TLS. The default is to use system settings, but # you can select your own file. tls_trust_file /etc/ssl/certs/ca-certificates.crt # The SMTP server account mx host mail.mx.example

fatal: Couldn't find remote ref master

If you are using Github then  master is now known as main . Whatever you want to do with a master must now be referred to a main . If you search for this error message on the Internet then you will encounter with a lot of old discussions on how to set up your master properly which is probably not what you are looking for. The master  is your problem. Rename it to main . I wrote Git My Way about two years ago. Today I created another Github repository. I got this  "fatal: Couldn't find remote ref master"  error message when I wanted to sync the new repo for the first time with my notebook using the notes I wrote in the blog. All the discussions around the error message I found on the Internet were perplexing. Then I recalled that Github had renamed master to main  due to the master-slave connotation. We always have a master copy of a code, never a slave copy. Now suddenly a word context has been diminished for good. What is going to happen to the existing vast documen