Compile the Firmware Code

NOTE: compiling the firmware code requires technical skills. Instructions are provided as is, we will not be able to help you with compilation issues, nor can we help you with modifying the code.

The OpenSprinkler Firmware is built around Arduino. If you are new to the Arduino software, please follow online tutorials first to get familiar with the development tools.

Instructions for OpenSprinkler 3.0 (based on ESP8266 WiFi)

  1. Download or git clone OpenSprinkler Firmware Code.
  2. Install ESP8266 Core for Arduino. Specifically, in Linux or Mac command line (the most recent core version at the time of this writing is 2.4.1):
    cd ~
    git clone esp8266_2.4
    cd esp8266_2.4

    git checkout tags/2.4.1
    cd tools
  3. Modify the Updater.h in ESP8266 core as follows:
    • Go to ~/esp8266_2.4/cores/esp8266
    • Open file Updater.h, and locate line 144 that says private:
    • Right above that line, add a function as follows:
      void reset() { _reset(); }
      basically it wraps the private _reset() function into a public reset() function.
  4. Install SSD1306 library and RCSwitch library. You can either download and unzip or git clone these into your ~/esp8266_2.4/libraries folder.
  5. The easiest way to compile is to use the makefile provided in the firmware code folder:
    make -f make.lin30
    In case you installed esp8266 core into a different folder, open make.lin30 and modify ESP_ROOT variable to point to the correct path. The makefile will compile the program into your system's temporary folder, as a bin file (e.g. mainArduino.bin).
  6. To upload the firmware, the easiest way is to use OTA (Over The Air) update. Assuming OpenSprinkler is already connected to your WiFi router, open a browser and type in:
    http://x.x.x.x/update (where x.x.x.x is your OpenSprinkler's IP address)
    Then select the .bin file and type in your OpenSprinkler's device password (the default password is opendoor if you have never changed it). Submit and wait until it completes firmware update/
  7. (Alternative) Starting from firmware 2.1.8, OTA firmware update is also supported in AP mode -- if your OpenSprinkler is in AP mode, use your computer or laptop to connect to its AP SSID, then open a browser and type in:
    Then follow the same as step 6 above to upload firmware.

Instructions for OpenSprinkler 2.x (based on ATmega644 or ATmega1284)

  1. Download Arduino Software.
  2. Download the OpenSprinkler Firmware Code. Alternatively, you can do a Git checkout from the OpenSprinkler Github repository.
  3. Unzip the file you just downloaded, and copy the entire folder to your Arduino's libraries folder (e.g. arduino-1.0.6/libraries/). It's recommended that you rename the folder to something easy to remember, such as OpenSprinkler.
  4. Download and unzip which defines the Arduino board profiles. Move it to your Arduino's hardware folder (e.g. arduino1.0.6/hardware/).
  5. Download the SdFat libraryand similar to Step 3 above, unzip and copy the folder SdFat to your Arduino's libraries folder.
  6. Run Arduino, go to File -> Examples -> OpenSprinklerGen, select mainArduino. Then go to Tools -> Board, select one of the OpenSprinkler boards corresponding to your hardware version. Then click compile () and that should compile the program. 

USING MAKEFILE: for those who have some exposure to Makefile, it's convenient to compile the firmware in command line, instead of having to launch Arduino each time. To use Makefile, you need to install arduino-mk. Also follow Steps 1 to 5 above to install Arduino software and the necessary libraries. In Step 6, instead of launching Arduino, you run make in the OpenSprinkler library folder to compile firmware. There is already a Makefile as a starting point, but you need to edit and modify it in order to point the necessary folders to your computer. 

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. 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.

Flash the Firmware using Arduino GUI

  • For OpenSprinkler 2.0, go to Tools -> Programmer, select USBtinyISP. Then click on the Upload button.
  • For OpenSprinkler 2.1, go to Tools -> Programmer, select USBasp, then follow the bootloading procedure to enter bootloader: turn off controller and unplug USB cable, press and hold B2 while plugging in USB cable, then release the button B2 within a couple seconds. Make sure the screen does not light up. Next, click on the Upload button.
  • For OpenSprinkler 2.2 and 2.3, go to Tools -> Serial Port, select the available Serial Port, and next click on the Upload button.

Flash the Firmware using Command Line

Tips: Arduino compiles the code into a machine binary (e.g. interval_program.cpp.hex) and it's usually stored in a temporary folder (check your system temp folder). If you run Makefile to compile the code, the compiled firmware will be placed in a subfolder under the OpenSprinkler library folder. You can run avrdude command in command line to manually flash the firmware to your OpenSprinkler. In the following, opensprinkler_firmware.hex is the example firmware name, you need to change it to match the actual firmware file name as it may differ on different computers.
  • For OpenSprinkler 2.0, the command is avrdude -c usbtiny -p m644 -F -U flash:w:opensprinkler_firmware.hex
  • For OpenSprinkler 2.1, the command is avrdude -c usbasp -p m644p -U flash:w:opensprinkler_firmware.hex
  • For OpenSprinkler 2.2, the command is avrdude -c arduino -P <serial_port_name> -p m644p -b 115200 -U flash:w:opensprinkler_firmware.hex
    where <serial_port_name> refers to the serial port name. For example, in Windows, it's usually COM? where ? is a number; in Linux it's /dev/ttyUSB? where ? is a number.
  • For OpenSprinkler 2.3, the command is avrdude -c arduino -P <serial_port_name> -p m1284p -b 115200 -U flash:w:opensprinkler_firmware.hex