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.

Committer:
bcostm
Date:
Fri Apr 14 16:25:51 2017 +0200
Revision:
6:ff641476ffe3
Parent:
5:2d1980c7ca2d
Child:
7:cccef81dc691
Add sensors demo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:280450d2b3cc 1 #include "mbed.h"
bcostm 6:ff641476ffe3 2 #include "stm32l475e_iot01_tsensor.h"
bcostm 6:ff641476ffe3 3 #include "stm32l475e_iot01_hsensor.h"
bcostm 6:ff641476ffe3 4 #include "stm32l475e_iot01_psensor.h"
bcostm 6:ff641476ffe3 5 #include "stm32l475e_iot01_magneto.h"
bcostm 6:ff641476ffe3 6 #include "stm32l475e_iot01_gyro.h"
bcostm 6:ff641476ffe3 7 #include "stm32l475e_iot01_accelero.h"
bcostm 0:280450d2b3cc 8
bcostm 0:280450d2b3cc 9 DigitalOut led1(LED1);
bcostm 5:2d1980c7ca2d 10 DigitalOut led2(LED2);
bcostm 5:2d1980c7ca2d 11 // This object drives both LD3 and LD4 on the board.
bcostm 5:2d1980c7ca2d 12 // Only one of these LEDs can be driven at a time.
bcostm 5:2d1980c7ca2d 13 DigitalInOut led3(LED3);
bcostm 5:2d1980c7ca2d 14
bcostm 5:2d1980c7ca2d 15 #define LD1_ON {led1 = 1;}
bcostm 5:2d1980c7ca2d 16 #define LD1_OFF {led1 = 0;}
bcostm 6:ff641476ffe3 17 #define LD1_TOG {led1 = !led1;}
bcostm 5:2d1980c7ca2d 18 #define LD2_ON {led2 = 1;}
bcostm 5:2d1980c7ca2d 19 #define LD2_OFF {led2 = 0;}
bcostm 6:ff641476ffe3 20 #define LD2_TOG {led2 = !led2;}
bcostm 5:2d1980c7ca2d 21 #define LD3_ON {led3.output(); led3 = 1;}
bcostm 6:ff641476ffe3 22 #define LD3_OFF {led3.input();}
bcostm 5:2d1980c7ca2d 23 #define LD4_ON {led3.output(); led3 = 0;}
bcostm 6:ff641476ffe3 24 #define LD4_OFF {led3.input();}
bcostm 5:2d1980c7ca2d 25
bcostm 5:2d1980c7ca2d 26 // Select your demo
bcostm 6:ff641476ffe3 27 //#define DEMO_TEMPERATURE_HUMIDITY_PRESSURE
bcostm 6:ff641476ffe3 28 #define DEMO_MAGNETO_GYRO_ACCELERO
bcostm 0:280450d2b3cc 29
bcostm 0:280450d2b3cc 30 int main()
bcostm 0:280450d2b3cc 31 {
bcostm 6:ff641476ffe3 32
bcostm 6:ff641476ffe3 33 #if defined(DEMO_TEMPERATURE_HUMIDITY_PRESSURE)
bcostm 6:ff641476ffe3 34 float sensor_value = 0;
bcostm 6:ff641476ffe3 35 BSP_TSENSOR_Init();
bcostm 6:ff641476ffe3 36 BSP_HSENSOR_Init();
bcostm 6:ff641476ffe3 37 BSP_PSENSOR_Init();
bcostm 6:ff641476ffe3 38 while(1) {
bcostm 6:ff641476ffe3 39 sensor_value = BSP_TSENSOR_ReadTemp();
bcostm 6:ff641476ffe3 40 printf("\nTEMPERATURE = %.2f degC\n", sensor_value);
bcostm 6:ff641476ffe3 41 sensor_value = BSP_HSENSOR_ReadHumidity();
bcostm 6:ff641476ffe3 42 printf("HUMIDITY = %.2f %\n", sensor_value);
bcostm 6:ff641476ffe3 43 sensor_value = BSP_PSENSOR_ReadPressure();
bcostm 6:ff641476ffe3 44 printf("PRESSURE is = %.2f mBar\n", sensor_value);
bcostm 6:ff641476ffe3 45 led1 = !led1;
bcostm 6:ff641476ffe3 46 wait(2);
bcostm 6:ff641476ffe3 47 }
bcostm 6:ff641476ffe3 48 #elif defined(DEMO_MAGNETO_GYRO_ACCELERO)
bcostm 6:ff641476ffe3 49 int16_t pDataXYZ[3] = {0};
bcostm 6:ff641476ffe3 50 float pGyroDataXYZ[3] = {0};
bcostm 6:ff641476ffe3 51 BSP_MAGNETO_Init();
bcostm 6:ff641476ffe3 52 BSP_GYRO_Init();
bcostm 6:ff641476ffe3 53 BSP_ACCELERO_Init();
bcostm 6:ff641476ffe3 54 while(1) {
bcostm 6:ff641476ffe3 55 BSP_MAGNETO_GetXYZ(pDataXYZ);
bcostm 6:ff641476ffe3 56 printf("\nMAGNETO_X = %d\n", pDataXYZ[0]);
bcostm 6:ff641476ffe3 57 printf("MAGNETO_Y = %d\n", pDataXYZ[1]);
bcostm 6:ff641476ffe3 58 printf("MAGNETO_Z = %d\n", pDataXYZ[2]);
bcostm 6:ff641476ffe3 59 wait(2);
bcostm 6:ff641476ffe3 60 BSP_GYRO_GetXYZ(pGyroDataXYZ);
bcostm 6:ff641476ffe3 61 printf("\nGYRO_X = %.2f\n", pGyroDataXYZ[0]);
bcostm 6:ff641476ffe3 62 printf("GYRO_Y = %.2f\n", pGyroDataXYZ[1]);
bcostm 6:ff641476ffe3 63 printf("GYRO_Z = %.2f\n", pGyroDataXYZ[2]);
bcostm 6:ff641476ffe3 64 wait(2);
bcostm 6:ff641476ffe3 65 BSP_ACCELERO_AccGetXYZ(pDataXYZ);
bcostm 6:ff641476ffe3 66 printf("\nACCELERO_X = %d\n", pDataXYZ[0]);
bcostm 6:ff641476ffe3 67 printf("ACCELERO_Y = %d\n", pDataXYZ[1]);
bcostm 6:ff641476ffe3 68 printf("ACCELERO_Z = %d\n", pDataXYZ[2]);
bcostm 6:ff641476ffe3 69 wait(2);
bcostm 6:ff641476ffe3 70 }
bcostm 6:ff641476ffe3 71 #else
bcostm 0:280450d2b3cc 72 while(1) {
bcostm 5:2d1980c7ca2d 73 LD1_ON;
bcostm 5:2d1980c7ca2d 74 wait(0.5);
bcostm 5:2d1980c7ca2d 75 LD2_ON;
bcostm 5:2d1980c7ca2d 76 wait(0.5);
bcostm 5:2d1980c7ca2d 77 LD3_ON;
bcostm 5:2d1980c7ca2d 78 wait(0.5);
bcostm 5:2d1980c7ca2d 79 LD4_ON;
bcostm 5:2d1980c7ca2d 80 wait(0.5);
bcostm 5:2d1980c7ca2d 81 LD1_OFF;
bcostm 5:2d1980c7ca2d 82 wait(0.5);
bcostm 5:2d1980c7ca2d 83 LD2_OFF;
bcostm 5:2d1980c7ca2d 84 wait(0.5);
bcostm 6:ff641476ffe3 85 LD3_OFF; // LD4 is also OFF
bcostm 5:2d1980c7ca2d 86 wait(0.5);
bcostm 6:ff641476ffe3 87 for(int i = 0; i < 10; i++) {
bcostm 6:ff641476ffe3 88 LD1_TOG;
bcostm 6:ff641476ffe3 89 LD2_TOG;
bcostm 6:ff641476ffe3 90 wait(0.2);
bcostm 6:ff641476ffe3 91 }
bcostm 5:2d1980c7ca2d 92 }
bcostm 5:2d1980c7ca2d 93 #endif
bcostm 0:280450d2b3cc 94 }