Marlin Firmware – Configuration

Marlin Firmware Configuration Using VS Code (Not Arduino IDE)

This guide outlines how to set up and configure Marlin firmware for 3D printers using Visual Studio Code (VS Code), targeting both beginners and advanced users. We will use the RAMPS 1.4 board as the example throughout this guide. Instructions for adapting to other boards are noted where relevant.

Prerequisites

  • Install VS Code: Download and install from https://code.visualstudio.com.
  • Install PlatformIO: Once VS Code is installed, go to the Extensions tab and search for PlatformIO. Install it.

Step-by-Step Configuration Guide

Step 1: Download Marlin Firmware

Download the latest Marlin firmware from the official GitHub repository.

Step 2: Extract and Open in VS Code

Extract the downloaded Marlin ZIP file and open the folder in VS Code.

Step 3: Open platformio.ini and Set Your Environment

Edit the platformio.ini file to select the correct environment for your board. For RAMPS 1.4 (which uses the ATmega2560 chip), find and uncomment:

[env:mega2560]

Comment out any other environment that was previously active.

Note: If you’re using a different board, find the corresponding environment name in the platformio.ini file or refer to your board manufacturer’s Marlin documentation.

Step 4: Configure Configuration.h

Open Marlin/Configuration.h and make the following changes:

1. #define MOTHERBOARD

Set your specific board:

#define MOTHERBOARD BOARD_RAMPS_14_EFB

This tells Marlin what type of mainboard you’re using. Each board has different pins and features, so selecting the right one ensures correct operation. For RAMPS 1.4, BOARD_RAMPS_14_EFB is used when your setup includes an extruder, a heated bed, and a fan.

Other boards: Replace BOARD_RAMPS_14_EFB with the appropriate definition for your board (e.g., BOARD_BTT_SKR_2BOARD_MKS_GEN_L, etc.). Check srcpins in Marlin for options.

2. #define EXTRUDERS

Set the number of extruders:

#define EXTRUDERS 1

This tells Marlin how many extruders your printer has. Set to 1 for a standard single-extruder printer.

3. #define DEFAULT_NOMINAL_FILAMENT_DIA

Set your filament diameter:

#define DEFAULT_NOMINAL_FILAMENT_DIA 1.75

This defines the filament size used for calculations. Most consumer 3D printers use 1.75mm filament.

4. #define TEMP_SENSOR_0

Configure your hotend temperature sensor:

#define TEMP_SENSOR_0 1

This sets the type of thermistor used for the hotend. The number refers to a predefined sensor type; 1 is common for standard 100k thermistors. Refer to Marlin’s documentation for the full list.

5. #define TEMP_SENSOR_BED

Configure your heated bed temperature sensor:

#define TEMP_SENSOR_BED 1

This defines the thermistor type used on the bed. Use the correct number matching your hardware.

6. #define HEATER_0_MAXTEMP and #define BED_MAXTEMP

Set safety temperature limits:

#define HEATER_0_MAXTEMP 275
#define BED_MAXTEMP 120

These define the maximum temperature allowed before Marlin shuts down the heater for safety.

7. #define DEFAULT_AXIS_STEPS_PER_UNIT

Configure the number of steps the stepper motors take per mm:

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

These values correspond to the X, Y, Z, and E (extruder) axes. They vary based on your printer’s mechanics. These values are good for many Cartesian printers with 1/16 microstepping and standard GT2 belts. If you’re unsure, start with these and calibrate later using M92 and M500 G-codes.

8. #define DEFAULT_MAX_FEEDRATE

Set the maximum movement speed in mm/s for each axis:

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

Limits how fast each axis can move. Too fast can cause missed steps.

9. #define DEFAULT_MAX_ACCELERATION

Set the acceleration limits:

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

These values reduce wear and prevent skipped steps when changing direction.

10. #define DEFAULT_ACCELERATION#define DEFAULT_RETRACT_ACCELERATION#define DEFAULT_TRAVEL_ACCELERATION

Fine-tune motion parameters:

#define DEFAULT_ACCELERATION 500
#define DEFAULT_RETRACT_ACCELERATION 500
#define DEFAULT_TRAVEL_ACCELERATION 500

Used to define general movement acceleration, retraction-specific, and non-print moves.

11. #define INVERT_X_DIRYZ

Set motor direction:

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

These should be changed if your axis moves in the wrong direction.

12. #define X_BED_SIZE and Y_BED_SIZE

Set your bed dimensions:

#define X_BED_SIZE 220
#define Y_BED_SIZE 220

Defines your printable area in mm.

13. #define Z_MIN_POS and Z_MAX_POS

Define Z-axis travel:

#define Z_MIN_POS 0
#define Z_MAX_POS 250

Defines the vertical build volume of your printer.

Step 5: Configure Configuration_adv.h

Adjust more advanced features here (for BLTouch, thermal runaway protection, advanced motion settings, etc.). This step depends on your printer’s components and preferences.

Step 6: Compile the Firmware

Click the check mark at the bottom bar in VS Code to compile. If successful, a firmware.hex file will be generated in the .pio/build/mega2560/ directory for RAMPS 1.4.

Other boards: The output file may be firmware.bin instead of .hex, depending on your board’s microcontroller.

Step 7: Flash the Firmware

For RAMPS 1.4, flash the firmware using a USB connection and a tool like AVRDUDE or XLoader, or upload directly from PlatformIO if configured.

Other boards (e.g., SKR 2): Copy the firmware.bin to an SD card, insert it into your printer, and reboot. The firmware will auto-flash and rename the file to FIRMWARE.CUR.

Troubleshooting Tips

  • If your axis moves the wrong way, change INVERT_X_DIR (or Y/Z).
  • If BLTouch doesn’t work, check Configuration_adv.h and wiring.
  • Use M503 after flashing to verify your config.

Next: Proceed to configuring BLTouch or LCD support based on your hardware.

Leave a comment

Your email address will not be published. Required fields are marked *