Add a new library to the Libelium WaspMote, case study with Arduino's String library

The WaspMote from Libelium come with a lot of nice libraries for handling the Libelium hardware and specific communication functions. However, it is still desirable to add new libraries, for instance more elaborated string manipulation libraries such as the one available with the Arduino's IDE.

In order to add a new library to your Libelium IDE, you have to perform the following steps, largely inspired from

1. You want to add the Arduino's String library: go to the Arduino core source tree to get the source code for WString.cpp and WString.h

2. Open directory of WASPMOTE IDE and go to hardware/cores/waspmote-api-v.023, depending on the API version you have

3. Copy files WString.cpp and WString.h into the previous directory

4. Open Waspclasses.h and include at the end your class linking the .h file : #include "WString.h"

5. Open WASPMOTE IDE and create a new sketch and write down your code.

For WString, you need to modify some lines in order to make it work with the Libelium API. Here is a modified version of WString.cpp and WString.h with the following minor modifications:

  1. in WString.cpp, comment the #include "WProgram.h" line : //#include "WProgram.h"
  2. in WString.h, add:

    #include "wiring.h"

    or alternatively, add

    include <inttypes.h>
    typedef uint8_t boolean;

    just before the String class definition

You can then try the Arduino's string manipulation example. Here is a slightly modified version of the StringAdditionOperator example shipped with the Arduino's IDE.

  Adding Strings together
 Examples of how to add strings together
 You can also add several different data types to string, as shown here:
 created 27 July 2010
 modified 2 Apr 2012
 by Tom Igoe
 This example code is in the public domain.
 modified by C. Pham to demonstrate the usage of the Arduino's String library on a Libelium WaspMote
 All calls to Serial are changed to USB

// declare three strings:
String stringOne, stringTwo, stringThree;

void setup() {
  // initialize serial and wait for port to open:
  //while (!Serial) {
  // ; // wait for serial port to connect. Needed for Leonardo only

  stringOne = String("stringThree = ");
  stringTwo = String("this string");
  stringThree = String ();
  // send an intro:
  USB.println("\n\nAdding strings together (concatenation):");

void loop() {
  // adding a constant integer to a string:
  stringThree =  stringOne + 123;
  USB.println((const char*)&stringThree[0]);    // prints "stringThree = 123"

  // adding a constant long interger to a string:
  stringThree = stringOne + 123456789;
USB.println((const char*)&stringThree[0]);    // prints "stringThree = 123456789"

  // adding a constant character to a string:
  stringThree =  stringOne + 'A';
USB.println((const char*)&stringThree[0]);    // prints "stringThree = A"

  // adding a constant string to a string:
  stringThree =  stringOne +  "abc";
USB.println((const char*)&stringThree[0]);    // prints "stringThree = abc"

  stringThree = stringOne + stringTwo;
USB.println((const char*)&stringThree[0]);    // prints "stringThree = this string"

  // adding a variable integer to a string:
  int sensorValue = 45;
  stringOne = "Sensor value: ";
  stringThree = stringOne  + sensorValue;
USB.println((const char*)&stringThree[0]);    // prints "Sensor Value: 45"

  // adding a variable long integer to a string:
  long currentTime = millis();
  stringOne="millis() value: ";
  stringThree = stringOne + currentTime;
USB.println((const char*)&stringThree[0]);    // prints "The millis: 345345" or whatever value currentTime has

  // do nothing while true:

This has been tested successfully on both Linux and Mac OSX Libelium IDE. For Mac OSX, in order to see the .cpp core files, you have to inspect the file and go to Contents/Resources/Java/hardware directory.

If you've read the page I wrote on "Communication between an iMote2 (CC2420, Crossbow),  WaspMote (Digi XBee, Libelium) and Arduino board (Mega 2560+XBee shield+Digi XBee)" here is an enhanced version of the WaspXBee802_2_receiving_imote2 that use the String library to display the sensor 's XBEE MAC address.

C. Pham