M3-M5 Spindle Control

Hi guys, I need your support because today I’m getting mad.
I’m trying to enable the spindle ON/OFF trough M3-M5 GCodes on my SKR 1.3 Board and a iot relay board.

I have configured marlin 2.0.3 in order to enable the function:
and disabling the other features:
#define SPINDLE_LASER_PWM false -> to send target speed reference
#define SPINDLE_INVERT_DIR false -> to send speed inversion

then I have mapped the output pin:
#define SPINDLE_LASER_ENA_PIN P2_00 -> SKR 1.3 servo output

with this modification the servo pin is 0 V or 3.3 V following coherently M3 and M5 commands.

the next step was connecting the relay:

Vcc to 5V (servo connector SKR 1.3)
Gnd to Gnd (servo connector SKR 1.3)
In1 to P2_00 (servo connector SKR 1.3)

swiched ON -> relay always active, no effect from M3-M5 commands

Then I connected the same relay board to an Arduino UNO, tested it with the Blink.ino sketch and I verified the correct behavior of the relay board that switches ON when In1 is connected to GND and OFF on other levels.

At this point I imagined that the SKR1.3 pin is not able to drive to Gnd the servo output and I found this resource:

found in my lab some components and I built this circuit:

This circuit inverts the command logic so I inverted command logic in the fw by #define SPINDLE_LASER_ACTIVE_HIGH true.

Tested again and everything seems to work:
M3 Command
M5 Command

But… when switch on the board supply for about 10 second the relay is switched ON
Start after SKR1.3 supply

I have verified that during this “BOOT” time the servo output is driven at 1.22 V causing the spurious relay activation.

That’s all, now I’m really stuck with my mechanical engineer background I don’t know how to proceed to remove this spurious relay activation at startup… maybe I have only bought the wrong relay board…

Thank you for your support


1 Like

Disclaimer - I’ve never used either the SKR board you’re using, or the relay board… But…

I would suspect the pin you’re using to drive that relay board is configured as an input during boot and only goes to output once your firmware is running. During that time the input to the base of Q2 is (effectively) unknown and I would guess is allowing your relay to be turned ON.

Try a 10K resistor from the (input) pin on R3 to GND. That should bias Q2 base to GND when the SKR isn’t driving the pin.

PS - don’t blame me if it blows up! (I know, very confidence inspiring) :man_shrugging:


My suggestion is drive the external relay from a different pin. Either a servo pin or one of the aux pins. I believe Zmin can be configured as a pwm output as well so you can just reassign Zmin to the zmax pin if you’re using it for a touch plate or whatever.

Hi All,
thank you very much for your support, at the end I have solved the problem using a Wemos Relay Shield for ESP8266 Lolin D1 mini boards.
This relay shield is equipped with a 10k pulldown resistor that keeps the Servo output to 0 level during board reset.

Now M3-M5 commands work fine with following Configuration_adv.h modifications:

#define SPINDLE_LASER_ACTIVE_HIGH     true  // Set to "true" if the on/off function is active HIGH
#define SPINDLE_LASER_PWM             false   // Set to "true" if your controller supports setting the speed/power
#define SPINDLE_LASER_PWM_INVERT      false   // Set to "true" if the speed/power goes up when you want it to go slower
#define SPINDLE_LASER_POWERUP_DELAY   2500   // (ms) Delay to allow the spindle/laser to come up to speed/power
#define SPINDLE_LASER_POWERDOWN_DELAY 2500   // (ms) Delay to allow the spindle to stop

//#define SPINDLE_CHANGE_DIR               // Enable if your spindle controller can change spindle direction
#define SPINDLE_CHANGE_DIR_STOP            // Enable if the spindle should stop before changing spin direction
#define SPINDLE_INVERT_DIR          false  // Set to "true" if the spin direction is reversed

Could you say me, which boards (RAMPS & Arduino…) did you used?

And which Output did you taked? Aux2 with D40?

And did you not changed the MOTHERBOARD to BOARD_RAMPS_14_SF e.g. in the configuration.h ?

Hi, I’m using bigtreetech skr1.3 board.
Servo output.

I just got the SKR 1.4 to work on one of the heater bed plugs, awesome…

1 Like

Maybe someone has faced this issue on Marlin I have made all the same configurations as described above in configuration_adv.h and replaced the SERVO0_PIN on P2_00 with SPINDLE_LASER_ENA_PIN (although I tried also the same with the heater pins, as the SPINDLE_LASER_PWM is false anyhow), but the Auto Build Marlin constantly reports an error:

Marlin/src/feature/spindle_laser.cpp: In static member function ‘static void SpindleLaser::init()’:
Marlin/src/feature/spindle_laser.cpp:57:29: error: ‘SPINDLE_LASER_PWM_PIN’ was not declared in this scope; did you mean ‘SPINDLE_LASER_PWM_OFF’?
57 | set_pwm_frequency(pin_t(SPINDLE_LASER_PWM_PIN), SPINDLE_LASER_FREQUENCY);
| ^~~~~~~~~~~~~~~~~~~~~
*** [.pio/build/LPC1768/src/src/feature/spindle_laser.cpp.o] Error 1

Does anyone have any suggestions?

In Configuration_adv.h, you need to comment out #define SPINDLE_LASER_FREQUENCY, I have :
#define SPINDLE_LASER_ACTIVE_STATE HIGH // Set to “HIGH” if the on/off function is active HIGH
#define SPINDLE_LASER_PWM false // Set to “true” if your controller supports setting the speed/power
#define SPINDLE_LASER_PWM_INVERT false // Set to “true” if the speed/power goes up when you want it to go slower

//#define SPINDLE_LASER_FREQUENCY 2500 // (Hz) Spindle/laser frequency (only on supported HALs: AVR and LPC)


  • Speed / Power can be set (‘M3 S’) and displayed in terms of:
    • PWM255 (S0 - S255)
    • PERCENT (S0 - S100)
    • RPM (S0 - S50000) Best for use with a spindle
      #define CUTTER_POWER_UNIT PWM255`