First Contact: Energia

In my previous post I mentioned Energia, a modification of the Arduino IDE that makes programming the TI MSP430 as easy as programming for the Arduino platform. Here, I go into more detail about how Energia may be used to program a Sprite.

Energia is an open-source integrated development environment (IDE) based on the Wiring and Arduino software. It uses the Processing IDE to make multi-platform programming for the Texas Instruments MSP430 Launchpad easy. Since the Sprite spacecraft has an MSP430 at its core, Zac, the driving force behind the KickSat project at Cornell, has started his own branch of the Energia project geared specifically for Sprite development.

An Arduino sketch loaded with the Blink program

The advantages of having an Arduino-like development environment for the Sprite is two fold. First, Arduino is cross-platform, which means that it runs on Windows, Mac, and Linux. When this project began, the only plug-and-play development solution was Windows-only. Second, an Arduino-like development environment means that the large amount of code already written for Arduino boards can be run with little to no modification on the Sprites.

To show this, Zac has gotten some Arduino code working on the (quite functional) souvenir boards. On these boards, the sensor area has been replaced with a group of LEDs. Zac wrote up a modified version of the classic Arduino Blink program, as seen below:

// Blink the LEDs on the Sprite souvenir board in sequence

void setup() {
  // initialize pins 1-6 as outputs.
  pinMode(1, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);

  digitalWrite(1, HIGH); // set the LED above the "i" on
}

void loop() {
  // Turn LEDs on in sequence
  digitalWrite(6, HIGH); // set the LED on
  delay(300);
  digitalWrite(5, HIGH); // set the LED on
  delay(300);
  digitalWrite(4, HIGH); // set the LED on
  delay(300);
  digitalWrite(3, HIGH); // set the LED on
  delay(300);
  digitalWrite(2, HIGH); // set the LED on
  delay(600);
  digitalWrite(2, LOW); // set the LED off
  digitalWrite(3, LOW); // set the LED off
  digitalWrite(4, LOW); // set the LED off
  digitalWrite(5, LOW); // set the LED off
  digitalWrite(6, LOW); // set the LED off
  delay(600);
}

(source)

He uploaded the modified Blink program onto a souvenir board and posted a video of the result:

More interestingly, Energia appears to support object-oriented design. Object-oriented design is a process in which virtual objects are built with the ability to interact in order to solve a programming problem. For example, in the following Energia code, SpriteRadio is the name of an object type. A SpriteRadio object (such as the radio object in this example) is designed to do things like transmit and radioSleep.

#include <SpriteRadio.h>

const char message[] = "Hello Earthlings"; // The transmit message

// Instantiate radio interface class with default settings
SpriteRadio radio = SpriteRadio();

void setup() {
  // Set the radio's transmit power in dBm.
  // This can vary from -30 to +10
  radio.setPower(10);
}

void loop() {

  radio.radioInit(); // Turn on the radio

  radio.transmit(message, 16); // Transmit the message

  radio.radioSleep(); // Turn the radio off

  delay(2000); // Wait 2 seconds

}

(source)

The Arduino Blink program loaded into a sketch in Zac's modified version of Energia, running on my computer

Object-oriented programming is much more modular, reusable, and readable than programming without objects. The modified LED blink program above does not take advantage of object-oriented design, and as a result the code is very repetitive and somewhat tedious to read.

For me, objects are always a welcome tool when programming. An object-oriented design makes code easier to maintain and debug. However, the closer to the actual hardware that a programmer works, the less likely it is that object-oriented programming will be possible. Objects can be expensive in terms of memory, which means that programmers working with embedded systems are often limited to procedural computer code. I’m glad to see object-oriented programming in Energia.

Leave a Reply