G-Code & Ender 3 Help

I have a couple of questions I hope you can help me out with.

A while back I changed the motor to my z-axis. Unfortunately, the g-code from my Cura then had the z-axis raising too high to print. I studied the g-code to the cat that comes with the Ender 3 printer and adjusted the beginning g-code. It works great - for small projects. For larger projects, it sends the skirt (and probably the print) off the bed.

How do I adjust the g-code so that it sets the start at the right position? I’ve tried looking it up, but I’m just getting confused.

Is there a grid displayed somewhere that tells me what the points are on the bed (in case I have to manually adjust it again)? I’m going on the (possibly erroneous) assumption that it’s set up like a standard grid with the bottom left corner being 0,0 or the center of the quadrants and the bed being the upper right quadrant (all positive #s). Am I close?

Is there anywhere to go that I could actually learn G-code for the Ender 3? I’ve found a few sites that explain the general uses, but nothing that goes into how it really works.

Thanks for your help.

Front left corner of the bed should be 0,0.
There are two Gcode commands that can be used to set where your origin point is. They are basically saying how far away the bed is from the end stop switches.
M428 sets your home position to where the print head is currently located
M206 lets you add or subtract from the currently saved home position
Both can then be saved to the EEPROM with M500

I usually end up using M206 most of the time because for some reason M428 which should be more simple seems to give me weird results sometimes. Your milage may vary.

What I usually do is move the X and Y to where the printer thinks 0,0 is. Then measure the difference from the tip of the nozzle to the corner of the bed where actual 0 is.
If the nozzle was sitting 10mm to the right of the corner you could use M206 X10 to move the home offset back to the left. Why you use a positive value to move it in the negative direction seem unintuitive to me but that’s how it works.
Save the setting with an M500 then try homing the printer and moving to 0,0 again to make sure you are now at the corner.

Give this video a watch, it covers this topic as well.

He is using pronterface to send the Gcode commands. I have a touch screen that has a terminal built in that I can send Gcode with. If neither of those are options for you then what you can do is just slice something in cura and edit the beginning of the .gcode file in a text editor to add your commands that you need assuming your menu doesn’t have options for changing these settings.

Hopefully that is of some use to you.
Good luck.


nicely said Blair, I learned something new today, I usually leave the default 0.0 along and M851 the offset to where I need it.


This is great for the starting point at 0,0. Then the code moves the nozzle to a starting position for the print. How do I set Cura up so that Cura designates the starting position of the print? Right now, I have a default starting position in the middle of the bed. That’s great for small projects, but it doesn’t work for projects that cover the entire length of the bed.

1 Like

Do you have this unchecked in the machine settings?

1 Like

Yes. Is it supposed to be?

1 Like

It is unchecked for my printers.
I think I’m now confused what situation and result actually is.
If you have something in the middle of the ‘bed’ in Cura and slice it, does your printer do the purge line in the center and the print is in the back right?
What is the expectation vs the actual result of what you have going on?

1 Like

If I print a mini, the nozzle goes towards the middle of the bed. It’s fine. It’s a small print and does fine. With a print that is generally the same size as the print surface (ie: almost entire width), the nozzle still goes to the middle to start, then runs off the bed. It’s not allowing for the depth and width of the item. If I take out the code that pushes the nozzle to the middle, it starts at the 1,1 position and still runs off the bed, only on the other side. I know Cura generates a starting point, but I don’t know how to access it.

When you slice this mini that is printing in the middle of the bed you had positioned it in the corner in Cura correct?

Now my only thought is that when you copied something from the pre sliced cat file it is messing with what the normal start code is.
You could try adding another machine in Cura - another of your version of Ender 3, then use that one to compare the stock start code to whatever you have going on.

I’m getting the feeling that when you did the stepper change you just ended up going down the wrong path to fix the z offset and added something that is overriding where the corner of the bed should be.

How far off was the z height when you initially had the problem? Just a little bit or was it nowhere close?

Post up your start gcode here, I’m curious to take a look to see if I can find something that looks suspicious. It might be worth reverting back to the stock start code though and taking another look at what’s up with the gap for your nozzle since that seems to be the root of the problem.

When I swapped out the Z motor, the raise in Z-axis was 15 to 20 mm instead of 1 or 2. The filament was cold before it ever hit the bed. I looked at the original g-code and couldn’t make heads or tails out of it.

Here’s what I have now. It works great for small projects, but as I mentioned, it goes off the bed when I start large projects.

; Ender 3 Customer Start G-code
G92 E0 ; Reset Extruder
G1 Z0.75 F3000 ; Move z Axis up little to prevent scratching heat bed
G1 X0.4 Y20 Z0.3 ; Move to start position
G1 X0.4 Y200.0 Z0.3 F1500.0 E15 ; Draw first line
G1 X0.6 Y200.0 Z0.3 F5000 ; Move to side a little
G1 X0.6 Y20 Z0.3 F1500.0 E30 ; Draw the second line
G92 E0 ; Reset Extruder
G1 Z2.0 F3000 ; Move Z axis up little to prevent scratching of Heat Bed
G1 X5 Y20 Z0.3 F5000 ; Move over to prevent blob squish

Looking at the code, I think the next to last line shouldn’t be there as it raises the Z Axis a little too high to start a first layer. Still, there’s nothing here to determine a start position. I purposely kept out the G28 code because for some reason the X and Y coordinates in the machine are set to 0 but Z is set to -70. No clue how that happened.

I’m assuming that the stepper you replaced was of matching specs to the original one at least as far as how many degrees it turns per step. If it wasn’t matching you would be seeing your models be really squished or the layers would be too far apart to print.
So, assuming the stepper is fine and didn’t need a change to the steps/mm for the Z axis then I really don’t get why plugging in a new stepper would cause your Z to all of a sudden have an enormous gap that wasn’t previously there. I feel like something else happened.

The second last line in your start code that moves the Z up 2.0 should be fine. Mine moves up 2.0. It just gets the nozzle out of the way then one of the first lines of gcode in the sliced file should move the nozzle over to its start point in the bed and move Z back down to the correct height.

The start code you posted looks like it makes sense apart from not having a G28 home command.

When you say that Z is showing -70, is that when you have the nozzle touching the front left corner of the bed the display is showing that you are at X:0 Y:0 Z: -70?
If so then I would think that the nozzle would end up 70mm in the air if it tried printing the first line at Z:0
It kind of sounds like a home offset thing again where you need to get that Z value down to 0. When your printer homes it should hit the Z end stop switch and think that point is Z:0. Then you adjust your gap for the first layer using the bed knobs.
If it thinks that where the end stop switch triggers is at -70 then you have some odd stuff going on and again I think you should dig into my earlier post about setting home offsets.
When you use the move commands on the printer and move Z to 0, where is it sitting for height compared to the bed. When you home Z, where is it sitting for height?

Basically I’m thinking that the printer has something stored in the EEPROM that is causing it to be confused about where its home position is. It might be worth looking into using Pronterface so that you can send commands and read the settings if your stock firmware isn’t showing you everything.

If I use the G28 code, the nozzle goes to 0,0,0 and keeps hitting the bed like it’s trying to go further down. When I took that out and manually set it, it works fine. Everything I’ve read so far says something about using a software on my computer to send a code into the printer. My computer isn’t hooked up to my printer since I don’t have a cable that will fit it (the printer).

During printing, the z-axis works great. It’s just getting it to the right height to lay the first layer. On the last two prints I tried, the Z2.0 is slightly too high for the filament to stick to the bed. I’m wondering if the starting code is raising it, then the slicing code is raising it more. I’ll pull open my latest slice and see what I can find.


Hook your printer up to your computer and use a terminal (actually, I think you do this through Octoprint too, come to think of it).

Home the print head (G28). Tell us where the print head ends up. It should be the corner of your build plate. If it’s the center, then your printer thinks it’s a Delta style instead of a Cartesian style printer.

Next, enter G0 X100. Does the print head move exactly 100mm?
Repeat for G0 Y100.

Some stepper motors have different degrees per step. The “standard” is 1.8. Also, some stepper motors are not able to handle microstepping as well. The above test should show whether the new stepper motor is moving the correct amount.

1 Like