How to Install Marlin Firmware
Firmware functions as the nucleus of the 3D printing workflow and is sometimes referred to as the operating system of a 3D printer. Via the controller board, the firmware “reads” G-code files, converts the commands into electrical signals, and transmits these commands to the mechanical components of the printer.
For beginning 3D printing hobbyists, the idea of messing around with core aspects of their machine may be off-putting, but tweaking your printer’s firmware can open up a work of possibility in terms of fine-tuning your prints and DIY-ing repairs and troubleshooting. This guide covers the basics of Marlin firmware—a highly popular open-source 3D printer firmware that has been out for just over a decade and is continuously being upgraded.
Thinking of upgrading?
There are several benefits to keeping your firmware updated or even replacing a stock firmware with Marlin if your printer isn’t one of the many that comes equipped with this printer driver. Owing to its strong community foundation and responsive development team, Marlin is a great option for all 3D printing enthusiasts who value open-source tech.
Marlin allows users to control each aspect of their machine with high precision and to even use the driver with modified machine parts, such as after-market hot ends or new controller boards. While messing with the brain of a 3D printer might seem like a thing that only the most dedicated hobbyists with multi-thousand-dollar setups might do, hobbyists of all levels are recommended to give this a shot as such fine-tuning and modifications can amp up the power of low-budget 3D printers.
Another benefit to upgrading and working with your firmware directly is that establishing a strong understanding of how your printer’s firmware works allows you to run your own diagnostics, modify and tune your hardware, and add new features to your printer.
Getting started with Marlin firmware
Before jumping into the nuts and bolts (or ones and zeros), you will need to get the details on your 3D printer’s mechanical configuration. Any changes made to the firmware are directly related to the printer’s hardware specifications, so having all the information handy will save you time down the line.
Most FDM printers operate with Cartesian, core XY, or Delta configurations. We won’t get into the details of these configurations in this article—these names simply refer to the movement mechanism of the printer. Depending on the number of axes and the directions along which the print mechanism moves, the firmware will have to read and convert instructions appropriately. Similarly, it’s important to take stock of any unique features like a heated bed, sensors, or multiple nozzles.
One of the most common configurations for lower and mid-level printers is the single-extruder core XY style printer. This details of this guide will use this style of printer as an example, but the general steps can be modified for whichever printer configuration you are working on.
Also, we cover the details for the most widely used version of Marlin (1.1.9), but there is a newer version that is currently being tested and modified. We focus on v 1.1.9 as it has been used on a variety of machines for numerous applications, leading to a wealth of troubleshooting information.
Setting up the software
Marlin 1.1.9 can be downloaded from the official Marlin website. We’ll be editing the firmware, which requires the Arduino Integrated Development Environment (IDE). Arduino IDE can be downloaded from the Arduino website.
After downloading Marlin, unzip the file, open the “Marlin 1.1.x” folder, and open the “Marlin” folder. The firmware file is named “marlin.ino.”
In the IDE, the Marlin firmware will have many tabs with each containing codes for specific tasks or features. In this guide, we’re only focusing on “configuration.h” on the fifth tab from the left.
Because any modifications you make will be directly incorporated into the firmware files, it’s important to keep track. The “info” section allows users to add notes using double quotation marks, and adding information on the date and changes made makes it easy to reference a log of any modifications rather than digging through the code.
First, navigate to the “machine” section. The default baud rate is the standard 250,000. This refers to the speed of communication between the computer and your controller board when connected via USB. Some host software requires baud rate information, so keep this value in mind.
Next, check that the firmware has the proper motherboard information, which allows it to accurately map the input/output pins. The motherboard settings are Ramps 1.4 with an extruder, a fan, and heated bed at 12 V. To change this, navigate to the “boards.h” file.
Select the drop down symbol in the top right corner and select the “boards.h” tab. From here, you can select the proper board setting. 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. For the MKS board, the number is 47.
Next, set the number of extruders for your printer. If your printer has a single extruder, enter 1 as follows:
#define EXTRUDERS 1
Then, set the filament diameter you’ll be working with:
#define DEFAULT_NOMINAL_FILAMENT_DIA 1.75
Mechanical settings
After adding your board and basic printing information to the firmware file, it’s time to jump into the technical settings.
Coordinate system designation
3D printers are equipped with movement mechanisms that position the hot end and print bed in relation to each other. There are a variety of mechanisms such as core XY, H-bot, and Cartesian that utilize different mathematical representations to define the machine’s movement. Many printers use the Cartesian mechanism, so Marlin’s default settings are for this style.
If you’re using a core XY or H-bot system, you can activate the appropriate settings by removing the two forward slashes in front of your selection and ensuring that all other entries begin with two forward slashes. Either “COREXY” or “COREYX” is commonly used for core XY and H-bot printers. Because they both use the same fundamental mathematical framework, one setting is typically suitable for either configuration.
For this guide, we’ll assume a core XY mechanism. The code should look like the following:
#define COREXY
//#define COREXZ
//#define COREYZ
//#define COREYX
//#define COREZX
//#define COREZY
End stop settings
End stop settings refer to the homing positions of your printer’s nozzle and bed. “XMIN” is the minimum position setting, which is typically 0. “XMAX” is the maximum position setting that can be set by the user.
Like the mechanism designation, the two forward slashes tell the firmware which lines to “read” and which to ignore:
#define USE_XMIN_PLUG
#define USE_YMIN_PLUG
#define USE_ZMIN_PLUG
//#define USE_XMAX_PLUG
//#define USE_YMAX_PLUG
//#define USE_ZMAX_PLUG
Here, the “MIN” positions for all axes are uncommented, which sets all three axes to their minimum positions (0,0,0). If X was set to home at the minimum position but Y and Z were set to home at their maximum positions, the code would look like this:
#define USE_XMIN_PLUG
//#define USE_YMIN_PLUG
//#define USE_ZMIN_PLUG
//#define USE_XMAX_PLUG
#define USE_YMAX_PLUG
#define USE_ZMAX_PLUG
Limit switches
For most limit switches, there are two basic modes for transmitting a signal to the controller board know depending on whether the switch is triggered: normally closed (NC) and normally open (NO). Depending on how the limit switch is wired, these settings may vary.
When the limit switch is triggered, it sends a specific signal to the board based on the type of sensor. This signal may be inverted, meaning the board assumes the switch is open when the extruder reaches its home position. If the end stop for your printer is not being triggered properly, you can invert the signal as follows:
#define X_MIN_ENDSTOP_INVERTING false // set to true to invert the end stop logic
Homing settings
Navigate to “HOME” settings. When an axis homes at the minimum position, the corresponding homing value should be set to -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 settings
By setting the build volume in Marlin, you can ensure that the movement settings defined earlier do not exceed the printer’s limits. The build volume settings also designate the maximum positions at which 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 X_MAX_POS X_BED_SIZE
#define Y_MAX_POS Y_BED_SIZE
#define Z_MAX_POS 200
Thermal settings
The basic printing mechanism of FDM printers is the deposition of heated thermoplastic, with temperatures reaching up to 300 °C. For this reason, each 3D printer is outfitted with a heater that includes a thermistor or thermocouple, which read the temperature values in real time and send feedback to the controller. This feedback loop sends signals to increase or decrease the temperature to maintain an adequate level of heat throughout the print and to shut off heating after the print is complete. Problems with thermistors can lead to incorrect temperature readings, which causes further problems with heating the plastic too much or too little.
Marlin includes a list of recognized thermistor. Based on the type of thermistor used in your printer, the hot end manufacturer provides relevant specifications for the thermistor, which can then be input into the firmware. Most printers are equipped with a 100K-Ohm thermistor with a 4.7K-Ohm pull-up, which has corresponding value of 5:
#define TEMP_SENSOR_0 5
For any additional heated parts such as a heated build surface, a thermistor must be selected. The most common thermistor value for all parts is 5:
#define TEMP_SENSOR_BED 5
For the sake of simplicity, we won’t cover PID settings because they are typically self-tuned and do not require user input.
In this section, you’ll see the thermal runaway settings. These commands are activated by default and serve as a fail-safe for your machine to avoid accidental thermistor failures. These should only be changed by users who are very familiar with their machines and any changes to the thermal settings. 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
For the vast majority of users, these changes are not required.
Movement settings
Most movement settings don’t require tuning in the firmware files. We’ll only modify “Steps per unit” in this section. To ensure that the 3D printer moves by the exact specified distance, the “steps per mm” value for each axis needs to be calculated.
Steps per mm refers to the number of steps required by the motor to make your machine move by 1 mm along the axis. As such, steps per mm needs to be calculated for the X, Y, and Z axes as well as for the extruder mechanism. The following line designates steps per mm:
#define DEFAULT_AXIS_STEPS_PER_UNIT { 80, 80, 4000, 500 }
The majority of 3D printers use belts to control movement along the X and Y axes and a lead screw to lift either the bed or the extruder along the Z axis. There are online calculators that simplify the steps per mm calculation, such as the Prusa calculator. Navigate to the stepper motors section, which has a belt-driven section and a lead screw–driven section.
Belts
To ensure that all calculations are accurate, you will need to know the following specifications for your machine to be able to set steps per mm values for the belts:
- Type of belt used
- Number of teeth on the pulley
- Driver micro-stepping
- Stepper motor step angle
- Lead screw pitch
Of these, there are four values that are required for the actual calculation:
- Motor step angle: This angle is 1.8° for most NEMA 17 motors. Check the documentation provided by your motor’s manufacturer to ensure that you have the correct value.
-
Driver micro-stepping: Most boards use 1/16th micro-stepping. As always, check the manufacturer’s specifications.
- If you purchased stepper sticks separately from your printer, the supplier should also have this information. Some stepper sticks may be set to 1/32, with others reaching 1/256. The higher the fraction, the more precise your steppers are going to be. Do not go lower than 1/16, as the motion gets jerky and rough.
- Belt pitch: For standard GT2 belts, the pitch value is 2 mm. If you are unsure, check the manufacturer's specifications.
- Pulley tooth count: GT2 pulleys are outfitted with a tooth number of between 8 and 20, so double check your printer’s information.
Lead screws
If your printer’s Z axis is controlled by a lead screw, the motor step angle and driver micro-stepping will be the same as the previous value. Pitch refers to the distance between two adjacent points in a threaded screw and can vary significantly on the lead screw (from 2 to 8 mm). If you are using gears to increase torque in your printer, the gear ratio can also be entered.
Extruder
Calculating the steps per mm for your extruder motor is a bit more complicated and requires actual measurements. You will need calipers and a calculator for this step.
First, using accurate calipers, measure the diameter of the toothed gear that moves the filament inside the printer. Using a simple formula and “d” as the diameter measured, you can determine the steps per mm:
(total number of steps for motor) * (micro-stepping value) / d * 3.14
For example, assume a diameter of 10 mm and a micro-stepping value of 16. For a NEMA 17 stepper motor, the total number of steps is 200 if the minimum step angle is 1.8°. Thus, we get the following value:
200 * 16 / 10 * 3.14 = 101.9 steps per mm
Once all values have been obtained, the previous line of code should look like this:
#define DEFAULT_AXIS_STEPS_PER_UNIT { 80, 80, 400, 101.9 }
Note: All values should be entered in the order X, Y, Z, E.
SD card and LCD screen settings
Some hobbyists have modified their 3D printing set up with an SD card reader or LCD screen, and some printers have these additional parts installed. These add-ons can greatly improve the 3D printing experience by making the printing station a one-stop-shop, minimizing the need for using a computer to control prints.
Navigate to the LCD and SD support section near “configuration.h”.
SD card support is disabled by default. To activate it, simply remove the forward slashes:
#define SDSUPPORT
To define the LCD support settings, you first need to check which type of LCD you’re using. Scroll down to the LCD controller section and search for the type of LCD you have. As an example, if you have the “Full Graphic Smart” controller, you’ll remove the slashes on this line:
#define REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER
To ensure that the firmware is linked with the LCD screen, you will need to download the u8glib library from GitHub and integrate the library into your IDE.
Uploading the firmware
Now that your version of Marlin has been tuned to your printer’s specifications, it’s time to install it onto your controller board.
First, connect your PC to the board via USB. Next, determine the communication port number by opening the Control Panel in Windows and navigate to Device Manager. Under the “Ports” section, you can find the “com” number for your USB connection. Take note of this number for the next step.
In the Arduino IDE, select “Tools” on the top left of your screen. Then, navigate to “Ports” and select the “com” that you identified previously. Then, select the “boards” option and choose “Arduino Mega or Mega 2560.” For any other boards, we recommend contacting your supplier to ensure that you select the correct one.
That’s it—click the “Upload” button in the top left corner to add the firmware to your controller board and get back to printing!
Leave a comment