Thursday 16 May 2013

Basic Marlin Configuration.h modification

In order to set up Marlin firmware to work with your 3D printer the Configuration.h file needs to be modified to match your hardware. This post will describe the basics of modifying Configuration.h.

The version of Marlin this is based on is the current (as at 15/05/13) Marlin_v1 version, modified slightly to incorporate the Think3dPrint3d Panelolu2. There are various different Marlin versions:

EricZalm master version
Think3DPrint3D version
RepRapPro version
Nophead version

This post is aimed at helping users of RepRapPro Marlin and Nophead's Marlin migrate their configurations to T3P3 Marlin in order to use the Panelolu2; however it may be helpful to others who are setting up their configuration.h for the first time.

Refer to the working/default Configuration.h from your current setup if you have one and use that as a guide to what settings to put at each stage - if in doubt use the default setting from your printer manufacturer as a start point.

Note: I do not cover every setting, just the main ones to get up and printing.

Environment

The T3P3 version of Marlin is only tested on Arduino-0023 and on the following electronics boards:

Sanguinololu 1.2, and 1.3a
Melzi
RAMPS 1.3 and 1.4
Printrboard

First open Configuration.h in your favourite text editor or the Arduino IDE (it is located in <Marlin Folder>\Marlin\Configuration.h)


(from this point on I am not going to use screen shots for each Configuration.h line)

I will refer to the line number in the version of the T3P3 firmware available today. This will change over time and get out of date but it will be a good start and it should be fairly obvious which line I am referring to. You can see the line number on the bottom left of the Arduino IDE screen - in the shot above the cursor is on line 12.

Add an Author/Version


Line 12
#define STRING_CONFIG_H_AUTHOR "(<something useful here>)" //Who made the changes.

This is helpful to confirm with a glance which version of your configuration.h is loaded on your hardware:



Baudrate


Line 20
// This determines the communication speed of the printer
#define BAUDRATE 250000
//#define BAUDRATE 115200


Keep this on the faster setting unless you have a need to use a slower setting. Make sure you select the same baudrate in Pronterface (or your control software) as you have set here when you connect.

Motherboard


Line 51
#define MOTHERBOARD 7

As the comment above this line shows there are many supported electronics motherboards. Make sure you chose the right version for your electronics (for example 63 for Melzi, 33 for RAMPS 1.3/1.4 with 1 extruder, 34 for RAMPS 1.3/1.4 with 2 extruders etc).

Temperature Measurement


Line 90
#define TEMP_SENSOR_0 1
#define TEMP_SENSOR_1 0
#define TEMP_SENSOR_2 0
#define TEMP_SENSOR_BED 1

Most printers will use a thermistor, and a common choice is the "EPCOS B57560G104F". The standard table number "1" works fine for this thermistor. I have copied two tables from Nophead's version of Marlin into the T3P3 version - numbers 11 and 12. If you have a Mendel90 kit from Nophead then these will probably be the best choice for you (although they were numbered 8 and 9 in Nophead's version, I had to change the numbering as 8 and 9 were already taken in the master version).

If you have a RepRapPro printer, their custom version of Marlin does not use a pre-calculated thermistor lookup table but computes the values directly. I have incorporated this into the latest T3P3 version on Marlin as described in my previous blog postMy copy is rather untested so use with caution. Even though on-the-fly calculation is now available, I recommend using tables. Nophead's blog describes the theory behind the table calculations and the "createTemperatureLookupMarlin.py" script in the Marlin folder allows for the calculation of an accurate table for your thermistor and temperature range of interest.

If you want to use the calculated thermistor values then:

Line 97
//use RepRapPro Algebraic Temperature calculation rather than
//the tables - still experimental in this version of Marlin.
#define ALGEBRA_TEMP 

Line 104 onwards
Choose the serial resistor for your electronics (4700 is standard)

#define SERIAL_R 4700
//#define SERIAL_R 10000

Choose your thermistor Beta values (from the data sheet, ask your supplier) and value at 25C (100K thermistor is 100000, 10K is 10000)

// EPCOS B57560G104F (the standard 100K one)
#define E_BETA 4036.0
#define E_NTC 100000.0
#define BED_BETA 4036.0
#define BED_NTC 100000.0

Other standard thermistor types that RepRapPro uses are already in configuration.h, commented out. If you change to these types then comment out the lines referring to the EPCOS and uncomment the lines for the thermistor values that match yours. For example to use the latest RepRapPro thermistor values comment out:


// EPCOS B57560G104F (the standard 100K one)
//#define E_BETA 4036.0
//#define E_NTC 100000.0
//#define BED_BETA 4036.0
//#define BED_NTC 100000.0

and uncomment

// RS 198-961
#define E_BETA 3960.0
#define E_NTC 100000.0
// Rapid 61-0446 ; Semitec 103GT-2 All RepRapPRo Mendels and Thermistors shipped after 1/4/13
#define BED_BETA 4126.0
#define BED_NTC 10000.0

Temperature at Print Start

Line 137
#define TEMP_RESIDENCY_TIME 10 // (seconds)
#define TEMP_HYSTERESIS 3       // (degC) range of +/- temperatures considered "close" to the target one
#define TEMP_WINDOW     1 // (degC) Window around target to start the residency timer x degC early.

These allow you to control how close to the exact set temperature the thermistor reading needs to be to begin extruding. The defaults work OK, however to get a quicker start, I change my TEMP_RESIDENCY_TIME to "5" and TEMP_WINDOW to "2".

Max and Min Temperatures


The printer will give an error if the temperatures are outside of these values. I find that in a cold garage in winter the MIN_TEMPs need to be "1" rather than "5". Don't comment out or set to 0 or else the hotend could overheat if the thermistor is disconnected or breaks.

Line 144-155
#define HEATER_0_MINTEMP 1
....
#define HEATER_0_MAXTEMP 275
....

PID Temperature control


In order to get more stable extruder temperature control the use of PID control is recommended. To enable it ensure PIDTEMP is uncommented.

Line 164
#define PIDTEMP

You need to set the PID constants specific to your hotend. See Wikipedia theory on PID control if interested (not required to make this work):-

Line 178 onwards
    #define  DEFAULT_Kp 22.2
    #define  DEFAULT_Ki 1.08  
    #define  DEFAULT_Kd 114 

By far the easiest way to calculate these is to use PID autotune once your firmware is uploaded to your printer. This function experiments with the reaction of your hotend and calculates the best PID values. For more detail of PID autotune check this wiki entry. Once you have the values you can save them to EEPROM (see the section later in this guide about enabling EEPROM) or you can replace the values in the firmware (at line 178 as shown above) and re-upload your firmware.

You can use PID on the heated bed in a similar manner but I don't find it necessary. To do so uncomment PID_TEMP_BED:

Line 203
#define PIDTEMPBED

and define the constants for your bed. It is best to use PID autotune for this as well, choosing a different target temperature, as suggested in the Marlin comment:

"FIND YOUR OWN: "M303 E-1 C8 S90" to run autotune on the bed at 90 degreesC for 8 cycles."

Line 216
    #define  DEFAULT_bedKp 10.00
    #define  DEFAULT_bedKi .023
    #define  DEFAULT_bedKd 305.4

Extruder protection

The following lines prevent extrusion when conditions are not right.

Line 233
#define PREVENT_DANGEROUS_EXTRUDE
#define PREVENT_LENGTHY_EXTRUDE

Only comment them out to override the effect they have if you have a specific reason for doing so.


Endstops

For Sanguinololu, RAMPS, Melzi and most other common electronics all the endstop pullups should be on - ensure line 248 is uncommented:

Line 248
#define ENDSTOPPULLUPS

Generally you want the endstops to trigger when open: this is controlled with the following lines:

Line 270
const bool X_ENDSTOPS_INVERTING = false; // set to true to invert the logic of the endstops. 
const bool Y_ENDSTOPS_INVERTING = false; // set to true to invert the logic of the endstops. 
const bool Z_ENDSTOPS_INVERTING = false; // set to true to invert the logic of the endstops. 

For more information on endstops and why it is generally better to have Normally Closed Endstops have a look at this part of the Reprap wiki and the linked forum post.

Axis direction is controlled by the motor wiring and by these lines:

Line 287
#define INVERT_X_DIR false    // for Mendel set to false, for Orca set to true
#define INVERT_Y_DIR false    // for Mendel set to true, for Orca set to false
#define INVERT_Z_DIR true     // for Mendel set to false, for Orca set to true

Many printers only have 3 endstops, one per axis, so you have to tell the firmware which end to home towards:

Line 296
// Sets direction of endstops when homing; 1=MAX, -1=MIN
#define X_HOME_DIR -1
#define Y_HOME_DIR -1
#define Z_HOME_DIR -1

This combined with the length of the axis sets the dimensions of the printer. It is worth using software endstops to keep the print head within the print area during normal operation:

These need to be set to the correct values for your printer or else you can command the printer to move outside of the area it can cover and potentially cause damage.

Line 300
#define min_software_endstops true //If true, axis won't move to coordinates less than HOME_POS.
#define max_software_endstops true  //If true, axis won't move to coordinates greater than the defined lengths below.
// Travel limits after homing
#define X_MAX_POS 205
#define X_MIN_POS 0
#define Y_MAX_POS 205
#define Y_MIN_POS 0
#define Z_MAX_POS 200
#define Z_MIN_POS 0

I find that it is safest with a new printer to set the MAX_POS values to less than the maximum theoretical sizes, then physically check how much more travel is possible and adjust the values upwards if appropriate.

Movement Settings

These settings define how fast your printer's axis move and set the accuracy of moves. In most cases there will be a direct copy from the configuration.h file of your printer supplier. First is the speed the axes move during homing; this is in mm/s and the format X,Y,Z,E. E is 0 because the extruder is not homed.

Line 325
#define HOMING_FEEDRATE {50*60, 50*60, 4*60, 0}  // set the homing speeds (mm/min)


The next line defines how many steps of the stepper motor are required to move an axis by 1mm. Getting this wrong means the printer axis will not move the right distance. You MUST change the settings from the defaults (unless you actually have an Ultimaker!). Once again the format is  X, Y, Z, E. Prusa's calculator is very helpful for calculating the appropriate X, Y and Z values for your stepper motors, belt pitch and pulley teeth. For E, because hobbed bolts all vary slightly, the only way to get the correct value is to start with a reasonable value (e.g. 700 for a Wade's) and calibrate your extruder: RichRap's Slic3r blog provides detailed instructions for doing this.

Line 329
#define DEFAULT_AXIS_STEPS_PER_UNIT   {78.7402,78.7402,200.0*8/3,760*1.1}  // default steps per unit for ultimaker


The following lines set the speed and acceleration of your printer. Often the quality of prints can be improved by using slower acceleration values and smaller XYJERK values. They definitely need setting down for less-rigid machines with threaded-rod frames. Check the default values in the Marlin as supplied with your machine and use these to start with.

Line 330 Onwards
#define DEFAULT_MAX_FEEDRATE          {500, 500, 5, 25}    // (mm/sec)
#define DEFAULT_MAX_ACCELERATION      {9000,9000,100,10000}    // X, Y, Z, E maximum start speed for accelerated moves. E default values are good for skeinforge 40+, for older versions raise them a lot.

#define DEFAULT_ACCELERATION          3000    // X, Y, Z and E max acceleration in mm/s^2 for printing moves 
#define DEFAULT_RETRACT_ACCELERATION  3000   // X, Y, Z and E max acceleration in mm/s^2 for r retracts

// The speed change that does not require acceleration (i.e. the software might assume it can be done instantaneously)
#define DEFAULT_XYJERK                20.0    // (mm/sec)
#define DEFAULT_ZJERK                 0.4     // (mm/sec)
#define DEFAULT_EJERK                 5.0    // (mm/sec)

EEPROM - Saving Settings without recompiling firmware

When EEPROM is enabled there are three locations where versions of the printer settings are stored.
  1. Hard-coded in Firmware in Configuration.h.
  2. In the running RAM of the microcontroller - not saved on power down or reset.
  3. In EEPROM
If EEPROM is enabled the settings are loaded from EEPROM, not from the hard-coded values in Configuration.h. EEPROM settings can be updated using a series of "M" commands. See the G-Code page on the RepRap wiki for a description of all the G and M codes including those for saving and reading from EEPROM.

I recommend enabling EEPROM_SETTINGS and EEPROM_CHITCHAT
Line 356

//define this to enable eeprom support
#define EEPROM_SETTINGS
//to disable EEPROM Serial responses and decrease program space by ~1700 byte: comment this out:
// please keep turned on if you can.
#define EEPROM_CHITCHAT

Display Screens - Panelolu2

There are an increasing number of LCD screens supported by Marlin, but this post only covers the Panelolu2. To enable the Panelolu2 uncomment the following line:

Line 381

#define PANELOLU2

If you don't like the buzzer making a beep sound then comment out the PAN_BEEP

Line 386
 #define PAN_BEEP //comment out to disable buzzer

I recommend that you get your printer working without enabling the Panelolu2 first and then uncomment the #define PANELOLU2 line afterwards. Note that Marlin will hang if the PANELOLU2 is enabled but not connected.

Thats it!

Please feel free to leave useful links to further information in the comments to this blog post.

30 comments:

  1. Hi Tony,
    One of my customers said he also had to make changes to allow negative coordinates to be displayed for Mendel90. Have those change been merged?

    ReplyDelete
    Replies
    1. Hi Chris

      I have the changes but have not had a chance to test them so they are not currently merged Is there a particular reason you have 0,0 in the bed centre? That is the only reason to display the negative numbers I can see.

      Delete
    2. Tony,
      Can you post the changes required to allow negative coordinates to be displayed as above?
      Thank you, Alan

      Delete
    3. Hi Alan

      I have emailed you through the work that Icare Design did - I have not had a chance to test it yet and incorporate it.

      Tony

      Delete
  2. Looks like a comprehensive write up which should be reasonably easy to follow - thank you. One question - does the MARLIN version on the T3DP3D Github repo have a proven and successful implementation of the M206 code as in the past I had to make some changes to get this command operational.
    Alan

    ReplyDelete
    Replies
    1. Hi Alan

      The implementation for the M206 is unchanged from the standard current Marlin. I have not used this function so not sure how well it works. The fix your incorporated previously should be able to be brought in in the same way if required.

      Delete
  3. Thank you for an extremely useful blogpost. I'm now running Think3DPrint3D version of Marlin on my Reprappro Huxley with a 20x4 display and rotary encoder. Would have been very difficult without this blogpost. My display-setup is explained here.

    ReplyDelete
    Replies
    1. Joakim

      Glad you found it helpful and good to see more hardware supported.

      Delete
  4. in nopheads configuration.h i can enter my E_STEPS_PER_MM only lines 4, 5 are missing in t3p3 as a result when compiling i get this error ConfigurationStore.cpp: In function 'void Config_ResetDefault()':
    ConfigurationStore.cpp:216: error: 'E_STEPS_PER_MM' was not declared in this scope.

    ReplyDelete
    Replies
    1. Hi macroneus

      In the T3P3 version just set the E steps here:

      DEFAULT_AXIS_STEPS_PER_UNIT {80,80,4000,655} //655 is esteps per mm

      Cheers

      Tony

      Delete
  5. Thanks Tony,
    more compiling errors I'm afraid.
    Marlin_main.cpp:201: error: 'analogInputToDigitalPin' was not declared in this scope

    ReplyDelete
    Replies
    1. Hi Macroneus are you using Arduino 0023 and the Sanguino version linked in this blog post?

      I guess you are using a Melzi?

      Delete
  6. Nophead Mendel90, Melzi with Arduino 1.01. the arduino link you supplied seems to only offer 1.05, if you have a direct link to 0023 then please post.
    thanks again Tony for your time and innovation.

    ReplyDelete
  7. Hey, on my phone if you go to the arduino website and link to previous versions you should find it there

    ReplyDelete
  8. hi Tony, ok back to it not sure what line in need to change to configure my Z height nophead supply's line 178 #define Z_HOME_POS (203.6) also theirs no melzi under tools/board.

    ReplyDelete
  9. Hey Macroneus

    If you have installed the Sanguino extensions into arduino 0023 then you should have "Sanguino W/ Atmega 1284P 16Mhz" as an option, this is what the Melzi uses.

    For the Z height in Marlin go to "#define Z_MAX_POS 200" and set to "#define Z_MAX_POS 203.6"

    ReplyDelete
  10. cheers Tony, I'm sure this is just a small thing but on upload I get this error arduino-0023\hardware/tools/avr/etc/avrdude.conf:4 unrecognized character: "<"

    ReplyDelete
  11. Hello Tony,

    Thanks for your informative and well-structured process presentation here. Your blog has inspired me a lot to do well in my project. I am mechatronics student from Leicestershire and I need to get into the codes of marling firmware and develop according to my needs.

    I am desperately looking for the flow-chart of the marlin firmware and possibly the ways to edit the libraries.

    Could you kindly please help me in this matter ??

    With Regards

    Fahim

    ReplyDelete
    Replies
    1. Hi Fahim

      Glad the blog post helped. I don't believe such a flow chart exists, Marlin has grown pretty organically and has many features added by individuals to support their specific hardware platforms. The whole codebase is opensource so you can edit any part you want to - the best place to go for support is the Marlin Github pages:
      https://github.com/ErikZalm/Marlin

      Cheers

      Tony

      Delete
  12. Hello ?

    where are my posts from today ??

    ReplyDelete
    Replies
    1. here:
      http://blog.think3dprint3d.com/2013/02/panelolu2.html

      Delete
  13. i'm so sorry tony ;o((

    ReplyDelete
  14. Hey Guys, Can Any one guide me to How can I change the name of the Machine from firmware. Like my machine starts and say "Mendel Ready". I want to replace Mendel with my own name. Let me know how can I do that.
    Thanks!
    Aalti

    ReplyDelete
    Replies
    1. In configuration.h find the following line, uncomment it and then put your name:

      // #define CUSTOM_MENDEL_NAME "This Mendel"

      To stop having the "ready"

      in language.h, find the section that applies to the language you are using and then edit this line (as shown in english):

      #define WELCOME_MSG MACHINE_NAME " Ready."

      to remove or replace "ready"

      Also if you have a board type, 7,71,11, or 80 then look at the top of language.h

      Cheers

      Tony

      Delete
  15. What will be the acceleration for the stepper motor for prusa i2? ?please help

    ReplyDelete
  16. Depends how well your printer is assembled.. start with 1000 or 2000 and see how you get on.

    ReplyDelete
  17. This comment has been removed by the author.

    ReplyDelete
  18. My Prusa I3 was going with high speed when homing and then automacticly went back for aprox. 1cm and then slowly went to the endstop.

    Yesterday I changed some speed settings, but now homing only goes to the endstop and then nothing.
    Changing the speed back as before does not help.

    Now the homing is not as precise as before, which is a problem for the Z axes.
    I can set the homing speed slower, but found it really nice option that it went back after hitting the endstop and then slowly homed again.

    ReplyDelete
  19. Hello,
    Thank you for the useful post. I have a question. I am woking with stepper motors and an AzteegX3 PRO 3D board. I want to add a code for managing feedback signal for the motor sensors in case of an error detected. I have no idea how to write a code like this. Do you have some advise?

    ReplyDelete
  20. Need help.
    Motors engage but dont turn.
    Melzi 2.0 v5
    Extruder motor got hot so I turned pots down. Its running repetier, I have installed this programme but dont get it all.
    Is there a eeprom I can upload that will be close or should I turnt the pots up?
    Extruder heats up and fan works. Click home all or any on repetier motors will clunk with in secs but not turn.

    Please advise been searching like mad for week and want this to work.
    No errors on my lcd. Tried to test run dry it heated up ect but no movement.

    Please help.

    ReplyDelete

Comments are now moderated to reduce spam, please excuse the additional time this will entail.

Note: only a member of this blog may post a comment.