## Drawbot G-Code Tutorial

When you first turn on the Drawbot in Arduino, you should see text similar to this:

```== HELLO WORLD ==
(-14.00,-30.00) - {14.00,21.50)
F8.90
A5.00
== <a href="/shop/index.php?main_page=product_info&#038;cPath=1&#038;products_id=2" title="">Drawbot</a> - 2012 Feb 28 - dan@marginallyclever.com ==
All commands end with a semi-colon.
HELP; - display this message
WHERE; - display current virtual coordinates
LIMITS; - display maximum distance plotter can move
DEMO; - draw a test pattern
TELEPORT [Xx.xx] [Yx.xx]; - move the virtual plotter.
As well as the following G-codes (http://en.wikipedia.org/wiki/G-code):
G01-G04,G20,G21,G90,G91
&gt; ```

Let’s take a look at each of these commands and what they do in detail.

HELP;

Type in this command and you’ll see the help message again.

WHERE;

When you first turn on the robot it assumes that it is at (0,0) and WHERE; would return exactly that.  If you moved X+10 and typed WHERE; again it would say (10,0).  X+ is to the right, Y+ is up just like on graphs you’d draw in class.

LIMITS;

limits are the maximum distance the robot will move the plotter.  This is the

```(-14.00,-30.00) - {14.00,21.50)
F8.90
A5.00```

part of the message when you turn it on.  the first parenthesis are the bottom left corner, the second parenthesis are the top right corner, F is the “feed rate” (maximum speed) and A is the maximum acceleration.

DEMO;

You’ve seen the youtube Drawbot video with the test pattern and halftones?  This is how you draw that test pattern.  It’s a great place to start to check if your steppers are backwards or your speeds are too high.  More on that in a future post.

TELEPORT [Xx.xx] [Yx.xx];

When you first turn on the robot it assumes that it is at (0,0).  Let’s say the actual position on the wall is (3,-5).  You need an easy way to correct this.  TELEPORT X3 Y-5; will tell the robot “no no, you’re actually over here.”  After that you could say G00 X0 Y0; and it would move to the actual (0,0).  If you don’t specify an X or Y, the current value will be used.

G00 [Xx.xx] [Yx.xx] [Fx.xx];

G01 [Xx.xx] [Yx.xx] [Fx.xx];

Draw a straight line from the current position to (X,Y) with a maximum speed of F.  If you don’t specify an X,Y, or F, the current value will used.

G02 [Xx.xx] [Yx.xx] [Fx.xx] [Ix.xx] [Jx.xx];

G03 [Xx.xx] [Yx.xx] [Fx.xx] [Ix.xx] [Jx.xx];

Draw a circular arc to from the starting point here to (X,Y).  The center of the circle is (I,J) away from the starting point.  G02 draws a clockwise arcs.  G03 draws a counter-clockwise arc.

G04 [Px.xx];

Dwell, aka wait P milliseconds.  Remember that you need 1000 milliseconds to pause for one second.

G20;

Programming in inches (in).  The robot works internally in centimeters (cm), so it will divide all coordinates you give it by 2.54 (cm/in).

G21;

Programming in millimeters (mm).  The robot works internally in centimeters (cm), so it will divide all coordinates you give it by 0.1 (cm/mm).  This is the default.

G90;

Absolute mode.  In this mode, a G00 X1 Y0; will move to (1,0).  This is the default.

G91;

Relative mode.  In this mode, a G00 X1 Y0; will move 1 cm to the right.

Tags: , , ,

### 2 Responses to “Drawbot G-Code Tutorial”

1. bob says:

Hi

I’ve built the mechanics and programmed the Arduino and steppers move OK and I can communicate with the Arduino OK via the serial port.

However, i can’t seem to get the Java code to work, when i execute the bat file it keeps on crashing, this is On Win7.

Also, when I try to compile it on my Mac it won’t compile, error messages regarding gnu.io

Any help would be much appreciated as it’s a great project!

Bob

• Dan says:

Aha! Thank you for posting and pointing out another step I missed. You’ll notice I don’t really talk about the Java stuff in the instructions because it’s still very much in development. To compile you need the RXTX library. link the RXTXComm.jar file to your project in Eclipse (or whatever Java compiler you use) and when you run the program make sure rxtxSerial.dll is in the right folder. The rules are slightly different on a mac, see the rxtx pages for more details.