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;
    }
    
  • thank you for your answer, my code is fine.. sorry for just just wrong variable in my code statement. this is the full link for my mbed code. but why there is wrong calculation for x array.

    for example I have x=-27, y=48, z 280.. after 10x mean calcutation. that's show x=-25882, y = 47, z=220. the main problem is why x calculate -25882 ? after 10x mean calculation must be -25 without 822 (-25,882) for example..

    how to replace last 3 value of the sensor?

Reply
  • thank you for your answer, my code is fine.. sorry for just just wrong variable in my code statement. this is the full link for my mbed code. but why there is wrong calculation for x array.

    for example I have x=-27, y=48, z 280.. after 10x mean calcutation. that's show x=-25882, y = 47, z=220. the main problem is why x calculate -25882 ? after 10x mean calculation must be -25 without 822 (-25,882) for example..

    how to replace last 3 value of the sensor?

Children
No Data
Related