Hi everyone !
Many of you have asked me how to make the electronics for your homemade CNC so this is what we will see in this article.
This article completes / resumes a YouTube video I made on this subject. (English subtitle avaible)
I invite you to watch it but you don't have to watch it to follow this article, I repeat all the steps.
Small precision before starting, we will only see here the bases to make the electronics of its CNC.
I know that there is more recent, more powerful material which allows more functionality etc ... But there, I will show you the main lines with simple material and without going into the detail of all the deep settings.
1 - MATERIAL
For the electronics that I am going to present to you, we will use an Arduino Uno card (on the left) which is simple to handle, equipped with a CNC Shield V3 from Protoneer (on the right):
We could have done without CNC Shield, but already:
- it's long, tedious.
- it's not resistant neither to dust nor to vibrations, it's a blow to have short circuits everywhere.
- it's very complicated to integrate neatly in a box because it takes up space and because of point 2) it must be well protected.
Here is the type of assembly that the CNC Shield avoids:
For the motorization we will use Nema17 motors, which are stepper motors, 200 steps per revolution. These motors are used in 99% of 3D printer and desktop CNC that can be found almost everywhere on Amazon or other.
The stepper motors are not conventional motors which are plugged into a power supply and which start to rotate as if by magic.
They perform a series of steps, to turn, which allows precise control of their speed, their direction of rotation and especially their position.
In our case the Nema17 take 200 steps to make a complete turn. This means that we can control their position to 360/200 = 1.8 ° close!
To make them take a step, we must sent them an electrical impulse. So, to rotate them, you need to send them a series of pulses:
- By controlling the number of pulses sent, we control their position
- By controlling the fréquency of pulses, we control their vitesse
Now you think it's more complicated than expected to drive a stepper motor, but in fact not. There is an electronic component that will manage for us the pulses to send to the motor. We call it a motor driver.
The motor driver will receive the orders of speed, direction of rotation and position from the control electronics, in our case the Arduino then transform these orders into a series of electrical pulses which it will send to the motor.
There are 2 references of motor driver which are very famous :
- The DRV8825 (left)
- The A4988 (right)
(Again I know that there is more reference of motor driver, more efficient with more advanced features etc ... but here I stay on simple things)
These two motor drivers are protected against overheating (within a certain limit obviously) but they have 2 big important differences:
- the maximum current that the driver can send to the motor
- the number of "micro-stepping" divisions
Here are the values for its two drivers :
- DRV8825 : Current admitted up to 1.5A without cooling, 2.2A with very efficient cooling (radiator + fan). Maximum division of 1/32 for micro-stepping.
- A4988 : Current admitted 1.2A with cooling, and 2A with efficient cooling (radiator). Maximum division of 1/16 for micro-stepping.
A higher current will make it possible to put larger motors therefore more greedy and / or to be able to force the motors a little more. Here the DRV8825 accepts more current so it allows more range to choose our motors.
Micro-stepping consists of dividing the steps of a motor into even smaller steps therefore multiplying the total number of steps of the motor to make 1 revolution.
For example, our Nema17 - 200pas motor per revolution, with a micro-stepping of 1/2, will take 200 x 2 = 400 steps to do a revolution.
So following the logic the DRV8825 is able to multiply by 32 the number of steps of our motor, while the A4988 multiplies it by a maximum of 16.
I naturally prefer the DRV8825 because it accepts more current and has a much finer micro-stepping, the only "negative" point is that is a little more expensive (over time the price difference is reduced).
And finally, to power all of this, we need a power supply powerful enough mainly to support the load of the motors. Each motor consumes about 5W, which gives us 20W on a 4-motor assembly.
I personally use a 12V 5A power supply (about 60W) which is more than enough for my use:
2 - SOFTWARE
Now that we have done a little tour of the hardware we will see the software necessary to program, configure and control a CNC.
The first software we will need is the Arduino IDE which is the Arduino development environment. It is completely free and will allow us to program in our Arduino board the embedded software, also called firmware.
To install it nothing complicated, just download it and follow a classic "Next Next ...".
Here is the link to download it: Arduino IDE - Sofware
Once you installed it, launch it to verify that it was correctly installed, you should have this window:
Connect your Arduino board to the computer and check in the "Tools" tab if the software is able to recognize your board correctly.
You can select the communication port (which should appear) and the type of card. Check that everything is detected, otherwise choose the right card type.
At this point, you are able to program your Arduino but the question is: With which firmware?
We will use here the GRBL firmware which is OpenSource (free) and widely used in public CNCs.
It is even used enough for well-known software like Fusion360 which integrates the export of machining paths in GRBL format.
Here is the link to download it: GRBL - Last Release
You will have to download the zip "Source code (zip)"
Then just extract it, you should have a folder and file tree, the only folder that will interest us is "grbl".
This folder is a library for the Arduino IDE software, so we will return to the software and include this folder by clicking on "Add ZIP library" in the "Sketch > Include library" tab.
There, you navigate to the place where you extracted the folder and you select the "grbl" folder (this is not a zip folder but it still works)
After that, going back to the sketch tab, you should have the grbl library which appeared in the same tab:
Now you got GRBL ready! We just have to program the Arduino board with it.
To do this, we will simply open the ArduinoIDE project provided with GRBL. As we added GRBL as a library we just have to go to "File> Examples> grbl> grblUpload", and the project will open in a new window!
It only remains to "upload" the program on the Arduino board by clicking on this small arrow button at the top left of the window:
in the black console at the bottom of the window, you should see things, compilation and upload information, you are programming GRBL in your Arduino!
Wait a bit until programming is complete, the console should look like this, displaying "Upload complete" if all is ok:
(There are warning messages in terms of available memory, this is normal, GRBL uses almost all of the space available on the Arduino's memory)
And There you go ! you have programmed your Arduino board, with GRBL, Arduino IDE tells you that the upload is OK, but we cant verify that GRBL itself is working well ...
So it's time to introduce the third and last software we will need, named: CNC JS!
CNC JS will allow us to communicate with GRBL. We will be able to configure it but also and above all, control our CNC!
As for the other software, we will download and install CNCJS, here is the link: CNCJS - Last release
Once installed, you can launch it, you should have this window:
You can see on the left a section called "Connection". Select the communication port of your Arduino (the same as in ArduinoIDE), set the transmission speed to 115200 (I will not go into details) then click on "Open".
The "Console" section just below should open and display a bunch of white parameters on a nice black background:
These parameters are sent by GRBL, which means that GRBL is correctly executed. Going up a little in the console, you should even find the version number of GRBL that you just installed.
We just finished installing the software and programming the arduino. We also checked that GRBL has been properly installed and that it responds, we will now proceed to the assembly of the components.
3 - ASSEMBLY
The assembly is pretty simple, it's like lego!
To start, we are going to mount the CNC Shield board on the arduino, at this level we can't really go wrong
Then we will place the micro-stepping jumpers, there are 3 possible locations under each motor driver location
Depending on how the jumpers are positioned, we select the micro-stepping division mode, here is the correspondence table for each driver reference:
"aucun micro-stepping" = No micro-stepping
Remember which mode you selected, it will be very important in the future!
Personally I put all the jumpers on the DRV8825. I am in 1/32 micro-stepping mode.
Then, we glue the radiators often delivered with the drivers. If, like me, you have a fairly large machine, I advise you to buy much larger radiators which will permit better cooling of your drivers
WARNING : Here, you have to watch and position the "Enable" pin (or "En") of the driver on the Enable pin of the CNC Shield, otherwise you can be sure to burn them all.
Once you have put all your drivers paying attention to the Enable pin, we will focus on the 4th location of motor driver.
On the CNC Shield, next to each motor driver location, there is the name of the axis that this driver will drive (X, Y or Z), but there is also a 4th driver titled 'A'.
This 4th driver will be able to copy all the movements of one of the 3 other axes, as desired. If like me, you have a CNC with 2 motors for 1 axis, you will have to use this axis duplication feature. (in my case it is the Y axis which have 2 motors)
On the side of the CNC Shield, you have places for jumpers with the names of the axis, you will have to place 2 jumpers side by side to select the axis you want to replicate
We just have to connect the power supply and the 4 motors. For power it is simple, there is a terminal block on the CNC Shield, we put the + on the red wire, the - on the black wire ...
Be careful though, do not connect the power supply to the Arduino directly but to the terminal block of the CNC Shield, the Arduino will simply be powered by the USB port.
To connect the motors there is a 4 pin connector next to each driver. There is no particular direction because by turning over the connector, we simply reverse the direction of rotation of the motor.
The assembly is finished! We can now go on to setting up GRBL
4 - CONFIGURATION
For the configuration we will reconnect our Arduino via USB to the computer and we will supply the CNC Shield with the power supply connected just before.
Once everything is connected we can return to CNCJS, open the communication and open the console section.
You should have all the above displayed :
CNCjs 1.9.20 [Grbl]
Connected to COM7 with a baud rate of 115200
Grbl 1.1h ['$' for help]
$0=10 (Step pulse time, microseconds)
$1=25 (Step idle delay, milliseconds)
$2=0 (Step pulse invert, mask)
$3=0 (Step direction invert, mask)
$4=0 (Invert step enable pin, boolean)
$5=0 (Invert limit pins, boolean)
$6=0 (Invert probe pin, boolean)
$10=3 (Status report options, mask)
$11=0.010 (Junction deviation, millimeters)
$12=0.002 (Arc tolerance, millimeters)
$13=0 (Report in inches, boolean)
$20=0 (Soft limits enable, boolean)
$21=1 (Hard limits enable, boolean)
$22=0 (Homing cycle enable, boolean)
$23=0 (Homing direction invert, mask)
$24=25.000 (Homing locate feed rate, mm/min)
$25=500.000 (Homing search seek rate, mm/min)
$26=250 (Homing switch debounce delay, milliseconds)
$27=1.000 (Homing switch pull-off distance, millimeters)
$30=17000 (Maximum spindle speed, RPM)
$31=3000 (Minimum spindle speed, RPM)
$32=0 (Laser-mode enable, boolean)
$100=50.000 (X-axis travel resolution, step/mm)
$101=50.000 (Y-axis travel resolution, step/mm)
$102=50.000 (Z-axis travel resolution, step/mm)
$110=500.000 (X-axis maximum rate, mm/min)
$111=500.000 (Y-axis maximum rate, mm/min)
$112=500.000 (Z-axis maximum rate, mm/min)
$120=50.000 (X-axis acceleration, mm/sec^2)
$121=50.000 (Y-axis acceleration, mm/sec^2)
$122=50.000 (Z-axis acceleration, mm/sec^2)
$130=400.000 (X-axis maximum travel, millimeters)
$131=400.000 (Y-axis maximum travel, millimeters)
$132=150.000 (Z-axis maximum travel, millimeters)
We will only focus on the 4 most important parameters.
First the parameter "$ 1 = 25", this is the parameter which will indicate to GRBL after how long it has to shut down (de-energized) the motor after a movement. The unit of this parameter is the millisecond.
By default, after a movement, the motor is switched off after 25ms.
A powered motor will force to keep its current position, if it is switched off, it will exert no force to keep its position and can turn very easily.
Take the example of the Z axis which raises / bring down the router. When cutting a wood sheet, the Z axis motor will bring down the cutter into the wood, then will remain in its position throughout the cut. This is where we begin to understand the problem.
If the motor go down to the right position and then turns off, since it does not apply any force to maintain its position, it will most likely "slide" lower due to the vibrations during milling!
To correct this problem, just set 255 to the $1 parameter. GRBL considers 255 to be an infinite time so it will never switch off the motors even after a movement. Warning, from 1 to 254, GRBL will take the parameter as milliseconds, only the value 255 is considered to be infinity.
So we will simply type this line in the console:
The second parameter is the group "$100", "$101" and "$102". This is the displacement resolution for each axis (X Y and Z in order).
The displacement resolution is expressed in steps per millimeter, it is the number of steps that the motor must do to move our machine by 1mm.
To calculate the resolution, we need:
- The number of steps of our motor (in our case it is 200)
- The micro-stepping mode chosen, this is where it is very important (in my case 1/32)
- The machine guidance system (in my case trapezoidal leadscrews, 8mm per revolution)
On my machine I use DRV8825 and trapezoidal screws making 8mm nut displacement each time the screw makes 1 turn.
Here is an example of calculation of the resolution based on the values of my machine:
(200steps (Nema17) x 32 (micro-stepping)) / 8 (trapezoidal leadscrew) = (200 x 32) / 8 = 800 steps / millimeter
We will make a second example for a GT2 belt machine. These are the classic belts used in 3D printing, they have a pitch of 2mm per tooth. We will also say that the engine is equipped with a 20-tooth pulley and that we use an A4988 in 1/16 microstepping.
So here is the calculation:
(200steps (Nema17) x 16 (micro-stepping)) / (2 (belt pitch) x 20 (number of pulley teeth)) = (200 x 16) / (2 x 20) = 80 steps / millimeter
We will therefore enter this value at GRBL (in my case 800):
With this value that we can calculate the accuracy achievable (theoretical) by our machine by dividing 1 millimeter by the number of steps:1mm / 800steps = 0,00125mm
1mm / 80steps = 0.0125mm
The third parameter is the group "$110", "$111" and "$112". It is the maximum displacement speed for each axis (X Y and Z in order).
The fourth parameter is the group "$120", "$121" and "$122". It is the acceleration for each axis (X Y and Z in order).
The speed is expressed in mm / min, literally "how many millimeters will the machine travel in 1 minute"
The acceleration is expressed in mm / sec², roughly the greater is the value entered here, the greater will be the acceleration.
These two values will depend a lot on your machine, its weight, its size and the type of machining you were going to perform (a laser engraving accept higher acceleration and a speed much higher than a wood cut for example)
So I cannot give you the perfect values for your machine ... You will have to experiment!
I can still give you an example to have starting parameters for your tests:
On my machine which is large, heavy and which cuts mainly wood, I have 2000mm / min in speed, and 200mm / sec² in acceleration:
And here this is the end ! I will soon make a new article on "how to generate a machining file for a CNC under GRBL." stay tuned and tell me in comment what you think about this article and which article you would like for the next time !
See you next time !