Compiling the Ninja Block's Arduino firmware

Checkout repository

The source code that compiles to the .hex that runs on the Arduino of the Ninja Block is located in this repository

  git clone

Arduino IDE Setup

Download and Install

The arduino IDE can be downloaded here

Library location

There are some libraries that are used by  arduino/Ninja/NinjaArduino/arduino.ino, and these need to be seen by the IDE. On can either copy these libraries to a location referenced by the arduino IDE, or use symbolic links if wanting to maintain a reference to the repository. Symbolic links allow easy updating of libraries without re-copying modified files each time (handy for quick development cycles).

Depending on your OS, libraries are looked for in different locations... "User-created libraries as of version 0017 go in a subdirectory of your default sketch directory. For example, on OSX, the new directory would be ~/Documents/Arduino/libraries/. On Windows, it would be My Documents\Arduino\libraries\." (Reference)

Or if you're running it from a directory in linux, it will be in the subdirectory "libraries", eg "arduino-1.0.5/libraries".

Copy or Link Libraries

If you're not already using libraries required by Ninja Blocks, you will need to copy or link them to the library location found in the previous section.

The libraries are as follows:

  • aJson
  • DHT22
  • DMD
  • MMA8453Q
  • Ninja
  • NinjaObjects
  • NinjaObjectsPi
  • RCSwitch
  • Sensors


For example on linux based OS's:

  cd <libDir>
  ln -s <repoDir>/arduino/aJson aJson
  ln -s <repoDir>/arduino/DHT22 DHT22
  ln -s <repoDir>/arduino/DMD DMD
  ln -s <repoDir>/arduino/MMA8453Q MMA8453Q
  ln -s <repoDir>/arduino/Ninja Ninja
  ln -s <repoDir>/arduino/NinjaObjects NinjaObjects
  ln -s <repoDir>/arduino/NinjaObjectsPi NinjaObjectsPi
  ln -s <repoDir>/arduino/RCSwitch RCSwitch
  ln -s <repoDir>/arduino/Sensors Sensors
  ln -s <repoDir>/arduino/I2C I2C

The library locations are updated when the Arduino IDE opens. If you already have it open, you will need to close then re-open it for the libraries to be checked.


Set Building Preference to Verbose

In the Arduino IDE you can find your preferences window via the menus.

The setting unfortunately does not reside directly on the preferences window, but instead in the preferences file referred to. For example, the user "dev" has their file located "/home/dev/.arduino/preferences.txt"

You can click directly on the link to open the file, then close the arduino IDE and insert the following.


By making the build logs more verbose, we will be able to see the obscure location where building occurs, and the resulting .hex location.



Go to the directory where your arduino repository is located, then open  arduino/Ninja/NinjaArduino/NinjaArduino.ino  in the arduino IDE.

Under the Tools menu:

  • Choose "Board" -> "Arduino Pro or Pro Mini (5V, 16MHz) w/ ATmega328"
  • Choose your usb "Serial port"
  • "Programmer" is irrelevant as the IDE is just use to compile the .hex, not program anything.

Click compile.


If you have any problems such as "warning: I2C.h: No such file or directory", verify that you have correctly linked or copied the library referred to in the error.

Note: You will then have to close and re-open the IDE for the updated library paths to take effect.

Resulting .hex file

As you compile, you will see the verbose build logs scroll by until it successfully completes.


For this example (on osx), the resulting .hex file is located:




Copy file to Ninja Block

First copy the file across to the ninjablock. For example:

scp /var/folders/xt/rdmp4qcj08xd1jnw_rrb_mnm0000gn/T/build2810045011440774543.tmp/NinjaArduino.cpp.hex ubuntu@<nb_ip_address>:newArduino.hex

After typing in the password for the Ninja Block's ubuntu user (default "temppwd"), the compiled file will reside on the Ninja Block's ubuntu users home directory.

Run install script

Now ssh into the Ninja Block. For example:

  ssh ubuntu@<nb_ip_address>

Then at the prompt, update the arduino with the file as the parameter. First you will need to manually stop the ninjablock service, then restart it after:

  ubuntu@ninjablock:~$ sudo stop ninjablock
  ubuntu@ninjablock:~$ sudo /opt/utilities/bin/ninja_update_arduino ~/newArduino.hex
  ubuntu@ninjablock:~$ sudo start ninjablock


Via Ninja Dashboard (for info)

If one happens to share their .hex file on an accessible server, it is also possible to flash via a direct URL. Or if at any time you wish to revert back to the official firmware, this too can be done from the dashboard.

Simply click on the "Drivers" button in the top-right (gear with yellow background), then "Configure" of "ninja-arduino".


Pete Moore
Pete Moore