I would like to know how to print debug information to the terminal in Marlin. Specifically, I’m searching for an alternative to System.out.println() or Console.WriteLine() that utilizes M118.
For instance, I want to send a message to the OctoPrint terminal every time a specific variable changes its value, simulating the behavior of M118.
To achieve this, I plan to hardcode these commands into the firmware files before compiling/flashing.
However, I’m uncertain about how to adapt M118.cpp, which is primarily intended for parsing user-provided strings, for this purpose.
I would appreciate any assistance or guidance on this matter.
If you’re using Marlin firmware and want to print debug messages to the terminal, you can achieve this by using the M118 command. M118 is the equivalent of System.out.println() or Console.WriteLine() in other programming languages.
Here’s what you can do:
SERIAL_MOTOR_DEBUG
option. By default, it is usually commented out with//
at the beginning of the line. Remove the//
to uncomment and enable serial debugging.M118 P<message>
Replace
<message>
with the debug message you want to display. For example:if (variableX != previousValueX) {
M118 P"Variable X changed its value!";
previousValueX = variableX;
}
Once the modified firmware is flashed and running, the debug messages specified by M118 commands will be sent to the OctoPrint terminal or any connected terminal software.
Note that M118.cpp is primarily designed to parse strings given by the user, but you can adapt it for your debugging purposes by embedding the M118 commands directly in the firmware files.
I hope this explanation helps! Feel free to ask if you have any further questions.