Barometric pressure and temperature sensing program example for Hexiwear

Dependencies:   MPL3115A2

Fork of Hexi_barom_alt_temp_app by Mac Lobdell

This project demonstrates the use of the MPL3115A2 pressure and temperature sensor embedded in hexiwear

Open a Hyperterminal tool on your computer and connect it to the "mbed Serial port (COMxx)" with Baud rate "9600bps"

Compile the project and copy the binary "Hexi_Pressure_Baro_Temp_Example_HEXIWEAR.bin" in the DAP-LINK drive from your computer file explorer Press the K64F-RESET button on the docking station to start the program on your board

Message "Begin Data Acquisition from MPL3115A2 sensor..." will appear in the Hyperterminal window
Then every 500ms the value of the pressure and the temperature will be displayed in the Hyperterminal window and the LED will blink Green

Committer:
GregC
Date:
Mon Aug 15 23:45:15 2016 +0000
Revision:
1:4cd4a1bd710b
Parent:
0:97dd02e37c94
Barometric pressure and temperature sensing program example for Hexiwear

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maclobdell 0:97dd02e37c94 1 #include "mbed.h"
maclobdell 0:97dd02e37c94 2 #include "MPL3115A2.h"
maclobdell 0:97dd02e37c94 3
maclobdell 0:97dd02e37c94 4 /* Check out the full featured example application for interfacing to the
maclobdell 0:97dd02e37c94 5 * Barometer/Altimeter/Thermometer device at the following URL
maclobdell 0:97dd02e37c94 6 * https://developer.mbed.org/users/clemente/code/WIGO_MPL3115A2/
maclobdell 0:97dd02e37c94 7 */
maclobdell 0:97dd02e37c94 8
maclobdell 0:97dd02e37c94 9 #define MPL3115A2_I2C_ADDRESS (0x60<<1)
maclobdell 0:97dd02e37c94 10
GregC 1:4cd4a1bd710b 11 DigitalOut led1(LED_GREEN);
GregC 1:4cd4a1bd710b 12
GregC 1:4cd4a1bd710b 13 // Initialize Serial port
GregC 1:4cd4a1bd710b 14 Serial pc(USBTX, USBRX);
maclobdell 0:97dd02e37c94 15
maclobdell 0:97dd02e37c94 16 // Pin connections for Hexiwear
maclobdell 0:97dd02e37c94 17 MPL3115A2 MPL3115A2( PTC11, PTC10, MPL3115A2_I2C_ADDRESS);
maclobdell 0:97dd02e37c94 18 /* pos [0] = altimeter or pressure value */
maclobdell 0:97dd02e37c94 19 /* pos [1] = temperature value */
GregC 1:4cd4a1bd710b 20
maclobdell 0:97dd02e37c94 21 float sensor_data[2];
maclobdell 0:97dd02e37c94 22
maclobdell 0:97dd02e37c94 23 // main() runs in its own thread in the OS
maclobdell 0:97dd02e37c94 24 // (note the calls to Thread::wait below for delays)
maclobdell 0:97dd02e37c94 25 int main() {
maclobdell 0:97dd02e37c94 26
maclobdell 0:97dd02e37c94 27
maclobdell 0:97dd02e37c94 28 // Set over sampling value (see MPL3115A2.h for details)
GregC 1:4cd4a1bd710b 29 MPL3115A2.Oversample_Ratio(OVERSAMPLE_RATIO_64);
maclobdell 0:97dd02e37c94 30 // Configure the sensor as Barometer.
maclobdell 0:97dd02e37c94 31 MPL3115A2.Barometric_Mode();
maclobdell 0:97dd02e37c94 32
GregC 1:4cd4a1bd710b 33 printf("\rBegin Data Acquisition from MPL3115A2 sensor....\r\n\r\n");
GregC 1:4cd4a1bd710b 34 wait(0.5);
maclobdell 0:97dd02e37c94 35
GregC 1:4cd4a1bd710b 36 while(1) {
GregC 1:4cd4a1bd710b 37 MPL3115A2.getAllData(&sensor_data[0]);
maclobdell 0:97dd02e37c94 38 printf("\tPressure: %f\tTemperature: %f\r\n", sensor_data[0], sensor_data[1]);
maclobdell 0:97dd02e37c94 39 led1 = !led1;
maclobdell 0:97dd02e37c94 40 Thread::wait(500);
maclobdell 0:97dd02e37c94 41 }
maclobdell 0:97dd02e37c94 42 }
maclobdell 0:97dd02e37c94 43