SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By cdude1990
#183148
I have the Redbot kit and I'm trying to use the accelerometer. It seems like vibrations make the readings almost meaningless. Below are my code and some outputs in various configurations. For all of these runs, I had the Redbot standing upright so the wheels are spinning in the air. For the 'isolated' case, I took the accelerometer off the board, connected it with wires and held it with a 'third hand'.

I can get good readings (+- 0.003g) with the motors turned off, but with the motors running full blast, there are huge fluctuations (+-1g). Isolated is better but still not usable (+-0.3g).

I'd love to have a low pass filter to smooth the data. The data sheet provides a number of settings for a high pass filter. There is mention of a low pass filter for motion detection, but I think this mode provides only minimal info about the motion, like which axis triggered. I thought maybe changing the 'output data rate' would do averaging, but it didn't help.

So am I doing something wrong? Are accelerometers at all useful for autonomous vehicles? Are there better devices out there with smoothing features?

My code:
Code: Select all
#include <RedBot.h>

RedBotMotors motors;
RedBotAccel accelerometer;

void setup(void)
{
  Serial.begin(9600);
  motors.drive(255);
}

void loop(void)
{
  accelerometer.read();
  int x = accelerometer.x;
  Serial.println(x);
  delay(2000);
}
Some output:
Code: Select all
Motors off, accelerometer on redbot
16416
16400
16336
16416
16432
16384
16368
16432

Motors on 100, accelerometer on redbot
17248
12640
15808
18992
15072
19232
17136
11856
18528
13968
14352
15600
17008

Motors on 255, accelerometer on redbot
6848
23424
19440
4272
16176
23952
1280
25936
23136
29408
5072
32752

Motors on 255, accelerometer isolated
18304
15120
18848
16304
18272
14800
16544
20304
15904
14400
16240
17088
13440
17888
10800
By jremington
#183163
Sounds like motor-induced electrical noise in the power wiring. If so, you need better supply filtering for the accelerometer.

Your motors should be fitted with noise reducing caps, as described here: https://www.pololu.com/docs/0J15/9
In extreme cases, you can put an inductor in each motor lead, too.
By Valen
#183169
And vibrations are actually oscillating accelerations. So yeah, it is normal that you get them with accelerometers. But it is likely electrical noise generated by the motors, fed back to the voltage supply.
By cdude1990
#183176
I don't think it is electrical noise. I hooked up the accelerometer to an oscilloscope. There was little fluctuation when the motors were turned on. There was a voltage drop of 0.2V, well within the specs of the MMA8452Q.

I tested the vibration hypothesis by removing the motors from the chassis and placing them on a soft object on the table. I also isolated the accelerometer by having the third hand hold it by the wires instead of the board.

This gave excellent results (+-0.006g):
Code: Select all
Motors on 255, accelerometer isolated, motors isolated
-16544
-16528
-16544
-16576
-16624
-16784
-16624
-16592
-16768
-16656
-16720
-16720
Of course there's no way I could isolate the accelerometer that well in a vehicle.