Charles Dove / Mbed 2 deprecated LSM9DS1_Demo

Dependencies:   mbed LSM9DS1

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 // LSM9DS91 Demo
00002 
00003 #include "mbed.h"
00004 #include "LSM9DS1.h"
00005 
00006 // refresh time. set to 500 for part 2 and 50 for part 4
00007 #define REFRESH_TIME_MS 1000
00008 
00009 // Verify that the pin assignments below match your breadboard
00010 LSM9DS1 imu(PC_9, PA_8);
00011 
00012 Serial pc(USBTX, USBRX);
00013 
00014 //Init Serial port and LSM9DS1 chip
00015 void setup()
00016 {
00017     // Use the begin() function to initialize the LSM9DS0 library.
00018     // You can either call it with no parameters (the easy way):
00019     uint16_t status = imu.begin();
00020 
00021     //Make sure communication is working
00022     pc.printf("LSM9DS1 WHO_AM_I's returned: 0x%X\r\n", status);
00023     pc.printf("Should be 0x683D\r\n");
00024 }
00025 
00026 int main()
00027 {
00028     setup();  //Setup sensor and Serial
00029     pc.printf("------ LSM9DS1 Demo -----------\r\n");
00030 
00031     while (true)
00032     {
00033         
00034         imu.readAccel();
00035     
00036         pc.printf("A: %2f, %2f, %2f\r\n", imu.ax, imu.ay, imu.az);
00037 
00038         imu.readGyro();
00039         
00040         pc.printf("G: %2f, %2f, %2f\r\n", imu.gx, imu.gy, imu.gz);
00041 
00042         imu.readMag();
00043         
00044         pc.printf("M: %2f, %2f, %2f\r\n\r\n", imu.mx, imu.my, imu.mz);
00045        
00046         wait_ms(REFRESH_TIME_MS);
00047     }
00048 }