ST / Mbed OS DISCO_L475VG_IOT01-Sensors-BSP

Dependencies:   BSP_B-L475E-IOT01

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 // Sensors drivers present in the BSP library
00004 #include "stm32l475e_iot01_tsensor.h"
00005 #include "stm32l475e_iot01_hsensor.h"
00006 #include "stm32l475e_iot01_psensor.h"
00007 #include "stm32l475e_iot01_magneto.h"
00008 #include "stm32l475e_iot01_gyro.h"
00009 #include "stm32l475e_iot01_accelero.h"
00010 
00011 DigitalOut led(LED1);
00012 
00013 int main()
00014 {
00015     float sensor_value = 0;
00016     int16_t pDataXYZ[3] = {0};
00017     float pGyroDataXYZ[3] = {0};
00018 
00019     printf("Start sensor init\n");
00020 
00021     BSP_TSENSOR_Init();
00022     BSP_HSENSOR_Init();
00023     BSP_PSENSOR_Init();
00024 
00025     BSP_MAGNETO_Init();
00026     BSP_GYRO_Init();
00027     BSP_ACCELERO_Init();
00028 
00029     while(1) {
00030         printf("\nNew loop, LED1 should blink during sensor read\n");
00031 
00032         led = 1;
00033 
00034         sensor_value = BSP_TSENSOR_ReadTemp();
00035         printf("\nTEMPERATURE = %.2f degC\n", sensor_value);
00036 
00037         sensor_value = BSP_HSENSOR_ReadHumidity();
00038         printf("HUMIDITY    = %.2f %%\n", sensor_value);
00039 
00040         sensor_value = BSP_PSENSOR_ReadPressure();
00041         printf("PRESSURE is = %.2f mBar\n", sensor_value);
00042 
00043         led = 0;
00044 
00045         ThisThread::sleep_for(1000);
00046 
00047         led = 1;
00048 
00049         BSP_MAGNETO_GetXYZ(pDataXYZ);
00050         printf("\nMAGNETO_X = %d\n", pDataXYZ[0]);
00051         printf("MAGNETO_Y = %d\n", pDataXYZ[1]);
00052         printf("MAGNETO_Z = %d\n", pDataXYZ[2]);
00053 
00054         BSP_GYRO_GetXYZ(pGyroDataXYZ);
00055         printf("\nGYRO_X = %.2f\n", pGyroDataXYZ[0]);
00056         printf("GYRO_Y = %.2f\n", pGyroDataXYZ[1]);
00057         printf("GYRO_Z = %.2f\n", pGyroDataXYZ[2]);
00058 
00059         BSP_ACCELERO_AccGetXYZ(pDataXYZ);
00060         printf("\nACCELERO_X = %d\n", pDataXYZ[0]);
00061         printf("ACCELERO_Y = %d\n", pDataXYZ[1]);
00062         printf("ACCELERO_Z = %d\n", pDataXYZ[2]);
00063 
00064         led = 0;
00065 
00066         ThisThread::sleep_for(1000);
00067 
00068     }
00069 }