Microcontroller Firmware Hints

From RepRap
Revision as of 20:16, 30 April 2009 by 216.162.199.202 (talk) (Sanguino Firmware)
Jump to: navigation, search

Compiling and downloading Arduino Firmware using Windows

  • Fresh Install Arduino version 011 software.
  • Copy sub directories in reprap-arduino-firmware-1.3/library (or any later version downloaded from sourceforge https://reprap.svn.sourceforge.net/svnroot/reprap) directory to Arduino hardware/libraries directory.
  • With reprap-arduino-firmware-1.3 you should end up with 14 sub directories below /libraries.
  • Open the appropriate Single_Arduino_SNAP.pde in arduino.
  • Compile.
  • You will see an error regarding obsolete header file.
  • BUT it will compile without error.
  • If you change a file in libraries which you invariably have to do to match your thermister/thermocouple delete the object file ?????.o
  • Otherwise it will not recompile using the changes

Sanguino Firmware

The Sanguino is an Arduino clone using the Atmega644p chip instead of the Atmeg168. The clone is software compatible except that the pins are moved around a bit.

  • First, install the arduino software. Version 12 is noted as being somewhat buggy, but can be used with these steps. Copy files into the arduino directory from the sanguino 1.3 folder as explained on the sanguino website under the section "use it". Follow the instructions to the letter.
  • if an error saying something about an undefined "byte" error, then go into the parameters.h tab and add the following early in the file

// from [www.arduino.cc]

// and [publications.gbdirect.co.uk]

typedef uint8_t byte;

This should solve the problem of undefined type "byte".

Note: the first 2 lines aren't really needed, but include the places where the solver of the problem learnt how to fix the issue.

  • Make any changes in the code that you need to as described on the software page. The most common change is removing the double slash in front of #use thermistor in the thermistor tale section if you are using the standard (ie cheaper) thermistor method of temperature analysis.
  • Assuming your code compiles correctly, attempt to upload the code to your sanguino, if it works first time, then you're very lucky. But most likely you'll get an error something like.

avrdude: stk500_getsync(): not in sync: resp=0x30 avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51

The solution is simple. Get one finger on the reboot button on your sanguino, then use the other one to hit "upload to I/O board". Now count to 10 and press the reset. After a few seconds, the light on the sanguino should start flashing like crazy(most likely a bit of flashing at first, then a period of flashing so fast the light is almost perminently lit up). If the same error comes back,do it again, but count to 10 a bit slower. This should allow the code to upload

  • explination of the above problem and note to developers:

This error is a side effect of using the arduino software to work on a sanguino. Long story short, the normal arduino uses a timeout period of about 20 seconds(it waits for the "I'm done uploading" message from the sanguino for 20 seconds). Because for a normal arduino, the code shouldn't take longer than 10 seconds to compile before it gets sent to the board. Sanguino's can store code 4 times as long, thus they should have a time out of about 30 seconds, but instead the arduino software waits 20 seconds, and assumes something has gone wrong and stops it all working. The next sanguino software needs to includes something to increase the upload timeout to 30 seconds or so to allow for longer code to be uploaded.

Initial testing on a Sanguino.

If you've just soldered up your Sanguino a good first program to run is Blink. You can find it from the menu in the Arduino host software at File => Sketchbook => Examples => Digital => Blink

The program will toggle “digital pin 13” which is pin 19 on the Atmega644p chip and the leg labelled 13 on the Sanguino board. This pin does not have an LED attached so you will see nothing flash.

If you want to see something flash change the line “int ledPin = 13;” to “int ledPin = 0;”. Compile and upload this and it will toggle digital pin 0 causing the red debug LED to flash.

Refer to the schematic and the pin-out diagram

Compiling and downloading Arduino Firmware using OSX

( Based on some information from here: http://reprap.org/bin/view/Main/Generation2Electronics#Program_the_Arduino )

  • Fresh Install Arduino version 012 software, including USB to serial drivers. follow this page: http://arduino.cc/en/Guide/MacOSX We suggest installing the software to the /Applications/arduino-0012/ folder.
  • Download the most recent RepRap Arduino firmware source: http://sourceforge.net/project/showfiles.php?group_id=159590&package_id=256565
  • Copy sub directories in reprap-arduino-firmware-1.3/library (or any later version downloaded from sourceforge https://reprap.svn.sourceforge.net/svnroot/reprap) directory to Arduino hardware/libraries directory.
  • With reprap-arduino-firmware-1.3 you should end up with 18 sub directories below /libraries.
  • If you were to try to "build" your sketch now, it would error out with math.h or stdlib.h errors.
  • To fix, edit the arduino-0012/hardware/cores/arduino/wiring.h and comment out the 7 defines listed here ( or surround them in a #ifdef like below, which is equivalent) :
  1. ifdef USE_PESKY_MACROS
  2. define int(x) ((int)(x))
  3. define char(x) ((char)(x))
  4. define long(x) ((long)(x))
  5. define byte(x) ((uint8_t)(x))
  6. define float(x) ((float)(x))
  7. define abs(x) ((x)>0?(x):-(x))
  8. define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
  9. endif
  • start the Arduino 12.app
  • Open the appropriate Single_Arduino_SNAP.pde in arduino.
  • Compile.
  • You will see an error regarding obsolete header file.
  • BUT it will compile without error.
  • If you change a file in libraries which you invariably have to do to match your thermister/thermocouple delete the object file ?????.o
  • Otherwise it will not recompile using the changes

Arduino Firmware using Ubuntu Linux

After downloading the linux firmware from the arduino site, If you cannot select the ttyUSB0 port from the arduino software menu - the entire tools/serial port menu is greyed out - the it could be a permission problem for /dev/ttyUSB0 If you run as root

 sudo ./arduino

then the USB port can be selected and it can be uploaded.

You can also add your normal user to the 'dialout' group ( through the System>Administration>Users and Groups menu). After rebooting, you can then run the arduino software as your normal user.

Note this also causes problems for the RepRap host software (can't open port /dev/usb0) and also for any G-Code uploaders (like ReplicatorG)