Accelerometer Calibration III: Improving Accuracy With Least-Squares and the Gauss-Newton Method

This is the third post in a series.  

  1. Introduction
  2. Simple Methods
  3. Least-Squares and Gauss Newton
  4. Streaming Gauss-Newton on an ATMEGA
  5. Error Analysis
  6. ?

In the last post we looked at some simple calibration methods and they didn’t seem to get us results that were better than the ones we got by just trusting the datasheet.  There were two obvious problems:

  1. Our calibration methods assumed we had placed our accelerometer in perfect axial alignment each time.  We were, um, less than perfect.
  2. We ignored the fact that there is noise in the sensor readings.  Eyeballing it, this alone would give us about ~1% error.

We could address problem (1) by finding ways to place our device very carefully before taking measurements. We could address problem (2) by averaging our samples (and assuming that the average was a good estimate of the real values).

Instead, we will use some Mathematics to develop a calibration method that is robust to noise and is not dependent on careful sensor placement. This will give more accurate results even though it requires less care by the user. Continue reading

Posted in Electronics | Tagged , , , , , , | 18 Comments

Accelerometer Calibration II: Simple Methods

This is the second post in a series.  It starts here.

Now let’s look at some of the simplest methods we can use to calibrate an accelerometer.   By “simple” here I mean simple all the way through: easy to wire the circuit, easy to code, easy to understand, easy to use.  Later we’ll see that these don’t always come as a package: fairly sophisticated software can make the users job even simpler than anything we see here.

The simple methods I will describe here all follow the same flow: the user carefully places the accelerometer in position, flips a switch to tell it to start recording data, flips the switch back to tell it to stop, then moves the accelerometer into a different position to start again.  The differences all come down to deciding how many measurements to take and what to do with the numbers we get.  Because of that, all of these methods can be performed using the same simple circuit.

Let’s build that before we go on. Continue reading

Posted in Electronics | Tagged , , , , | 3 Comments

Accelerometer Calibration I: Introduction

In my last post I described how to start reading data from an ADXL335 accelerometer with an Arduino and convert those voltage readings into standard units. I even showed some real data coming out of my device and when you looked at it, it was pretty clear that:

  1. The data coming out were stable and repeatable
  2. The conversion I used wasn’t right:  the acceleration of gravity changed depending on the tilt of the accelerometer.

The problem is that I wasn’t really calibrating.  I never took measurements from my device and compared them with known values.  I just trusted the datasheet (which doesn’t promise anything precise, by the way).  Even if the datasheet promised exact sensitivity, it doesn’t know how the sensor will be placed in the circuit.  For example:

  • Is the soldering dodgy on any of the pins?
  • Is the sensor tilted in the device? (yep, it is off by a few degrees thanks to that dodgy soldering.)
  • Is everything on the circuit exactly the same downstream from the sensor pins?

Because the sensor readings are stable and repeatable, real calibration gives much better results. It just takes a bit more work.  In this series of posts I’ll survey a few calibration methods starting with faith-based methods like reading datasheets, moving on to naïve but effective calibration, and finishing off with nonlinear least-squares based approaches that require a bit more Math.

Evaluating calibration methods

Before jumping in to the specific techniques, I want to say a few words about how I evaluate them.  I have two basic metrics:

  1. How accurate is the calibration?
  2. How easy is it to perform the calibration?

To evaluate accuracy, I produced a standard data set with the accelerometer held fixed in 14 different known positions (approximately corresponding to the faces of a truncated cube).  I use methods I’ll describe in another post to determine what the “true” accelerometer reading should be at each of these positions then compare that to the reading I get from whatever calibration method I am testing.

If I have such a great calibration method and can get the “true” values out of my device, why do I bother with other techniques?  Well, for one I am curious about how good they are.  But the real problem is that the best calibration method is not easy to perform: it involved 30 minutes of careful device placements, measurements, button pushing, and data recording.  If it were possible to get an error on the order of 1% with less than 10 seconds of work wouldn’t you consider making that trade-off?

That is why I also evaluate how easy each calibration method is to perform.  When I talk about ease of calibration, I am not talking about how easy it is to write the code.  I’m giving you all the code anyway.  All I care about is this:

How easy is it to get a device calibrated after it has been programmed?

If calibration takes thirty minutes of futzing and special equipment, I’ll say the easiness is bad.  If it just takes a button press and 10 seconds of moving the device around I’ll say it is pretty good.  If it doesn’t require anything at all, then it is great.

Sure, you can automate a tedious and error-prone calibration process if the results are so much better it makes it worthwhile, but that is not much help for DIYers or prototyping.  Also, for the skiing devices I’m building I want to have a way to recalibrate them in the field when I reconfigure them or even just because the temperature changed.

So every calibration method I describe will get two grades: one for accuracy and one for easiness.  In the end, we will see that there are some methods that get good marks in both categories.

Posted in Electronics | Tagged , , , , | 3 Comments

Getting Started with Accelerometers and Micro-controllers: Arduino + ADXL335

My first home electronics project — a device to measure leg acceleration and balance while skiing — involved connecting an ADXL335 on a Sparkfun breakout board to an Arduino Uno.  Going in, I was an experienced programmer but knew nothing about electronics.  The online resources are good, but I found some important information was missing.  Some of it seems like stuff that just goes without saying in the community, but I’m going to go ahead and say it to save other newbies like myself any trouble.

So this is the post I wish I had found before I started working with the ADXL335.  I will assume that:

  • you know how to build simple circuits
  • you know how to write and upload a sketch
  • you know how to open the serial monitor

If you can’t do any of these things, go spend an hour playing with some of the basic examples at then come back here.

To get an ADXL335 talking to an Arduino, there is not much to do.  Here are the key steps:

  1. Solder pins to the breakout board or do something else to get a good connection.
  2. Build the circuit with 3.3V power and AREF to normalize the analog input.
  3. Write a basic sketch.
  4. Calibrate.

Let me elaborate. Continue reading

Posted in Electronics, How To | Tagged , , | 39 Comments