GRBL is an arduino program for controlling each of the XYZ stepping motors on 3-axis machines such as 3D-printers and milling machines. Servo motors require pulse width modulation (PWM) signal to operate. Unfortunately GRBL has allocated another task to each of the PWM pins. We need to borrow one of these pins to control our servo.Pin 11 is an ideal candidate as the “Limit Z-Axis” function is not required when plotting. But to access this pin we must replace the “spindlecontrol.c” code module within GRBL with code of our own.This solves one problem but creates another. Any G-code that we send to the plotter now requires “special” code sequences for raising and lowering the pen.Generating the Code SequencesThere are two distinctly different ways of doing this:.
Grbl is software for controlling the motion of machines that make things. If the maker movement was an industry, Grbl would be the industry standard. Most MakerBots and open source 3D printers have Grbl in their hearts. It has been adapted for use in hundreds of projects including laser cutters, automatic hand writers, hole drillers, graffiti.
add an “extension” to Inkscape. 1. insert the required M3,M5 code sequences into existing G-code using a post-processor.The end result from both approaches is the same.An example of post-processing using my “GcodePostProcessor” is shown in photo 1. The left-hand file contains the original Inkscape g-code. The right-hand file contains the additional GRBL command sequences.
Lines that have been deleted are shown with a red “minus” sign and red highlight. Lines that have been added are shown with a green “plus” sign and green highlight.Let’s get started.1A video demonstrating this process may be found at and is fully documented in the comment section below the video.A downside to this approach is that the extension may become obsolete. For example the “MI Inkscape Extension” used in the above video only works with Inkscape 0.47.2A post-processor offers the following advantages:. existing G-code files don’t have to be recreated. it works with any G-code software generator. it is compatible with the latest versions of Inkscape.
The following steps are required:. Download and unzip “grbl-1.1f.20170131.zip” (photo 1) from. Download “spindlecontrol.c” (photo 2) from. 1 2. Navigate to the “grbl” folder within the zip file we have downloaded and replace the “spindle.control.c” file with the “spindlecontrol.c” file from “www.buildlog.net”. If you have a COREXY plotter you must edit line 189 in the file “config.h” to read “#define COREXY;” as shown in photo3.
Use a text editor such as Notepad to do this. Do NOT use a word processor. Copy the “grbl folder” to the arduino “libraries” folder and rename to say “grbl1.1fservo”. The name doesn’t matter so long as you can find the folder. The path to this folder is normally C:DocumentsArduinolibraries. Open your arduino IDE and navigate to the folder C:DocumentsArduinolibrariesgrbl1.1fservoexamplesgrblUpload.
Select the sketch “grblUpload.ino” then upload it to your arduino.That’s it. GRBL is installed.1This blog fully explains the process. It is helpful to have a calibration file for checking the accuracy of your plotter.Let’s generate the g-code for a 100mm square using the latest version of Inkscape 1, then insert the required GBRL servo commands using “GcodePostProcessor”.Create a “square” using InkscapeThe following steps are required:.
Launch Inkscape. Click 'File Document properties' (Shift+Ctrl+D)and set your paper size. Click 'Create Rectangles & Squares' (F4) from the sidebar. Click and drag a rough square shape.
(photo 1). Click 'Select and transform objects' (F1) from the sidebar. Our square will become surrounded by tiny arrows. At this point we could simply drag this shape onto our work area, but let's add some accurate dimensions so that we can check our plotter calibration. Change the (W)idth and (H)eight measurements to 100mm then click the padlock. (photo 3). Now drag the square onto the work area.
Set the X & Y positional values to whole numbers. (photo 4)We are now ready to create our G-code.Generate the G-codeThe following steps are required:.
Click 'Path Object to path'. Nothing appears to happen but it does. Click 'Extensions Gcodetools Orientation points Apply. Orientation points will appear. (photo 5). Click the square to bring back the arrows.
Click 'Extensions Gcodetools Tools library Default. A green screen will appear. (photo 6). Click the 'Create and edit text objects' (F8) from the sidebar. Carefully edit the speeds in the green box. I've set my plotter speeds to 10000mm per minute in this example. (photo 7).
Click and drag the green box to one side of our work space. Click our square to select it. Click 'Extensions Gcodetools Path to Gcode Preferences' and complete the form. (photo 8). Click 'Options' and make any changes.
For test purposes I have increased the arc radius to 1mm. The default value is 0.02mm (photo 9). Click 'Path to Gcode'. (photo 10).
Click 'Apply' and a toolpath with tiny direction arrows will eventually appear. (photo 11). You may now close Inkscape. A file 'square.gcode' should appear on your desktop. The contents of this file are shown in photo 12.If you examine the code in photo 12 you will see that Inkscape has inserted some M2,M3,M5 codes.These codes are for a milling machine, not a plotter, and need to be stripped out and replaced with custom codes of our own.Let's do this. This step explains how to:. install, and run, “GcodePostProcessor” 1.
create a standalone executable version of “GcodePostProcessor.exe”.Install the Post ProcessorThe next three steps only have to be done once:. launch Processing 3.
copy the contents of “GcodePostProcessor.pde” (attached) into the Processing 3 sketch. save the sketch as “GcodePostProcessor” without the quotes. This will create a folder C:DocumentsProcessingGcodePostProcessor.Run the Post ProcessorThe following steps are required for every plotter file:. open the “GcodePostProcessor” sketch (photo 1). copy “square.gcode” from your desktop to folder C:DocumentsProcessing GcodePostProcessor.
click the Processing “Run” button (top-left arrow-head). A series of popup boxes will appear (photos 2.5). click the the first pop-up box and type the filename (in this case “square.gcode”). A file, “square.gcode.gcode”, will appear in your C:DocumentsProcessingGcodePostProcessor folder. 2We will send this file to our plotter shortly.Create an Executable Version of the Post ProcessorThis (optional) once-only step creates an executable version of “GcodePostProcessor.exe”The following steps are required:. open the “GcodePostProcessor” sketch. click File Export Application.
![Grbl Grbl](/uploads/1/2/5/6/125630552/336268145.jpg)
complete the pop-up box (photo 6). click Export. An application.windows64 folder will appear in C:DocumentsProcessinginsertGcode (photo 7).
copy/move this application.windows64 folder to your desktop and rename it “Post Processor”. (photo 8). copy “square.gcode” file to this folder. double-click “GcodePostProcessor.exe” and follow the prompts. The program works as before.1My “GcodePostProcessor” algorithm:. strips out the M2 code at the end of the program.
This prevents the pen marking the paper when the plot is complete. strips out all M3, M5 codes to avoid unwanted pen-lift conflicts. inserts an M3, or M5 code, sequence whenever the g-code changes from G0 to any of the G1,G2,G3 commands, and vice versa.
When plotting, the pen is always down unless a G0 command is received.2“GcodePostProcessor” adds a “.gcode” extension to your original filename which:. groups the source and plotter files together. clearly identifies which of the two files is the plotter file (the filename is longer). makes your plotter file easier to find when using the UGS file browser (otherwise you have to select “all files”).Attachments. GRBL comes with a number of default plotter settings. In most cases these setting are not what we want and need to be edited prior to plotting.
This is a once-only process.There are two ways we can do this:. edit the GRBL settings using the arduino “Serial Monitor”. use the command line in “Universal code Sender”.Both methods are similar.
Let’s use the command line in “Universal Gcode Sender” as that requires less cable swapping:Connect your plotterTo do this:. Plug the arduino USB cable into your computer.
launch “Universal Gcode Sender”. select your COM port. set the communications speed to 115200 bauds. click “Open”.
A list of plotter settings will appear 1Change your plotter settingsThe settings for your plotter are stored in non-volatile memory which means they only need to be configured once. Positioning your penWithout limit switches, your arduino thinks that the pen is resting at Inkscap coordinate (0,0) when power is applied. I must be doing something wrong because this rarely happens.The following neat trick solves two startup problems in a single operation:.
![Ecut Ecut](http://eng.e-cut.ru/siteimgen/articles/notebook.png)
remove the pen. plot something small, such as our square. the GRBL (0,0) coordinate is wherever the pen stops. GodePostProcessor leaves your pen pointing upwards. (problem 1 solved). switch off the power to the motors. reattach the pen and move it to your Inkscape (0,0) coordinate.(problem 2 solved).
switch the power back on to the motors.You can plot all day now. The plotter will always return to this coordinate:)6 March 2018Finally, with a little help, I have solved the pen positioning problem:. run UGS and 'open' a connection to your arduino. from the command line type 'M3 S90' to raise the pen. (comment: the command 'M5' lowers the pen). 'check' the box labelled 'Enable Keyboard Movement' (photo 1).
set the 'XY step size' to 10 mm. set the 'Feed rate' to 1000 mm/minute. click the +X, -X, +Y, -Y buttons to move the pen.
when the pen is in the correct position click the 'Reset Zero' button. uncheck the 'Enable Keyboard Movement' boxThe plotter will now return to this position.Plotting an imageUsing photo 2 as a reference:. launch “Universal Gcode Sender”. enter the COM port attached to your plotter. set the communication speed to 115200 bauds. browse for a modified g-code file.
click “Visualize” and a screen will (eventually) appear. The solid blue path indicates when your pen will be up. click “Open”. Your arduino settings will roll down the screen 1.
click send. The yellow virtual pen, and your plotter, should both start moving1Check your paper dimensions, and other settings, before you press “send”.
If necessary correct them using the command line. There are several ways to control your vertical pen-movement should it raise when you want it lowered:(1)The simplest solution is to unscrew the servo arm and rotate the arm through 90 degrees as you are only using 90 degrees of the possible 180 degrees offered by servos.(2)Photo 1 shows a software method for reversing the your pen direction.
Change the value of line 48 in “spindlecontrol.c” from 16 to 31, and the value of line 49 from 31 to 16, then recompile and upload GRBL to your arduino.Changing these numbers slightly enables you to obtain 90 degrees exactly. In practice these values are close enough.(3)I discovered this method quite by accident. But first we need some background.In order to free-up the arduino PWM pin (pin 11) we swapped “spindlecontrol.c” with code of our own which tricks GRBL into accepting a command such as “M3 S1000” to move the servo-arm on our plotter. Similarly we use the command “M5” to restore the servo-arm to it’s original position.While on the subject of M3 and M5, GRBL requires a NON-ZERO spindle-speed value before these commands will work. For this reason most programs send an intial “M3 S1000” to the plotter after which you can use M3 without the “S” (spindle speed) value.Here is where you have to “think outside of the square”. “S1000” is not a command. It is a value parameter that can be attached to either the “M3” or the “M5” command.
Why then do most programs send an initial “M3 S1000” to the plotter, then use M3 for pen-down which leaves an unwanted ink-mark on your paper?I get the impression that since you would only lower the spindle on a milling-machine while it is spinning, everyone uses “M3 S1000” for pen-down.When writing GcodePostProcessor I decided to use M3 for pen-up and M5 for pen-down which works beautifully. The only problem that I have encountered is that your pen is is up when it should be down when sending G-code directly to your plotter from third-party programs.
Just unscrew the servo-arm.But there is a simpler solution. Instead of tricking GRBL with a little white lie (“M3 S1000”) why not tell it a great big whopper in the form of “M5 S1000” which, when interpreted, means “spindle off, but rotate at 1000rpm”. Much to my amazement, this actually works!!!!The beauty of “M5 S1000” is that our M3 and M5 commands are now in sync with the rest of the world. For this reason I have rewritten “GcodePostProcessor” using “M5 S100” to initialise the servo.I have called this new version “GPP.pde” to avoid confusing the two programs.
Download and “unzip” the attached “GPP.zip “file to your desktop (or other convenient location) and double-click the file “GPP.pde” to run.The two extra “header” and “footer” files suppress Inkscape “headers “ and “footers” if you direct the g-code output from Inkscape into this folder. These two files are blank text files that have been renamed.The file “target.gcode” is a small GPP test file should you wish to confirm that the program works as described. Just compare the contents of “target.gcode” with the contents of “target.gcode.gcode” once you have run GPP.to view my other instructables. 'Step 8: Raising and Lowering Your Pen' of this instructable lists several methods for solving your problem. If you are using the 'spindlecontrol.c' file that is attached to 'Step 3: Modifying GRBL' then I suggest that you: - rotate the servo arm 90 degrees such that the pen is up when power is first applied. run your code through 'GPP.pde' before sending. The file is attached to Step 8.
The above version of spindlecontrol.c uses M-codes for raising and lowering the pen. GPP.pde simply inserts the correct M-code sequences into your g-code. The latest GITHUB version of 'spindlecontrol.c', however, appears to use a negative Z value for pen down and a positive Z value for pen up in which case the GPP,pde solution may not work. The following comment is attached to the latest GITHUB version of 'spindlecontrol.c': 'If you want to have the pen go to the up position at turn on, define a negative Z work offset. Send the command 'G10 L2 P0 Z-2'. This will trick Grbl into thinking the pen needs to be up.' As yet I haven't tried this new version so am unable to comment.
If all else fails, place a piece of scrap paper beneath the pen tip until the plotter starts working. Hopefully it won't come to this. In answer to your question. 'I don't know':( But you have raised my curiosity!! There are three versions of the file 'spindle)control.c': - the original version - the version which I have archived in Step 3 of this instructable - the latest version which may be found at The original version supports the laser mode, details of which may be found at The archived version is a substantial rewrite of spindlecontrol.c and requires that M4, M5 codes be inserted into the g-code output from Inkscape The latest Github version uses the positive and negative z-axis values in the g-code output from Inkscape to raise and lower the pen. This version sounds promising.
At present I don't have a laser to try. The Notepad text editor has a file compare function, an example of which is shown in Step 1 of this instructable. My guess is that the code with the least changes is more likely to work. My first approach to finding out would be to try each of these versions in turn. Sorry that I can't be more helpful. If I find an answer I will let you know. Well I was actually using GPP when this was happening.
But my solution was to use the original code the ‘Gcodepostprosess’ version. And it worked fine. I tried the GPP again after I got it working with the first version but again it was in reverse.
So am sticking with first version. The only problem I have now is size.
I have the 0:0 start point but it always tries to go off the page. I’ve started using a 100:100 page and it seams to help but still not perfect. Going to add endstop see if that will work. Thanks again for your reply. Glad that GcodePostProcessor.pde has solved your problem:) I'm not certain that I understand your 100:100 problem?
If the command G00 X100 Y100 is moving your plotter more than 100 millimeters then you need to change the $100,$101,$102 values shown in Step 6. The values of 80 for my plotter were calculated as follows: GT2-20 motor pulley = 2.20 = 40mm per revolution 1.8 degrees per step motor = 360/1.8 = 200 steps per revolution. Motor controller micro-stepping = 16 From which steps/mm = 200.16/40 = 80.
Thanks so much for the tutorial! I'm having trouble with the new spindlecontrol.c file. I don't see anywhere to 'download' it on the buildlog website, so I'm assuming I copy and paste the code? It's giving me trouble, as I think the formatting on the webpage has a few mistakes. Maybe I'm making a simple mistake, but I haven't edited anything yet. Arduino IDE is giving me syntax errors on the code I directly got from buildlog.