Luca De Vito / Mbed OS LabSMT32Sensors

Dependencies:   X_NUCLEO_IKS01A2

Committer:
lucadevito
Date:
Tue Apr 27 09:10:44 2021 +0000
Revision:
0:ace8017575ea
Project created

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lucadevito 0:ace8017575ea 1 /*----------------------------------------------------------------------------
lucadevito 0:ace8017575ea 2 LAB EXERCISE - Environmental sensors measurements
lucadevito 0:ace8017575ea 3 ----------------------------------------
lucadevito 0:ace8017575ea 4 In this exercise we will read the environmental sensors on the Nucleo sensors shield (X-NUCLEO-IKS01A1)
lucadevito 0:ace8017575ea 5 with the help of the ST Nucleo Sensor Shield library which is compatible with the MBED API.
lucadevito 0:ace8017575ea 6 Then we will send the measurements via USB to our PC using serial communication.
lucadevito 0:ace8017575ea 7 We can then display the results using a terminal emulation program (e.g. Termite).
lucadevito 0:ace8017575ea 8
lucadevito 0:ace8017575ea 9 At the same time the program blinks the on board LED to show alivness.
lucadevito 0:ace8017575ea 10
lucadevito 0:ace8017575ea 11
lucadevito 0:ace8017575ea 12 GOOD LUCK!
lucadevito 0:ace8017575ea 13 *----------------------------------------------------------------------------*/
lucadevito 0:ace8017575ea 14
lucadevito 0:ace8017575ea 15 #include "mbed.h"
lucadevito 0:ace8017575ea 16 #include "x_cube_mems.h"
lucadevito 0:ace8017575ea 17
lucadevito 0:ace8017575ea 18 // Create a DigitalOut objects for the LED
lucadevito 0:ace8017575ea 19
lucadevito 0:ace8017575ea 20 // Create a Serial objects to communicate via USB
lucadevito 0:ace8017575ea 21
lucadevito 0:ace8017575ea 22 // Create 2 Ticker objects for recurring interrupts. One for blink a LED and the other one to update the sensor lectures periodicly
lucadevito 0:ace8017575ea 23
lucadevito 0:ace8017575ea 24 // Initialize variables
lucadevito 0:ace8017575ea 25
lucadevito 0:ace8017575ea 26 // Handler for the aliveness LED; to be called every 0.5s
lucadevito 0:ace8017575ea 27
lucadevito 0:ace8017575ea 28 // Handler for the measurements update; rise a flag every 3 seconds
lucadevito 0:ace8017575ea 29
lucadevito 0:ace8017575ea 30
lucadevito 0:ace8017575ea 31
lucadevito 0:ace8017575ea 32 int main() {
lucadevito 0:ace8017575ea 33
lucadevito 0:ace8017575ea 34 /* Create sensor shield object */
lucadevito 0:ace8017575ea 35
lucadevito 0:ace8017575ea 36 /* Attach a function to be called by the Ticker objects at a specific interval in seconds */
lucadevito 0:ace8017575ea 37
lucadevito 0:ace8017575ea 38
lucadevito 0:ace8017575ea 39 while(1) {
lucadevito 0:ace8017575ea 40
lucadevito 0:ace8017575ea 41 /* Check for the measurements update flag */
lucadevito 0:ace8017575ea 42
lucadevito 0:ace8017575ea 43 /* Read the environmental sensors */
lucadevito 0:ace8017575ea 44
lucadevito 0:ace8017575ea 45 /* Calculate temperature in Fahrenheit and Kelvins */
lucadevito 0:ace8017575ea 46
lucadevito 0:ace8017575ea 47 /*Send data through serial communication */
lucadevito 0:ace8017575ea 48
lucadevito 0:ace8017575ea 49 /* Turn down the measurements update flag */
lucadevito 0:ace8017575ea 50
lucadevito 0:ace8017575ea 51 /*Wait for interrupts*/
lucadevito 0:ace8017575ea 52 }
lucadevito 0:ace8017575ea 53 }
lucadevito 0:ace8017575ea 54 // *******************************ARM University Program Copyright � ARM Ltd 2015*************************************