how do I control a stepper with g code

I have been looking at various addresses on the internet trying to find a simple piece of code to run a stepper using grbl and g-code. The nearest I can get is here It says 'From here, you can simply start sending Grbl some G-code commands, and it'll perform them for you' I can use the monitor and send a single command eg x20, but I have no idea how to write the information into a program. Would someone mind just giving me a start? a simple sketch that I could experiment with that allows me to add instructions to move the stepper? thanks.

I have not used GRBL but as far as I know it expects to get a sequence of GCode instructions from somewhere. I think it can read them from a file on an SD Card or receive them via Serial from a file on a PC. The PC would need to have a program to read the file and send the instuctions. AFAIK there is a program called GCodeSender or similar.

You can create a GCode file with any text editor.


I have found one called gcode_interpreter here but it is a rar file, I have never been able to open rar files? Would it then have to be opened on the pc and send information from there?

Use 7-zip to decompress it, as I did (attached as .zip file) (130 KB)

matelot: but it is a rar file,

When you come up against that sort of problem Google is your friend.


does anyone have any experience with the gcode_interpreterdc found here I can get it to load and look as if it is working with a h bridge like this but no movement from the motor. The motor works using similar instructions and the grbl program installed so it is not a controller/motor fault. The interpreterdc calls for signals from the end stops but I don't have those yet, I have put signals on the pins that read the end stops, both 0v and 5 v but no change. thanks

Grbl works pretty well. I've installed v0.9 on an uno for the CNC router I'm building.

To move the X motor you need to send a G01 X20 F100 to move the motor 20 units at a feed rate of 100, Where G01 is a move command, x is the distance to move in mm or inches depending, and F is the federate.

Grbl setup converts the 20 to the number of units to the number of pulses.

You can use the serial window to send the g code commands, or you can download one of the g code senders that are linked to on the grbl site.

Using Grbl, you do not embed the movement into the program, it acts as a interpreter to convert the g code to machine movements.

Generation of the g code can be manual or from CAD/CAM software. I've even seen a g code generator for ink scape.

If you want a good example of interpreting g code without grbl. take a look at:

I have grbl 0.9 in my arduino connected to a servo via a controller like this one If I put x20 into the monitor the stepper moves. That is perfect. What I now want is to be able to give it a list of instructions that can be repeated from somewhere? I have put an interpreter from here into the arduino and the information on the monitor looks good but when I enter x20 into the monitor nothing happens, the monitor says 'ok' but the motor doesn't move. I have moved the control pins to the ones named in the program but it also talks about endstops and execute commands but doesn't say where they should be.

I would be happy to use the grbl 0.9 but I assume I have to send the information (g code) from somewhere but how?

one of the choices in the grbl website is a program called Easel, if I click on it I get a drawing program that I have played a little with but can't find any way of being able to send the info to the arduino? Do you use a different program? which one? how do you send info? thanks.

Try searching for shapoko, those guys run G code to an uno to control a CNC machine. Chances are they have this figured out.

the only thing I could find on the shapeoko web site was this

"plug the machine into the computer on which you've installed your choice of Communication / Control software (note that even if you're not using the Carbide Motion Machine Control Software you may need to install it so as to provide driver support)"

nothing about arduinos?

I'm using the Universal G Code Sender. It is a java based program. Here is the link:

sorry for the late reply. That is exactly what I am wanting. I have been playing with it and writing small programmes in notepad that work. I only have one stepper connected at the moment but now I know I can run steppers I will look at building something like this . The next step is to find somewhere that gives a run down of the simple instructions of c gode with examples. Thank you.

The internet knows everything about G-code, and the many many variants. Its a horrid ancient thing (1950's I think initially), and is as clunky as it gets.

Unsurprizingly its reasonable to start here:

matelot: That is exactly what I am wanting.

I got very close to it in Reply #1 :)