# Gcode button, odd behaviour, interaction with macro. Bug?

**URL:** <https://klipper.discourse.group/t/gcode-button-odd-behaviour-interaction-with-macro-bug/10475>\
**Category:** General Discussion\
**Created:** [September 14, 2023, 9:17pm UTC](https://klipper.discourse.group/t/gcode-button-odd-behaviour-interaction-with-macro-bug/10475 "2023-09-14T21:17:28Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![CityWrecker](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/citywrecker/32/1742_2.png) [@CityWrecker](https://klipper.discourse.group/u/CityWrecker)\
**Post date:** [September 14, 2023, 9:17pm UTC](https://klipper.discourse.group/t/gcode-button-odd-behaviour-interaction-with-macro-bug/10475/1 "2023-09-14T21:17:28Z")

</div>

### Basic Information:

Printer Model: Voron 2.4, Pi4a,  
 MCU / Printerboard: Spider 1.1  
 `klippy.log`  
…  
[klippy.log](https://klipper.discourse.group/uploads/short-url/r40cQfr2R6TxHWqErcHUdM9H24Z.log) (1.4 MB)

I’m seeing odd behavior from a G-Code button, that seems to depend on some aspects of the macro, potentially simply the length?

So,

1. pressing the button will trigger the macro and the macro will complete.
2. then on pressing the button again nothing will happen, unless there is a release g code specified, in which case the release g code will play when the button is pushed a second time
3. Then after pushing the button a third time the macro will play through and the cycle will start again.

After debugging it appears that it’s potentially even simply the length of the macro that will produce this odd behavior. I will include two versions of a very similar macro the first does not create the issue the second does.

Pull-up, or inversion don’t appear to have anything to do with the issue. Neither does the board pin, i’ve tried different pins. Also commenting out release\_gcode entirely has no effect. It also doesn’t seem to matter if the button is triggering a macro or the code directly.

Is this potentially a bug? None of this occurs triggering the macro from the Mainsail interface.

…  
[gcode\_button F\_PURGE\_BUTTON]  
pin:^!PA3  
press\_gcode:  
FIL\_PURGE

release\_gcode:  
M117 Released  
…

```auto
[gcode_macro FIL_PURGE] (Button works as expected)
gcode:

  {% if printer.extruder.temperature > 50.0|int %} ; Nozzle temp based 
  {% set varix = (range(0, 25) | random) + 35 %} ; x = to random between 35-55

 STATUS_HEATING
 M204 S7000 
 G91 ; relative for lift 
 G1 Z3.00 ; Raise before move Purge XY
 G90 ; Absolute for move 
 G1 F24000 X{varix} Y359.3 ; Move to Purge XY
 G1 Z8 ; Move to Purge Z
 M117 Filament down

 G1 Z5.75 ; Move to Purge Z
 G1 F8000 X75 Y359.3 ; Move to Purge Z	

 G0 X125 F14000 ; Wipe back
 G0 X75 F14000 ; Wipe forth

    {% else %}
 M117 Too Cold! 209C                   
         {% endif %}

```

```auto
[gcode_macro FIL_PURGE] (Button exhibits behaviour described above)
gcode:

  {% if printer.extruder.temperature > 50.0|int %} ; Nozzle temp based 
  {% set varix = (range(0, 25) | random) + 35 %} ; x = to random between 35-55

 STATUS_HEATING
 M204 S7000 
 G91 ; relative for lift 
 G1 Z3.00 ; Raise before move Purge XY
 G90 ; Absolute for move 
 G1 F24000 X{varix} Y359.3 ; Move to Purge XY
 G1 Z8 ; Move to Purge Z
 M117 Filament down

 G1 Z5.75 ; Move to Purge Z
 G1 F8000 X75 Y359.3 ; Move to Purge Z	

 G0 X125 F14000 ; Wipe back
 G0 X75 F14000 ; Wipe forth
 G0 X125 F14000 ; Wipe back
 G0 X75 F14000 ; Wipe forth
 G0 X125 F14000 ; Wipe back
 G0 X75 F14000 ; Wipe forth
 G0 X125 F14000 ; Wipe back
 G0 X75 F14000 ; Wipe forth
 G0 X125 F14000 ; Wipe back
 G0 X75 F14000 ; Wipe forth
    
   {% else %}
 M117 Too Cold! 209C                   
         {% endif %}

```

---

<div class="post-metadata">

**Author:** ![EddyMI3D](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/eddymi3d/32/1981_2.png) [@EddyMI3D](https://klipper.discourse.group/u/EddyMI3D)\
**Post date:** [September 14, 2023, 9:35pm UTC](https://klipper.discourse.group/t/gcode-button-odd-behaviour-interaction-with-macro-bug/10475/2 "2023-09-14T21:35:04Z")

</div>

Over 5000 lines of printer.cfg? All written yourself?  
2000 lines of these are just bed meshes 🙄

Can’t imagine someone will dig through all of this.

---

<div class="post-metadata">

**Author:** ![theophile](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/theophile/32/31_2.png) [@theophile](https://klipper.discourse.group/u/theophile)\
**Post date:** [September 15, 2023, 12:49pm UTC](https://klipper.discourse.group/t/gcode-button-odd-behaviour-interaction-with-macro-bug/10475/3 "2023-09-15T12:49:30Z")

</div>

Have you tried tossing an ‘M400’ in there after all the ‘G0’ commands?

---

<div class="post-metadata">

**Author:** ![CityWrecker](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/citywrecker/32/1742_2.png) [@CityWrecker](https://klipper.discourse.group/u/CityWrecker)\
**Post date:** [September 15, 2023, 2:37pm UTC](https://klipper.discourse.group/t/gcode-button-odd-behaviour-interaction-with-macro-bug/10475/4 "2023-09-15T14:37:52Z")

</div>

No I haven’t. It should go after the series of wipe (back and forth) moves?

---

<div class="post-metadata">

**Author:** ![theophile](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/theophile/32/31_2.png) [@theophile](https://klipper.discourse.group/u/theophile)\
**Post date:** [September 15, 2023, 3:27pm UTC](https://klipper.discourse.group/t/gcode-button-odd-behaviour-interaction-with-macro-bug/10475/5 "2023-09-15T15:27:46Z")

</div>

That’s where I’d try it first. If that doesn’t change anything, try moving it around or even adding additional ones. It may have no effect but it’s an easy thing to try.

---

<div class="post-metadata">

**Author:** ![CityWrecker](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/citywrecker/32/1742_2.png) [@CityWrecker](https://klipper.discourse.group/u/CityWrecker)\
**Post date:** [September 15, 2023, 4:44pm UTC](https://klipper.discourse.group/t/gcode-button-odd-behaviour-interaction-with-macro-bug/10475/6 "2023-09-15T16:44:32Z")

</div>

> [@theophile](#):
>
> M400

If I put an M400 at the end of the wipe series the button stops working completely after the first press. It even stops working when triggered from Mainsail interface rather than the button. Maybe this is indicative of why this odd behaviour is happening?

But other than that it didn’t solve the issue. If i move it around and even try it in a few places I can see the macro pausing before it carries on. But the odd button behaviour described in the first post persists.

---

<div class="post-metadata">

**Author:** ![theophile](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/theophile/32/31_2.png) [@theophile](https://klipper.discourse.group/u/theophile)\
**Post date:** [September 15, 2023, 5:08pm UTC](https://klipper.discourse.group/t/gcode-button-odd-behaviour-interaction-with-macro-bug/10475/7 "2023-09-15T17:08:35Z")

</div>

Hmmm, that’s interesting. What if you put it in the press\_gcode: section instead of the macro itself? Or even the release\_gcode: section for that matter?

---

<div class="post-metadata">

**Author:** ![CityWrecker](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/citywrecker/32/1742_2.png) [@CityWrecker](https://klipper.discourse.group/u/CityWrecker)\
**Post date:** [September 15, 2023, 5:20pm UTC](https://klipper.discourse.group/t/gcode-button-odd-behaviour-interaction-with-macro-bug/10475/8 "2023-09-15T17:20:12Z")

</div>

Ahh, interesting…Ill try it out.

---

<div class="post-metadata">

**Author:** ![CityWrecker](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/citywrecker/32/1742_2.png) [@CityWrecker](https://klipper.discourse.group/u/CityWrecker)\
**Post date:** [September 15, 2023, 7:30pm UTC](https://klipper.discourse.group/t/gcode-button-odd-behaviour-interaction-with-macro-bug/10475/9 "2023-09-15T19:30:31Z")

</div>

Same behaviour. But good idea for a test, for sure. Not sure what to conclude from this though.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/klipper/original/1X/64419bf2aac6639e6ef5cef200dcd456b0a01ac3.png) [@system](https://klipper.discourse.group/u/system)\
**Post date:** [November 14, 2023, 7:31pm UTC](https://klipper.discourse.group/t/gcode-button-odd-behaviour-interaction-with-macro-bug/10475/10 "2023-11-14T19:31:09Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
