Zum Inhalt

GRBL 0.9j – Running your laser with spindle pin

It has been a while, since I wrote something about my eShapeOko and GRBL. In the meantime, I upgraded my hardware to the black Pololu Edition, desoldered the GRBL Shield caps, and put them on the other side of the PCB, to cool the drivers from top and from the bottom with a heat sink.

The new big upgrade to my eShapeOko was a 250mW laser, ordered by Banggood for 10€. These can be driven with 5V and come with nearly everything you need, to get started. First of all, I upgraded the GRBL version on my Arduino Uno and ran into some problems, on how to drive the laser, to avoid, that this little beast is turned on all the time and leaves track, while speedfeeding to the next „cut location“.

I found out, that some people realized it, by using the spindle enable pin of GRBL. Thats what I wanted to do, because I don’t use the spindle control at the moment. So first of all I had to deal with the new GRBL version, which was v0.9j. In the 0.9 version, the pins for spindle enable and z limit were switched. But that isn’t our problem at the moment. Our current problem is, that GRBL 0.9j uses variable spindle speed on the pin I mentioned above and no spindle enable anymore. I need a clear 5v / 0v Signal (equivalent to spindle enabled = true/false).

To get the spindle enable feature back, you need to download the GRBL Sourcecode, and patch it, compile it and upload it. I’m glad, the developer thought of this scenario :).
These are the steps I did, to get there:

(Please read all possible ways in order to save some time 🙂 )
1a. Download GRBL sourcecode from github ( https://github.com/grbl/grbl )
2a. Extract zip File
3a. Use Notepad++ and open the file called config.h (Folder: grbl-master\grbl)
4a. Search for a line, that starts with „#define VARIABLE_SPINDLE“
5a. Comment this line out ( Use a double Slash // )
6a. Save the File
7a. Download a Compiler. I have a Windows box and used WINAVR GCC from http://winavr.sourceforge.net/
8a. Install Compiler
9a. Open a Command prompt, switch to the grbl-master Folder, where the makefile is located
10a. type „make“ and wait until a grbl.hex file is compiled in the same directory
1-10b. Or you can Copy the Hex Information from here to a file (this is my compiled Version of GRBL with disabled variable spindle)
11. Backup your current GRBL Settings
12. Use a tool to upload the hex file to your Arduino Uno (I use xloader from here: http://russemotto.com/xloader/ )
13. Done

Now we are prepared. We didn’t only change the behaviour of our Arduino, we change the pin outputs as well.
Here is the code, where you can read it (from GRBL):

Now your Arduino GRBL Box has GRBL 0.9j running, but with the pinlayout and pin functionality like 0.8. Now you can use Pin 12 on your Arduino to control the laser. In order to do this, I used and BS170 I have from a previous project. You need to read the Datasheet in order to know, if this transistor works for you.
The BS170 has 3 Pins, Source, Gate, Drain. This is how I connected it.

1. Connect Source to GND of power supply
2. Connect Gate to Arduino Pin12
3. Connect Drain to black cable of the Laser

Thats it, now you can use the GCode commands M3 / M03 to turn your Laser and M5 / M05 to turn your laser off. In the most cases, you can configure your CAM software, to add these commands, while speedfeeding / feeding, to get what you want.

If you need these settings for CAMBAM, leave me a message!

Veröffentlicht inAllgemeinCNC ProjekteShapeOkoHobby

46 Kommentare

  1. Justin Justin

    Thank you man.
    You saved my time and money 🙂

  2. Hey Justin, I’m glad I can help you. I wasted alot of time to figure out, how other people did it 😀

  3. Tukaram kadam Tukaram kadam

    Dear Marco Di Feo,

    Please can you give me corrected .hex file for laser.

    Thank you
    Tukaram

  4. Hi Tukaram,

    as mentioned in my posting, you can download the Hexfile from here: http://pastebin.com/MfWhR9Lk
    Copy all the lines in a .txt file, save it and rename it to grbl.hex.

    Kind Regards
    Marco

  5. Tukaram Tukaram

    thank you Marco, it is working great!!!!!!!

  6. Glad to hear it is working! Have fun with it 🙂

  7. Tukaram kadam Tukaram kadam

    Hi how are you, Dear Marco , I am going to do Dot pin Marking machine ,can you help me , I have any other idea please share with me.

    Thanking You,
    Tukaram

  8. Harry Harry

    Dear Marco, nice done… I wanted exactly the same, and I found out that you can get a signal 0f 5V when using S1000 in combination with m03 or m05.. Once the speed is set, you only have to use M03 and M05… This is working under 0.9i ..

    Maybe I also make the step you made, but that looks more difficult for me with compiling ….

  9. Hey Harry, this is a really nice tweak, to get a 5v signal out of the variable spindle. Didn’t thought about this clean solution, because I am familiar with reading code and flashing things, this was the first thing, that came to my mind.
    Thanks for you comment, maybe someone else will help your great idea. I think about putting a hint for your comment into my post.

    Kind Regards
    Marco

  10. Hans Andersen Hans Andersen

    Thank you so much. The relay for my laser immediately turned on after upload!

    Kind regards
    Hans

  11. Hey Hans, thanks for your comment! Glad I could help!

  12. Nathan B Nathan B

    THANK YOU for your help! I struggled forever with a pre-made „EleksMaker“ PCB because it only allows D12 to connect to a MOSFET for laser power, and with VARIABLE_SPINDLE enabled it was using the wrong pin. Your firmware update allowed me to set D12 high/low as desired to power the laser on/off.

    Also, it was easier for me to compile and push my updated code via the Arduino IDE (https://github.com/grbl/grbl/wiki/Compiling-Grbl). First run the code once so that the IDE builds the library. After that you can open config.h, make edits, and then just connect your Arduino and it will compile and push the code directly to the board (no extra steps of making hex and then uploading it later).

    Thanks again – this was really helpful!

  13. Hey Nathan, I’m glad my little tutorial helped you to find your way and get your laser setup to work. I knew, uploading the firmware by arduino is quite easy.
    Because I started with compiling and uploading hex files (on attiny/atmega), I thouth it is more understandable, what you are doing, instead of clicking some buttons and after some magic is done, everything works :D.
    I think, if someone is familiar with the Arduino IDE, they will do it your way.

    Thanks for your comment! It’s nice to see, that this post helps so many people and you all spent some time to write about your success and give each other another advice on how it can be done in a slightly different way!

  14. Peter Harris Peter Harris

    This has been helpful (partially) I am not using a laser but want to control the spindle on/off via a relay using the spindle enable pin. (I am not controlling speed using pwm)

    If I comment out the #define VARIABLE_SPINDLE line, the output appears as expected on D12. However M3 only switches D12 HIGH if I have previously sent S=1000. I expected the „S“ setting to be irrelevant if VARIABLE_SPINDLE is not defined.

    Can you advise?

  15. Hey Peter, glad it helped you. You are right, as I am interpreting the code right.
    First of all, lets check config.h.

    I found a setting called: „USE_SPINDLE_DIR_AS_ENABLE_PIN“. Maybe this is the one you want to use.
    Here is the commented section:

    // By default on a 328p(Uno), Grbl combines the variable spindle PWM and the enable into one pin to help
    // preserve I/O pins. For certain setups, these may need to be separate pins. This configure option uses
    // the spindle direction pin(D13) as a separate spindle enable pin along with spindle speed PWM on pin D11.
    // NOTE: This configure option only works with VARIABLE_SPINDLE enabled and a 328p processor (Uno).
    // NOTE: With no direction pin, the spindle clockwise M4 g-code command will be removed. M3 and M5 still work.
    // NOTE: BEWARE! The Arduino bootloader toggles the D13 pin when it powers up. If you flash Grbl with
    // a programmer (you can use a spare Arduino as "Arduino as ISP". Search the web on how to wire this.),
    // this D13 LED toggling should go away. We haven't tested this though. Please report how it goes!
    // #define USE_SPINDLE_DIR_AS_ENABLE_PIN // Default disabled. Uncomment to enable.

    I’ve seen in the code (spindle_control.c) that this setting doesn’t have something to do with RPM of your spindle and the S setting.
    Try to comment out „VARIABLE_SPINDLE“ as before and uncomment „USE_SPINDLE_DIR_AS_ENABLE_PIN“

    Hopefully you have an Arduino Uno.
    Kind Regards
    Marco

  16. Hello. you do not tell me how to invert the switch spindle? when fed to 5 volts on the spindle M05 that was on or off the team, and when it was not served or M03 command is enabled. Thank you.

  17. Peter Harris Peter Harris

    Thanks

    I already tried that and it didn’t work. However I now think setting S to enable it could be seen as a safety feature.

    I now send S1 before sending any other code (I discovered any value of S other than zero enables the spindle)

    I may post the same question on the Openbuilds GRBL forum

  18. Peter Harris Peter Harris

    I have found a solution on the Openbuilds forum. If you issue $N0=S1 then S1 gets sent whenever GRBL is started or reset.

  19. John John

    Hello. please give me your file config.h

  20. Hey Peter! I’m glad you found a solution and you are so kind to share it with us! Thank you!

  21. John John

    Marco, I do a third day as it is written in your instructions. but the D12 is not included. your file works and the fact that I do not work. you compile through the Programmers Notepad [WinAVR] ? what else you change the settings for?

  22. John John

    Sie ignorieren mich?

  23. Hey John,
    thanks for your comment. No I’m not ignoring you, but I have something else to do instead of maintainig this site. Because this is just my hobby, and I try to help people with my hints, this site isn’t something like a service hotline, where you can get help for every problem and can request something. If you don’t have the ability to work on all of your problems by your own, this maybe is the wrong place for you, because I can give you ideas, what you can do to get your problems solved, but I don’t solve your problems, if you don’t have any clue where the problem could come from and how to work on that.

    Nevertheless, here is my requested config.h file: http://pastebin.com/U1B4QBTY . Maybe you have the chance to get your problem solved with this, but I don’t think so, because the change I have done is the same as in my instruction.

    As you mentioned, I compiled it with WINAVR, yes

    Good luck!

    Regards
    Marco

  24. John John

    very thank Marco! I want to do better GRBL. I need any help since the pro version 0.9 is very little information. Your compiled file running without no problems, and if I do the same thing that I did not work. and I can not understand what the problem is.

  25. John John

    Marco ((((your file does not work .. what is the difference as I can not understand. I can something not so I do? Can not compile correctly? With the size of the original file exactly the same, tried through andruino compile effect the same ((((and I really need to change the settings. that would be on the spindle off was applied to +5 volts and 0 volts in the switch. off +5 on 0 V

  26. John John

    do you have Skype?

  27. No I don’t and this is the end of my help. I can’t spent time for someone, to fix their problem. You need to do it on your own. If you can’t do it you need to pay a friend or get more into your problem by lerning things depending on that.

    There is no such setting you can change to geh 0 -> 5v and 1 -> 0v. In order to do this, you have to rewrite grbl or fix this in hardware (electronics). Both things have to be solved by yourself.

    I only changed variable_spindle setting and uncommented it to get 0 or 1 instead of something between 0v – 5v.

  28. John John

    Marco, sorry again. I understand that I am tired of you and that you do not have time for me. nemogli but would you please send me your Makefile / in my Makefile no mention config.h/ likely to set the settings of me not compiled in HEX.

  29. Stuart Bassett Stuart Bassett

    HI Marco.
    Just wanted to say thanks.
    I have my laser running through a relay switched on by a Tip31 transistor connected to pin 12 on my UNO. I was just coming on and staying on throughout the burning process so I was getting tracks all over the place.

    I just downloaded your Hex file and sent it to the UNO and now the laser is switching off and on as it should, no more tracks.
    Did not have to change anything else, it just works. Excellent.

    Thankyou very much.

    Regards
    Stuart Bassett.

  30. Hey Stuart,
    Thanks for your comment! Glad it worked out of the box! Thats the way I had it in the beginning – tracks everywhere. :). Bug I’m happy now!

    Regards
    Marco

  31. Rob Rob

    Worked for me too thanks!

    Just had a quick question. I’ve been experimenting with Inkscape’s gcodetools and I’m wondering how to get it to spit out the m3/m5 commands for me. What do you all use to generate your gcode?

  32. Jay Jay

    Dear Marco,
    Thanks for your efforts,really aprreciate.

    Since I used your version of grbl all my machining is in mirrored. I tried to change the spindle direction by changing reversing the polarity of stepper motors but it only made the machining in inverse still mirrored. to get it correct now I have to mirror my job which is very awkward.
    Any suggestions on why it is so.
    Thanks in advance.

  33. He Jay, I don’t know, because it’s the stock firmware of grbl. Everything should work as defined, like axis mirroring and so on. Did you try to use a hex file from the grbl site and check if the mirroring still exists? Maybe you can download a working sourcecode and compile your own version with the spindle change.
    Regards Marco

  34. Ishaan Ishaan

    hi, went through your instructions but i am unable to figure out the part to change the pinout. I want to use D12 to enable and disable the laser as you have mentioned can you let me know the changes needed in the latest grbl version.

  35. Marcel ( Joe ) Deman Marcel ( Joe ) Deman

    Just a quick question on the limit switch’s.

    If i eliminate the Z axis does that stop the homing for the Z seeing it looks for it first, and since I am not homing it or do I still need a z limit switch just actuate it by hand to do the homing.

    and thanks for your post I think it helped me greatly, for me turning my plotter to a laser engraver. Well when I get it al done.

    Marcel

  36. Good question, I think you have to try it. I didn’t do that at the moment, because I use the z axis for focusing the Laser.

    Kind Regards
    Marco

  37. Marcel ( Joe ) Deman Marcel ( Joe ) Deman

    Thanks for the quick reply. if I have to i will just put a but and use it to home the z manuely as a work around.. Still trying to get my laser head wired . as it did not come with any sort of data but there are three wires coming out. and not sure which does what. I have sent to Sunwin for how to wire into the arduino. So when I get it done I will let you know about the z axis.

    Thanks
    Marcel

  38. Sergii Sergii

    Maybe it looks silly (shame on me), but correction, You mentioned, doesn’t work on my project with Arduino Uno . I tryed both ways – with copiing hex from pastebin and config.h modification and further compiling, but none of them starts work correctly. G-code sender doesn’t even see a GRBL firmware in my Arduino. What did I do wrong?

  39. Sergii Sergii

    Arrrrghhh. It was only because of bitrate of Gcode sender, I tried tio connect on 9600… Sorry. In any case, laser doesn’t work

  40. What did you do with the laser? Have you used the custom commands for turning it on and off?

  41. AuLeeFor AuLeeFor

    Vielen Dank ! Ich hatte schon selber in der Config rumgestuempert, aber nichts erreicht.

  42. human human

    Hello
    I’m sorry I do not understand how the wiring MOSFET
    Can you take a picture?
    Or send me
    thanks a lot

  43. Luigi Amo Luigi Amo

    Hi Marco,

    Your name seems to be italian, such as me 🙂

    I have a woodpecker board with GRBL 0.8 and a chinese laser with no upgradable software to 1.1 (that I would…)
    I don’t know if I can upgrade (and HOW) to 0.9j with your instructions. I don’t know if woodpecker would be Arduino. Sorry for my incompetence

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.