This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How anomaly ADXL345 data UART? needed help

Here is calibration of UART data using ADXL345.i2c calibration

and the data is followed by x, y & z value, for example x = -42, y = 20, z = 268. and then after calibrated 10x which is I got mean value from (x,y,z*10 of data)/10.0.. I've got x = -26237, y = -18, z = 278.

and my question is why the data of x value is large to calculated, perhaps it's just maybe around -45 (above/lower).

anyone who can explain to fix it..

here is the code:

int calibratex()
{
  int readings[3] = {0, 0, 0};
  led1=1;
  long int sum1  = 0;
  for (int i=0; i<10; i++)
 {
   accelerometer.getOutput(readings);
   xval[i]=(readings[0]);  //nilai x adxl345
   sum1 = yval[i]+sum1;
 }

  xavg=sum1/10.0;

  led1=0;     
  return xavg;
}
 int calibratey()
 {
  int readings[3] = {0, 0, 0};
  led1=1;
  long int sum2 = 0;
  for (int i=0; i<10; i++)
  {
   accelerometer.getOutput(readings);
    yval[i]=(readings[1]); //nilai y adxl345
   sum2 = yval[i]+sum2;
 }
   yavg=sum2/10.0;
   led1=0;     
   return yavg;
 }
  int calibratez()
  {
     int readings[3] = {0, 0, 0};

     led1=1;
     long int sum3 = 0;
     for (int i=0; i<10; i++)
     {
      accelerometer.getOutput(readings);
      zval[i]=(readings[2]); //nilai z adxl345
      sum3 = zval[i]+sum3;
  }

    zavg=sum3/10.0;
    led1=0;     
    return zavg;
 }
Parents
  • Not sure if this is the solution, but there is an inconsistency in your three calibration functions:

    int calibratex()
    {
    	int readings[3] = {0, 0, 0};
    	led1=1;
    	long int sum1  = 0;
    	for (int i=0; i<10; i++)
    	{
    		accelerometer.getOutput(readings);
    		xval[i]=(readings[0]);  //nilai x adxl345
    		sum1 = yval[i]+sum1;                                     // <- BUG???? Should it be xval?
    	}
    
    	xavg=sum1/10.0;
    
    	led1=0;     
    	return xavg;
    }
    
  • I was thinking more like this:

    From your mbed code:

    while (1) 
    {
    	ble.waitForEvent();
    	wait(0.1);
    	accelerometer.getOutput(readings);
    	uart1.printf("\n%i, %i, %i\n", (int16_t)readings[0], (int16_t)readings[1], (int16_t)readings[2]);
    
    	int avg1 = calibratex();
    	int avg2 = calibratey();
    	int avg3 = calibratez();
    	// Print the values, etc.
    	// ....
    }
    

    I think that if you read the data immediately after you power up the accelerometer like you do now, it is not certain that the accelerometer has actually had the time to do any real measurements and hence you get bad data. If you start to measure periodically, or at least try again a short while after you power up the accelerometer, you will find out if this is the case.

Reply
  • I was thinking more like this:

    From your mbed code:

    while (1) 
    {
    	ble.waitForEvent();
    	wait(0.1);
    	accelerometer.getOutput(readings);
    	uart1.printf("\n%i, %i, %i\n", (int16_t)readings[0], (int16_t)readings[1], (int16_t)readings[2]);
    
    	int avg1 = calibratex();
    	int avg2 = calibratey();
    	int avg3 = calibratez();
    	// Print the values, etc.
    	// ....
    }
    

    I think that if you read the data immediately after you power up the accelerometer like you do now, it is not certain that the accelerometer has actually had the time to do any real measurements and hence you get bad data. If you start to measure periodically, or at least try again a short while after you power up the accelerometer, you will find out if this is the case.

Children
No Data
Related