Duet 2 CNC Controller – Part 2

#54 Setting Up External Triggers / Push Button / E-Stop & Pause Failsafe’s

In this video I go over how I set up the external triggers with push buttons switches for the Duet 2 Wifi. I focus on the e-stop and pause functions, which I ensure have failsafe’s to prevent the machine being operated if those buttons were to become disconnected. I share how I set up the relevant files and prattle on about other random things.

  • 00:00 – Introduction
  • 02:06 – The Funny Bit
  • 02:35 – Changes From Previous Video
  • 03:20 – External Triggers
  • 03:45 – Normally Closed Buttons
  • 04:52 – Config.g & Trigger#.g Files
  • 06:54 – The Failsafe
  • 08:20 – Normally Open Buttons
  • 09:22 – What’s Next

I’ve put so many screw in this floor and it still creeks. So I’ve jumped a little ahead here – I’ve added my proximity sensor my buttons. I’ve also got my LED strips here and I’ve done quite a bit of work on the config file, and other files in the system directory on the Duet 2. I still haven’t connected my additional power supply which will power up the laser but I’m not quite there yet. I still have other things to do. I’ve also managed to drop my tangential knife and crack it on the edge there. It’s a miracle it didn’t crack any more, so I will need to print another one of these.

So a few things have changed. I’ve changed how I’ve set up the barrier blocks. I’m also going to use a combination to two LED strips because I found that the yellow light just didn’t look good enough when it was a combination of green and… blue? How to make yellow? Sorry green and red.

My art credential may have flushed down the toilet there –

but yellow is a primary colour and normally comes in tube – and I’m not a painter, and learnt the lessons of a sculptor who only understood the world by touch and sometimes breaking parts of it.

In this video I want to talk about the inputs to the duet 2 when setting it up for CNC, and I’ve mentioned some of these already such as the external trigger buttons and touch probe but there are others – some are essential like the end stops for homing and others are optional like a door enclosure switch. But I will focus on the external triggers for now which includes the art stop or e-stop, pause and resume and in fact anything you want to write in the external trigger file which can be called when a push switch is pressed.

This controller is still in the testing stage, and I also updated to the latest beta version of the reprap firmware – at the time of filming which was 3.2beta2, and want to make sure everything is behaving as I expect before transferring to the enclosure where my life will get more difficult – because I’ll be confined in a box, in a box, in a box, in a round box. So before I mention the changes from the previous video just a reminder that there are links to time codes in the description for this video – and along the timeline itself so you can find relevant sections more easily.

The main changes from the previous video are that I had to move the relay module triggers from the PWM fan headers to the thermistor ones. This was because the latest version of the firmware had replicated the starting or booting behaviour of fan1 onto fan 2. This would have resulted in one of the relay modules momentarily turning on during start-up and caused whatever was plugged in – like an extractor, to briefly turn on.

That said I then realised the temp headers were still doing the same thing, but not enough current to turn the relay on… but could turn it on if ground potential changes for some reason. I am now going to have to beg the programming priests on the duet forum to revert this behaviour, or share how to edit the bootloader on the duet 2 – which I think you can do on the duet 3 via the web interface but not on the duet 2 at the moment.

I also changed how I wired the buttons for the external triggers – on screen you can see from the previous video the 24v power looping to what will be the five trigger terminals pairs – which I’ve now changed using two 24v and three grounds, which go to two active high and three active low inputs on the 8 channel relay module.

I’ll start with this and talk about how they work and show you the relevant codes in the system directory. The 24v power loops to normally closed push switch. When the switch or button is connected and system powered, the relay energises and remains in that state until the button is pushed, and the circuit opens.

On the opposite side of the relay I’ve connected the I/O and ground pins from duex.e2stop to the normally open and common terminals. Remember when powered the relay is energies so the NO terminal is actually closed. I’ve done this for two of the external triggers while the other three are set up differently. I’ll now show you the relevant code in the config.g file and focus on those two buttons for now. I set up the pin using M950 and labelling the GPIO J1 assigning this to the pin name which was duex.e2stop. The J parameter during M950 refers to input pins while P to output, F for fan, H for heater. I then configured the external trigger so T0 or trigger 0 which calls an M112 emergency stop, is assigned to GPIO 1 or P1, and for the trigger to occur on the inactive-to-active edge of the signal, and for this to occur at any time the machine is on R0. If I want to the external trigger to only occur when a job is running I change this to R1.

Each input pin triggers an associated trigger file. On the Duet, the T0 external trigger refers to an M112 emergency stop, T1 to a M25 pause, while T2, T3 and onwards refers to files in the system directory labelled trigger2.g, trigger3.g etc. And you can write whatever combination of gcode you want in those.

I have connected a raise red button to use with the T0 emergency stop, because the estop should be the most accessible button when thinking about risk and how to avoid it. The flat yellow button operates the T1 pause, although I wrote a new pause script and called it T6 changing the behaviour so a single press pauses the job, and a second press cancels the job.

Where it gets confusing, is I have the relay module in-between the push buttons and the duets inputs pins, and that there are two different methods of triggering on either side to consider. The push button with its normally closed switch triggers from the active to inactive – but the opposite end of can be either active to inactive, or inactive to active.

If I pull out the estop cable either before or after the 8-channel relay module while the machine is on – it will be read as a trigger and alarm. I’ve wire them in a way that provides safety failsafe features, and prevents the machine from operating if the trigger connections and something as critical as an emergency stop or pause are broken or disconnected. But if I reset the controller while the said wires are disconnected, I’d eventually accessed the web interface where I could use the machine – without the estop working.

To get around this I created a conditional script that is called into the config.g file during start-up that queries the pins state. That can be either 1 or 0. 1 is triggered or active, and 0 is untriggered or inactive – which I can check with an M409 K”sensors.gpIn[0]”

While the pin value of General purpose input 0 is 1, display message and option S2 response displaying only an “OK” blocking progress. If I now disconnect the estop and reset the controller, when I get to the web interface, the config.g file has loaded the conditional script which detects that the estop is disconnected – forcing me to addressed the error and preventing me operating the machine.

I also set up the same condition to check the pause button. The three other buttons use active low triggers and normally open contact blocks. This results in the relay module only switching when the buttons are pressed, and the circuit goes from open to closed. One will be for an external trigger to resume from a pause, and the other two are will toggle the output relay module for the dust extractor and air filter. Simply put, you don’t want to find out your estop doesn’t work when you have to press it – because the risk of danger if that fails is high so I’ve wire those button to include additional protection to prevent that failing unnoticed. But it doesn’t matter so much for the other buttons, because their functions are less dangerous if they were to fail.

I’ll gloss over the possibility that the relay’s modules themselves might fail during the on states, which means all this might be for nothing but I’ve got a massive flap in front of my power button and that will be about 400mm away from the e-stop.

Essentially the other inputs like the touch probe, the proximity sensors for the axes and this thing here which I’ve been using as a surrogate door switch which is closed in this state and open in this state – all work with the same principles. They are set up in slightly different ways because eg these inputs are linked to individual stepper motors and it makes more sense if talk about those in relation to these and to show you how I set the motors up as well. In a separate video.  I’ve also made some progress with setting up new macros to automate the tool height process using the stationary touch probe – again that’s a lot of information to share so that’ll be another video. I’ve also finally worked out how to toggle the relays on and off using a single button. So I’m going to cut this video short. I know I said I was going to few other things in it but there’s no point – it would make the video too long, and I’d probably make mistakes in it and some other things will probably change along the way. I’m at a good stage with this and feel like I’m very close to moving it over into the enclosure but I want to do a few more things to make sure that I  don’t have to do any fiddley things  while it’s in there.