Write gcode to draw some corners

Hi!

I want to write some gcode that draws corners on the table with my pen that is mounted on the gantry, to be able to quickly calibrate my LR2.

By corners, I mean something like this:

How would something like that look like in gcode? Would be nice to be able to also change the size of the area.

I don’t know how to do this in a easy way. I hope maybe someone of you can help me :slight_smile:

/ Oskar

this assumes you put your pen to just touching the paper close to the lower right corner.
It will zero out everthing when you hit go.

G92 X0 Y0 Z0
G0 Z10 F1200
G0 X20 Y20 F3600
G0 Z-.5 F1200
G0 X10 Y20 F3600
G0 X10 Y30 F3600
G0 Z10 F1200
G0 X10 Y100 F3600
G0 Z-.5 F1200
G0 X10 Y110 F3600
G0 X20 Y110 F3600
G0 Z10 F1200
G0 X100 Y110 F3600
G0 Z-.5 F1200
G0 X110 Y110 F3600
G0 X110 Y100 F3600
G0 Z10 F1200
G0 X110 Y30 F3600
G0 Z-.5 F1200
G0 X110 Y20 F3600
G0 X100 Y20 F3600
G0 Z10 F1200
G0 X0 Y0 F3600
2 Likes

I wrote a page about some basic gcode here:

https://docs.v1engineering.com/learn/gcode/

Hopefully you can get to the point where you can read what Barry wrote and then write your own.

1 Like

There is value in learning g-code and even hand code some things as exercises, but typically, you don’t want to hand write g-code. It can be done (as Barry as done), but 99.999% of all g-code is created by programs from some sort of drawing or model. It would take just a few minutes to draw your corners and generate g-code in Inkscape, Fusion 360, Lightburn, or a number of other programs, and changes like resizing or picking a new origin point would be simple once you have your initial drawing done.

The problem is that Marlin’s g-code does not have programming concepts like variables or functions. That means if you want to make changes like resizing your “frame” or making the center of the frame rather than the corner the origin point, you would need to recalculate most, if not all, of the coordinates, and completely rewrite the code. And there is more room for errors when writing g-code directly. That is less of an issue when drawing with a pen, but bad things can happen with g-code mistakes and a router.

In addition to Jeff’s g-code basics, you might want to take a look at Marlin’s g-code reference. Re-writing Barry’s g-code to be the size and orientation you want is a good exercise, just not a general purpose solution. Also, it is not a bad idea to take a look at handwritten g-code in a g-code simulator like this one before running it on your machine.

2 Likes

That’s definitely true, Robert. Learning the CAM and design tools are much more useful. This particular job would be easy to do in CAD/CAM. I also agree that learning the basics is really helpful. It helps you when debugging problems (when you can read the gcode created by CAM) and when configuring those tools (they often ask you to set the preambles, or choose options directly related to the gcode).

This particular problem might be a good chance to get more familiar with gcode, but it isn’t required.

1 Like

Definately reccoment sanity checking gcode before running it. I use this.

2 Likes

I love this forum.

All of your replies are so helpful and written in such a sweet way :innocent: Really just like, “Oh you need help, here’s help, and some more help”.

And am VERY grateful! Thank you so much!

I do understand gcode to some minor degree, but I was not sure about how to put something like this together. Now I know, and I am able to tweak this to fit my needs! THANK YOU!

5 Likes