Getting started with a BrainStem using C++

INTRODUCTION

This guide describes the necessary steps to using the BrainStem C++ API along with providing a basic example for flashing the User LED.

REQUIRED ITEMS

This guide was designed using the following items:

  • BrainStem Module
  • BrainStem Development Board
  • Link transport cable
  • BrainStem Support Package

A BrainStem Module and BrainStem Development Board can be purchased from the Acroname Store. The latest version of the BrainStem Support Package can be downloaded from the Acroname Download page. Extract the package to the location of your choice when the download has finished.

ABOUT C++ API

The BrainStem C++ API provides a cross platform way to interface between a host machine and a BrainStem module.  The API provides a user with virtually unconstrained computing power in a familiar development environment when working with a BrainStem.

BUILD ENVIRONMENT REQUIREMENTS

The following items are required to develop using the BrainStem C++ API:

  • A C++11 compliant compiler
  • Append the header search paths to include "aBrainStem" and the module header files (in a folder named "aInclude" by default)
  • Append the library search path to include "aBrainStem2" libraries (in a folder named "aBinary" by default)

Most recent compilers are C++11 compliant. Some examples on various platforms are:

  • MacOS X: Xcode 4 or newer
  • Windows: Microsoft Visual Studio 2012 or newer
  • Linux: gcc 4.7 or newer

EXAMPLE CODE

The aBrainStemExample is included in the examples folder of the BrainStem Support Package and shows how to toggle the User LED on a BrainStem using the C++ API.  Included with the example are IDE projects for Windows, Mac OS X and Linux.  The following code shows how to toggle the User LED.  Please visit the Flash an External LED example page for a detailed explanation.

TOGGLING THE LED

#include "a40PinModule.h"

// 1 second delay
#define DELAY 1000

int
main(const int argc,
     const char* argv[])
{
  // Create a link to the first BrainStem found on the specified
  // transport linktype
  aLink link(aLink::specifier::USB);

  printf("connecting to stem...");

  if (!link.isConnected(3000)) {
    printf("timed out\n");
    return aErrTimeout;
  }
  printf("connected\n");

  // Need a link and I2C module address to create a BrainStem object
  a40PinModule stem(link, a40PINSTEM_MODULE);

  uint8_t bLEDState = 0;

  for (uint8_t i = 0; i < 10; i++) {
    stem.system.setLED(bLEDState);
    stem.system.setSleep(DELAY);
    bLEDState = !bLEDState;
  } // end of for loop

  // Turn the LED off before exiting
  stem.system.setLED(0);
  printf("goodbye\n");

  return 0;
} // main

 

If the User LED turns on and off 5 times after the example code is run, then the code worked successfully.

Weight
-99