Sensorian  1.0
C API Reference Guide Library
main.c
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (C) 2015 Sensorian
3  * *
4  * This file is part of Sensorian. *
5  * *
6  * Sensorian is free software: you can redistribute it and/or modify it *
7  * under the terms of the GNU Lesser General Public License as published *
8  * by the Free Software Foundation, either version 3 of the License, or *
9  * (at your option) any later version. *
10  * *
11  * Sensorian is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with Sensorian. *
18  * If not, see <http://www.gnu.org/licenses/>. *
19  ****************************************************************************/
20 
21 
29 #include <bcm2835.h>
30 #include <stdio.h>
31 #include "MPL3115A2.h"
32 #include "i2c.h"
33 #include "Utilities.h"
34 
35 int main(int argc, char **argv)
36 {
37 
38  I2C_Initialize(MPL3115A2_ADDRESS); //Initialize I2C and setup chip address
41 
42  printf("MPL3115A2 Altimeter/Barometer sensor demo.\r\n");
43 
44  unsigned char id = MPL3115A2_ID(); //Verify chip id
45  printf("Chip ID: 0x%02X . \r\n", id);
46 
47  while(1)
48  {
51  float alt = MPL3115A2_ReadAltitude(); //Take an altimeter reading
52  printf("Altimeter: %0.2f m above sea level.\r\n", alt/100);
53  delay_ms(500);
54 
57  float press = MPL3115A2_ReadBarometricPressure(); //Take a pressure reading
58  printf("Pressure: %0.2f Pascal. \r\n", press);
59  delay_ms(500);
60 
61  }
62 
63 return 0;
64 }
65 
MPL3115A2 driver header.
unsigned char MPL3115A2_ID(void)
Returns the Factory Chip ID.
Definition: MPL3115A2.c:51
float MPL3115A2_ReadAltitude(void)
Returns the number of meters above sea level,Returns -1 if no new data is available.
Definition: MPL3115A2.c:107
void MPL3115A2_BarometerMode(void)
Configure the sensor in Barometer mode.
Definition: MPL3115A2.c:135
#define MPL3115A2_ADDRESS
The I2C address of the MPL3115A2 barometer altimeter sensor.
Definition: MPL3115A2.h:40
I2C driver header.
float MPL3115A2_ReadBarometricPressure(void)
Reads the current pressure in Pa.
Definition: MPL3115A2.c:205
void I2C_Initialize(unsigned char address)
Initializes the I2C peripheral.
Definition: i2c.c:36
void MPL3115A2_Initialize(void)
Initialize the sensor and enable interrupts.
Definition: MPL3115A2.c:40
int main(int argc, char **argv)
Definition: main.c:34
void delay_ms(unsigned int ms)
Delay in ms.
Definition: Utilities.c:39
void MPL3115A2_AltimeterMode(void)
Sets the mode to Altimeter.
Definition: MPL3115A2.c:93
void MPL3115A2_ActiveMode(void)
Puts the sensor in active mode, needed is the sensor is in standby mode.
Definition: MPL3115A2.c:82
void MPL3115A2_StandbyMode(void)
Puts the sensor in standby mode, the user must do this in order to modify the major control registers...
Definition: MPL3115A2.c:71