Duet 2 CNC Controller – Part 3

In this video I’m going to talk about the stepper motors which drive the different axes, and their associated limit switches for homing.

Homing a CNC machine at start-up is probably the most important part of what makes a CNC machine a versatile tool. That processes defines the G53 machine positions for the different axes – setting their maximum and minimum locations. Those provide the reference points for all other movements. If for some reason the limit switches are adjusted – this can have a knock-on effect on subsequent movements, work coordinates and macros. In my case macros which would be affected include locating the stationary probe, and the dual y-axis homing which squares the y axis to the x axis.

When the machine turns on the LED lights on the proximity limit switches also remain on. These are Normally Closed sensors, but Normally Open ones will also work. When a metal object is detected in front of the sensor the circuit is opened and the light goes out. This is read as a signal by the relay module which I’m using to create a logical connection between the sensors and controller.

The Relays are held in an energies state while powered, and those lights also go out as the proximity sensors are triggered.

The pin from the controller for the different axes are wired via the Normally Open and common relay terminals, which when everything is powered is closed. In essence at all three points when the sensor is not triggered the lights remain on and then triggered the lights turn off.

Before you can home and move the axes, you need to setup the stepper drivers and limits switches in the config.g file within the system directory. To set up the steppers you will need to address the following commands with the relevant information based on your stepper motors and CNC machine configurations.

M569 sets the motor driver direction. P refers to the driver and S0 or 1 refers to the direction – of which there are two. Either clockwise or anticlockwise.

I’ll briefly explain how to install the steppers. You will be using steppers with four wires of which there are two pairs to the motor coils. You can identify the pairs by the documentation from your supplier or by holding the exposed ends of two wires together and trying to turn the motor shaft. If you feel resistance you have a pair. Those are then wired to the relevant terminals – of which these are labelled 1B, 1A, 2A, 2B… or not to be. My stepper motors happen to correspond with the colours that are on the diagram, but you may find cheaper steppes do not – and the method I just described will help in that situation.

For instructional on crimping the terminal ends see the first video in this series.

M584 maps the drives to the axis they will be used for. Note I have two additional drives for my Moot_One three-axis CNC machine. U is an experiment with a tangential knife, and V is the second Y axis. Drive 1 & 4 are mapped to the Y axis, and the P4 at the end reveals the number of axes in the web interface.

M350 sets the micro-stepping and interpolation. The higher the microstepping the quieter the motors will be at the expense of torque. For CNC use which requires high torque to overcome the resistance of cutting into materials, it’s not advised to use interpolation.

M906 sets the current to the drivers – see your stepper drivers’ documentation for correct values. However you typically set this to 80% within the config file. I’m currently using Nema 17 for the test rig but on my CNC machine I will have 3amp motors which I set to 2.4amps or 2400miliamps, which is the max that the duet 2 can supply. The “I” value sets the motor current Idle factor in percentage – which reduces the current to the motors during the machines idle state – saving power and preventing heat build-up.

M92 sets the steps per mm – which is what configures the rotational movement of the steppers to equate to distance moved along the axes. There are calculators online to work that out and that dependent on your lead or ball-screw pitch dimensions.

M566 sets the max instantaneous speed change which effects whether your machine will rattle itself apart or become too slow when cutting curves.

M203 sets the maximum speed or feed-rate used when moving with a G0 rapid move – This is useful to do so you don’t accidently overdrive your axes and physically damage components.

M201 sets the acceleration of which the higher the number the quicker the steppers get to their allotted speeds.

M208 sets the max and min axis travel, and the software limits within the G53 machine position. This prevents the machine from overshooting those coordinates and crashing, and depending on how you set up your homing cycles you’ll either moving to the max or min and the appropriate values are set when to the limit switches are triggered.

Now for the limit switches.

M574 configures the endstops to the axis, so the motor and switch are linked. The number next to the axis letter refers to which end of the axis the endstop is positioned – so either 1 at the low end or in my case 2 at the high end. S refers to the switch-type where 1 is an endstop input physically connected to the control board. P refers to the pin name which you can find in the RRF version 3 overview. If I wanted to invert the pin’s behaviour I would use an exclamation mark before the name.

You can read more about these and other functions on the Duet G code library. lAnd I’ve only mentioned a brief range of the things you can do focusing on my particular setup, so it’s worth doing additional research before building your controller.

Now before I go on, I’ll just make a note here that I’ve swapped over from the Ooznest Workbee Web Controls which were last updated in 2019, to the latest Duet Web Controller which has a custom layout for CNC mode. I’m also filming these screen captures with my spare Duet controller at my flat during lockdown in early 2021 – so I’m matching old video footage with new screen capture.  So I apologies if I make any mistakes along the way – and I’ll try maintain the illusion.

To home your axes you will need the relevant firmware macros in the system directory – the full list of which can be found at the duet 3d website which I’ll link to in the description.

The files called when homing include homeall.g, homex.g, homey.g and homez.g. I also have a homeu.g for my tangential knife which I’m still working on.

I’ll begin with the z axis homing cycle which is often the first movement while homing on a CNC machine because this clear the spindle from material and the wasteboard – preventing the spindle or tool from knocking into anything in its way.

All my homing macros begin by calling condition4.g into the homing macro with an M98 command. The condition checks the status of the end-stops. This is a safety feature which will prevent the machine from homing if the end-stops are already triggered or if the end-stops have been disconnected.

I lifted this script itself from the duet forum which posted by OwenD, with only a minor change to the abort message.

We know from earlier that the different axes are mapped numbers. X0 Y1:4 Z2 U3 V which is the second axis when separated during the homing cycle, is 4.

While iterating across all the endstops available, if any iteration of endstops is triggered – no matter which axis is being homes, display message indicating the drive number that is triggered, and abort displaying a message containing all the drive numbers and their axis for reference.

After which G21 ensuring the units are set to mm, and G91 swaps over to relative positioning or incremental movement. This makes all movement relative to the last.

G1 H1 Z190 F1000, Perform a speed controlled move of the Z axis, 190mm in the positive direction, with a speed of 1000 mm/min, and terminate the move when the endstop is triggered.

Perform a speed control move of the Z axis in the negative direction 10mm at a speed of 800 mm/min. Perform a second pass, slowly towards the Z axis endstop. Set current machine position to Z0. Rapid move with no specific action clearing proximity sensors. G90 returns to absolute positioning will now reference the new zero coordinate for movement for both the machine position and subsequent work coordinates for movement for both the machine position and subsequeny work coordinates. G4 P1000 performs a dwell for one second and M500 save current parameters.

The other homing cycles work in a similar way apart for homeall.g and homey.g, which includes an M584 Drive Mapping command. That splits the Y axis to Y and V, and maps them to the drives 1 and 4. P5 reveals all the axes in Web Controller although this was not necessary for dual axis homing to work, and is just a visual indicator of what’s going on. These are then homed individually, and the standoff distance is worked out to square the X and Y axis – which on the current machine worked out to 0.4mm difference between the two sides of the Y axis. And the important thing to remember is at the end of the homing cycle, is to map the drives back together into a single Y axis uses drive 1 and 4. And P4 hides the V axis from the web controls.

Now if I hold a metal object in front of any limit switch, which is simulating either the limit being triggered or the cabling being damaged or some link being unplugged, I start any of the homing cycles, these types of error messages on screen. Which I can then use to identify the axis by the drive number and investigate.

The only problem I can envisage is with the tangential knife, that could be stopped at an angle where the internal proximity sensor is triggered – and if the machine starts the code in condition4.g will probably interpret will as an error . But I’m filming with on my kitchen table so that’s something to think about later. Maybe I may need a start-up procedure to de-trigger the sensor for the U Axis.

Anyway I’ll end the video here with a montage of the stepper motors homing, I’ll leave some useful link in the description below. Thanks again for all my patreons for their support, don’t forget to sacrifice a thumb which basically means press the like button – that helps this video thwart the pesky algorithm gods, stay safe and you’ll catch me in the next one.