RUG/Pennsylvania/State College/Electronics/Flashing tutorial

From RepRap
Jump to: navigation, search


The 'firmware' is a program loaded on the board fixed on the printer (Arduino or RAMBo). This program interprets the g-code commands sent by the computer (using a g-code sender such as Pronterface) and turns them into electric signals to command the motors.

Flashing consists in compiling this firmware on a computer and copying it on the board. Before compiling it, you will need to edit the source code to adapt the firmware to your printer.


In order to compile the firmware and send it to the board, you need to download and install the Arduino IDE software.

You also need to download the Marlin firmware source code. You can either clone the repository if you're familiar with Github, or download the code as a .zip file ('download ZIP' button on the right).

Prepare the code

The Marlin firmware is written in C and C++. If you don't know those languages, be sure to respect the syntax when you change the code. Anyway, in order to flash a printer, you'll only need to edit a few files that were designed to ease this process.

Once you've downloaded the Marlin source code, un-zip it and open the Marlin-Marlin_v1/Marlin/Marlin.ino file. This file opens the Arduino editor, which allows you to change the source code. All the changes are referenced by line number. Those numbers are likely to change over versions.

You can actually use any text editor to change the code. However, if you do so you'll need to restart the Arduino IDE after you saved your changes, or else they won't be taken into account. All the files you may want to change are located in the same folder as the Marlin.ino file.

Edit the configuration.h file

This file allows you to edit all the basic settings of the firmware. You need to edit it whenever you want to flash a printer.

Configuration.h uses pre-processing commands (# in the beginning of the line), which define constants when the code is compiled, saving both space and memory usage for the board. Basic logic can be used on those commands.

General settings

Line 28: Change the Baudrate to 115200:

#define BAUDRATE 115200

Motherboard and extruders

Line 73: Select a motherboard. The options are described above this line. For an Arduino + RAMPS with a single extruder:

#define MOTHERBOARD 33

Line 84: Choose the number of extruders. For a single extruder:

#define EXTRUDERS 1


Line 124: Define the temperature sensor used for each extruder and the bed. The options are described above this line. If you set the number of extruders to 1, the sensors defined for the other extruders won't be used (you don't need to set them to 0). For a thermocouple:

#define TEMP_SENSOR_0 -1

Line 149: Define the heater max temperature. It depends on the working temperature of your printer. A good value is around 20 degrees higher than the working temperature (high enough so that the temperature can be increased a little without throwing an error, and low enough to prevent any damage to the extruder if someone sets a temperature way too high). If you don't know the working temperature of the printer yet, you can use the default value of 275°C:

#define HEATER_0_MAXTEMP 275
Line 234: Define the extrusion min temperature. A good value is around 20 degrees less than the working temperature. If you don't know the working temperature of the printer yet, you can use the default value of 170°C:


Line 290: Disable the Z axis when it's not in use. This option should be set to true (the Z-axis uses an irreversible mechanism, therefore there is no need to hold the motor's position with a constant current). This allows you to adjust the Z-height in the beginning of the print, and it prevents the Z-motors from overheating. Note that for the other axis, the 'disable' option should be left to false.

#define DISABLE_Z true

Line 293: In order to have the same default direction on each printer, define the 'invert direction' options as follows:

#define INVERT_X_DIR false
#define INVERT_Y_DIR true
#define INVERT_Z_DIR false
#define INVERT_E0_DIR false
#define INVERT_E1_DIR false
#define INVERT_E2_DIR false 

Feed rates

Feed rates depend on the board, the printer design and the extruder. You can determine them with the following tables:

Board Motherboard factor
Arduino + RAMPS M = 1
RAMBo (v < 1.2) M = 0.5
RAMBo (v ≥ 1.2) M = 1
Z-Axis design Z design factor Z feed rate factor
Two motors Zd = 1 Zf = 1
One motor + belt Zd = 2.625 Zf = 0.4
Extruder type Extruder factor
Open Hybrid Mendel E = 1
Extruder 1040222 E = 1.07
Extruder 1040220 E = 1.78

Then apply the following formulas:

Homing feed rate: { 1800, 1800, 144 * Zf, 0 }
Steps per unit: { 80.376 * M, 80.376 * M, 2560 * M * Zd, 645 * M * E }
Max feed rate: { 30, 30, 2.4 * Zf, 30 }

Example for an Arduino + RAMPS, with two Z-motors and an Open Hybrid Mendel extruder:

Line 395: Change the homing feed rates. They are defined in mm/min:

#define HOMING_FEEDRATE { 1800, 1800, 144, 0 }

Line 399: Change the axis steps per unit. They depend on the reduction ratio of the gears you use:

#define DEFAULT_AXIS_STEPS_PER_UNIT { 80.376, 80.376, 2560, 645 }

Line 400: Change the max feed rates. They are defined in mm/s:

#define DEFAULT_MAX_FEEDRATE { 30, 30, 2.4, 30 }

Those numbers are a good set of default values. However, the actual steps for a given printer depend on the size of the gears and pulleys. If you want to finely tune your printer, read the calibration page.

Edit the pins.h file

This file defines the pins numbers. You need to edit it whenever you want to flash a printer. It tells the firmware which output pin corresponds to each motor / heater / fan, and which input pin corresponds to each thermistor / thermocouple / end-stop. Those pins numbers depend on the board in use, and the way it is wired.

Most default pins definitions are good, except for the temperature pins, which differs since most printers use a thermocouple. If the line numbers have changed, you can find which section you're supposed to edit based on the motherboard number.

If you use an Arduino + RAMPS

Line 522:
With a thermocouple:

#define TEMP_0_PIN 3

With a thermistor:

#define TEMP_0_PIN 13

If you use a RAMBo

Line 1881:
With a thermocouple:

#define TEMP_0_PIN 3

With a thermistor:

#define TEMP_0_PIN 0

Edit the configuration_adv.h file

This file helps you define advanced features. You generally don't need to edit it. However, when you want to flash a RAMBo, you need to change the drivers current default values (on a RAMPS, you can adjust those values with the potentiometer on each driver).

Line 269: Good default values for the current on a RAMBo are:

#define DIGIPOT_MOTOR_CURRENT {80,80,100,80,80}

Flash the code

  • Once you've done all the changes to the source code, save it. If you've been using an other text editor than the Arduino IDE, start (or restart) it by opening the Marlin.ino file
  • From the drop-down menu on top, select Tools -> Board, and set it to 'Arduino Mega 2560 or Mega ADK'
  • Connect the board to your computer with a USB cable. Make sure that no software, especially Pronterface, is connected to to the board
  • From the drop-down menu on top, select Tools -> Serial port, and set it to the USB port on which you connected the board
  • Click the 'Upload' button (Arduino-upload-button.png). The Arduino IDE will first compile the code, then send it to the board. While the code is being copied, LEDs on the board should start blinking. Once they stop blinking, you can start Pronterface and make sure that the printer is working