Using with the Spark Concepts CNC xPRO controller - pFenners/Sonoff-S20-Simple-Wired-Control GitHub Wiki
Background
- I have an OX CNC machine the uses the xPRO v3 controller: https://github.com/Spark-Concepts/xPRO/wiki
- I wanted the xPRO to be able to turn on and off my Makita router and Dust Vac when a CNC job is started (both run off of 240v).
Problem
- The xPRO v3 has spindle control but this is not capable of controlling mains powered devices without the use of an external relay
- The spindle control is by default PWM (on v3 of the controller) but my Makita is a simple on/off router
Solution
My solution is to use two Sonoff S20's flashed with custom firmware. Both will be connected to the xPRO controller and will be toggled on and off when the M03 and M05 g-code commands are processed by the controller.
You can connect multiple S20's to the same pin on the xPRO to control multiple devices (in my case both the Router and Vac).
Why use the Sonoff S20?
- I had some spare lying around (they are cheap).
- The have mains rated relays and handle loads up to 10A.
- There are plenty of guides around on how to customise them.
- They are enclosed so will keep me safely away from mains voltage.
How to
Prepare the Sonoff S20
Follow the steps on the README file.
Prepare the xPRO v3 controller
By default the xPRO v3 has PWM enabled on the spindle control pin, this is not ideal for controlling a relay as it will be switching on and off rapidly. It is possible to disable the PWM output (VARIABLE_SPINDLE variable) but this will cause the Z-limit D11 pin and spindle enable D12 pin to be switched. I wanted to keep my Z-Limit switches connected as they were. You can also use USE_SPINDLE_DIR_AS_ENABLE_PIN which will use pin D13 (Spindle Direction on the xPro) but I had trouble with this causing false triggers during initial power on of the xPRO (due to the onboard LED and the Arduino boot loader).
I opted for a different solution:
- Modify GRBL to use the Coolant enable pin on the xPRO as spindle control.
- Download the latest version of grbl from https://github.com/grbl/grbl.
- Modify the cpu_map/cpu_map_atmega328p.h file:
- Change line 76 from
#define SPINDLE_ENABLE_DDR DDRB
to#define SPINDLE_ENABLE_DDR DDRC
- Change line 77 from
#define SPINDLE_ENABLE_PORT PORTB
to#define SPINDLE_ENABLE_PORT PORTC
- This switches spindle enable to pin A3 (Coolant Enable on the xPro)
- Change line 76 from
- Upload modified GRBL to xPRO: https://github.com/Spark-Concepts/xPRO/wiki/3.-Updating-GRBL-Firmware#method-2-via-the-arduino-ide-all-platforms
Connect it all up
- Connect GND from the S20 to a GND pin on the xPRO
- Connect the input pin on the S20 to the Coolant enable pin on the xPRO
Test it out!
In your favourite g-code sender send an M03 command, this should turn on the device connected to the S20. Enter M05 to switch them off again.
BONUS (Fusion 360 custom GRBL post processor)
If you use Fusion 360 CAM you will have experience issues using the default GRBL post-processor. The grblModded.cps post-processer can be used instead (found in the bonus folder). This has the following enhancements:
- Adds M05 at the end of the job to turn off the spindle
- Removes the tool change commands which are typically a source of errors if using UGS
- Disables G28 by default