Home 3D Printer Upgrades Compiling Marlin 2.0 for Ender3 v2

Compiling Marlin 2.0 for Ender3 v2

Everything you need to know to compile Marlin 2.0 for Ender 3v2

Ever since I got Ender 3 v2 (review), I wanted to upgrade a couple of things. As Creality’s firmware doesn’t cover every hardware upgrade that comes to my mind, I have to resort to compiling Marlin firmware myself. Don’t be put off, behind the complex programming lingo, lays a fairly straight forward list of values to change to tailor Marlin firmware to your needs. If you follow this guide, it’s unlikely you screw anything up. Let’s build Marlin 2.0 for Ender3 v2 to enable various upgrades.

Current Ender3 v2 upgrades

My list of upgrades isn’t massive just yet, but I upgrade my machine as I go. So far I have added the following modules to my Ender 3 v2:

The upgrade list may change in the future, so this article will remain separate from the project articles above, so it is always up to date and relevant. If you own an Ender 3 v2, chances are that the upgrades you will opt-out for will be the same.

Each upgrade has a dedicated article, that explains everything you need to do to complete the upgrade yourself.


I would strongly recommend to use Visual Studio Code and PlatformIO to configure Marlin 2.0 for Ender3 v2 and build your firmware. It takes only a couple of moments to set up, and you will be ready to compile (build your own) firmware.

Visual Studio Code

During the installation, use the option to add the VSC as Path in Windows, this will make certain things easier for you moving forward. Once installed, the left side will have an extension option. Select PlatformIO and C/C++. You should be able to see the “ant” head from PlatformIO.

Marlin 2.0

Download .zip files from GitHub for Marlin 2.0 and Configurations. Extract both zip files to separate folders. If you know how to build your firmware, don’t copy the files over just yet. First go to VSC, open PlatformIO and the folder containing Marlin 2.0.

Open subfolders until you see platformio.ini file. This is your root folder. Locate the build option at the bottom of the VSC (checkmark at the bottom of the file) and try to compile the default firmware. If you succeed, you are good to go, otherwise here are some things to try:

Error Possible Solution
Random errors in supporting libraries unplug USB devices check the ports in configuration and build again
Not defined or used out of scope Check if Marlin version and Configuration version files are the same

Building Marlin 2.0 firmware for Ender 3 v2 from source

While the guide is specifically catered for Ender 3 v2, you could apply other configuration and consult the changes made in this article to what you are trying to achieve. It could help you understand the process and build the firmware for other printers. If you have an Ender 3 v2 machine, you will find it easier.

Before you change anything, you will need to check the revision of your motherboard. Pop the cover open and check what’s printed on the board. At the time of the writing Ender 3 v2 comes with two board revisions: 4.2.2 and 4.2.7.

Setting up the build environment

PlatformIO needs to know what microcontroller is at the heart of your board. This information is stored in the platformio.ini file and you have to type in the model of the processor used for your board. In both cases (4.2.2 and 4.2.7) it’s the same:

src_dir      = Marlin
boards_dir   = buildroot/share/PlatformIO/boards
default_envs = STM32F103RET6_creality
include_dir  = Marlin

Save the file. PlatformIO will prep the build environment for you. For the most part, all you have to do is to modify 2 files responsible for configuring your printer parameters. These will differ based on the installed upgrades and preferences.

The easiest way to find the line responsible for the parameter is by searching for it using Crtl+F. The modification will require you to change the values, disabling lines using comment annotation “//” or enabling settings by uncommenting the lines.

I will split this part per upgrade so you know which settings are important to your use case.

Configuration files

Marlin GitHub comes with configuration files for each printer. Both Ender 3 and Ender 3v2 are supported so if you are not making any special changes, you can simply grab the files from the correct directory and replace files in Marlin2.0/Marlin folder.

LCD screen

Configuration folder for Ender 3 v2 will also include screen-specific files. You may need to flash the screen separately to update the display firmware. The procedure is very simple. Drag the DWIN_SET folder onto an SDCard and put the card into the reader hidden behind the screen (you need to open the back cover). Then power up your printer and wait until the screen turns orange. Turn off the printer again, remove the card and you are all set.


These files will change a number of settings to set up your Ender 3 v2 with Marlin 2.0. It’s not all just drag and drop as your first changes will depend on the motherboard revision. Go to #define MOTHERBOARD section and use:

  • for 4.2.2 boards : BOARD_CREALITY_V4
  • for 4.2.7 boards : BOARD_CREALITY_V427

Here is the list of changes for Ender 3 v2 vs default configuration file.

Changes to Configuration.h

#pragma once
#define CONFIG_EXAMPLES_DIR "Creality/Ender-3 V2"

#define SERIAL_PORT 1
#define SERIAL_PORT_2 3

#define BAUDRATE 115200

#define MOTHERBOARD BOARD_CREALITY_V4 // for 4.2.2, anyone with 4.2.7 has to use BOARD_CREALITY_V427

#define CUSTOM_MACHINE_NAME "Ender-3 V2"


#define HEATER_0_MINTEMP 0
#define BED_MINTEMP 0

#define BED_MAXTEMP 120

#define DEFAULT_Kp_LIST { 28.72, 28.72 }
#define DEFAULT_Ki_LIST { 2.62, 2.62 }
#define DEFAULT_Kd_LIST { 78.81, 78.81 }

#define DEFAULT_Kp 28.72
#define DEFAULT_Ki 2.62
#define DEFAULT_Kd 78.81


#define DEFAULT_bedKp 462.10
#define DEFAULT_bedKi 85.47
#define DEFAULT_bedKd 624.59






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

#define DEFAULT_MAX_FEEDRATE { 500, 500, 5, 25 }

#define DEFAULT_MAX_ACCELERATION { 500, 500, 100, 1000 }

DEFAULT_ACCELERATION 500 // X, Y, Z and E acceleration for printing moves
#define DEFAULT_RETRACT_ACCELERATION 500 // E acceleration for retracts
#define DEFAULT_TRAVEL_ACCELERATION 1000 // X, Y, Z acceleration for travel (non printing) moves


#define INVERT_X_DIR false
#define INVERT_Y_DIR false
#define INVERT_Z_DIR true

#define X_BED_SIZE 220
#define Y_BED_SIZE 220
#define Z_MAX_POS 250






Changes to Configuration_adv.h

#define CONFIG_EXAMPLES_DIR "Creality/Ender-3 V2"




#define FAN_MIN_PWM 50


#define ENCODER_10X_STEPS_PER_SEC 80 // (steps/s) Encoder rate for 10x speed
#define ENCODER_100X_STEPS_PER_SEC 130 //add below the line above



#define SDSORT_USES_RAM true // Pre-allocate a static array for faster pre-sorting.
#define SDSORT_CACHE_NAMES true // Keep sorted items in RAM longer for speedy performance. Most expensive option.



I listed these changes for reference, if you replace default files with configured files, most of the changes would be done for you already. Please note that this guide is done according to Marlin and with time some of the parameters can get outdated.


If you have a BL Touch, you can enable it in Marlin firmware as well. Changes will strictly depend on the type of the sensor and how you want to use it. I have this BL Touch sensor added to my Ender 3 v2 (guide), and I will share with you my configuration.

There are a couple of things you should consider. Check the sensor revision (mine is v3.1) as different revisions support different voltages. If you have other than BL Touch sensor, Marlin software provides you with alternative definitions that could meet your needs.

Depending on how your sensor is connected, you may need to define it differently in the configuration.

  • sensors with 3pin + 2 pin cable use: #define Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN
  • sensors with 5pin cable use #define USE_PROBE_FOR_Z_HOMING

// BL Touch with 5 pin header

// BL Touch with 3 pin header and 2 pin Z-stop connector

#define BLTOUCH
// you probably want to pick your own values (X, Y, Z)
#define NOZZLE_TO_PROBE_OFFSET { -44, -6, -4.2 }
#define XY_PROBE_SPEED (100*60)



#define Z_SAFE_HOMING_X_POINT ((X_BED_SIZE - 10) / 2) // X point for Z homing
#define Z_SAFE_HOMING_Y_POINT ((Y_BED_SIZE - 10) / 2) // Y point for Z homing

// Homing speeds (mm/min)
#define HOMING_FEEDRATE_XY (120*60)
#define HOMING_FEEDRATE_Z (8*60)




//use with caution on compatible BL TOUCH versions (mine is 3.1)


Adding Filament Runout Sensor

After upgrading Ender 3 v2 with BL Touch I ended up with an unused Z-stop. I quickly found a way to repurpose it into a filament runout sensor. You can read it all about it here. If you already have a sensor in mind, you can simply enable it by modifying config files.

Pay extra attention to filament runout state as this will determine if you should set it to LOW or HIGH. Use M119 console command to get the current state of the sensor. If the filament is inside the sensor using M119 should show:

  • Triggered – the settings should be set to HIGH
  • Open – the setting should be set to LOW

#define FIL_RUNOUT_STATE HIGH // Pin state indicating that filament is NOT present.

// number should represent the length of your bowden tube

All Metal Hotend with higher temperatures

I got a BigTreeTech all-metal-hotend recently, as I want to try very expensive Onyx nylon I pinched for testing from work. Unfortunately, the stock nozzle and firmware is capped at 260℃ and I need 280℃ to get this stuff running. I have a separate guide (pending) that shows you changes I had to make to my Ender 3 v2 to add the new hotend.

Increasing the temperature comes with problems. It’s not as simple as changing the values in settings. You have to consider other factors. Depending on the final temperature and duration of use, you may also get a better heating element and more resistant to temperature thermistor.

Whatever your hardware choice is, to increase the temperature in the menu, you have to raise the maximum temp in the configuration file by 15℃ more than the desired value. Marlin 2.0 will shut off power to the heating element if the temperature reaches the max value and printer will let you set max temperature which is 15℃ lower than specified in the file.


// if you using other temperature sensor check the most correct one
#define TEMP_SENSOR_0 13

#define HEATER_0_MAXTEMP 315
#define HEATER_1_MAXTEMP 315
#define HEATER_2_MAXTEMP 315
#define HEATER_3_MAXTEMP 315
#define HEATER_4_MAXTEMP 315
#define HEATER_5_MAXTEMP 315
#define HEATER_6_MAXTEMP 315
#define HEATER_7_MAXTEMP 315
#define BED_MAXTEMP 120

//PID tuning - your values will likely differ
#define DEFAULT_Kp 15
#define DEFAULT_Ki 1
#define DEFAULT_Kd 44

With new hardware come new… parameters. If you notice oscillation of the temperature, you have to tune in your PID controller. Before you dive into the rabbit hole, if the autotune doesn’t work well for you, consider testing other thermistor values.

To tune it, open the printer’s terminal (via Octoprint or your fav software) and run the tuning process: M303 E0 S275 C15 (Tuning, Extruder number, Temperature, Iterations). The process will measure deviation and try to retune the printer by giving you new values to enter by displaying:

#define DEFAULT_Kp 15 
#define DEFAULT_Ki 1    
#define DEFAULT_Kd 44

You can quickly test the new values without building the new firmware. To do so, use M303 command with PID params: M304 P15 I1 D44. This will set new PID values for your hotend. Test the temperature again and adjust if necessary.

Additional modifications can be done manually. To understand how PID values control the heat curve, take a closer look at this GIF. It shows you relations between all parameters. I found the automatic PID to be a great starting point.

Source Wikipedia

Final thoughts

Whatever upgrade my Ender 3 v2 will get next, I will update this post to keep it relevant. It should serve me as a reminder of how to recompile firmware for specific printers and speed up the build process. If you also take advantage of this guide, that’s even better. If you have cool upgrades for your printer, let me know in this Reddit thread. Who knows, I may end up adding it to my 3D printer.


Nothing says "Thank you" better than keeping my coffee jar topped up!


Support me on Patreon and get an early access to tutorial files and videos.


Bitcoin (BTC)

Use this QR to keep me caffeinated with BTC: 1FwFqqh71mUTENcRe9q4s9AWFgoc8BA9ZU

Main 3D-printerCreality Ender 3

Get FilamentSupport NotEnoughTech

PLA Filament

ABS Filament

PETG Filament

TPE Filament

Nylon Filament

Carbon Filament

Best 3D designs

Lights, Camera… but mostly lights

Grab VIJIM VL81 - panels that are useful not just for vloggers. Add one part and make the lights even better

Argon18: Argon ONE SSD modification

Argon One case just got better - now you can boot it from USB without ruining the design thanks to Argon 18: Argon One SSD modification

32mm adapter for Zemismart Roller

Adapter for 32 mm roller blinds to drive it with a Zemismart smart roller shaft

3D Printed miniDSO ES121 case

ES121 is an amazing tool, but comes without a case. I fixed that by designing my own carrying case with charging!

Fixing the 2nd cheapest soldering stand (DANIU)

I have upgraded from the cheapest soldering stand you could get, to the second soldering stand. Now, let's make this DANIU Soldering stand a tiny bit better with a little bit of printing.