As of Version 0.9, GRBL supports PWM for controlling variable spindles and lasers. (Both our Arduino CNC shield(V3.10+) and Raspberry Pi CNC Boards support the PWM functionality. )
To use the functionality there are two parts to look at. The first part is the way GRBL firmware is set up when compiled. Luckily most of it will work out of the box.
For advanced users the following might be helpful:
- #define VARIABLE_SPINDLE // This enables PWM spindle Control. Remove to disable PWM.
- #define SPINDLE_MAX_RPM 1000.0 // Max spindle RPM. This value is equal to 100% duty cycle on the PWM.
- #define SPINDLE_MIN_RPM 0.0 // Min spindle RPM. This value is equal to (1/256) duty cycle on the PWM.
- // #define MINIMUM_SPINDLE_PWM 5 // Default disabled. Uncomment to enable. Integer (0-255)
The second part is where the real G-Code commands are used. Below is a list of G-Code commands and what they do:
- S command
- Sets the Spindle speed.(0-1000 with default build)
- M3 Command
- Sets Spindle Pin to the PWM rate as specified by the S command. (Clockwise)
- Sets Spindle Direction pin High
- M4 Command
- Sets Spindle Pin to the PWM rate as specified by the S command.(Counter Clockwise)
- Sets Spindle Direction pin Low
- M5 Command
- Sets Spindle pin Low. (PWM 0)
- Keeps the Direction Pin as is.
- M7 / M8 Command
- Sets the Coolant pin High.
- M9 Command
- Sets the Coolant pin Low.
G-Code Examples
The following examples are from the standard GRBL V0.9i build.
Set the spindle to full speed and switch it off after 5 seconds.
1 2 3 4 5 6 |
S1000 M3 G4 P5000 M5 |
Set the spindle to 50% speed and switch it off after 5 seconds.
1 2 3 4 5 6 |
S500 M3 G4 P5000 M5 |
This example will do the following:
- Move the machine to X0 and Z0.
- Switch on the spindle.
- Move Z down into the material.(Milling bit)
- Move side ways on the axis.
- Move Z out of the material.
- Switch off the spindle.
1 2 3 4 5 6 7 8 9 |
X0Z0 S1000 M3 Z10 X100 Z0 M5 |
That should do it for now. Please add comments below if you have questions or suggestions.
Probe can be tested with the following commands:
1 2 3 4 |
G0 F1000 X20 Y30 Z0 (position probe at high speed) G38.2 F10 Z-100 (moves probe toward table at 10mm/sec) |
And how to control laser ? Use m7/m8 and m9 commands? I.e. Turn laser instead of cooler, or together with it?
M3/M4 and S0-S1000 for Laser PWM signal
The M3 command triggers my spindle, it starts and then stops again straight away, any help would be great!
Best to ask on the GRBL github page… https://github.com/grbl/grbl/wiki
while testing , command P50 gave me 5 second delay instead of P5000
Best to ask on the GRBL github page… https://github.com/grbl/grbl/wiki
hi, How to add a cooling cycle for a long project like work for 30 rest for 20mn and continue until end of project?
That will need to be done with the G-Code sender.
For more discussions on this topic please join or forum: forum.protoneer.co.nz
Pingback: K40 eBay Chinese CO2 Laser Cutter – Flashing the Arduino UNO with GRBL Part 2! – DIY 3D Tech