Example program for the LSM9DS1 SPI library

Dependencies:   LSM9DS1_SPI mbed

Committer:
Anaesthetix
Date:
Wed Oct 18 09:23:32 2017 +0000
Revision:
0:1b12560a5651
First commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Anaesthetix 0:1b12560a5651 1 #include "mbed.h"
Anaesthetix 0:1b12560a5651 2 #include "LSM9DS1_SPI.h"
Anaesthetix 0:1b12560a5651 3
Anaesthetix 0:1b12560a5651 4 SPI spi(p11, p12, p13); //mosi, miso, sclk
Anaesthetix 0:1b12560a5651 5 lsm9ds1_spi lsm9ds1(spi, p14, p21); //spi, CS_ag, CS_m
Anaesthetix 0:1b12560a5651 6 Serial pc(USBTX, USBRX);
Anaesthetix 0:1b12560a5651 7
Anaesthetix 0:1b12560a5651 8 int main() {
Anaesthetix 0:1b12560a5651 9 float temp = 0;
Anaesthetix 0:1b12560a5651 10 lsm9ds1.init();
Anaesthetix 0:1b12560a5651 11
Anaesthetix 0:1b12560a5651 12 while(1) {
Anaesthetix 0:1b12560a5651 13 temp = lsm9ds1.read_temp();
Anaesthetix 0:1b12560a5651 14 lsm9ds1.read_all();
Anaesthetix 0:1b12560a5651 15 pc.printf("Accelerometer values: \r\n");
Anaesthetix 0:1b12560a5651 16 pc.printf("x:%.2f y:%.2f z:%.2f\r\n", lsm9ds1.accelerometer_data[0], lsm9ds1.accelerometer_data[1], lsm9ds1.accelerometer_data[2]);
Anaesthetix 0:1b12560a5651 17 pc.printf("Gyro values: \r\n");
Anaesthetix 0:1b12560a5651 18 pc.printf("x:%.2f y:%.2f z:%.2f\r\n", lsm9ds1.gyroscope_data[0], lsm9ds1.gyroscope_data[1], lsm9ds1.gyroscope_data[2]);
Anaesthetix 0:1b12560a5651 19 pc.printf("Magnetometer values: \r\n");
Anaesthetix 0:1b12560a5651 20 pc.printf("x:%.2f y:%.2f z:%.2f\r\n", lsm9ds1.magnetometer_data[0], lsm9ds1.magnetometer_data[1], lsm9ds1.magnetometer_data[2]);
Anaesthetix 0:1b12560a5651 21 pc.printf("And last but not least, it's %.2f degrees celcius.\r\n", temp);
Anaesthetix 0:1b12560a5651 22 wait(1);
Anaesthetix 0:1b12560a5651 23 }
Anaesthetix 0:1b12560a5651 24 }