Welcome to Our Community

Unlock hidden features. Sign Up for Free Today!

Using GRBL 0.9 to switch spindle on/off

Discussion in 'Control Software' started by drpeej, Mar 11, 2016.

  1. drpeej

    drpeej Well-Known
    Builder

    Joined:
    Feb 23, 2016
    Messages:
    19
    Likes Received:
    2
    I want to control the spindle on/off via a relay using the spindle enable pin with M3 and M5. (I am not controlling speed using pwm). I understand that GRBL 0.9 changed the pinout to allow PWM speed control.

    I am using GRBL 0.9j. If I comment out the #define VARIABLE_SPINDLE line in config.h, the output appears as expected on D12. However M3 only switches D12 HIGH if I have previously set S to some value other than zero. I expected the 'S' setting to be irrelevant if VARIABLE_SPINDLE is not defined. The S value doesn't persist and always resets to zero (presumably a safety feature) so I need to send S1 after every reset to allow motor control.

    Is it possible to change this behaviour or set S to default to a non-zero value? I have tried several compile-time options in config.h but am reluctant to change the main code with my limited knowledge.
     
  2. David the swarfer

    David the swarfer OpenBuilds Team
    Staff Member Moderator Builder

    Joined:
    Aug 6, 2013
    Messages:
    521
    Likes Received:
    250
    You can set it to a startup block so it always runs when GRBL turns on or resets, so you do not need to change the code other than turning off PWM.
    Configuring Grbl v0.9 · grbl/grbl Wiki · GitHub
    look for $N
    Code:
    $Nx are the startup blocks that Grbl runs every time you power on Grbl or reset Grbl. In other words, a startup block is a line of G-code that you can have Grbl auto-magically run to set your G-code modal defaults, or anything else you need Grbl to do everytime you start up your machine. Grbl can store two blocks of G-code as a system default.
    
    So, when connected to Grbl, type $N and then enter. Grbl should respond with something short like:
    
    $N0=
    $N1=
    ok
    
     
  3. drpeej

    drpeej Well-Known
    Builder

    Joined:
    Feb 23, 2016
    Messages:
    19
    Likes Received:
    2
    Thanks for that. I'll investigate
     
  4. OldDogSleeping

    OldDogSleeping Well-Known
    Builder

    Joined:
    Oct 22, 2015
    Messages:
    10
    Likes Received:
    10
    I use a similar configuration, controlling my spindle via a solid state relay. M3 & M5 seem to just work for me, no need to set S, no startup blocks that I can see. I'm fairly certain that all I changed was commenting out the VARIABLE SPINDLE line in config.h. so I'm wondering what is different with my setup.
    The only thing I can think of is that I have homing enabled, so have to perform a homing cycle before I can do anything else.
     
  5. drpeej

    drpeej Well-Known
    Builder

    Joined:
    Feb 23, 2016
    Messages:
    19
    Likes Received:
    2
    Thanks, thats helpful. I haven't yet enabled my limit switches so don't use homing but I will in the future.
     
  6. David the swarfer

    David the swarfer OpenBuilds Team
    Staff Member Moderator Builder

    Joined:
    Aug 6, 2013
    Messages:
    521
    Likes Received:
    250
    it also depends on your Gcode creator. If you use SketchUcam, it always puts in an Sxxxx instruction along with the
    M03 motor start command.
    other generators may/should do so as well, but the original posters one obviously does not, though there must be a way to tell it to set a spindle speed which would also solve the problem. After all, if you want the spindle to run it does make sense to tell it how fast to run at the same time.
     
  7. David the swarfer

    David the swarfer OpenBuilds Team
    Staff Member Moderator Builder

    Joined:
    Aug 6, 2013
    Messages:
    521
    Likes Received:
    250
    btw it can be done without recompiling with the PWM turned off. S0 will turn it off and S1000 or whatever the defined max speed is will turn it on, equivalent o 0 and 5 volts on the pin. BUT you have to make sure that no other speeds are selected, ever, since the relay is unlikely to enjoy being pulsed one and off at some 400 hz.
     
  8. drpeej

    drpeej Well-Known
    Builder

    Joined:
    Feb 23, 2016
    Messages:
    19
    Likes Received:
    2
    Thanks for all the advice. I realise that many Gcode creators already add in S commands. However the $N0=S1 solution has achieved what I want - thanks.
     
    David the swarfer likes this.
  9. Sonny Jeon

    Sonny Jeon Veteran
    Staff Member Moderator Builder

    Joined:
    Aug 6, 2015
    Messages:
    110
    Likes Received:
    36
    FYI, this issue has been fixed in the most recent version of Grbl. When VARIABLE_SPINDLE is disabled, Grbl will ignore the S value and turn on the spindle with S0.
     
  10. drpeej

    drpeej Well-Known
    Builder

    Joined:
    Feb 23, 2016
    Messages:
    19
    Likes Received:
    2

Share This Page

  • About Us

    The OpenBuilds Team is dedicated helping you to Dream it - Build it - Share it! Collaborate on our forums and be sure to visit the Part Store for all your Building needs!
  • Like us on Facebook

  • Support Open Source FairShare Program!

    OpenBuilds FairShare Give Back Program provide resources to Open Source projects, developers and schools around the world. Invest in your future by helping others develop theirs!

    Donate to FairShare!