A simple 3 axis XY plane gCode interpreter
If you have one of these then you will need Grbl to run it.
The above image came from Protoneer so can I suggest having a look at their site.
Not Grbl
This project "Not Grbl" replaces the great Grbl firmware with an inferior partially compatible version.
Implemented:
- G0 Rapid movement
- G1 Cut movement
- G92 Set position
- M0 Stop (pause)
- M3 Spindle/laser on
- M5 Spindle/laser off
- M17 Enable motors
- M18 Disable motors
- M30 End program (reset)
- T0 Laser (if tool==1 then use special laser code)
- T1 Engraver (default)
- T? Tools (1-255)
- S? Spindle (?) - Interpreted but does not actually do anything
Assumes:
- G17 XY plane only
- G21 Metric
- G90 Absolute coordinates
- G94 mm/min
Immediate codes:
- ! Pause
- ~ Resume
- % Reset
- ? Status
Works with the Arduino serial window (for testing only).
Works well with gcode sender by Otto Hermansson.
Also works okay with Grbl Controller by "Zapmaker".
The Arduino code has the follow defaults
Hardware mapping :
- #define MXstep 2
- #define MYstep 3
- #define MZstep 4
- #define MXDir 5
- #define MYDir 6
- #define MZDir 7
- #define Enable 8
- #define Spindle 12
Baud rate:
- #define BAUD 9600
Stepper/controller settings:
- #define StepsPerMM 100 // All axes
Axis directions:
- bool xReverse=false;
- bool yReverse=true;
- bool zReverse=false;
General Approach
This project uses the "Blink without delay" approach to control the stepper motors.
This avoids the use of hardware specific timer (for interrupts).
In exchange the code is awkward as it has to "pass through" as fast as possible.
Basically code processes each character as it is received.
Code Overview
Setup()
loop () {
// Some LED flasshing code to show it is busy
tokeniseGCode(); // Tokenise a character at a time from the serial stream
parseGCode(); // Parse the code on end of line received
advanceSteppers(); // Advance the stepper motors one step
}
More about the code later.
Serial Control
Uses XON/XOFF to control the serial flow.
But G Code Sender and Grbl Controller wait for an "ok" from "Not Grbl" before sending the next command.
Actually Grbl Controller sends 10 commands before waiting for an "ok" which is no problem.
So "Not Grbl" will reply with an "ok" after every command is sent and interpreted (but usually before the command is executed".
Motion Control
Steppers have a maximum under load (pulse per second (pps) or speed that they can start and stop from without losing steps. For most steppers this is in the order of 500 pps. Not Grbl at the beginning of a movement will ramp up from 500 pps to the specified speed and ramp down to 500 pps before the end of the movement.
The ramps will slow the average speed of short segments so filtering out of these short segments from the gCode will help a lot (particularly with laser over burning).
Maximum Stepper Speed
On my Arduino UNO the "pass through" frequency varied from 12kHz (idle) down to about 8kHz (working). This implies a maximum pulse rate of 8kHz (or 4800mm/min on my 100 steps per MM machine). In reality 2400 mm/min would be a practical maximum.
I don't think many steppers will work to 8kHz anyway.
Immediate Codes
- ! Pause
- ~ Resume
- % Reset
- ? Status
Basically immediate codes (providing they are not in-bedded in comment fields) will executed after the Enter key.
Laser Control
if Tool 0 (i.e. "T0") is added to the top of your G Code then:
- G0 codes will turn the laser off and G1 Codes will turn the laser on.
- All Z movements will be updated immediately but with no actual motion.
- These code will override the M3/M5 commands.
Nothing stopping you from using the default tool (i.e. "T1") and using the M3/M5 codes to turn on/off the laser.
The spindle control command (S) is recognised but not implemented.
Hardware Mapping
The current hardware mapping models D2-D8 and D12 at present (see below):
The above image came from Protoneer so can I suggest having a look at their site.
Code
The code has been tested with a Chinese Laser Engrave and works within expectations.
It is about 500 lines long:
// Simple 3 axis XY plane gCode interpreter
// Implemented:
// G0 Rapid movement...
Read more »
You may also want to have a look at my GCode Cleaner. It strips out as many short segments as you find tolerable. I use it for may laser to speed things up and to stop burning.
AlanX