Hello, trying to make an arduino code for a (virtual) CNC plotter which returns absolute X-Y coordinates based on G-code inputs. My linemoves in all directions and arcs all give the correct output by themselves, but having trouble with stringing multiple G-codes together.
This is my project developed on WOKWI
This is the g-code set which I would like the plotter output for
Well the way to analyse this is to add a lot of serial debug-output to make visible what is going in in your code.
I tested the second line
G03 X5.0 Y5.0 I5.0 J10.0 #
does not work too. So as soon as you combine more than one cooordinate the parser does not work
If you want to do this as an exercise to learn very good.
If you just need the functionality itself
use grbl or an existing g-code-parses
For your developping-process add one small thing at a time.
Go back to a much earlier code-version that is parsing a single coordinate
and then add the second coordinate including serial debug-output in the parsing section
Me personal I use these three macros for debugging
one that prints each time it is called
one that print only after a specified time-interval
one that prints once if an integer-variable has changed its value
// MACRO-START * MACRO-START * MACRO-START * MACRO-START * MACRO-START * MACRO-START *
// a detailed explanation how these macros work is given in this tutorial
// https://forum.arduino.cc/t/comfortable-serial-debug-output-short-to-write-fixed-text-name-and-content-of-any-variable-code-example/888298
#define dbg(myFixedText, variableName) \
Serial.print( F(#myFixedText " " #variableName"=") ); \
Serial.println(variableName);
// usage: dbg("1:my fixed text",myVariable);
// myVariable can be any variable or expression that is defined in scope
#define dbgi(myFixedText, variableName,timeInterval) \
do { \
static unsigned long intervalStartTime; \
if ( millis() - intervalStartTime >= timeInterval ){ \
intervalStartTime = millis(); \
Serial.print( F(#myFixedText " " #variableName"=") ); \
Serial.println(variableName); \
} \
} while (false);
// usage: dbgi("2:my fixed text",myVariable,1000);
// myVariable can be any variable or expression that is defined in scope
// third parameter is the time in milliseconds that must pass by until the next time a
// Serial.print is executed
// end of macros dbg and dbgi
// print only once when value has changed
#define dbgc(myFixedText, variableName) \
do { \
static long lastState; \
if ( lastState != variableName ){ \
Serial.print( F(#myFixedText " " #variableName" changed from ") ); \
Serial.print(lastState); \
Serial.print( F(" to ") ); \
Serial.println(variableName); \
lastState = variableName; \
} \
} while (false);
// MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END *
Right, I have tried your code in both Camotics and Mach3 now. Both give errors in your original but both work perfectly if you remove the # at the end of the line. That's your problem.