Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 8 months 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, 8 months 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 27 Mar 2015