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;
    }
    
Reply
  • 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;
    }
    
Children
Related