Barometric pressure and temperature sensing program example for Hexiwear
Dependencies: MPL3115A2
Fork of Hexi_barom_alt_temp_app by
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
Revision 1:4cd4a1bd710b, committed 2016-08-15
- Comitter:
- GregC
- Date:
- Mon Aug 15 23:45:15 2016 +0000
- Parent:
- 0:97dd02e37c94
- Commit message:
- Barometric pressure and temperature sensing program example for Hexiwear
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Aug 13 16:02:39 2016 +0000 +++ b/main.cpp Mon Aug 15 23:45:15 2016 +0000 @@ -8,12 +8,16 @@ #define MPL3115A2_I2C_ADDRESS (0x60<<1) -DigitalOut led1(LED1); +DigitalOut led1(LED_GREEN); + +// Initialize Serial port +Serial pc(USBTX, USBRX); // Pin connections for Hexiwear MPL3115A2 MPL3115A2( PTC11, PTC10, MPL3115A2_I2C_ADDRESS); /* pos [0] = altimeter or pressure value */ /* pos [1] = temperature value */ + float sensor_data[2]; // main() runs in its own thread in the OS @@ -22,13 +26,15 @@ // Set over sampling value (see MPL3115A2.h for details) - MPL3115A2.Oversample_Ratio( OVERSAMPLE_RATIO_64); + MPL3115A2.Oversample_Ratio(OVERSAMPLE_RATIO_64); // Configure the sensor as Barometer. MPL3115A2.Barometric_Mode(); - while (true) { + printf("\rBegin Data Acquisition from MPL3115A2 sensor....\r\n\r\n"); + wait(0.5); - MPL3115A2.getAllData( &sensor_data[0]); + while(1) { + MPL3115A2.getAllData(&sensor_data[0]); printf("\tPressure: %f\tTemperature: %f\r\n", sensor_data[0], sensor_data[1]); led1 = !led1; Thread::wait(500);