plot accelerometer data

Dependencies:   mbed LSM9DS1_Library_cal

main.cpp

Committer:
chebbi
Date:
2020-06-25
Revision:
1:9e6bd185745d
Parent:
0:e693d5bf0a25
Child:
3:201ee5790c15

File content as of revision 1:9e6bd185745d:

#include "mbed.h"
#include "LSM9DS1.h"

// Earth's magnetic field varies by location. Add or subtract
// a declination to get a more accurate heading. Calculate
// your's here:



Serial pc(USBTX, USBRX);




int main()
{
    
    LSM9DS1 IMU(PC4, PC5,0xD6, 0x3C);
    IMU.begin();
    if (!IMU.begin()) {
        pc.printf("Failed to communicate with LSM9DS1.\n");
    }
    
    while(1) {
        
        while(!IMU.accelAvailable());
        IMU.readAccel();
        
        float acc = sqrt(IMU.calcAccel(IMU.ax)*IMU.calcAccel(IMU.ax)+IMU.calcAccel(IMU.ay)*IMU.calcAccel(IMU.ay)+IMU.calcAccel(IMU.az)*IMU.calcAccel(IMU.az));
        
        pc.printf("%9f\n",acc) ;
        wait(0.1) ; 
         
        
        
        
      
    }
}