# How do GCode and MCU interact?

**URL:** <https://klipper.discourse.group/t/how-do-gcode-and-mcu-interact/18509>\
**Category:** Developers\
**Created:** [August 28, 2024, 2:06am UTC](https://klipper.discourse.group/t/how-do-gcode-and-mcu-interact/18509 "2024-08-28T02:06:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Flander](https://avatars.discourse-cdn.com/v4/letter/f/8c91f0/32.png) [@Flander](https://klipper.discourse.group/u/Flander)\
**Post date:** [August 28, 2024, 2:06am UTC](https://klipper.discourse.group/t/how-do-gcode-and-mcu-interact/18509/1 "2024-08-28T02:06:40Z")

</div>

How to call the function in mcu.py after processing the gcode command with the \_process\_command function of gcode.py?

---

<div class="post-metadata">

**Author:** ![3dcoded](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/3dcoded/32/20297_2.png) [@3dcoded](https://klipper.discourse.group/u/3dcoded)\
**Post date:** [August 28, 2024, 10:32am UTC](https://klipper.discourse.group/t/how-do-gcode-and-mcu-interact/18509/2 "2024-08-28T10:32:44Z")

</div>

I’m not entirely sure what you’re trying to do, but if you’re trying to run GCode commands from a Klippy extra, [here](https://3dcoded.github.io/DynamicMacros/extras/extras-intro/#the-gcode-object) is a tutorial. If you’re trying to run a function when a certain GCode command is run, [here](https://3dcoded.github.io/DynamicMacros/extras/extras-ex1/#initializer) is an example of how.

---

<div class="post-metadata">

**Author:** ![Flander](https://avatars.discourse-cdn.com/v4/letter/f/8c91f0/32.png) [@Flander](https://klipper.discourse.group/u/Flander)\
**Post date:** [August 29, 2024, 12:27am UTC](https://klipper.discourse.group/t/how-do-gcode-and-mcu-interact/18509/3 "2024-08-29T00:27:51Z")

</div>

The complete process of calling gcode commands and how do gcode threads interact with serial threads?

---

<div class="post-metadata">

**Author:** ![BevanWeiss](https://avatars.discourse-cdn.com/v4/letter/b/c5a1d2/32.png) [@BevanWeiss](https://klipper.discourse.group/u/BevanWeiss)\
**Post date:** [August 30, 2024, 11:37am UTC](https://klipper.discourse.group/t/how-do-gcode-and-mcu-interact/18509/4 "2024-08-30T11:37:06Z")

</div>

When the GCode command is parsed if it matches your registered command, then it will call your method for it.  
Like this…

> <https://github.com/Klipper3d/klipper/blob/f71d2c7cfc97d3e7964403463e513ac7f9b90050/klippy/extras/bed_screws.py#L64>

So when ACCEPT is called from the console, or gcode, then it will call the cmd\_ACCEPT function.

It’s up to this function to decide whether it will call one of the pre-configured mcu commands. If it does decide to send something to the MCU, it would do it like this…

> <https://github.com/Klipper3d/klipper/blob/f71d2c7cfc97d3e7964403463e513ac7f9b90050/klippy/extras/bus.py#L193>

Or it might just call a higher level function like the i2c read/write stuff… or the spi stuff… which will in turn call its own mcu interfacing commands.
