Read board sensors (temperature, humidity, pressure, gyroscope, accelerometer, magnetometer) using ST BSP drivers. This example is superceded with the HelloWorld_ST_Sensors example.
Dependencies: BSP_B-L475E-IOT01
Information
This example is superceded with the HelloWorld_ST_Sensors example.
Import programHelloWorld_ST_Sensors
Simple application to test ST motion and environmental MEMS sensors. Supports NUCLEO+X-NUCLEO-IKS01A2 , STEVAL-STLKT01V1 (a.k.a. SensorTile) and B-L475E-IOT01A boards.
main.cpp@12:688020afdae7, 2019-09-24 (annotated)
- Committer:
- jeromecoutant
- Date:
- Tue Sep 24 15:42:22 2019 +0200
- Revision:
- 12:688020afdae7
- Parent:
- 11:986c1f5db128
Update with STM32Cube L4 V1.14.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bcostm | 0:280450d2b3cc | 1 | #include "mbed.h" |
bcostm | 10:0964ad447861 | 2 | |
bcostm | 10:0964ad447861 | 3 | // Sensors drivers present in the BSP library |
bcostm | 6:ff641476ffe3 | 4 | #include "stm32l475e_iot01_tsensor.h" |
bcostm | 6:ff641476ffe3 | 5 | #include "stm32l475e_iot01_hsensor.h" |
bcostm | 6:ff641476ffe3 | 6 | #include "stm32l475e_iot01_psensor.h" |
bcostm | 6:ff641476ffe3 | 7 | #include "stm32l475e_iot01_magneto.h" |
bcostm | 6:ff641476ffe3 | 8 | #include "stm32l475e_iot01_gyro.h" |
bcostm | 6:ff641476ffe3 | 9 | #include "stm32l475e_iot01_accelero.h" |
bcostm | 0:280450d2b3cc | 10 | |
bcostm | 11:986c1f5db128 | 11 | DigitalOut led(LED1); |
bcostm | 0:280450d2b3cc | 12 | |
bcostm | 0:280450d2b3cc | 13 | int main() |
bcostm | 0:280450d2b3cc | 14 | { |
bcostm | 10:0964ad447861 | 15 | float sensor_value = 0; |
bcostm | 10:0964ad447861 | 16 | int16_t pDataXYZ[3] = {0}; |
bcostm | 10:0964ad447861 | 17 | float pGyroDataXYZ[3] = {0}; |
bcostm | 6:ff641476ffe3 | 18 | |
jeromecoutant | 12:688020afdae7 | 19 | printf("Start sensor init\n"); |
jeromecoutant | 12:688020afdae7 | 20 | |
bcostm | 6:ff641476ffe3 | 21 | BSP_TSENSOR_Init(); |
bcostm | 6:ff641476ffe3 | 22 | BSP_HSENSOR_Init(); |
bcostm | 6:ff641476ffe3 | 23 | BSP_PSENSOR_Init(); |
bcostm | 10:0964ad447861 | 24 | |
bcostm | 6:ff641476ffe3 | 25 | BSP_MAGNETO_Init(); |
bcostm | 6:ff641476ffe3 | 26 | BSP_GYRO_Init(); |
bcostm | 6:ff641476ffe3 | 27 | BSP_ACCELERO_Init(); |
bcostm | 10:0964ad447861 | 28 | |
bcostm | 6:ff641476ffe3 | 29 | while(1) { |
jeromecoutant | 12:688020afdae7 | 30 | printf("\nNew loop, LED1 should blink during sensor read\n"); |
bcostm | 10:0964ad447861 | 31 | |
bcostm | 11:986c1f5db128 | 32 | led = 1; |
bcostm | 10:0964ad447861 | 33 | |
bcostm | 10:0964ad447861 | 34 | sensor_value = BSP_TSENSOR_ReadTemp(); |
bcostm | 10:0964ad447861 | 35 | printf("\nTEMPERATURE = %.2f degC\n", sensor_value); |
bcostm | 10:0964ad447861 | 36 | |
bcostm | 10:0964ad447861 | 37 | sensor_value = BSP_HSENSOR_ReadHumidity(); |
bcostm | 10:0964ad447861 | 38 | printf("HUMIDITY = %.2f %%\n", sensor_value); |
bcostm | 10:0964ad447861 | 39 | |
bcostm | 10:0964ad447861 | 40 | sensor_value = BSP_PSENSOR_ReadPressure(); |
bcostm | 10:0964ad447861 | 41 | printf("PRESSURE is = %.2f mBar\n", sensor_value); |
bcostm | 10:0964ad447861 | 42 | |
bcostm | 11:986c1f5db128 | 43 | led = 0; |
bcostm | 10:0964ad447861 | 44 | |
jeromecoutant | 12:688020afdae7 | 45 | ThisThread::sleep_for(1000); |
bcostm | 10:0964ad447861 | 46 | |
bcostm | 11:986c1f5db128 | 47 | led = 1; |
bcostm | 10:0964ad447861 | 48 | |
bcostm | 6:ff641476ffe3 | 49 | BSP_MAGNETO_GetXYZ(pDataXYZ); |
bcostm | 6:ff641476ffe3 | 50 | printf("\nMAGNETO_X = %d\n", pDataXYZ[0]); |
bcostm | 6:ff641476ffe3 | 51 | printf("MAGNETO_Y = %d\n", pDataXYZ[1]); |
bcostm | 6:ff641476ffe3 | 52 | printf("MAGNETO_Z = %d\n", pDataXYZ[2]); |
bcostm | 10:0964ad447861 | 53 | |
bcostm | 6:ff641476ffe3 | 54 | BSP_GYRO_GetXYZ(pGyroDataXYZ); |
bcostm | 6:ff641476ffe3 | 55 | printf("\nGYRO_X = %.2f\n", pGyroDataXYZ[0]); |
bcostm | 6:ff641476ffe3 | 56 | printf("GYRO_Y = %.2f\n", pGyroDataXYZ[1]); |
bcostm | 6:ff641476ffe3 | 57 | printf("GYRO_Z = %.2f\n", pGyroDataXYZ[2]); |
bcostm | 10:0964ad447861 | 58 | |
bcostm | 6:ff641476ffe3 | 59 | BSP_ACCELERO_AccGetXYZ(pDataXYZ); |
bcostm | 6:ff641476ffe3 | 60 | printf("\nACCELERO_X = %d\n", pDataXYZ[0]); |
bcostm | 6:ff641476ffe3 | 61 | printf("ACCELERO_Y = %d\n", pDataXYZ[1]); |
bcostm | 6:ff641476ffe3 | 62 | printf("ACCELERO_Z = %d\n", pDataXYZ[2]); |
bcostm | 10:0964ad447861 | 63 | |
bcostm | 11:986c1f5db128 | 64 | led = 0; |
bcostm | 10:0964ad447861 | 65 | |
jeromecoutant | 12:688020afdae7 | 66 | ThisThread::sleep_for(1000); |
bcostm | 10:0964ad447861 | 67 | |
bcostm | 6:ff641476ffe3 | 68 | } |
bcostm | 0:280450d2b3cc | 69 | } |