Featured image of Marlin Firmware – How to Get Started
Making Your Printer Your Printer

Marlin Firmware – How to Get Started

Picture of Hussain Bhavnagarwala
by Hussain Bhavnagarwala
Jul 24, 2019

Take control of your 3D printer's firmware and discover a world of possibilities. We show you how to set up Marlin, one of the most popular firmware options among 3D printing enthusiasts!

Setting Up Marlin Firmware What Is Firmware?

Firmware lives in the motherboard.
Firmware lives in the motherboard. Source: disk91.com

Firmware is the heart of the 3D printing workflow and can be thought of as the “operating system” of a 3D printer. Residing in the controller board, it takes in G-code files and converts the corresponding commands into electrical pulses and signals, which are then sent to the various motors and sensors.

In development since 2010, the Marlin firmware is one of the oldest and most popular 3D printer firmwares. It’s been improved upon constantly by the community, with new features constantly being added. This article will cover the latest stable version: Marlin 1.1.9.


Setting Up Marlin Firmware Why Upgrade?

One of the first desktop 3D printers.
One of the first desktop 3D printers. Source: Kickstarter

Modifying your firmware will help you make changes to your machine, such as adding reliable lead screws instead of threaded rods, changing your hot end, or even replacing your controller board if the need arises. These changes are pretty common in DIY kits or low-budget 3D printers since things more frequently go wrong.

Knowing how to play with your firmware will also be helpful in tuning and calibrating your machine. Want to add new features, such as auto bed-leveling, run out sensors, and more? For these, you’ll definitely need to make some firmware changes.

Finally, having a basic understanding of your machine’s firmware will help you diagnose issues, improve hardware, and let you access new features.


Setting Up Marlin Firmware Getting Started

Setting the baud rate and motherboard.
Setting the baud rate and motherboard. Source: Hussain Bhavnagarwala / All3DP

Hardware Considerations

Before you start messing around with firmware, you’ll need to determine your 3D printer’s mechanical configuration. The changes that you make to the firmware will be based on these hardware specifications, so make sure you understand your hardware before diving in.

The three most popular FDM configurations are:

  1. Cartesian
  2. Core XY
  3. Delta

Also important to keep in mind are features like multiple nozzles, a heated bed, and additional sensors.

This guide will assume a single-extruder core XY style printer.

Software Setup

The 1.1.9 firmware can be downloaded from the official Marlin website. To edit it, you’ll need the Arduino Integraded Development Environment (IDE), which can be downloaded from the Arduino website.

Once you’ve downloaded the 1.1.9 version of Marlin, unzip the contents, enter the “Marlin 1.1.x” folder, and further open the “Marlin” folder. There, you should find the file “marlin.ino”, which will open the Marlin firmware.

Within the IDE, the Marlin firmware will consist of many tabs at the top of the page, each containing code for specific tasks or features. However, we’ll only be making changes to “configuration.h”, which is the fifth tab from the left.

Initial Configuration

When working with the firmware, it’s important to keep track of the changes you make. The “info” section allows you to add any text you like within the double quotations. Entering the date and type of changes made will help you keep track of your machine settings instead of going through the code again. Note that this does not affect the code and will not be displayed when the machine starts running.

Now, let’s enter the “machine” section. By default, the baud rate is set at the standard 250,000. This is the speed of communication between the computer and your controller board when connected via USB. It’s important to be aware of this value, as you may be prompted to choose a baud rate to connect to a host software, such as pronter face.

Next, you’ll have to select the motherboard that you’re using. This is important, as it will decide the mapping of input/output pins. By default, the motherboard is set to a Ramps 1.4 with an extruder, a fan, and a heated bed as 12-V outputs. If you want to change this, you’ll need to navigate to the “boards.h” file.

Click on the small drop-down symbol in the top right corner and select the “boards.h” tab from the list. If you’re unable to see it immediately, scroll down. For example, if you’re using an MKS board, change the board from the default setting to “BOARD_MKS_GEN_13”. You can either copy the name of the board that follows “#define” or use the number directly. In this case, the number is 47.

Next, you’ll need to set the number of extruders. Since we’re using a single extruder, we enter 1 as the value:

#define EXTRUDERS 1

Finally, let’s indicate the filament diameter:



Setting Up Marlin Firmware Thermal Settings

Select your thermistor.
Select your thermistor. Source: Hussain Bhavnagarwala / All3DP

FDM 3D printers extrude plastic by heating them to temperatures as high as 300 °C. For this reason, every heater comes with a thermistor or thermocouple, devices which read the actual temperature values in real time and send feedback to the controller, telling it when to turn the heat up or down. Poorly selected or malfunctioning thermistors can lead to incorrect temperature readings, and this can further cause the heater either to overheat or to provide insufficient heat for extrusion.

We need to select a thermistor from the list of thermistor types recognized by Marlin. Based on the type of thermistor being used, a corresponding value needs to be plugged in. Typically, the hot end manufacturer provides the specifications of the thermistor. The most common type is a 100K-Ohm thermistor with a 4.7K-Ohm pull-up, which leads to the corresponding value of 5:

#define TEMP_SENSOR_0 5

If you have a heated bed, select the thermistor for that, as well. Again, the most common thermistor value is 5:


We can skip the PID settings, as these are well-calibrated and tuned by themselves.

Next, we come to thermal runaway. These two commands are activated by default, protecting your machine from accidental thermistor failures. To deactivate them, you can add two forward slashes in front:

//#define THERMAL_PROTECTION_HOTENDS // Enable thermal protection for all extruders

//#define THERMAL_PROTECTION_BED // Enable thermal protection for the heated bed

Note: Only deactivate these if you have a good reason to do so and know what you are doing.


Setting Up Marlin Firmware Mechanical Settings

Limit switch settings.
Limit switch settings. Source: Hussain Bhavnagarwala / All3DP

Coordinate System

3D printers use motion mechanisms to move the hot end and print bed relative to each other. You may have heard of terms such as “core XY”, “H-bot”, and “Cartesian”. These different mechanisms use different mathematical representations to define the motion of the machine. By default, Marlin assumes that you’re going ahead with a Cartesian style 3D printer

If you’re using a core XY or H-bot system, make sure to activate the appropriate settings. This is done by removing the two forward slashes in front of your selection (and adding them to all others). “COREXY” and “COREYX” are most common for Core XY and H-bot printers. They both share the same fundamental mathematical framework and, hence, a single setting works for either style.

Since we’re using a core XY mechanism, this is how our code will look:

#define COREXY

//#define COREXZ

//#define COREYZ

//#define COREYX

//#define COREZX

//#define COREZY

End Stops

The end stop settings let you choose where you want the homing position of your nozzle and bed to be.

“XMIN” is the minimum position, which will be 0 in most cases, and “XMAX” will be the maximum position for the axis defined by you.

Once again, you’ll need to manipulate the forward slashes:




//#define USE_XMAX_PLUG

//#define USE_YMAX_PLUG

//#define USE_ZMAX_PLUG

Since we have uncommented the “MIN” position for all axes, we have defined all three axes to be homed at their minimum positions (0,0,0). 

If we wanted X to home at the minimum position, but Y and Z to home at their maximum positions, the code would look like this:


//#define USE_YMIN_PLUG

//#define USE_ZMIN_PLUG

//#define USE_XMAX_PLUG



Limit Switches

Most limit switches have two basic modes for letting the controller board know whether the switch is triggered or not. The first is “normally closed” (NC) and the other is “normally open” (NO). Depending on how the limit switch is wired, this can vary.

When the limit switch is pressed, it sends a signal to the board based on the type of sensor. Sometimes this signal can be inverted, meaning the board assumes the switch is open when the extruder has reached its home position. If you feel that your end stop is not being triggered properly, try inverting the signal:

#define X_MIN_ENDSTOP_INVERTING false // set to true to invert the logic of the end stop

Homing Settings

Scroll down further until you see the “HOME” settings. When an axis homes at the minimum position, the corresponding homing value needs to be -1, and vice versa.

// Direction of end stops when homing; 1=MAX, -1=MIN

#define X_HOME_DIR -1

#define Y_HOME_DIR -1

#define Z_HOME_DIR -1

Build Volume

You will also need to define the size of your build volume so as to not accidentally move an axis beyond its limits. These are also the maximum positions that the printer can move.

// The size of the print bed

#define X_BED_SIZE 200

#define Y_BED_SIZE 200

// Travel limits (mm) after homing, corresponding to end stop positions

#define X_MIN_POS 0

#define Y_MIN_POS 0

#define Z_MIN_POS 0



#define Z_MAX_POS 200


Setting Up Marlin Firmware Movement Settings

Setting the steps per unit.
Setting the steps per unit. Source: Hussain Bhavnagarwala / All3DP

Steps per unit is the only setting that we will deal with in the “movement” section, but that doesn’t mean it’ll be easy… To ensure that your 3D printer moves by the exact specified distance, we will need to calculate the “steps per mm” value for each axis. 

Steps per mm means the number of steps a motor has to make for your machine to move by 1 mm along its particular axis. The steps per mm value needs to be calculated for the X, Y, and Z axes and for the extruder mechanism. This is the line of code that we will need to modify:

#define DEFAULT_AXIS_STEPS_PER_UNIT   { 80, 80, 4000, 500 }

Most machines use a belt for the X and Y axes, and a lead screw to lift either the bed or the extruder. Making things easier are online calculators, like the the Prusa calculator. Scroll down to the stepper motors section, which has a belt-driven section and a lead-screw-driven section. 


For belts, you will need to know the following specifications of your machine to be able to set the steps per mm values:

  • Type of belt used
  • Number of teeth on the pulley
  • Micro-stepping of the driver
  • Step angle of the stepper motor
  • Pitch of the lead screw

There are 4 values we need to key to figure out the steps per mm:

  • Motor step angle: For most NEMA 17 motors, this will be 1.8°. To be sure, check the documentation provided by your motor’s manufacturer.
  • Driver micro-stepping: Most boards out there use 1/16th micro-stepping, but in general, this information will be provided by your board manufacturer. If you bought the stepper sticks separately, you can check with your supplier. Some stepper sticks can do 1/32, with others going down to 1/256 . The higher the number in the denominator, the smoother and more precise your steppers are going to be. Make sure not to go above 1/16, as the motion gets jerky and rough.
  • Belt pitch: If you’re using standard GT2 belts, then the pitch will be 2 mm. Otherwise, make sure to check the specifications.
  • Pulley tooth count: GT2 pulleys come in a few varieties, with between 8 teeth and 20 teeth.

Once all values are entered, the final value is automatically calculated.

Lead Screws

For the Z axis with a lead screw, the motor step angle and the driver micro-stepping will be the same as before. What remains to be determined is the pitch of the lead screw, which can vary quite a bit, from 2 mm all the way up to 8 mm. (Pitch is the distance between two adjacent identical points in a thread.)

If you’re using gears to increase torque, you can also enter the gear ratio.

With this information, you should be able to calculate your steps per mm value of the Z axis.


Now we’ll calculate the steps per mm for your extruder motor.

First, using an accurate caliper, measure the diameter of the toothed gear that drives the filament inside. Let’s call that value d. The formula is

(total number of steps for motor) * (micro-stepping value) / d * 3.14

As an example, let’s assume we have a diameter of 10 mm and a micro-stepping value of 16. For a NEMA 17 stepper motor, the total number of steps will be 200 if the minimum step angle is 1.8°. Thus, we arrive at

200 * 16 / 10 * 3.14 = 101.9 steps per mm

Once you have all your values dialed in, the previous line of code should look like this:

#define DEFAULT_AXIS_STEPS_PER_UNIT   { 80, 80, 400, 101.9 }

Remember that the values must be in the order X, Y, Z, E.

Note that, you may still have to calibrate these values. Check out our calibration guide to further tune them.

The rest of the settings in the “movement” section can be left as they are.


Setting Up Marlin Firmware LCD and SD Card Support

Activating SD support.
Activating SD support. Source: Hussain Bhavnagarwala / All3DP

Having an SD card reader and LCD screen makes 3D printing a lot more convenient and also frees up your computer. Scroll down to the LCD and SD support section, this is towards the end “configuration.h”.

SD card support is disabled by default. To activate it, simply remove the forward slashes:


For LCD support, you’ll need to know what type of LCD you’re using. Scroll down to the LCD controller section and search for the type of LCD you have. We’ll assume a “Full Graphic Smart” controller as an example. Once again, remove the slashes:


You’ll also need to install the u8glib library. To do this, download the u8glib library from GitHub. Arduino provides instructions to help you integrate the library into your IDE.


Setting Up Marlin Firmware Uploading the Code

Selecting the port.
Selecting the port. Source: Hussain Bhavnagarwala / All3DP

Now that you’ve completed the necessary modifications, you’ll need to upload the code to your controller board.

First, you’ll need to connect your PC to your board via USB. Once you’re done with that, find out what the communication port number is. To do this, open the Control Panel in Windows and navigate to Device Manager. Once there, you should have a “Ports” section, which will give you the “com” number for your USB connection.

Keeping that in mind, go back to the Arduino IDE and click on the “Tools” option in the top left of your screen. Then, go to “Ports” and select the “com” that you identified in Device Manager.

Again in “Tools”, select the boards option and choose “Arduino Mega or Mega 2560”. If you’re using a different board, contact your supplier to help you with board selection.

You’re ready to upload! Simply click on the “Upload” button in the top left corner and wait for the magic to happen.


Setting Up Marlin Firmware A Better 3D Printing Experience

Marlin Lead developer Scott Lahteine.
Marlin Lead developer Scott Lahteine. Source: Thomas Sanladerer / YouTube

Understanding how Marlin works will enable you to make use of mods and customize your machine.

So what’s the next step? Learning about and trying other features of Marlin: automatic bed-leveling, filament sensors, heated beds – the list of possibilities is endless with this fantastic firmware!

Feature image source: stylesuxx / YouTube

License: The text of "Marlin Firmware – How to Get Started" by All3DP is licensed under a Creative Commons Attribution 4.0 International License.

Subscribe to updates from All3DP

You are subscribed to updates from All3DP

You can’t subscribe to updates from All3DP. Learn more… Subscribe

You can’t subscribe to updates from All3DP. Learn more…

Recommended for you