
1
Dependencies: BSP_B-L475E-IOT01
main.cpp@0:3f352f83430d, 2021-07-07 (annotated)
- Committer:
- zhongrui
- Date:
- Wed Jul 07 07:47:12 2021 +0000
- Revision:
- 0:3f352f83430d
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
zhongrui | 0:3f352f83430d | 1 | #include "mbed.h" |
zhongrui | 0:3f352f83430d | 2 | |
zhongrui | 0:3f352f83430d | 3 | // Sensors drivers present in the BSP library |
zhongrui | 0:3f352f83430d | 4 | #include "stm32l475e_iot01_tsensor.h" |
zhongrui | 0:3f352f83430d | 5 | #include "stm32l475e_iot01_hsensor.h" |
zhongrui | 0:3f352f83430d | 6 | #include "stm32l475e_iot01_psensor.h" |
zhongrui | 0:3f352f83430d | 7 | #include "stm32l475e_iot01_magneto.h" |
zhongrui | 0:3f352f83430d | 8 | #include "stm32l475e_iot01_gyro.h" |
zhongrui | 0:3f352f83430d | 9 | #include "stm32l475e_iot01_accelero.h" |
zhongrui | 0:3f352f83430d | 10 | |
zhongrui | 0:3f352f83430d | 11 | DigitalOut led(LED1); |
zhongrui | 0:3f352f83430d | 12 | |
zhongrui | 0:3f352f83430d | 13 | int main() |
zhongrui | 0:3f352f83430d | 14 | { |
zhongrui | 0:3f352f83430d | 15 | float sensor_value = 0; |
zhongrui | 0:3f352f83430d | 16 | int16_t pDataXYZ[3] = {0}; |
zhongrui | 0:3f352f83430d | 17 | float pGyroDataXYZ[3] = {0}; |
zhongrui | 0:3f352f83430d | 18 | |
zhongrui | 0:3f352f83430d | 19 | printf("Start sensor init\n"); |
zhongrui | 0:3f352f83430d | 20 | |
zhongrui | 0:3f352f83430d | 21 | BSP_TSENSOR_Init(); |
zhongrui | 0:3f352f83430d | 22 | BSP_HSENSOR_Init(); |
zhongrui | 0:3f352f83430d | 23 | BSP_PSENSOR_Init(); |
zhongrui | 0:3f352f83430d | 24 | |
zhongrui | 0:3f352f83430d | 25 | BSP_MAGNETO_Init(); |
zhongrui | 0:3f352f83430d | 26 | BSP_GYRO_Init(); |
zhongrui | 0:3f352f83430d | 27 | BSP_ACCELERO_Init(); |
zhongrui | 0:3f352f83430d | 28 | |
zhongrui | 0:3f352f83430d | 29 | while(1) { |
zhongrui | 0:3f352f83430d | 30 | printf("\nNew loop, LED1 should blink during sensor read\n"); |
zhongrui | 0:3f352f83430d | 31 | |
zhongrui | 0:3f352f83430d | 32 | led = 1; |
zhongrui | 0:3f352f83430d | 33 | |
zhongrui | 0:3f352f83430d | 34 | sensor_value = BSP_TSENSOR_ReadTemp(); |
zhongrui | 0:3f352f83430d | 35 | printf("\nTEMPERATURE = %.2f degC\n", sensor_value); |
zhongrui | 0:3f352f83430d | 36 | |
zhongrui | 0:3f352f83430d | 37 | sensor_value = BSP_HSENSOR_ReadHumidity(); |
zhongrui | 0:3f352f83430d | 38 | printf("HUMIDITY = %.2f %%\n", sensor_value); |
zhongrui | 0:3f352f83430d | 39 | |
zhongrui | 0:3f352f83430d | 40 | sensor_value = BSP_PSENSOR_ReadPressure(); |
zhongrui | 0:3f352f83430d | 41 | printf("PRESSURE is = %.2f mBar\n", sensor_value); |
zhongrui | 0:3f352f83430d | 42 | |
zhongrui | 0:3f352f83430d | 43 | led = 0; |
zhongrui | 0:3f352f83430d | 44 | |
zhongrui | 0:3f352f83430d | 45 | ThisThread::sleep_for(1000); |
zhongrui | 0:3f352f83430d | 46 | |
zhongrui | 0:3f352f83430d | 47 | led = 1; |
zhongrui | 0:3f352f83430d | 48 | |
zhongrui | 0:3f352f83430d | 49 | BSP_MAGNETO_GetXYZ(pDataXYZ); |
zhongrui | 0:3f352f83430d | 50 | printf("\nMAGNETO_X = %d\n", pDataXYZ[0]); |
zhongrui | 0:3f352f83430d | 51 | printf("MAGNETO_Y = %d\n", pDataXYZ[1]); |
zhongrui | 0:3f352f83430d | 52 | printf("MAGNETO_Z = %d\n", pDataXYZ[2]); |
zhongrui | 0:3f352f83430d | 53 | |
zhongrui | 0:3f352f83430d | 54 | BSP_GYRO_GetXYZ(pGyroDataXYZ); |
zhongrui | 0:3f352f83430d | 55 | printf("\nGYRO_X = %.2f\n", pGyroDataXYZ[0]); |
zhongrui | 0:3f352f83430d | 56 | printf("GYRO_Y = %.2f\n", pGyroDataXYZ[1]); |
zhongrui | 0:3f352f83430d | 57 | printf("GYRO_Z = %.2f\n", pGyroDataXYZ[2]); |
zhongrui | 0:3f352f83430d | 58 | |
zhongrui | 0:3f352f83430d | 59 | BSP_ACCELERO_AccGetXYZ(pDataXYZ); |
zhongrui | 0:3f352f83430d | 60 | printf("\nACCELERO_X = %d\n", pDataXYZ[0]); |
zhongrui | 0:3f352f83430d | 61 | printf("ACCELERO_Y = %d\n", pDataXYZ[1]); |
zhongrui | 0:3f352f83430d | 62 | printf("ACCELERO_Z = %d\n", pDataXYZ[2]); |
zhongrui | 0:3f352f83430d | 63 | |
zhongrui | 0:3f352f83430d | 64 | led = 0; |
zhongrui | 0:3f352f83430d | 65 | |
zhongrui | 0:3f352f83430d | 66 | ThisThread::sleep_for(1000); |
zhongrui | 0:3f352f83430d | 67 | |
zhongrui | 0:3f352f83430d | 68 | } |
zhongrui | 0:3f352f83430d | 69 | } |