- Choose a code in the >10,000 in case new codes are added. But in this example I will choose 13
- Navigate to 'src' folder of Marlin
- Edit the file
gcode.cpp
around line 223 to have a new unused number. For example, this will create a new G code function for the label G13
.
...
// Handle a known G, M, or T
switch (parser.command_letter) {
case 'G': switch (parser.codenum) {
case 13: G13(); break;
case 0: case 1: G0_G1(
...
On line 375 of gcode.h
add: static void G13();
to declare it.
In my case i was reading values from an analog system. So I went to src/temperatures
and copied M105.cpp
to be G13.cpp
. Then inside the file I replaced GcodeSuite::M105
to be GcodeSuite::G13
. I am using this to take in the weight of something using a [scale][1] but for now I just want to test functionality so here is my test function:
void GcodeSuite::G13() {
SERIAL_ECHOPGM(MSG_OK);
SERIAL_ECHOLNPGM("here is where weights are broadcast");
}
And again this is the only part I changed in my new copy of M105.cpp (a new file named G13.cpp). There is still more stuff in the file than just these few lines.
Upload to board
When going to octoprint and typing in G13
I get:
Send: G13
Recv: okhere is where weights are broadcast
A bit more work can be done to make it look nice, but this was the hard part.
[1]: https://www.instructables.com/id/Arduino-Bathroom-Scale-With-50-Kg-Load-Cells-and-H/