# Marlin customization; additional output after G0/G1 move

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.

Which section handles G-code processing?

In Marlin Firmware, G-code is processed by procedure void process_parsed_command() in file Marlin_main.cpp

I need to generate an additional digital output

A G-code that is able to set a port value is M42.

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

• 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
Apr 19 '19 at 8:29
• @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
Apr 19 '19 at 8:53
• @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
Apr 26 '19 at 11:26