G-Code Cheat Sheet + MDI: Your CNC Secret Weapon

5 months by cncdivi

G-Code Cheat Sheet + MDI: Your CNC Secret Weapon

CNCCookbook’s G-Code Tutorial

G-Code Cheat Sheet?  Now You’re Talking!

Here’s an insider tip for you: by utilizing just 9 g-codes along with a feature called “MDI”, you are capable of performing all the tasks of a manual machinist using a CNC, but in an improved and quicker manner.

If you’re a manual machinist looking to become productive fast on a CNC, this is your secret weapon and shortcut.  If you’re a beginner starting out with CNC, this is a way to quickly do some simple things before having to learn all the rest of it.

Have I got your attention?  Cool!

CNC Can Be Quick and Dirty Too!

Many manual machinists are under the impression that CNC is only good for manufacturing multiple identical parts, and that one offs are a lot faster to do on manual machines. They have visions of spending hours making CAD drawings of even the simplest parts and then feeding those CAD drawings through a CAM program to finally produce G-Code, at which point they are finally ready to make some chips.

It just ain’t so!

Good CNC machinists can do most anything a manual machinist can do and then some. This article will teach you how.

Lathe Gal

You can do anything on your CNC that the manual machinist can and often faster once you know how…

DRO’s and Power Feeds

The first trick is to forget about G-Code, CAD, and CAM. Think of that fancy CNC machine as nothing more than a manual machine that has DRO’s (digital read outs) and Power Feeds on all of the axes.

For beginners:

  • Power Feeds:  The machine can move under motorized control.  Easy, right?
  • DRO:  DRO is short for “Digital Read Out”.  It’s just an indicator telling you the exact coordinates the machine is at every step of the way.

Most manual machinists would see a machine like that as a tremendous improvement over handwheels and no DRO’s, and wouldn’t hesitate to use such a machine.

But it gets better.  By mastering those 9 simple g-codes I mentioned and a feature called MDI that we’ll cover shortly, you can tell your “power feed” exactly what coordinate to stop on.  Imagine how much that would improve your productivity and your parts if all power feeds had that capability.

Once you get used to the idea of using your CNC in that capacity, you’ll be surprised at how easy it is.

Fanuc Panel

A typical Fanuc panel you might use…

Let’s get started.

Power Feeds for your CNC: Jog Mode

What about those Power Feeds?

There are two approaches and each one involves a “mode”.  Your CNC machine has a variety of modes.  For example, you probably already know about “Jog Mode”, which is one way to cause the machine to move.

Jogging is where you’re spinning a simulated electronic handwheel, or holding down a button or joystick to make the axis move. You generally select an axis, select a speed or multiplier (x1, x5, x100 or whatever), and then operate the control to move the axis. It’s pretty easy. Here is a typical pendant with an electronic handwheel (called an “MPG” or “Manual Pulse Generator”) for jogging:

jog mode Pendant

A pendant for jogging a CNC. Select axis and speed then spin the wheel…

But, there is a better approach if you’re actually trying to do some machining as opposed to touching off a setup.

MDI Mode

MDI Mode is the trick you’ll use to unlock even more productivity than Jog Mode.   Yes, you can cut in Jog Mode and it’s sort of like using handwheels or a power feed on your manual machine.  But setting up to precisely cut to a certain point is much faster and easier with MDI Mode.

The Manual Data Input Mode (MDI) is one of the modes your CNC machine can operate in. The idea is to enter g-codes on a line which are executed immediately by the machine–you don’t have to write an entire g-code program when a line or two will suffice.  You just type in your line of g-code, press a button, and the machine executes it.

MDI offers a lot of power while requiring very little learning. With MDI, CNC can be quick and dirty just like manual machining.  You can use MDI commands to machine your part, but even if you plan to run a part program, MDI is still super useful for setup operations.

MDI is accessed via the MDI key on your CNC machine’s control panel:

Press the MDI key on your CNC control panel to go to MDI mode.

Press the MDI key on your CNC control panel to go to MDI mode…

With MDI, you input short commands that tell the machine what to do.  We’ll get to our g-code cheat sheet for you shortly, but let me finish setting the stage first.

Digital Read Outs (DRO’s)

Check out this Mach3 Standard Mill home screen:

Mach3 Standard Mill

Mach3 Standard Mill Screen Set…

You can see the XYZ DRO’s on the lower right. Just to the left of them is the MDI type-in field. When not running a program, you can type G-Code commands into the MDI field for immediate execution. Look up in your operator’s manual how to go about accessing MDI for your controller.

Get familiar with where the DRO’s are located on your CNC machine.

G-Code Cheat Sheet for MDI Commands

You’ve got the basic picture of how MDI will work, so now it’s time to get into the exact g-codes you’ll want to use and get them together on a Cheat Sheet for you.

Move in a Straight Line:  G01

G01 straight line move in CNC g-code

G01 is the very first g-code you should learn as it is the one you’ll use the most.  It causes the machine to move in a straight line based on the coordinates you enter afterward.  For example, let’s say you’ve got a piece of material in the machinist vise, and the top left corner is at 0, 0, 0.  You want to move the cutter tip to that location, but a little above the work as you’re not ready to cut yet.  You could use this MDI command:

G01 X0 Y0 Z0.5

You can see how that would move to X = 0, Y=0, and Z=0.5.  Congratulations, you’ve just learned your first g-code and it was pretty obvious.  Some things to take note of:

–  G-Code ignores spaces.  You could’ve also typed (and you will often see in programs) this:  G01 X0Y0Z0.5

–  The Z-axis is positive in the “up” direction.  As you can imagine, it’s extremely important to get used to which way the spindle will move, up or down, based on your commands.  If it moves the opposite of what you’d expect and you’re at all close to anything, you may crash into it.

–  The g-code dialect will determine whether you need that leading zero or could write “G1” and whether you need a decimal point no matter what like “X0. Y0. Z0.5”.  If things act odd, be sure to check on that for your machine.  Many CNC’ers just always use a leading zero because the next machine they use may require it.

For an understanding of how to establish the part corner being at 0,0,0, consult your machine’s manual or check out our article on setting part zero.  I will tell you in advance it’s just like using a DRO.  You position the tip of the cutter somewhere and press buttons that set the “DRO’s” to be zeroed.  Easy, but just a little different on each machine.

Helpful Tip:  Use G01, not G00 to avoid high speed crashes

The experienced CNC’er reading this will wonder why I didn’t start with G00 instead of G01.  After all, most g-code programs start with G00.  This is a bit of extra credit, but an important bonus point.  G00 is a rapids move in a straight line.  It has the same syntax as G01, so that last move would be:

G00 X0 Y0 Z0.5

The difference is that G01 moves at feed rate and G00 moves at rapids, which is the fastest your machine can go.  When I am operating a CNC manually in MDI mode, I prefer not to use G00.  It’s just too fast and G01 is safer.  Plenty of time to hit that red button if you type in the wrong thing.

You can move pretty fast too in feed rate, so let’s make our next g-code the “F” word (hey, what did you think that meant?).

Feedrate: F

F feedrate CNC g-code

“F” word, eh?  No, not that F-word, silly!

In g-code we refer to words and addresses.  The word is the letter and the address is the number that follows.  “G01” is word “G” and address “01”.  Hence, we call it the “F-word” because it uses the letter “F”.  This is the g-code needed to set your feedrate.

For example, on a machine using Imperial units, “F100” tells the machine to move at 100 inches per minute.  When I am just moving the tip around in air, I generally will use “F100” as the rate I move.  I consider that to be my “rapids” speed for MDI work.  It’s slow enough you have plenty of time to react and fast enough so you don’t grow too old waiting.

You specify the F-Word before the move. So, to plunge down from our last move at a feedrate of 5 inches per minute to a depth of 1/2″ after our last MDI command we’d enter something like this at the MDI prompt:

F5

Z-0.5

Some things to note:

–  We didn’t have to specify G01 again, although we could have.  CNC is modal, meaning it remembers a lot of things for you.  In particular, the motion is modal.  If we had just run a G00 and no other motion commands since, any coordinates we enter result in G00 moves.  In this case, we depended on the prior G01 mode to still be in effect.  This is another reason I dislike using G00 for MDI work.  I’m just the kind of guy who’d do a G00, get distracted, think I was in G01, and enter a move.  DOH!  Broke another tool, darn it!

– By convention, we often run our machines with Z=0.0 corresponding to top of material.  So, that Z-0.5 commands the tool to feed downward half an inch into the material.  Any time you enter a negative Z value, be in the habit of checking carefully that the feedrate is set properly and that you really do want to put the cutter into the material at that location.

–  Not only does g-code not care about spaces, it doesn’t care about any white space.  I could’ve put the F-Word on the same line:

F5 Z-0.5

Okay, you’re cooking with fire now.  You can move the tool and control how fast it moves.  Hopefully you like my use of a big F-word instead of G00, and I also hope you have a good tool like G-Wizard CNC Calculator to help you determine the right F-Word to use.  In other words, the correct Feeds and Speeds.

Spindle Speed: S

Speaking of Speeds, it’s time to set the spindle rpm.  For that, we’ll use the S-Word and follow it up with rpms.  “S1000” gives 1000 rpm on the spindle.

Except it doesn’t.

You type that in and the spindle just sits there. All S is doing is telling the spindle that when it starts spinning, it will do so at 1000 rpm.  Kind of like “F” not causing any motion, just telling the CNC that when the motion happens, that’s how fast it should move.

To actually start the spindle spinning you will need:

Clockwise Spindle:  M03

As soon as you enter the “M03”, the spindle will start to rotate clockwise at its programmed speed.

Now you really are in business.

You can move the tool tip at feed speeds and you can turn on the spindle.  Pretty easy so far, right?

You can stop the spindle with M05 if need be too.

And we’ve got most of it down.  Just one thing, you probably don’t want to be cutting without some coolant, right?

Coolant:  M07/M08/M09

Good idea, let’s don’t cut without coolant unless we really understand dry machining, and even then, we probably want an air blast.

There are definitions for what M07 and M08 are supposed to do, but I am not going to tell you what they are because they change from machine to machine.  People can hook up the machines to do all sorts of things.  For example, M07 could turn on an air blast or mist and M08 could turn on full flood coolant.  Suffice to say M07 and M08 turn on two different kinds of coolant.  Give each one a try to see what it does.  M09 turns off the coolant, which is another good one to know.

That ought to do it.  You should be ready to cut.  But wait, there’s one thing missing.  How about selecting a tool?

Tool Changing:  T+M06

You could certainly manually insert a tool in the spindle taper.  That’s not hard and you need to know how to do that.  But if your machine has a tool changer, there’s a bunch of them sitting there and probably several would be convenient to access.

With just two more g-codes, you’ll know how.

Tool Changing is a two step process on a mill (and on some lathes, but most lathes don’t use the M06).

First, you select the tool with a T-Word followed by the tool number.  Then you perform the tool change with M06.  You can put them on two lines or write them together:

T12 M06

Select tool in slot #12 and swap it into the spindle.

One more for extra credit:  Peck Drilling

With those 9 g-codes, you can do a lot.  You can run circles around your manual machinist friend, for example.  And it wasn’t hard to learn or understand either, right?

Well, in for a penny, in for a pound!

Let me give you one more, just because it is often convenient to drill holes using MDI g-code, and when you drill a hole deeper than one diameter, you really ought to peck drill.

G- Code includes what are called “Canned Cycles.”  Canned cycles do all sorts of miraculous things in one command instead of requiring you to write a bunch of g-code.  Imagine how painful peck drilling would be if you were programming each in and out cycle all the way down the hole with G01.  You could do it, but it wouldn’t be much fun.

Canned cycles are available for all sorts of functions, but right now let’s learn how to do a simple G83 deep hole peck drilling cycle.  I picked that one because it is fairly universal.  There are faster cycles for special cases and slower cycles for other special cases, but this one will work for a lot of holes.

A typical G83 looks like this:

G83 XYZ R P Q F L

XY: Coordinates of the hole

Z: Hole bottom

R: Retract position in Z. Motions from initial Z to R are performed at rapids speeds. From R to hole bottom is done at feed speed.

P: Dwell time at bottom of hole.

Q: Depth to increase on each peck.

F: Cutting feedrate

L: Number of repeats

I’ve left out the addresses associated with X, Y, Z, R, P, Q, F, and L.  Once the drill reaches the bottom of hole and has finished dwelling, retraction is at rapids speeds.

Now here is a real example:

G01 X0 Y0 Z0.5

G83 X0Y0Z-1.0 R0.1 P0.1 Q0.1 F2

We’ll ignore L for the time being.  Repeats are probably not something you will use much for MDI.  I stuck the G01 in so we would have a frame of reference.

So, the tool tip moves to X0Y0 and is 1/2″ above 0, which I usually program to be 1/2″ above my workpiece.  We’re going to peck every 0.1″ on the way down.  What that means is the drill will retract every 0.1″ of additional depth drilled.  And, we’re going to dwell a tenth of a second at the bottom of the hole.  This just cleans up the bottom and makes sure there’s no chips left down there.

Important:  Once you complete a drill cycle, every move will start a new drill cycle at the new location.  Cancel the drill cycle by running “G80”.

That’s it!

You’re now armed with 10 basic g-codes you can use at the MDI prompt of your machine to do all sorts of things.  Go ahead and practice them a bit with G-Wizard G-Code Editor and Simulator.  You can learn a lot of an nc viewer like G-Wizard.  Once your confident on the simulator, try it at your machine.  It’s very convenient to drill a quick hole or to face off the top of some material without having to go fire up your CAD/CAM software each time.

Freebie: G-Code Cheat Sheet

Would you like to download a nice pdf cheat sheet you can print and tape to your machine enclosure?

Using G-Wizard Editor’s Wizards to Help Keep Track of the Codes

OK, now I’m going to give you something even better than a g-code cheat sheet.

You’re probably starting to wonder how you’re going to memorize all these codes. After all G00 and G01 don’t exactly mean anything by themselves–they’re pretty arbitrary. Don’t worry, there aren’t all that many g-codes you’ll be using on a regular basis, certainly not on MDI. You’ll pick them up quickly with practice, and for the rest, there are quick reference tables and other tools.

But what if you had a smart assistant right near your elbow at all times?  This assistant knows all about g-code and can either help you find and use the g-code you need, or tell you what a particular g-code does.

We call that handy tool G-Wizard Editor, and one of it’s best features is its G-Code Wizards. They remember all this for you so you don’t have to remember the exact codes when you’re writing a program. For example, the Toolbar groups different G-Code functions you can select for entry:

GWE Wizards

The buttons to the right of “Insert” trigger the various code insertion Wizards…

If you select “M-Code” (or type “Ctrl+M” for M-Code on the keyboard), you’ll get the Wizard for entering M-Codes:

M-Code Wizard

Each code is called out with a description of what it does…

Each code is called out in the list with a description of what it does. Just select the code you want (or type its number, the Wizards are designed so you need not use a mouse) and click “Insert” (or press Enter) and it goes into your program.

Don’t see it on the list? You can close and pop up a different Wizard or switch directly to G-Codes using the radio button at the top of the panel. The G-Code Wizard is a little fancier than the M-Code Wizard:

G-Code Wizard

G-Codes are grouped in categories…

The G-Codes are grouped into categories by the buttons at the top to help you narrow your search. So far we have only considered G-Codes from the Motion category, G00 and G01, but there are many more and we’ll be going through all of them.

Another thing to note: the Wizards only show you codes that are enabled by the Post for your control so you can’t inadvertantly enter a code that won’t be recognized and will cause an alarm (CNC jargon for an error). There are a lot more handy capabilities in the Wizards that we’ll be covering during the rest of this course.

Conversational Programming with G-Wizard Editor

Did you like the G-Code Wizards?

They’re real time savers, but it gets even better.  GW Editor has what’s called Conversational Programming.  It lets you choose a basic operation from a graphical menu like this:

Once you’ve picked the operation, the Conversational Programming Wizard asks you a few simple questions and BOOM! (no that wasn’t a machine crash, I just got excited), it creates a little custom g-code to do just what you want.

Learn more about Conversational Programming here.

Final Word: Watch Out Below!

MDI is almost too easy, in fact. I broke more tools when I was learning CNC by fat fingering MDI than running programs. If you get confused, it’s very easy to start the cutter moving at high speed in totally the wrong direction. If you’re lucky, it’ll strike the edge of the workpiece moving too quickly and just snap off the cutter clean. If you’re not so lucky, you can run it into the vise or worse, your table.

Here are some tips to try to cut down on the incidence of accidents with MDI:

– Always think carefully about what’s about to happen before hitting the Enter key to initiate the MDI command.

– The bigger the tool, the worse the mishap if it crashes. Start out with small cheap endmills and leave the big expensive facemills and indexable tooling until you’re sure you have the hang of it.

– Beware dropped digits and signs. This is an easy way to go somewhere you didn’t expect.

– Use your FRO (Feedrate Override) to slow everything down until you’re sure. In fact, crank it way down before you start the command and inch it up as things look to be going okay.

– Remember, avoid G00 and stick to G01 with a slow feedrate. First because you’ll move more slowly and second because you won’t get confused about whether the machine is in G00 or G01 when you’re first starting out.

– Use your pendant and jog. It’s easier to let up if things start to get pear shaped on you. Save MDI for feeding cuts.

– Entering the workpiece or moving close to the workpiece requires the most vigilance. Once you’re in the neighborhood, small moves at feedrates are less likely to be a problem.

– Before you issue an MDI, make sure you know where the big red E-Stop button is. Visualize pressing it a couple of times. Don’t hesitate to reach for it if you don’t understand what’s going on.

– A lot of CNC controllers have a distance to go DRO readout. Use it to make a quick check as the cutter starts getting close to cutting–if distance to go is wildly greater than the amount you expect the cutter to have to move to finish your command, you have a problem.

– Don’t allow distractions while you’re running the machine. Give it your full attention, and don’t walk away. When a pilot is landing a plane, he uses his full concentration–all conversation in the cockpit not specific to landing the plane is stopped.

Exercises

1. Take out your manual and figure out how to jog your CNC machine and how to issue MDI commands.

2. Use GWE as a G-Code simulator. Start with an empty file and issue your faux-MDI commands by just typing them into the text pane. Watch what happens. Get good at predicting what will happen. Learn to make the cutter go where you want it to go.

3. Once you’ve mastered getting G01 to go where you want it to in GWE, get comfortable practicing MDI commands on the machine without turning on the spindle. Start out with the spindle high above anything it might touch, and don’t issue any “Z” axis moves until you’ve got the hang of X and Y.

4. Load a piece of scrap material and a cutter and try some practice passes under MDI control.

5. Learn to use touch offs and an edge finder to precisely locate the tool just as you would with your manual machine. If you don’t know how to do this, stay tuned as we’re covering it next.

6.  Learn even more about g-code by studying our free collection of g-code files and examples.

 

Like what you read on CNCCookbook?

Join 100,000+ CNC'ers!  Get our latest blog posts delivered straight to your email inbox once a week for free. Plus, we’ll give you access to some great CNC reference materials including:

  • Our Big List of over 200 CNC Tips and Techniques
  • Our Free GCode Programming Basics Course
  • And more!

Just enter your name and email address below:

Full Name
Email *
100% Privacy: We will never Spam you!

4.4/5 - (14 votes)

Recently updated on April 30th, 2024 at 11:10 am