Feed on
Posts
Comments

Firmware Compilation Instructions for 1.x hardware with ATmega328 MCU

Notice: Firmware 1.8 currently only builds in Linux with avr-gcc version 4.5.3. Because Arduino for Windows and Mac use older versions of avr-gcc, they produce binary code that is too big to fit in ATmega328’s flash memory. If you must compile the code in Windows or Mac, there are two workarounds:

  • If there are features you don’t need, such as manual mode or directly setting station bits through http commands, you can comment those functions out to reduce code size.
  • Alternatively, install a virtual Linux (we recommend 32-bit Ubuntu 12.04 or Linux Mint 13) in Windows or Mac using the free VirtualBox software. Then compile the code in virtual Linux. VirtualBox supports USB device pass-through, so the built-in USBtiny programmer can be used in virtual Linux as well.

Preparation:

  • Install the Arduino software (recommended version 0023).
  • Download the OpenSprinkler software package from the GitHub download page. You can either click on the Zip icon, or do a Git checkout. Then copy the software/arduino-code/libraries/OpenSprinklerGen1 directory to your Arduino’s libraries folder (e.g. arduino-0023/libraries).
  • Specify your hardware version by opening file OpenSprinklerGen1/defines.h, and uncomment one of the lines #define SVC_HW_VERSION that corresponds to your hardware version. To identify your hardware version, check the version number at the top of your OpenSprinkler circuit board.
  • Note: If you own OpenSprinkler v1.0 or 1.1, you can no longer upload a program through FTDI. Instead, you need an external ISP programmer. An inexpensive USBtiny programmer specially designed for OpenSprinkler v1.0/1.1 is available at Rayshobby Shop.

Arduino Versions: OpenSprinkler library works with both Arduino 0023 and 1.0 (or above). We strongly recommend version 0023 due to the smaller code size it produces.

Compilation Errors: if you encounter errors when compiling the Arduino code, don’t give up, Google the error message you have seen and there should be a solution on the web already. For example, this is an error I encountered when compiling the code in Linux Mint 13:

/usr/lib/gcc/avr/4.5.3/../../../avr/include/math.h:426:15: error: expected identifier or ‘(’ before ‘double’

After Googling the error message, I found that the solution is to open that math.h file and add #undef round at line 426. Understanding that compilation errors are common, you shouldn’t feel discouraged simply by seeing an error message and not knowing what to do. If after searching you still cannot solve the issue, post a message on the forum and we will help.

Instructions:

Warning: never click on the ‘Burn Bootloader’ menu option in Arduino. If you do so, the microcontroller’s fuse bits will be modified. As a consequence, the microcontroller may fail to start. Note that OpenSprinkler does not use a bootloader, so please do not upload any bootloader to it.

1. Add OpenSprinkler to Arduino’s boards.txt
From the OpenSprinkler software package directory, copy software/arduino-code/hardware/arduino/boards.txt to the corresponding folder in your Arduino’s installation path, for example: arduino-0023/hardware/arduino/. This will overwrite the existing boards.txt.

Alternatively, open your existing boards.txt, and add the following lines to the top of the file:

##############################################################
svc.name=OpenSprinkler
svc.upload.using=arduino:usbtinyisp
svc.upload.maximum_size=32768
svc.bootloader.low_fuses=0xE2
svc.bootloader.high_fuses=0xD1
svc.bootloader.extended_fuses=0x06
svc.bootloader.path=optiboot
svc.bootloader.file=optiboot_atmega328.hex
svc.bootloader.unlock_bits=0x3F
svc.bootloader.lock_bits=0x0F
svc.build.mcu=atmega328p
svc.build.f_cpu=8000000L
svc.build.core=arduino

Important: if you are compiling in Arduino 1.0, you need to add an extra line: svc.build.variant=standard

2. Modify ATmega328 Signature in avrdude.conf
OpenSprinkler uses ATmega328 non-P version. This is different from standard Arduino that uses ATmega328P. Thus you need to change the signature in avrdude.conf to avoid signature check error. To do so, simply open avrdude.conf:

  • In Linux, it is located at arduino-0023/hardware/tools/
  • In Mac, it is located at Programs/Arduino/Arduino.app/Contents/Resources/Java/hardware/tools/avr/etc/
  • In Windows, it is located at arduino-0023/hardware/tools/avr/etc/

Search in the file and locate the section of ATmega328, then change the signature from 0x1e 0×95 0x0F to 0x1e 0×95 0×14. Save the changes.

3. Upload a Program
Start the Arduino program, go to Tools->Board and select OpenSprinkler. Then go to File->Examples->OpenSprinkler and select any example program. Finally, click on the Upload button to upload. See screenshots below:

USB Device Permission in Linux
In Linux, you need to give USB device permission to use the USBtiny ISP in Arduino. There are two ways to do this:

  • Run Arduino in sudo mode or as root user;
  • Alternatively, add the USBtiny vendor ID and device ID to /etc/udev/rules.d. See instructions here.

Important: if you are using 64-bit Linux, the avrdude included in Arduino 0023 has a bug which results in 'avrdude: error: usbtiny_receive: No error (expected 8, got 4)' error. To fix this issue, use the avrdude program included in Arduino 1.0. Specifically, copy avrdude and avrdude64 from arduino-1.0/hardware/tools/ to arduino-0023/hardware/tools/.


Leave a Reply