Rostock, Sanguinololu, and ATmega1284P

One of the challenges I am facing with the mini-version of the Rostock delta 3D printer is using Johann’s modified version of the Marlin firmware with a Sanguinololu printer controller. My logic being there’s no point making a smaller printer if you can’t use a smaller controller. (The $60 savings is an added bonus not to mention the design of the RAMPS controller gives me a migraine…) So to be clear:

The Rostock firmware will not work with a standard Sanguinololu.

Why? Because the default Sanguinololu uses an Atmel ATmega644P for a brain and the available amount of SRAM on that chip is a measly 4k. Thats half the space as the ATmega2560 found on the Arduino Mega and its just not enough RAM for the delta firmware, because of it’s additional code to convert standard Cartesian coordinates into a format for the delta printer. With the larger RAM requirements combined with Arduino’s inability to check its RAM usage, the firmware will upload and act like its working but gives you all manner of weird issues caused by memory overflow. Enter the ATmega1284P with its colassal 16k SRAM, which according to the RepRap wiki is a “drop in replacement” for the 644P. Again to be clear:

It’s not.

Finding the right combination of steps to get a working bootloader on a blank 1284P and then get firmware loaded onto it that works turned out to be a sisyphean task. In the end it isn’t too hard to do but getting the right steps ironed out took its tole on the brain cells.

Sure there were a vast number of tutorials out there to consult for performing this upgrade but none of them really worked for me until I worked out this method.

  1. Replace the 644P chip with a 1284P
  2. Download the AzteegX1 board definition for Arduino 0023
  3. Edit the boards.txt file to set the fuses for a 1284P using a ceramic resonator
  4. Edit the avrdude.conf file to support the 1284P
  5. Upload the AzteegX1 bootloader for the 1284P using Arduino 0023 and compatible ISP
  6. Open the latest version of the Marlin Rostock firmware in Arduino 0023
  7. Edit the firmware to support the Sanguinololu and the configuration of your printer
  8. Upload new firmware to the controller and test

Obviously you need to pick up a new microcontroller, I bought mine at Mouser. With the board powered down, pry out the old 644P (assuming you’re upgrading) being careful to not bend the pins in the process by pulling the chip upward in a position as close to horizontal as possible. Insert the new chip in the same orientation–in this case it might help to bend the pins in on a tabletop like this so that it fits in the socket. Now we need to enable uploads to this new chip on the Arduino by installing some files into the hardware folder inside the Arduino software. After trying too many things to list here, I remembered that the Azteeg X1 printer controller board is based on the Sanguinololu and the newest version uses the 1284P. Looking for the software used on the X1, you’ll find a patch here, these are basically the board definition files for the Sanguino based controller modified for the X1. To install, you’ll have to have Arduino 0023 installed and then copy the entire Sanguino folder that you downloaded in the Azteeg X1 patch to the arduino-0023/hardware/ folder; or on the Mac, right click on the Arduino 0023 icon, select Show Package Contents then navigate to contents/resources/java/hardware/ and paste the Sanguino folder here. You should now have three folders in the hardware folder: arduino, sanguino, and tools.

Inside the sanguino folder there is a file called boards.txt. Open this file and edit the following three lines to set the fuses for the ATmega1284 to work properly with the ceramic resonator on the Sanguinololu board. (Without this weird things happen.)


Save the file and then go back to the hardware folder. Navigate to hardware/avr/etc/ and look for the file avrdude.conf. The instructions for the Axteeg X1 say to replace this file with the one included in their patch but this caused all sorts of problems for me. Instead, all that really needs to happen is to add the definition for the ATmega1284P alongside the rest of the microcontrollers found in this file. Open avrdude.conf in a text editor and then paste this code just before the entry for the ATmega162, and then save the file.

Now Arduino 0023 should know what our new chip is and we can install a bootloader. If you open Arduino 0023 and look in the Tools > Board menu you’ll now find a couple options for the Azteeg controller.

We want to select Azteeg X1 v1.5 w/ ATmega1284p 16Mhz from this menu. Next we need to burn the bootloader onto the chip using an in-system programmer or ISP. There are numerous ISP’s available and you can even use a spare Arduino (who doesn’t have one of these?) but it is important to use an ISP that supports the 128k flash memory available on the 1284P and not all do. I use an Atmel AVRISP Mk II, which has never failed me. The AVRISP will need to be connected via USB to your computer (and any necessary drivers installed) as well as to the 6-pin ISP connector on the edge of the sanguinololu. You’ll also need to seperately power the sanguinololu but it is preferable to have the motors powered off. To do this I use a second USB cable plugged into the USB port on the sanguinololu with the main power supply switched off or unplugged. Here’s what this looks like.

This way, the controller’s logic is powered by the +5 volts from USB and the motors don’t create any problems. After getting everything connected, choose the AVRISP mkII option from the Tools > Burn Bootloader menu.

The main LED on the AVRISP will change from green to orange while a second green LED will flash while it writes the bootloader to the chip and this process will take a little while to complete. If instead of a green light when you start you get a red one then the controller is not properly powered. If the Arduino throws an error out you might not have the 1284p definition in the avrdude.conf file. Overwriting the old version of this file as the Azteeg instructions told me to do also gave error messages in Arduino about a parallel programmer not being available. That’s why I found it best to use the existing version and just amend it with the definition for the 1284p.

Assuming all goes well with the bootloader the next step is to modify and setup the Rostock firmware to use with the Sanguinololu. After downloading the firmware from github, open it in Arduino 0023 (if you haven’t already), and then we need to set some of the parameters for the delta configuration. For the Rostock mini, the values for the diagonal rod length and tower radius, which are calculated in the OpenSCAD model, are entered in the following two lines in the Marlin tab:

#define DELTA_DIAGONAL_ROD 186.0

Everything else should stay the same. Next we need to click on the Configuration.h tab and set #define MOTHERBOARD 62 for the sanguinololu. Scrolling a little ways down I like to wire my endstops a little differently so I have to invert their logic here:

const bool X_ENDSTOPS_INVERTING = true;
const bool Y_ENDSTOPS_INVERTING = true;
const bool Z_ENDSTOPS_INVERTING = true;

Since I seem to do everything backwards, I have my motors wired in the order of red, blue, green, black so I need to invert their direction in these lines:

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

Next we need to set the max positions for the travel of the carriage. This is not exact.

#define X_MAX_POS 400
#define X_MIN_POS 0
#define Y_MAX_POS 400
#define Y_MIN_POS 0
#define Z_MAX_POS 400
#define Z_MIN_POS 0

For the Rostock Mini, there is not as much travel from the print surface to the top of the print volume so we need to make sure to get the following line calculated precisely. I haven’t done this yet but here’s where I started.

#define Z_HOME_POS 175

Moving down the list, we need to set our movement settings which include the feedrates and steps per mm for each motor. Right now I have my homing feedrate set to {800,800,800,0} and the default max feedrate to {1200,1200,1200,300} although I need to play with these numbers more. Because I’m using 36-tooth pulleys instead of the default 40, my steps per mm for each axis is higher and I am also using a geared stepper extruder so my DEFAULT_AXIS_STEPS_PER_UNIT is set to {44.4444,44.4444,44.4444,1385.2846}. YMMV.

Because I print almost exclusively in PLA, I designed a fan holder for a 40mm fan to be mounted very close to the nozzle to cool the extrusion. To set this up we need to find the pins.h file by clicking the right facing area in the menu bar and selecting the file from the drop down menu. About halfway down the file you’ll find:

* Sanguinololu pin assignment

Look for the line #define FAN_PIN and change its value from -1 to 4. Of course, you’ll need to wire a MOSFET to the sanguinololu but thats a topic for another time.

And with that you can save your changes and upload to the microcontroller. Once that is done you should open Pronterface and, while keeping your hand close to the power switch, hit the home all axes button and see what happens. Good Luck!

Tags: , , , ,

  • Arvin Evans

    OMG! And a fun time was had by all…

    • Brian Evans

      And there was much rejoicing…

  • Auzzemit

    I have a PIC3 programming is that OK?
    Sorry for the question, I’m new to this.


  • teeh

    Maybe if you use BLOCK_BUFFER_SIZE forced to be 16, no need change cpu and all that pain.

  • Arnold

    is it possible to fasten open ended timing belts? It is not so easy to get the right length in Europe.

  • Matthew LaBerge

    I am building a Rostock Mini right now and plan on using the RAMPS board from my Sells Mendel, Will this firmware work on RAMPS?

  • Bruno

    Where is pin4 to plug the fan and… if I need a z-min endstop (to auto bed leveling), where to plug it in sanguino? Thanks