G Code Example: How to Run Your First CNC Program

Visualization from Universal gCode Sender of the g code example program.

Congratulations, you machine is under its own power. By now you have spent some time jogging the machine around using the keyboard or the buttons on Universal G-Code Sender. This is all well and good, but the real power of your CNC machine lies in its ability to run long complex gcode programs. The following is a step by step guide on how to run a CNC program. We even include a gcode example program to run that will draw a circle. If you don’t have your machine running just yet and would like some guidance, check out How to setup your Arduino CNC Machine.

G Code Example

The following is exactly what is saved in the circle.nc file. Click the link below to download the file.

[thrive_2step id=’558′]Download the g code example file[/thrive_2step]

 

G17 G20 G90 G94 G54
G0 Z0.25
X-0.5 Y0.
Z0.1
G01 Z0. F5.
G02 X0. Y0.5 I0.5 J0. F2.5
X0.5 Y0. I0. J-0.5
X0. Y-0.5 I-0.5 J0.
X-0.5 Y0. I0. J0.5
G01 Z0.1 F5.
G00 X0. Y0. Z0.25

This simple program will draw a 1” diameter circle about the origin. Use this program to test your CNC machine and confirm your axis directions are set correctly.

Note all gcode programs a simple text files save with a “.nc” extension. You can open the “circle.nc” file downloaded above in a text editor like Notepad. You can also copy and past the above lines into a text editor and create your very own CNC program. Simply save the file with a .nc extension.

Start Here

Use the following steps to run the program… If you are more of a visual learner, scroll down and click on the video below for walk through of the process.

1. Load a marker into the spindle (Keep the spindle off!) Markers work better than pens or pencils because the tip is softer and more forgiving. Also setup a piece of paper or other material on which to draw near the center of your machine’s work envelop.
2. Power on your machine
3. Connect to the machine with Universal gCode Sender

Set Your Zero Position

4. Jog (move) the spindle to the center of your machine table

a. Under the “Machine Control” Tab enter “.1” into the “Step Size” box & press enter
b. Ensure “inches” is selected
c. Use the X+,X-,Y+ and Y- buttons to move the machine close to the center of your work table (You can also use the arrow keys on the keyboard)
d. Press the “Reset X Axis” button (This tells the machine to remember this position as your X zero location)
e. Press the “Reset Y Axis” button (This tells the machine to remember this position as your Y zero location)
f. Now slowly use the “Z-“ button to lower the marker tip. When the marker tip gets close to the paper, stop.
g. Adjust the “Step Size” to .01 (Remember to hit enter after you enter your value)
h. Continue lowering the marker until it touches the paper by tapping the “Z-“ button.
i. Press the “Reset Z Axis” button (This tells the machine to remember this position as your Z zero location)
j. Retract the marker from the paper using the “Z+” button. Go at least .1” above the paper. This is equal to 10 clicks of the “Z+” button when your step size is set to .01

Load the CNC Program

5. Ok, now the machine is almost ready.
6. Go to the “File Mode” tab
7. Select “Browse” and search for the “circle.nc” file (If you have not downloaded the file click [thrive_2step id=’558′]here[/thrive_2step])
8. Click “Open”
9. The next button press will send the “circle.nc” g Code program to your machine and it will start to move. As soon as I hit “Send” I like to move my mouse cursor over the “Pause” button. If anything goes wrong, all I have to do is click the mouse to stop the program since it’s over the pause button.
10. This is for all the marbles. Click the “Send” button.
11. The machine will start moving.
a. First, it will move the Z axis to .25”
b. Next, the machine will move to X = -0.5 and Y = 0.0 (Note the marker should not be touching the paper yet)
c. Now the machine will lower to Z = 0.0 and then marker should touch the paper)
d. The machine will slowly draw a clockwise circle.
e. When the circle is complete, the machine will move the Z axis up to .1”
f. Now that machine will return to the X & Y zero position.
g. Finally the z axis will move back up to the original .25” starting position.

Video Walk Through

 

Click here to watch the video on YouTube.

Conclusion

That’s it! You just ran your first CNC program. As you run more programs, this process will become second nature. Again you can download the g code example by clinking the link below.

[thrive_2step id=’558′]Download the g code example file[/thrive_2step]

 

If you run into any problems, contact me at tim@diymachining.com or in the comment section.

What CNC program are you going to run next? Leave a comment and let me know.

Thanks for reading. Until next time…

Tim

17 Comments

  1. bovb

    home made cnc…Arduino Uno with a cnc shield running universal gcode sender…and your code drew a square….what am i doing wrong?

    Reply
    1. Tim (Post author)

      Hmm, that’s frustrating. The first thing I would try is using the visualize feature in Universal GCode Sender. If you run the visualization and the gcode draws a circle, then the problem is likely with your GRBL settings.

      Reply
  2. Alexis Jiménez

    Hi, I am knew in cnc world. I try to learn before to buy a cnc machine. I am from. Dominican Republic. What books you recomend to study and be familiar with this vast World. I want start with basic program lessons and go increasing my level. Thanks for your article.

    Reply
    1. Tim (Post author)

      Alexis, glad you are interested in learning more about CNC machining. In place of books, I am going to recommend a website and a software tool. First, the web site, I would check out http://www.cnccookbook.com/ This site has tons of general CNC information. Great place to learn. Second, the software tool, I recommend you start with Fusion360 https://www.autodesk.com/products/fusion-360/overview to learn the CAD and CAM side of CNC machining. In my experience the CAD and CAM present the biggest learning curves. Hope that helps. Thanks for the comment.

      Reply
  3. CAN

    GREAT JOB THANKS

    Reply
  4. Afshin

    Hi dear tim.

    my name is afshin and i recently made a cnc just for fun.i used arduino uno and cnc shield plus A4988 drivers.and for stepper motors i using nema 23.after plenty search i fined your article and i did everything you said but when i ran the circle.nc code my stepper made the weird sound.i didn’t do any flashing or adjusting my arduino or drivers.i think it needs some kind of adjustment.i dont know what to do pleas help me bro im devastated.thank you for your help.

    Reply
    1. Tim (Post author)

      Afshin, I am not too familiar with the CNC shield and A4988 drivers. However, based on the weird sound from the stepper motor, I suspect you may have one of the motor connections wired incorrectly. I would double check the wiring and try it again.

      Reply
  5. can

    no, you should read about A4966 user manuel
    there is tiney potansiometer you must turn it till souns come normal..
    cheers

    p.c. :for all axis

    Reply
    1. Tim (Post author)

      Can – Good suggestion. I take it you are referring to the comment left by Afshin looking for help with his A4966 drivers. gShield has the same current limiting potentiometers for each axis. This should be set once the final assembly of the machine is complete. If I recall correctly when I set mine, I started with the potentiometers at ~1/2 of the available current and fine tuned from there.

      Reply
  6. Vaire

    Can I use this with the 3d printer its the same setup right?

    Reply
    1. Tim (Post author)

      Vaire – Good question, I don’t see why it would not work. I am not sure how you hold a pencil or marker in the hot end of a 3D printer. Maybe you can tape the marker to the side of the hot end. Will you give it a try and let us know how it goes?

      Reply
  7. UCHE

    Can you run fusion360 with this arduino setup, i am a novice yet thanks TIM

    Reply
    1. Tim (Post author)

      Great question! Yes, you most certainly can us Fusion360 with the arduino + grbl setup. That’s what I use. Fusion360 includes a post processor specifically for grbl. My work flow looks like the following: CAD – Fusion360 then CAM – Fusion360, then post process – Fusion360 which produces the .nc (gcode) file. Next I copy the .nc (gcode) file to my laptop that runs Universal Gcode Sender and is connected to my Arduino+grbl controlled CNC machine. Let me know if you have other questions. -Tim

      Reply
  8. FA

    HI
    my GRBL controller cant send only ( .nc ) file and i dont know how to save it in that form with inkspace ?

    thanks

    Reply
    1. Tim (Post author)

      FA – You are correct, GRBL will only accept gcode (.nc files) streamed to the Arduino using something like Universal Gcode Sender. To generate a gcode file from InkScape, you need an extension. The good people at Norwegian Creations have a great write up about how to do exactly what you want. See the link below…

      https://www.norwegiancreations.com/2015/08/an-intro-to-g-code-and-how-to-generate-it-using-inkscape/

      If that doesn’t get you going, let me know and we can find another solution.

      Reply
  9. FA

    Thanks Pal — it solve the issue
    now i have new one i am trying to fiend G-code controller to my UBUNTU system and run
    smooth ?

    Thanks again

    Reply
    1. Tim (Post author)

      I don’t have any experience with LinuxCNC but I have heard good things. Check out the following link… http://linuxcnc.org/ If that’s not what you are looking for let me know and we will keep working on this.

      Reply

Leave a Comment

Your email address will not be published. Required fields are marked *