-1

I tried to implement the autoCalibrateAccelerometerOffset() function, through the code below on Arduino Genuino 101.

In a static test, without any stress or noise, I read the three axis value.

When I see the data on the serial monitor or on my file created with processing, the Z acceleration values changes from 1~0,99 to 0,00 g.

I think there is an error in my code.

#include "SoftwareSerial.h"
#include "CurieIMU.h"

float sensorVals[] = {0,0,0}; 

void setup() {

    Serial.begin(9600); 
    while (!Serial);    

    Serial.println("Inizializzazione del device...");
    CurieIMU.begin();

    CurieIMU.setAccelerometerRange(2);
    CurieIMU.autoCalibrateAccelerometerOffset(X_AXIS,0);
    CurieIMU.autoCalibrateAccelerometerOffset(Y_AXIS,0);
    CurieIMU.autoCalibrateAccelerometerOffset(Z_AXIS,1);
}

void loop() {

    sensorVals[0] = CurieIMU.readAccelerometerScaled(0);
    sensorVals[1] = CurieIMU.readAccelerometerScaled(1);
    sensorVals[2] = CurieIMU.readAccelerometerScaled(2);

    Serial.print(sensorVals[0]); 
    Serial.print(",");
    Serial.print(sensorVals[1]);
    Serial.print(",");
    Serial.println(sensorVals[2]);
    delay(100);
}
Andrea Ciufo
  • 235
  • 1
  • 3
  • 9

1 Answers1

1

Assuming you aren't jumping up and down while this is happening then it could be:

  • A loose wire
  • A dodgy power supply
  • A bad earth connection
  • A fault sensor
  • A weird magnetic field/flux thing

Check you wiring, make sure all the connections are secure, etc. I bet you have done that already.

I have no idea how to check a power supply, but if you have a different one you could switch that in. Also look into smoothing the power supply with decoupling capacitors (?)

A bad earth, all sorts of weird [stuff] happens when you haven't earthed things properly. Different power supplies need to share earths, but I suspect that doesn't apply here.

A faulty sensor - again, unless you have a duplicate you might not know.

Weird flux. I think the sensor is a magnetic sensor and so it could be the natural eddies and flows of magnetic flux have conspired against you. Move the sensor away from power supplies, electrical things and specifically anything you are hacking. Also rotate the sensor through 90 degrees and see if it still happens (With RF it will polarise the fields in a different way, and school was a long time ago and I can't remember if that works with magnetic fields too)

Code Gorilla
  • 5,652
  • 1
  • 17
  • 31