Intel Edison + Scala = BlinkOnboard

Jakub Kramarz
May 19, 2015 · 3 min read

For a long time programming embedded systems with limited hardware resources forced you to use native languages and run your firmware bare-metal. That effectively meant that being a Scala software house and doing embedded weren’t an easy job. Fortunately, more and more relatively high-performance platforms have been recently emerging. After playing for some time with Arduino™ ecosystem, we’ve decided to give Intel® Edison a try — a tiny computer offered by Intel, hosting dual core Intel Atom “Tangier” for main applications, Intel Quark (not-yet-available) core for real-time use and Broadcom Wi-Fi and Bluetooth Low Energy chips. Our goal was to prove that:
– you can actually run Scala applications on this platform,
– Scala applications can easily be integrated with underlying hardware,
– you are able to program with reactive paradigm in mind while exploiting low-level features like hardware interrupts.

We set out by throwing together a simple Scala application that starts blinking an on-board LED diode on pressing a hardware button and turns it off when you click it for the second time. To further validate our claims, we decided not to program asynchronous parts by hand but rather employ Akka to do it for us.

Setting up run-time environment

To get started, we need JDK installed on our Intel® Edison.

Installing Oracle JRE 8

Installing mraajava

Libmraa is a C/C++ low-level skeleton library from Intel to interface with the IO on Edison and few other GNU/Linux embedded platforms, providing well structured API and making your high-level languages & constructs portable across supported boards. After playing around SDKs for different platforms, we really appreciate developers’ intent to make communication with hardware easier and more consistent. Thanks to SWIG one can generate Java wrapper for this library, but this feature is quite new and not enabled by default.

To create required library, you can compile it on your own (takes less than one minute)…

… or download prebuild by us

Running simple Akka-powered BlinkOnboard example

We’re using Intel® Edison for Arduino Breakout Kit which has LED already connected to GPIO 13. To get started, you need to connect push button between GND, +3V and our external interrupt source — GPIO 4.
According to Hardware Guide, describing the hardware interface of the Intel® Edison kit for Arduino expansion board, all GPIO pins are interrupt-capable.

Then download our pre-build JAR and give it a try:

It should start blinking after pressing the button.

GPIO

Led actor, defined in Led.scala is an example of simple GPIO operations – it sets adequate state on output pin using mraa.Gpio.write.

Setting up interrupt service routines

In BlinkOnboard.scala you can find an interrupt service routine for rising edge interrupt on GPIO 4 – defined as:

Blinky from Blinky.scala is a glue between Led and ISR, reacting to button pressed messages and blinking the LED periodically by means of posting messages to LED actor via akka.system.Scheduler .

Tying it all together

Full project source code of this a-bit-over-engineered 1.2Hz soft-PWM is available at VirtusLab/Edison-BlinkOnboard GitHub repository.
Build using sbt assembly to pack all required dependencies into JAR. We’re looking forward to creating more intelligent way of deploying and running Akka applications on Intel Edison, but for this simple proof-of-concept does the job just right.

VirtusLab

Virtus Lab company blog

Jakub Kramarz

Written by

VirtusLab

VirtusLab

Virtus Lab company blog