Marlin Tuning

To get the most out of Marlin, here are a few simple tweaks.

1. EEPROM Settings

By default, Marlin forgets any configuration changes you make via the Mxxx G-codes whenever you reset or power cycle your controller. If you want to remember the settings, so you don’t have to set them every time you power up your controller, Marlin can store them in EEPROM. In Configuration.h, uncomment


EEPROM_CHITCHAT is optional:

//to disable EEPROM Serial responses and decrease program space by ~1700 byte: comment this out:
// please keep turned on if you can.

You will need to compile Marlin and then upload the modified firmware to your controller in order to take advantage of the changes.

After sending your Mxxx G-codes to Marlin, send M500 to save them to EEPROM.  You can also revert to default (“factory settings”) with M502.

One nice feature of Repetier-Host is that you can use it to set your EEPROM, rather than manually typing in Mxxx G-codes.  Simply go to Config->Firmware EEPROM Settings from the menu.

Personally, I prefer to just set all my Mxxx G-codes as start G-codes in Slic3r, rather than storing them in EEPROM, but most people will probably prefer to use EEPROM.

2. PID Auto Tune

When I first switched to Marlin, I was not at all happy with the temperature control of my extruder.  It was taking a long time for my hot end to heat up, and the temperature was still varying a lot. While the hot bed is controlled using bang-bang (traditional on/off temperature control), the extruder uses a more sophisticated algorithm, called PID, which should yield better temperature stability.

Initially, I tried turning off PID by commenting out

#define PIDTEMP

in Configuration.h.  My hot end heated up much faster, but the temperature was still fluctuating a lot.  I decided to try to get PID working better.  In order to get best performance out of PID, there are some parameters which need to be tuned: Kp,Ki, and Kd.  Configuration.h contains settings for Ultimaker, Makergear, and Mendel Parts hot ends, but I’m using a JHead.  I had no idea what values to use for After doing a bit of googling around, I found out that Marlin has a way for it to automatically calculate PID parameters, G-code M303 – PID relay autotune.  To automatically tune your hot end PID parameters, start with your hot end at room temperature, and using Pronterface, send it the M303 G-code as follows:

M303 S230

The parameter is the target temperature in celcius.  If your target temperature is different, substitute it for the 230.   Marlin will then heat up and cool down your hot end, while taking measurements.  This will take a while.  When it’s done, it will output a message similar to this one:

bias: 103 d: 103 min: 147.98 max: 152.02
Ku: 65.06 Tu: 30.67
Clasic PID
Kp: 39.04
Ki: 2.55
Kd: 149.66

Next, you need to tell Marlin to use the calculated Kp, Ki, Kd values.  If you don’t want to hassle with compiling/reloading Marlin, you can just use the M301 – Set PID parameters P I and D G-code.  Using the my values above, it looks like this:

M301 P39.04 I2.55 D149.66

I simply added the line to my start G-code in Slic3r.  Setting the PID parameters in G-code allows you to change them on the fly for different profiles, for instance, if you like to switch back and forth between PLA and ABS.

If you prefer to hardcode the values as defaults in the firmware, set them as follows in Configuration.h:

#define  DEFAULT_Kp  39.04
#define  DEFAULT_Ki 2.55
#define  DEFAULT_Kd 149.66

3. Acceleration and Jerk

If your printer vibrates a lot when printing at higher feedrates, causing wiggly prints, you can improve the quality without slowing down your prints too badly by lowering the acceleration and/or XY-jerk values. In Marlin, acceleration is specified in mm/s^2. The default is 3000. On my Printrbot, I slowed it down to 1000 with G-code as follows:

M201 X1000 Y1000; // max accel print
M202 X1000 Y1000; // max accel travel
M204 S1000; // default accel for normal moves

You can also change the value in Configuration.h, if you prefer:

#define DEFAULT_ACCELERATION 1000 // X, Y, Z and E max acceleration in mm/s^2 for printing moves

If you have a slow extruder, you can also slow down the retraction acceleration, but generally, there’s no reason do do this:

#define DEFAULT_RETRACT_ACCELERATION  3000   // X, Y, Z and E max acceleration in mm/s^2 for r retracts

3000 is the default value.

The jerk value is also useful, and affects the speed at which Marlin joins two segments. The default XY-jerk value is 20 mm/s.  Lowering the value will slow down the transitions between segments.  This is especially helpful for smoothing out ringing waviness on 90 degree turns.  I found that 15mm/s is a good balance between speed an quality on my Printrbot.  G-code:

M205 X15; // max xyjerk mm/s


#define DEFAULT_XYJERK                20.0    // (mm/sec)

There are also values for the z-axis and extruder, but I didn’t need to change them:

#define DEFAULT_ZJERK                 0.4     // (mm/sec)
#define DEFAULT_EJERK                 5.0    // (mm/sec)

When tuning acceleration and jerk values, a handy way to test the effects of your new settings is the Dry Run feature of Repetier Host.  When Dry Run is enabled, the extruder is disabled while printing, so you can observe its motion without wasting filament.

After tuning the acceleration and jerk values my prints are better quality at higher feedrates, without sacrificing too much speed.  Note that depending on your print, the lower acceleration/jerk values will have more or less effect on the total time it takes to complete it.  Prints that have more short segments will be slowed down a bit more.

Even though my discussion was about slowing down the printer, you can also tune the acceleration/jerk parameters to speed things up, if you have a particularly well-tuned bot.

There are 17 Comments to "Marlin Tuning"

  • John Varga says:

    Good blog! Learned much! Thanks!

  • Alastair says:

    Hi I tried the M302 command and got nothing looking at the Comments in the marlin file M302 was not listed, Is this a new addition? Could you tell me which version of Marlin you are using?

    • lincomatic says:

      I think I last synced the code in June

      • lincomatic says:

        Actually, I use M302 all the time. You can see that it’s implemented in Marlin.pde

        • Chris says:

          Actually M303 is the Autotune feature, and the parameter (according to the github readme) is S (e.g. M303 S150 is the default if you just put M303, it uses 150)

          M302 is to allow cold extrusion.

          whatever the case – a great resource for these commands is:

          in the readme, there’s a list of all the non-standard G-Code commands. 🙂

          • lincomatic says:

            Isn’t that what I said? And I didn’t even mention M302. When I wrote the article, M302 was not described in the README.. only in Marlin.pde.

  • nonaak says:

    Thanks, super handy.

  • bigfilsing says:

    Great blog i often wondered how to use the autotune . Thanks
    The only thing i would add is that the fan (s) if any should be on while running the auto tune command as a fan may alter the hot end temp.
    If you really were to be picky then the extuder should be running as well as the PLA absorbs heat in the extrusion process. In theory these will effect the ID parts of PID

  • TheTechGuru says:

    Thanks for the guide. Slight update. In order to specify a temp to cycle at, you need to include the “S” syntax. So it would need to be M303 S230. Otherwise it reverts to 150Celcius.

    You can also specify number of “cycles” to run before it gives you the PID. So M303 S230 C5, would cycle the test 5 times.

  • Lux_Linutz says:

    well, great work, dude.

    i want to add an other blog-tut i used for calibrating the Marlin firmware:
    and of cause the great calculator for the steps per unit calibration by
    and last but not least a NICCCE idea for automatic calibration for the heatbed:

    if you like to sent me an email, pls use the formular in Thingiverse.

  • dean says:

    hi ~

    i want got your sameple code for how control the printer, can you sent it to me ? thanks!


    • lincomatic says:

      I’m just using Repetier Host .. you can download for free from github

      • deanzheng says:

        thanks . i have already download it , the problem is it’s still a little hard for me to found the key point ,means i dont know how it is communication with the marlin . how sent Gcode to marlin. i wrote a simple soft try to control it . unfortunately, i can connect it but cant sent the Gcode . i need if is possible help me to fix it .

        • lincomatic says:

          Sorry, I can’t help you to get it working, but the best approach is to get a serial terminal emulator, such as PuTTY, and try typing GCODE commands to it.
          Once you get that communication working properly, use the same settings with whatever host software you want to use, and it should just work.

          • deanzheng says:

            thanks ,lincomatic. i will try to do it as what you taught . i come from china , i have a company make the 3D printer . hope to learn more from you. and if possible we can cooperate with some project perhaps in the future.

Write a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>