<blockquote>
  <p>Which section handles G-code processing?</p>
</blockquote>

<p>In Marlin Firmware, G-code is processed by procedure <code>void process_parsed_command()</code> in file <a href="https://github.com/MarlinFirmware/Marlin/blob/bugfix-1.1.x/Marlin/Marlin_main.cpp" rel="nofollow noreferrer"><code>Marlin_main.cpp</code></a></p>

<blockquote>
  <p>I need to generate an additional digital output</p>
</blockquote>

<p>A G-code that is able to set a port value is <a href="https://reprap.org/wiki/G-code#M42:_Switch_I.2FO_pin" rel="nofollow noreferrer"><code>M42</code></a>.</p>

<p>You could write a procedure that schedules  certain port after a <code>G0</code> or <code>G1</code> move, recompile and upload the firmware.</p>

CC BY-SA 4.0
2019-04-19T08:29:52.103Z
If I edit gcode_G0_G1() function in the marlin_main.cpp and write direct directly to  AVR registers DDR and PORT to toggle pins used to drive the extruder. Since I'm not using an extruder in the system will It be ok?

What I need is a blocking function till G0/G1 commands are complete
Would adding planner.synchronize(); to the end of the function achieve this.
Instead of sending M400 followed by the command.
Ahe
CC BY-SA 4.0
2019-04-19T08:53:25.670Z
@Ahe That wouldn't probably be a problem as you are not using them. But I don't know if these ports are reset by any function or so. You could comment out the extruder pin assignment in `pins_ANET_10.h` to be sure, but please try, it might be that these port constant definitions are uses somewhere in the code. Just search the code base, I suspect that you have some programming experience to figure it out. Good luck!
0scar
CC BY-SA 4.0
2019-04-26T11:26:04.723Z
@Ahe You may want to look at the `M400` "Finish Moves" G-Code.
If you were to set the G-Code buffer to a size of 1 and inject `M400` after each G1 / G0 command, you could then toggle your pin using e.g. `M42 P123 S255 -> G4 P10 -> M42 P123 S0` with 123 being your digital pin number.
towe
CC BY-SA 4.0
2019-04-19T07:25:33.503Z
2019-04-19T07:25:33.503Z
0scar
<p>This question concerns an Anet A8 with customized Marlin Firmware 1.1.9.</p>

<p>I need to generate an additional digital output to signal move complete to trigger some data acquisition process. The extruder is not connected and was planning to use those outputs.</p>

<p>Which section handles G-code processing and is there an already available option to get the job done?</p>

<p>Basically, I'm trying to use the Anet A8 as a computer-controlled positioning system. It involves some other elements which need to be triggered in a stationary state. The requirement is: <code>G0 X10 Y10</code> after this is complete: set a pin high and low after a 10&nbsp;ms delay. this after every move. Additionally if I could add my own G-code to preserve the original operation would be ideal.</p>

<marlin><anet-a8>
Marlin customization; additional output after G0/G1 move
Ahe
# Marlin customization; additional output after G0/G1 move

(Asked by: username_0 on 2019-04-18)

This question concerns an Anet A8 with customized Marlin Firmware 1.1.9.

I need to generate an additional digital output to signal move complete to trigger some data acquisition process. The extruder is not connected and was planning to use those outputs.

Which section handles G-code processing and is there an already available option to get the job done?

Basically, I'm trying to use the Anet A8 as a computer-controlled positioning system. It involves some other elements which need to be triggered in a stationary state. The requirement is: `G0 X10 Y10` after this is complete: set a pin high and low after a 10 ms delay. this after every move. Additionally if I could add my own G-code to preserve the original operation would be ideal.

**Tags:** marlin, anet-a8


---

## 1 answers

### Answer by username_1 on 2019-04-19. Score: 2 | Accepted answer

> Which section handles G-code processing?

In Marlin Firmware, G-code is processed by procedure `void process_parsed_command()` in file [`Marlin_main.cpp`](https://github.com/MarlinFirmware/Marlin/blob/bugfix-1.1.x/Marlin/Marlin_main.cpp)

> I need to generate an additional digital output

A G-code that is able to set a port value is [`M42`](https://reprap.org/wiki/G-code#M42:_Switch_I.2FO_pin).

You could write a procedure that schedules certain port after a `G0` or `G1` move, recompile and upload the firmware.

> **Comments:**
> **username_0**: If I edit gcode_G0_G1() function in the marlin_main.cpp and write direct directly to  AVR registers DDR and PORT to toggle pins used to drive the extruder. Since I'm not using an extruder in the system will It be ok?  What I need is a blocking function till G0/G1 commands are complete Would adding planner.synchronize(); to the end of the function achieve this. Instead of sending M400 followed by the command.  
> **username_1**: @username_0 That wouldn't probably be a problem as you are not using them. But I don't know if these ports are reset by any function or so. You could comment out the extruder pin assignment in `pins_ANET_10.h` to be sure, but please try, it might be that these port constant definitions are uses somewhere in the code. Just search the code base, I suspect that you have some programming experience to figure it out. Good luck!  
> **username_2**: @username_0 You may want to look at the `M400` "Finish Moves" G-Code. If you were to set the G-Code buffer to a size of 1 and inject `M400` after each G1 / G0 command, you could then toggle your pin using e.g. `M42 P123 S255 -> G4 P10 -> M42 P123 S0` with 123 being your digital pin number.  

---

