Triggering a macro with foot switch



  • I have an unusual task to complete. I want to trigger a macro with a foot switch. I have a small CNC machine for PCB milling and drilling controlled by Duet WIFI, which is working fine, but I want to make a simple mod to drill single holes in PCB with both hands free. The macro should enable Z axis to go below 0, set moving speed and move Z 2mm down and back and should be triggered by foot switch. How do I connect the switch and what the code should be for the macro? Any help will be highly appreciated. I'm running firmware 2.05 on a Duet WIFI.



  • Connect it like any other micro switch used as a endstop and use M581 to trigger the macro.



  • as for what the code should be; you say enable z to go below 0? presumably you mean to drill through your stock, but if below 0 is outside the movement set for the machine by m208 you should consider other options. if not going below 0 isn't something that needs enabling.



  • Thanks a lot for your reply, i'm very familiar with all kind of hardware, but codes, commands and macros are realy not my strenght. By enable Z to go below zero I mean that I have a macro for zeroing all axis at a current pozition and switch to work coordinates and the foot switch macro will run after I zerowed xyz and this 2 mm will be -2, below zero, into my stock as you said. I would appreasiate some sample code, realy don't know where to start. Lets say I connect the switch to my x endstop, what shall the code be looking like?


  • Moderator

    If you have a spare endstop switch you can connect it to an open endstop connection.

    Then you can create a macro with what you want to happen.
    Then you create an M581 command in your config.g to associate that endstop triggering to that macro.

    The details are mostly in the M581 documentation.

    Your macro would be called trigger1.g

    M581 E1:2 S1 T2 C1

    The values used there are going to depend on what you want to happen.

    It gets a bit more logical and flexible when using RRF3, but since you're on 2.05 we can work with that.



  • Shouldn't the macro be called trigger2.g in this case?



  • @Pakue said in Triggering a macro with foot switch:

    Shouldn't the macro be called trigger2.g in this case?

    It most certainly should. From the Wiki (quote).........

    "Trigger number 0 causes an emergency stop as if M112 had been received. Trigger number 1 causes the print to be paused as if M25 had been received. Any trigger number # greater than 1 causes the macro file sys/trigger#.g to be executed."

    So the macro needs to be trigger >1 (i.e 2 or above).



  • Thank you all so much, I'll start with that and report back later.



  • @Valld said in Triggering a macro with foot switch:

    By enable Z to go below zero I mean that I have a macro for zeroing all axis at a current pozition and switch to work coordinates and the foot switch macro will run after I zerowed xyz and this 2 mm will be -2, below zero, into my stock as you said.

    if you switch to work coordinates first then zero them, you should again always stay in positive machine coords?

    anyways, if you need to ignore the machine limits use M564 S1 at the top of your macro and M564 S0 at the bottom

    The just use something like making sure the relative Z motion is in the correct direction and replace slow and fast with actual feed rates.

    M120
    G91 G1 Z-2 Fslow
    G91 G1 Z2 Ffast
    M121
    

    (using relative moves you don't need to zero and switch work coordinates btw, push and pop will restore to absolute moves if that was in use before)


Log in to reply