Skip to content

SDK Transition Information

Sam Olds edited this page Jul 8, 2016 · 5 revisions

Overview

The ArdusatSDK has recently gone through some major updates to make it more robust, and easier to use. However, this means that there were a few changes that had to be made that affected the interface. This page will try and be a comprehensive guide as to how to update any existing Arduino sketches you might have that used the ArdsuatSDK before July 8, 2016, to be compatible with the latest ArdusatSDK. From here on out, the SDK that existed before July 8 will be referred to as SDKv1, and the SDK that has since been released will be referred to as SDKv2.

One of the primary changes was making the SDK more object oriented as this makes the interface friendlier and is a best practice. Each of the physical sensors we provide are contained within sensor objects that encapsulate any functionality you might want. In addition, the SDK is now smart enough to be able to distinguish between the sensor break out boards and the SpaceBoard, so you will not need to do anything special for your sketches to work with either set of hardware. There has also been a handful of advance configurations and new functionality added to the SDK which is explained in the README.

Sensor Basics

There are no longer special functions for each sensor type like beginTemperatureSensor, readTemperature, or temperatureToJSON. All sensor types use the same handful of functions:

  • begin()
  • read()
  • readToCSV("sensor name")
  • readToJSON("sensor name")
  • toCSV("sensor name")
  • toJSON("sensor name")

You would then call these functions on the different types of sensor objects:

  • Acceleration
  • Gyro
  • Luminosity
  • Magnetic
  • Orientation
  • Pressure
  • RGBLight
  • Temperature
  • TemperatureMLX (Infrared Temperature)
  • UVLight

Arduino Sketch Examples

SDKv1

#include <Arduino.h>
#include <Wire.h>
#include <ArdusatSDK.h>

temperature_t temp;

void setup(void) {
  Serial.begin(9600);
  beginTemperatureSensor();
}

void loop(void) {
  readTemperature(temp);
  Serial.println(temperatureToJSON("ambient_temp", temp));
}

SDKv2

#include <Arduino.h>
#include <Wire.h>
#include <ArdusatSDK.h>

Temperature temp;

void setup(void) {
  Serial.begin(9600);
  temp.begin();
}

void loop(void) {
  temp.read();
  Serial.println(temp.toJSON("ambient_temp"));
}

There are more examples of how to use SDKv2 in the GitHub repository.

Updating a SDKv1 sketch for SDKv2

If you have any sketches that no longer work with the latest SDK, you should be able to update your sketch with a few minimal changes. This should be a comprehensive list of everything you might need to update, but make sure to pay close attention to the names of your variables. Simply replace anything you see in the "Find" column with the accompanying line in the "Replace" column. After you have successfully done this, your SDKv1 sketch should work with SDKv2.

Find Replace
acceleration_t accel Acceleration accel
gyro_t gyro Gyro gyro
luminosity_t lum Luminosity lum
magnetic_t mag Magnetic mag
orientation_t orient Orientation orient
pressure_t pressure Pressure pressure
temperature_t temp Temperature temp
temperature_t irTemp TemperatureMLX irTemp
uvlight_t uv UVLight uv
beginAccelerationSensor() accel.begin()
beginGyroSensor() gyro.begin()
beginLuminositySensor() lum.begin()
beginMagneticSensor() mag.begin()
beginOrientationSensor() orient.begin()
beginBarometricPressureSensor() pressure.begin()
beginTemperatureSensor() temp.begin()
beginInfraredTemperatureSensor() irTemp.begin()
beginUVLightSensor() uv.begin()
readAcceleration(accel) accel.read()
readGyro(gyro) gyro.read()
readLuminosity(lum) lum.read()
readMagnetic(mag) mag.read()
calculateOrientation(accel, mag, orient) orient.read()
readBarometricPressure(pressure) pressure.read()
readTemperature(temp) temp.read()
readInfraredTemperature(irTemp) irTemp.read()
readUVLight(uv) uv.read()
accelerationToJSON("...", accel) accel.toJSON("...")
gyroToJSON("...", gyro) gyro.toJSON("...")
luminosityToJSON("...", lum) lum.toJSON("...")
magneticToJSON("...", mag) mag.toJSON("...")
orientationToJSON("...", orient) orient.toJSON("...")
pressureToJSON("...", pressure) pressure.toJSON("...")
temperatureToJSON("...", temp) temp.toJSON("...")
temperatureToJSON("...", irTemp) irTemp.toJSON("...")
uvlightToJSON("...", uv) uv.toJSON("...")
accelerationToCSV("...", accel) accel.toCSV("...")
gyroToCSV("...", gyro) gyro.toCSV("...")
luminosityToCSV("...", lum) lum.toCSV("...")
magneticToCSV("...", mag) mag.toCSV("...")
orientationToCSV("...", orient) orient.toCSV("...")
pressureToCSV("...", pressure) pressure.toCSV("...")
temperatureToCSV("...", temp) temp.toCSV("...")
temperatureToCSV("...", irTemp) irTemp.toCSV("...")
uvlightToCSV("...", uv) uv.toCSV("...")

Additional Notes

The Orientation sensor requires a little bit extra. Orientation is derived from values from the Accelerometer and Magnetometer, so you have to provide Acceleration and Magnetic sensor objects when instantiating the Orientation object.

Acceleration accel;
Magnetic mag;
Orientation orient(accel, mag);

void setup(void) {
  ...
  accel.begin();
  mag.begin();
  orient.begin();
  ...
}

void loop(void) {
  ...
  orient.read();
  ...
}

Need More Help?

If you're still having trouble updating one of your old sketches to work with the latest SDK, please get in touch with us and we will try and help. You can get in touch with us using our Community Discussion Board.