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:
#define SPINDLE_FEATURE
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:
#ifndef SPINDLE_LASER_ENA_PIN
#define SPINDLE_LASER_ENA_PIN P2_00 -> SKR 1.3 servo output
#endif

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:
relay

wired:
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:
https://electronics.stackexchange.com/questions/245976/control-5v-relay-through-3-3v-gpio-using-npn-transistor

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

Gabriele

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:

4 Likes

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_FEATURE // LOK Edit
//#define LASER_FEATURE
#if EITHER(SPINDLE_FEATURE, LASER_FEATURE)
#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

#if ENABLED(SPINDLE_FEATURE)
//#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
2 Likes

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