Intro: Two Axis CNC
I built this two axis cnc-machine to use as a lazer-engraver. I'm waiting for the lazer at the moment, so this insutructable will be continued. For The first time I would like to show you how I wired all my components.
Step 1: Hardware
For the power supply, I use an old PC-Power-Supply with 16A. For the wiring I use 0.125mm (5V) and 1.5mm (12V 6A) cooper braid. The wiring is easy and done fast. The hardest part was to shield the wires from the motors. This was done by using aluminum foil around the wires and to insert an RC-Low-Pass-Filter between my limit switches and the input pins of the Arduino.
This sounds way more complicated than it is. Its just a resistor and a capacitor. Because I use grl, I can use the pull-up-pin-mode to get the resistor, so I just needed a capacitor. Grbl is using pull-up-pin-mode because this causes less distortion for the switches. That means, the switches do not forward +5V, they forward GND and the pins are pulled down from 5V to GND by triggering the switches. This capacitor should be something between 10uF and 0.47uF depending on the distortion. In my case I use a .47uF (50V) for the Y-axis and a 1uF (50V) for the X-axis. These small capacitors a polarised, so watch out to connect the GND part to GND, and plus to the limit-switch and the input pin.
This RC-Low-Pass-Filter filters our the signals with high frequency. So just low frequencies can pass through. That means your limit-switch signal is slower (you can not recognise without oscilloscope), but you do not read the distortion.
Step 2: Software
I use the grbl library to control the Arduino with simple G-Code.
- Download all the code from github/grbl.
- Download the config.h file I added underneath.
- Replace the config.h in grbl/grbl with my file (I used the file from MichielD99 and adjusted it to work properly with 2-axis)
- Pack the grbl folder (which is including the config.h file) to a ZIP-file.
- Goto your Arduino ide.
- Add the ZIP-file to the Arduino libraries.
- Remove the whole code of your sketch.
- Include the grbl library. (So you just have includes in your sketch)
- Compile and Flash to your Arduino.
To send G-Code to the Arduino I use the old Grbl-Controller. Some of the functions do not work properly. To change the settings you have to use the $ commands because the grbl-library changed and the controller is really old. But it works for sending G-Code and moving the axis.
Before the first use, we have to configure our Arduino with the machine-specific data. We have to adjust the steps per mm for our axis, if we want to use limit-switches and so on.
Todo so, enter the command $$, in the Command input field in the grbl-controller, to get a list of the possible settings. We have to enable the hard-limit-switches. This is done by entering $5 = 1. Now adjust all the other settings for your needs. In my case I just had to adjust the steps per mm for both axis ($100 and $101). For better homing behaviour you can also adjust the homing feed rates...
After the configuration is done, enter $H in the command-field to start the homing-cycle for the machine. The machine should move each axis to the limit-switches twice. Once with fast and once with slow moving axis. (Depending on your configuration). After the machine did that, this are your zero-coordinates of your machine.
Now you are ready to generate some G-Code and load it into the Grbl-Controller.
Note: You always should do a homing ($H) and zero (by clicking the zero button) before starting any G-Code to get a proper result.
Step 3: Adaption
If you want to use this tutorial with a PWM-Signal to run your spindle or laser, leave all settings as they are. If you want to use a relay or just on / off your spindle or laser you have to change something in the config.h.
For on/off usage
// #define VARIABLE_SPINDLE
So just comment it out. After that you are able to use the Arduino pin 12 as an on/off for your relay.