9 years, 1 month ago.

Trouble with FXOS8700 accelerometer on k64F platform

I've written a simple program for the FRDM-k64F platform that uses the onboard accelerometer that calculates the tilt angle and prints the results to TeraTerm, but all I get is the number 1610612736. I'm not sure what I'm doing wrong. Can anyone help me out? Here is my code:

Accelerometer Level


#include "mbed.h"
#include "math.h"
#include "FXOS8700Q.h"

FXOS8700Q_acc sensor(PTE25, PTE24, 0x1D);
Serial pc(USBTX, USBRX);

float deg_x, deg_y;
float x, y, z;

int main(){
    
    sensor.enable();
    
    while(true){
        
        sensor.getY(&y);
        sensor.getX(&x);
        sensor.getZ(&z);
    
        deg_x = abs(atan(z / x));
        deg_y = abs(atan(z / y));
                
        pc.printf("x axis offset angle: ");
        pc.printf("%d\n\r", deg_x);
        pc.printf("y axis offset angle: ");
        pc.printf("%d\n\n\r", deg_y);
        
        wait(1);
    }    
}

1 Answer

9 years, 1 month ago.

Hi,
Since deg_x, deg_y are float numbers,
how about using "%f" instead of "%d" ?

pc.printf("%f\n\r", deg_x) ;

moto

Hmm, now I only get 0.785398. I don't think I've really established communication with the sensor.

posted by Caleb Washburn 27 Mar 2015

I've changed a few things, but nothing very significant. I have verified the address is 0x1D using an I2C scanner program, still no luck. I have also tried the K64F_eCompass program, which appears to function properly.

posted by Caleb Washburn 07 Apr 2015

Hi,
In my TFT_test_frdm-k64f program
I was doing...

 
#define MMA8451_I2C_ADDRESS (0x1d<<1)
MMA8451Q *acc = 0 ;
...
   acc = new MMA8451Q(PTE25, PTE24, MMA8451_I2C_ADDRESS) ;
...
 acc->getAccX() ;
...

moto

posted by Motoo Tanaka 07 Apr 2015