One Type to Rule Them All

Adafruit has always prided itself on going the extra mile and providing basic drivers for all of our sensors, but as the number of sensor breakouts we have has steadily grown over the years, it seemed worthwhile to take a step back and ask if we can do things a bit better.

While digging around in the Android source code for something entirely unrelated, I noticed the intelligent way Android abstracts away all sensor data into a single 'type' and uses standard, pre-defined SI units of measure.

This makes sense since HW manufacturers are free to put whatever sensors they want in their phone, but Android needs a way to understand sensor data from any source and translate that into something it knows what to do with (i.e., number that make sense).

This is also (conveniently) that exact same problem many people playing with embedded systems have! They may need to swap out one accelerometer for another depending on price, availability, resolution, or any number of factors. The traditional approach of one-off drivers doesn't work well here, though, since every driver probably reports separate units and scales of measure, in different types and sizes, etc., and it can be painful to switch from one sensor to another, even if they offer similar functionality.

The Adafruit Unified Sensor driver follows Android's lead here and tries to harmonize sensor data into a single (lighter weight than the heavier Android model) 'type', and also abstracts away details about the sensor into another common 'type' that lets us describe sensors in a well-defined manner.

Why Is This a Good Thing?

The biggest advantage is that using drivers based on the Adafruit Unified Sensor Driver allows you to take any supported sensor, drop it into your system, and it should just work out of the box with the rest of your code.

Any related driver will report the same SI units, using the same scale, and you will call exactly the same functions to read your data.

The ADXL345 accelerometer isn't available or you need something cheaper? Just grab any other accelerometer (the LSM303DLHC for example), change the constructor and off you go!

This guide was first published on Feb 28, 2013. It was last updated on Feb 28, 2013.

This page (Introduction) was last updated on Feb 07, 2013.

Text editor powered by tinymce.