Wednesday, October 27, 2010

Building a Prusa i3 printer - Configuring and compiling the firmware

Printer firmware

This page is instructions for compiling your own firmware.  If you're just trying to use a ready-to-go printer, go to the calibration page instead.

I will cover a lot of topics in this area that are related but some of them are not necessary to get started.  You can return here later to expand your knowledge.

I’m only covering the “Marlin” firmware variant here.  There are others but that’s what I use.  It’s among the better firmwares available now.

Setting up the software

RepRap printers use a small board with a CPU on them made by Atmel.  They are programmed using an open source development environment called “Arduino” using the “C” programming language.  You don’t really have to know any C to get started, or even really anything about programming, because the software is all written.  However, you do need to use the programming environment and edit a few values during calibration unless your supplier set up the firmware with the correct values to start with.

I assume you have basic skills - you can run Windows apps, can deal with ZIP files, aren't afraid to muck around in driver settings and such.


What you do next depends on which electronics you're using.
  • RAMPS with Arduino Mega 2560
This is the most common way to go these days (late 2013) - price drops have made it price competitive with the others and you don't have to do any fiddling around with weird setups to get advanced stuff working. There is no special setup for the Arduino 2560, it's fully supported and has plenty of memory for any feature you want.  You can use the latest Arduino release - 1.0.5 or whatever is new now.
  • Sanguinololu WITHOUT LCD
Sanguino based RepRap electronics require you to use a 3rd party set of configuration files plugged into the Arduino software.  I recommend sticking with the 0023 release for this, NOT the latest 1.x or higher releases.
  • Sanguinololu WITH LCD
If you are using Sanguinololu and want to use an LCD panel, this gets more complicated.  The standard 644 chip does not have enough program space to hold the LCD driver code. You need to use an ATMega1284P chip which is almost exactly the same as the 644 chip but has more memory. To use it you'll need to use Arduino versions 0022 or 0023

Go to this page on getting the Arduino environment set up and other things you may have to do, then come back here and proceed.

A lot of stuff in the RepRap community runs on Python.  Download this file, then install each of the four things in order.  The stuff is compiled for those specific version so don't go grabbing more recent versions unless you know what you're doing.

Pronterface is a simple app that gives you control over your printer, allowing you to move the motors, control temperature and print things. It's a good app to use to calibrate things.  Download the "printrun" software here: using the "download ZIP" link in the lower right.  Unzip the file somewhere like "c:\reprap\".  Go to this directory and run "" - if you've installed the python stuff above it will run and come up with a control panel. You don't need this until later, close it.

Get the firmware

Your electronics provider may have a location to download the firmware from.  If not or if you just want to get the latest stuff, Marlin is hosted at - go there and click the “ZIP” button at the top of the page.

Unzip that in a good location like C:\reprap\firmware


Start the Arduino IDE.  Select the correct board in Tools/Board – for RAMPS people, Arduino Mega 2560.  For Sanguinololu, Sanguino 644p or 1284p 16 MHz.  Select the correct COM port in Tools/Serial port – if you have more than one and don’t know which, close the Tools menu, unplug the board, then look again and see which port just went away.  Close the Tools menu again, plug it back in and select the COM port that just re-appeared.

Use File/Open to open the “Marlin.pde” file in the location you saved the firmware.  If you are running Arduino 1.x it will ask to convert the project.  Go ahead and do that.  That opens up all the files in the project.

All the configuration happens in “configuration.h”. Here are some that I have compiled up already, if you find your configuration here you can use these:

  • configuration.h for Sanguinololu/i3
  • Sanguinololu electronics, no HPB, 20 tooth GT2 timing belts, M5 x 0.8mm z drive, JHead hotend, Wade's extruder, 200 step / 16x microstep motors, hall Z stop, mechanical x/y stops

If you need to modify configuration.h, read on.  Things you will be interested in:

  • BAUDRATE – probably 250000 though that’s up to you.
  • MOTHERBOARD – there’s a list, change the #DEFINE MOTHERBOARD value to whatever you’re using.  Probably 62 for Sanguinololu users.
  • TEMP_SENSOR_0 and TEMP_SENSOR_BED – set to 1, I think everyone is using the EPCOS 100k thermistor.
  • HEATER_x_MINTEMP – Heater 0 and bed (if you have a heated print bed) leave set to 5, set the others to 0. If you don't have a heated print bed, set that to 0 as well.
  • X_ENDSTOPS_INVERTING – Leave these alone at first, switch them if the motors run backwards (or just flip the connector around on the motor).
  • DISABLE_Z true – I really recommend this.  There’s no reason to keep the Z motors powered up most of the time.
  • INVERT_x_DIR – you’ll need to tweak these if your motors are running backward on any axis
  • DEFAULT_AXIS_STEPS_PER_UNIT – This is the big one.  See below for calculating these values
When you’re done, click the “upload to board” button (it’s a right arrow in the upper left of the IDE).  If you get compile errors, then probably you wonked something up in the edit.

When it's done uploading, start Pronterface to test.  You’ll almost certainly have to go back to configuration.h several times to get the motors running in the right direction and other things, so don't close Arduino just yet.

Testing your electronics and wiring
Start pronterface.  Select the correct serial port and baud rate (probably 250000).  Hit "Connect".  The right hand panel should read "Printer is now online" - and possibly a ton of other stuff. If not double check your com port and speed.

Turn on power to the printer.  We're going to do one axis at a time.  Be ready to flip off the power if the motors start doing something unfortunate.  It doesn't hurt the motors if they bang against the far end but it's irritating.

Warning: Do not plug motors in and out of your electronics with 12V power applied.  You can burn out a motor driver doing that.

Start off by hitting "Home X" in the upper left of the bullseye.  The X carriage should start to move towards the endstop (on the left) and stop, reverse twice and stop.

Possible problems:

  • If some other motor moves instead, then you have the motors plugged in to the wrong port.  Shut down and change the wiring.
  • If the motor only moves a little (possibly to the right) then stops every time you hit Home, your endstop could be wired wrong or is stuck - try holding down the endstop switch and hit home again - if it now moves then you might have wired to the "Normally Closed" side of the switch - power down and fix this.
  • If the motor moves in the wrong direction, you need to either change the configuration.h file or (easier) power off, flip the motor connector around, and try again.
  • If the motor crashes past the endstop and doesn't stop, it's possible your endstop isn't plugged in to the wrong endstop position, or it's wired wrong (like, wires to NC and NO instead of COM and NO). Stop and double check your wiring.

Once the X axis is working correctly, do the same with the Y.

Now do the same with Z except start with the Z endstop a few inches off the bed.  You don't want to crash the head into the glass and break it.  Once you have it stopping properly with the Z axis you can leave it until calibration and levelling.

Calculating STEPS_PER_UNIT

These values tell the printer how many pulses it needs to send to the stepper motors to get them to move a millimeter.  The best way to determine this is to calculate the values.

WE ALWAYS WORK IN MILLIMETERS.  It’s theoretically possible to work in any unit you want, but the entire world is uploading objects in metric.  Set your printer up in furlongs if you want but you’ll be fighting the rest of the world constantly.

First, determine how many step pulses will make your motor turn one revolution.  Most people use 1.8 degree per step motors which means 200 steps per revolution.  HOWEVER most people are also setting their motor controllers to 1/16 microstepping, which means that they have to pulse the controller 16 times to get the motor to move one full step.  That means that you have 200*16 = 3200 steps per revolution.

Now you have to calculate how far your axis moves for one revolution.  For our example, let’s do the X/Y axis with GT2 belt using 20 tooth pulleys.  The GT2 belt that we use has a 2mm pitch per tooth, so one revolution is 20 * 2 = 40mm.

Now divide it out.  3200/40 = 80 steps per millimeter.  That’s what you would use for X and Y axes for that setup.

On the Z axis, we probably have the same 3200 steps per revolution, but that revolution makes us go one thread on the rod.  Assuming you’re using M5 x 0.8 thread per mm rod, one revolution will move the Z axis 0.8mm, so our value is 3200/0.8 = 4000 steps per millimeter

For the extruder, you can’t really just calculate the value.  You need to have the extruder unmounted.  Put a value like maybe 700 in there and compile and upload the firmware.  Start Pronterface, load filament into the extruder and advance it by hand until it is just flush with the extruder surface.  Tell it in Pronterface to extrude 100mm of filament.  Measure how much actually comes out, then multiply your made-up value by the difference.  For example, if you put in 700, and actually got 77 mm of filament instead of 100, then change the value to 700 * (100/77) = 909.1.  Feed that back into the configuration, upload and test again.  You should be on the money now.

Finally, do a sanity check in Pronterface.  Home the axes and put a ruler down on the bed near the printhead, then hit +100mm on X, make sure it moves 100mm.  Move the ruler and check the Y in the same way.  Then hit +10 on Z and see if it moves kinda about 10mm (you can measure more accurately if you have a dial indicator)

When you get your printer running, print a calibration test object from Thingiverse.  A good first one is the Better Nickel Calibration Test, - print it, see if a nickel fits perfectly in there.


velociwrapper said...

Hi! When I try to connect via pronterface I get this error: Connecting...
Printer is now online.
echo: External Reset
echo: Last Updated: Dec 28 2014 15:08:06 | Author: (none, default config)
Compiled: Dec 28 2014
echo: Free Memory: 5250 PlannerBufferBytes: 1232
echo:Hardcoded Default Settings Loaded
echo:Steps per unit:
echo: M92 X88.00 Y88.00 Z4000.00 E473.60
echo:Maximum feedrates (mm/s):
echo: M203 X500.00 Y500.00 Z5.00 E25.00
echo:Maximum Acceleration (mm/s2):
echo: M201 X3000 Y3000 Z100 E10000
echo:Acceleration: S=acceleration, T=retract acceleration
echo: M204 S3000.00 T3000.00
echo:Advanced variables: S=Min feedrate (mm/s), T=Min travel feedrate (mm/s), B=minimum segment time (ms), X=maximum XY jerk (mm/s), Z=maximum Z jerk (mm/s), E=maximum E jerk (mm/s)
echo: M205 S0.00 T0.00 B20000 X20.00 Z0.40 E5.00
echo:Home offset (mm):
echo: M206 X0.00 Y0.00 Z0.00
echo:PID settings:
echo: M301 P22.20 I1.08 D114.00
[ERROR] Error:0

: Extruder switched off. MINTEMP triggered !
Error:Printer stopped due to errors. Fix the error and use M999 to restart. (Temperature is reset. Set it after restarting)
[ERROR] Error:Printer stopped due to errors. Fix the error and use M999 to restart. (Temperature is reset. Set it after restarting)

I'm not using a heated build plate and I tried to remove that from the firmware but I'm not sure I did it correctly- otherwise I can't figure out what's going on or how to fix it. Something I found online says it means my mega is blown out but I don't see how that's possible. If you have any idea what's going on I'd really appreciate it.

John Ridley said...

I find it very doubtful that your Mega is broken. Clearly it's at least mostly working because it's initializing and echoing back all that stuff. Usually a Mintemp trigger just means the connection to the thermistor (on the hotend) is broken. Disconnect the thermistor from the board and measure its resistance. If it's less than 100K ohms, then it's fine and maybe there's something wrong with your electronics, though I'd suspect a bad solder joint on the RAMPS or Arduino board before thinking that the A/D on the chip was bad - this would be a very unlikely case.

New printer: JGAurora A3

This week I decided I'd had it with all the other printers in my stable.  The CTC is stable and decent but it just bugs me (can't st...