Pages: [1]   Go Down
Author Topic: Accelerometer not working as expected  (Read 2205 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just bought an Esplora. It's my first product from Arduino. Most of its features work perfectly. My only problem relates to the accelerometer which is doing several unexpected things. I'm using the built-in example code to test the accelerometer, here's the code:

#include <Esplora.h>
void setup()
{
  Serial.begin(9600);        // initialize serial communications with your computer
}

void loop()
{
  int xAxis = Esplora.readAccelerometer(X_AXIS);    // read the X axis
  int yAxis = Esplora.readAccelerometer(Y_AXIS);    // read the Y axis
  int zAxis = Esplora.readAccelerometer(Z_AXIS);    // read the Z axis

  Serial.print("x: ");      // print the label for X
  Serial.print(xAxis);      // print the value for the X axis
  Serial.print("\ty: ");    // print a tab character, then the label for Y
  Serial.print(yAxis);      // print the value for the Y axis
  Serial.print("\tz: ");    // print a tab character, then the label for Z
  Serial.println(zAxis);    // print the value for the Z axis

  delay(500);              // wait half a second (500 milliseconds)
}

Shouldn't the accelerometer report changes in all 3 dimensions? When I rotate the Esplora around a vertical access (think: spin it on a table) none of the three readouts change. Nothing! (They all stay around 15,15,160.) When I hold it like I would a game controller, then raise my hands in opposite directions (left=up, right=down) the X_AXIS and the Z_AXIS results change approximately the same amounts. When I tilt it forwards or backwards the Y_AXIS and the Z_AXIS results change approximately the same amounts.

Am I just misunderstanding how accelerometers work? To me they should independently map the three different axes. But as far as I can tell the value for Z_AXIS represents some strange axis that I'm unable to pin down. So I've only got two dimensions that work, and they aren't my preferred ones.

A second problem is that I would have imagined they would report values something like "0..359" or maybe "-180..180" but instead they peak around "-150" and "+170". And the peaks aren't the same for each axis. So the numerical range isn't 360 but around 320. Yes, I can map these values to proper mathematical values, but it's a minor complication I could do without.

A third problem is that they should be proportional to the amount that you turn them. But when I turn my Esplora very very slowly the numbers often go like this: "120 121 122 123 150 151" Why does it jump so suddenly? And at other times it doesn't change the reading at all even though I've turned the Esplora a lot!

The label on the Esplora board next to its accelerometer shows where the X, Y and Z axes should be located. Based on what I observe when I run the program above they mixed up the X and Y in the diagram, and the Z doesn't work when I rotate the device around the Z-axis.

Disclaimer: I'm an idiot on occasion.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 637
Posts: 34602
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Am I just misunderstanding how accelerometers work?
I think so.
They work by detecting forces on them and they are detecting mainly gravity. Any acceleration of the sensors looks like gravity but a constant velocity would not. There are three sensors mounted orthogonally. So when you rotate this round on your desk the sensors are at right angles to gravity and so do not change. If you were to make it rotate fast enough you would see a difference due to the centripetal force on the sensors. When moved around in free space they respond as gravity acts on each sensor differently depending on the angle.
The way they work is that each sensor has tiny silicon hairs on it, these hairs are bent depending on the orientation of the base and it is this bend that is being measured by producing an electrical signal proportional to the bend.

They are not angle detectors which is why the output is not calibrated in degrees. A sensor in free fall will register zero.
Logged

US
Offline Offline
Full Member
***
Karma: 4
Posts: 183
Electronics are the new Legos
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You probably want something like a compass module.  You would have to add that on.  Check Sparkfun or Adafruit for such items.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe I am misunderstanding what an accelerometer measures. Thanks for the ideas. Still, some of the problems I'm reporting could either be a defective unit or worse maybe a problematic implementation.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 637
Posts: 34602
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This is what I get when I have my Esplora flat on the bench. As I rotate it the numbers change a bit but return to this when I stop moving it. This is what I would expect.
Code:
x: 16 y: 27 z: 146
x: 16 y: 26 z: 145
x: 16 y: 26 z: 146
x: 16 y: 26 z: 144
x: 16 y: 27 z: 146
x: 17 y: 27 z: 144
x: 16 y: 26 z: 145
x: 16 y: 27 z: 145
x: 16 y: 27 z: 145
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
A second problem is that I would have imagined they would report values something like "0..359" or maybe "-180..180" but instead they peak around "-150" and "+170". And the peaks aren't the same for each axis. So the numerical range isn't 360 but around 320. Yes, I can map these values to proper mathematical values, but it's a minor complication I could do without.

Yeah, its kinda confusing, and you are confused.

I suggest reading;
http://en.wikipedia.org/wiki/Inertial_navigation_system
http://en.wikipedia.org/wiki/Accelerometer
http://en.wikipedia.org/wiki/Gyroscope

The short answer - the accelerometers output is a measurement of 'g-force' (often expressed in units of ft/sec/sec) a measurement that is about how much change in some period of time. so you measure time change while in accelerating/decelerating to calculate orientation in 0-360 or -180 to 180. But it doesn't measure orientation. Gyroscopes do that.

edit/ ps: accelerometers, as you can see in the wiki, are SOOO MUCH more versatile than a gyro alone. detecting taps on a touch screen, pedometers, earthquake/vibration detection.... an accelerometer is a very useful device indeed - albeit confusing. (I think its the multiple axis' that contributed to my learning curve that Im still on.) /edit
« Last Edit: October 12, 2013, 04:45:45 pm by Hrendor66 » Logged

Pages: [1]   Go Up
Jump to: