Test on STM32-L1

Dependencies:   Nucleo_Sensor_Shield mbed

Fork of Nucleo_Sensors_Demo by ST Americas mbed Team

Committer:
dangriffin
Date:
Tue Dec 16 21:42:27 2014 +0000
Revision:
1:0031e5245714
Parent:
0:ff0b8b759dfa
Use public version of Nucleo sensor shield library.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dangriffin 0:ff0b8b759dfa 1 #include "mbed.h"
dangriffin 0:ff0b8b759dfa 2 #include "x_cube_mems.h"
dangriffin 0:ff0b8b759dfa 3
dangriffin 0:ff0b8b759dfa 4 DigitalOut myled(LED1);
dangriffin 0:ff0b8b759dfa 5 Serial pc(SERIAL_TX, SERIAL_RX);
dangriffin 0:ff0b8b759dfa 6 volatile float TEMPERATURE_Value_C;
dangriffin 0:ff0b8b759dfa 7 volatile float TEMPERATURE_Value_F;
dangriffin 0:ff0b8b759dfa 8 volatile float HUMIDITY_Value;
dangriffin 0:ff0b8b759dfa 9 volatile float PRESSURE_Value;
dangriffin 0:ff0b8b759dfa 10 volatile AxesRaw_TypeDef MAG_Value;
dangriffin 0:ff0b8b759dfa 11 volatile AxesRaw_TypeDef ACC_Value;
dangriffin 0:ff0b8b759dfa 12 volatile AxesRaw_TypeDef GYR_Value;
dangriffin 0:ff0b8b759dfa 13
dangriffin 0:ff0b8b759dfa 14 int main() {
dangriffin 0:ff0b8b759dfa 15
dangriffin 0:ff0b8b759dfa 16 /* Create sensor board object */
dangriffin 0:ff0b8b759dfa 17 static X_CUBE_MEMS *mems_expansion_board = X_CUBE_MEMS::Instance();
dangriffin 0:ff0b8b759dfa 18
dangriffin 0:ff0b8b759dfa 19 while(1) {
dangriffin 0:ff0b8b759dfa 20 myled = 1; // LED is ON
dangriffin 0:ff0b8b759dfa 21 wait(0.2); // 200 ms
dangriffin 0:ff0b8b759dfa 22 myled = 0; // LED is OFF
dangriffin 0:ff0b8b759dfa 23 wait(1.0); // 1 sec
dangriffin 0:ff0b8b759dfa 24
dangriffin 0:ff0b8b759dfa 25 /* Get instantaneous data from all sensors */
dangriffin 0:ff0b8b759dfa 26 mems_expansion_board->hts221.GetTemperature((float *)&TEMPERATURE_Value_C);
dangriffin 0:ff0b8b759dfa 27 mems_expansion_board->hts221.GetHumidity((float *)&HUMIDITY_Value);
dangriffin 0:ff0b8b759dfa 28 mems_expansion_board->lps25h.GetPressure((float *)&PRESSURE_Value);
dangriffin 0:ff0b8b759dfa 29 mems_expansion_board->lis3mdl.GetAxes((AxesRaw_TypeDef *)&MAG_Value);
dangriffin 0:ff0b8b759dfa 30 mems_expansion_board->lsm6ds0.Acc_GetAxes((AxesRaw_TypeDef *)&ACC_Value);
dangriffin 0:ff0b8b759dfa 31 mems_expansion_board->lsm6ds0.Gyro_GetAxes((AxesRaw_TypeDef *)&GYR_Value);
dangriffin 0:ff0b8b759dfa 32
dangriffin 0:ff0b8b759dfa 33 TEMPERATURE_Value_F = (TEMPERATURE_Value_C * 1.8f) + 32.0f;
dangriffin 0:ff0b8b759dfa 34 pc.printf("Temperature:\t\t %f C / %f F\r\n", TEMPERATURE_Value_C, TEMPERATURE_Value_F);
dangriffin 0:ff0b8b759dfa 35 pc.printf("Humidity:\t\t %f%%\r\n", HUMIDITY_Value);
dangriffin 0:ff0b8b759dfa 36 pc.printf("Pressure:\t\t %f hPa\r\n", PRESSURE_Value);
dangriffin 0:ff0b8b759dfa 37 pc.printf("Magnetometer (mGauss):\t X: %d, Y: %d, Z: %d\r\n", MAG_Value.AXIS_X, MAG_Value.AXIS_Y, MAG_Value.AXIS_Z);
dangriffin 0:ff0b8b759dfa 38 pc.printf("Accelerometer (mg):\t X: %d, Y: %d, Z: %d\r\n", ACC_Value.AXIS_X, ACC_Value.AXIS_Y, ACC_Value.AXIS_Z);
dangriffin 0:ff0b8b759dfa 39 pc.printf("Gyroscope (mdps):\t X: %d, Y: %d, Z: %d\r\n", GYR_Value.AXIS_X, GYR_Value.AXIS_Y, GYR_Value.AXIS_Z);
dangriffin 0:ff0b8b759dfa 40 pc.printf("\r\n");
dangriffin 0:ff0b8b759dfa 41 }
dangriffin 0:ff0b8b759dfa 42 }