Monday, 30 April 2012

1284P - Success with Sprinter

After my previous post which detailed the process for getting a bootloader and firmware installed on an ATmega 1284P in a set of Sanguinololu electronics we have been printing solidly for the last week using this setup, with great success or rather, no difference at all from the 644P.

This was what we hoped and expected; we are using the stock settings in Sprinter for a Sanguinololu which work fine for a 644P and demonstratively for the 1284P as well.

So why bother?

The answer lies in our desire to expand the capabilities of the Sanguinololu by allowing it to interface with an LCD screen. This is currently not a default feature in Sprinter but it is included in Marlin so we are going to switch to using Marlin for a bit and get to grips with how that works and is configured.

An example of a LCD screen and input option that is available right now and working for RAMPS is the "PanelMax", a neat solution that uses RP parts as well as a 20x4 LCD screen, and a rotary encoder for input. The ATmega2560 has more I/O pins than the Sanguinololu so it may be a challenge to use the same method. I am going to throw together a bread board circuit in the next couple of days when my LCD and click encoder arrive and will post with an update.


Sunday, 22 April 2012

 Double the space – using a 1284P on Sanguinololu.

(Edit - see summary at end, the first attempts were not completely successful)

We have recently had a number of inquiries about upgrading the ATMEGA 644P on Sanguinololu to the ATMEGA 1284P. The original specs on the reprap wiki for the board stated it was “drop-in compatible”. It is physically; both the 644P and the 1284P are the same 40 pin DIP package, with the same pin-outs. Turns out it is not as “drop-in compatible” as far as bootloaders and firmware go.

A number of threads on the forums have talked about using this chip, either on the Sanguinololu or the Gen 7 electronics with people suggesting the Mighty 1248P bootloader. Written by ManiacBug and available on github this bootloader suffers from one rather large issue – it's designed for Arduino 1.0. The firmware I am familiar with  (Sprinter and Marlin) are pre-1.0 Arduino. A bit more searching found that there was a version of Sanguino available for Arduino 0023 which supported the 1284P. Brilliant!

Loading the bootloader

The first thing to be aware of is that you need a ISP capable of working with the 1284P. We have previously used the USBTiny ISP by ladyada, which works great; reliable and economical, but cannot handle AVRs with flash memory over 64k. Looking around I got hold of a Pololu ISP, which can handle the 1284P.

Getting the Pololu ISP recognised by my computer in Windows 7 was straightforward. The ISP also has a TTL breakout as a second COM port but this is not required here. If you are used to the USBtiny, be aware that the Pololu ISP does not provide power through the ISCP connection. This fact was lost on me the first time I tried to load the bootloader, but after applying power separately to the Sanguinololu board it works fine.

Be sure to pick the Pololu USB AVR Programmer Programming Port – COM 40 in this example.

The next step is to get the Arduino IDE setup right in order to burn the bootloader. I had to configure two things, the new Pololu ISP, and the 1284P bootloader.
Starting with the ISP; I added the following lines to “Arduino-0023\hardware\arduino\programmers.txt”: ISP v2

The  option “AVR ISP v2” will now appear within the IDE under the programmers menu.

For the 1284P bootloader I got the Sanguino files from google code and installed them within the Arduino directory. I extracted the entire zip into “Arduino-0023\hardware\Sanguino\”. Restarting the Arduino-0023 IDE gives:
 (note the Mighty 1284P... listing is there from previous experimenting)

I burnt the “Sanguino W/ATMega1284p 16Mhz” bootloader using the AVR ISP v2 programmer selection with no issues.

Quick Test

To confirm the bootloader had uploaded properly I ran a couple of quick test programs from the Arduino examples:

“Blink” worked fine, changed the blinking pin to pin 31 as this is easily accessible on the expansion header (A0 on extension header). (edit thanks to Alan Ryder - I had my analogue port numbering back to front and originally wrote pin 24, which is actually A7)

Next test was the “AnalogInOutSerial” example which also worked fine:

Passing these quick tests gave me the confidence that the bootloader was working. Next: Firmware.


Sprinter compiles fine in Arduino 0023 choosing the Sanguino 644P option and so I had high hopes for it compiling with no issues choosing the 1284P. It did compile ok but then proceeded to hand on upload with no errors, just an infinite time to upload.

Doing a bit more searching I came across eMaker’s 1284P Github download (not sure why I did not find this earlier!). JM references Steve’s Fix It Shop blog where he mentions the different fuse settings required as the Sanguinololu uses a ceramic resonator, not a crystal oscillator:

Low 0xD6
High 0xDC
Ext  0xFD

These fuses get set in the boards.txt file.

So with a new fuse settings in the boards.txt I started from the beginning again. Upload bootloader: Tried the Sanguino 0023 version again with the different fuse settings and got the following error for the Arduino IDE:

avrdude: invalid byte value (null) specified for immediate mode
avrdude: write to file 'null' failed

With more than a little frustration I gave up on the Sanguino 0023R3 bootloader and switched to the version that came in the zip from JM at eMaker linked above. In the readme it is stated to be the Mighty 1284P; however the boards.txt file looks identical to the Sanguino 0023R3 with the modified fuse settings.

Update: make sure you copy the avrdude.conf from JM's zip. This contains the definition of the 1284p - if you don't have this then the Arduino environment will say that a 1284p is "unknown". I overwrote the stock avrdude.conf in arduino-0023\hardware\tools\avr\etc\

 This time the bootloader uploaded with no problems and a quick test with the "AnalogInOutSerial" example went fine as well.

Third time lucky with the Sprinter upload! A quick test with pronterface shows the firmware connects and talks back (M105 gives temp return).

Next test was Marlin which also uploaded fine. I setup the board in a test environment with a potentiometer in place of the hotend thermistor for the extruder (to trick the firmware into thinking the hotend was hot) and with no stepper drivers or anything connected. I then dumped a large g-code file onto an SD card and will let that run for a bit to see if anything breaks before connecting the board to an actual printer:


  • Use a ISP programmer capable of burning a AVR with 128k flash, like the Pololu programmer.
  • Check your fuse settings, Crystal Oscillators vs Ceramic Resonators.
  • I had best luck with Jean-Marc's bundle of bootloader and Sanguno core, available on github