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 
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  printf("MPL3115A2 Altimeter/Barometer/Temperature sensor demo.\r\n");
38 
39  I2C_Initialize(MPL3115A2_ADDRESS); //Initialize I2C peripheral
40  MPL3115A2_Initialize(); //Initialize the sensor
41  MPL3115A2_ActiveMode(); //Configure the sensor for active mode
42 
43  unsigned char id = MPL3115A2_ID(); //Verify chip id
44  printf("Chip ID: 0x%02X . \r\n", id);
45 
46  while(1)
47  {
48  float temp = MPL3115A2_ReadTemperature();//Take a temperature reading
49  printf("Temperature : %0.2f degree Celsius.\r\n", temp);
50  delay_ms(500);
51  }
52 
53 return 0;
54 }
55 
unsigned char MPL3115A2_ID(void)
Returns the Factory Chip ID.
Definition: MPL3115A2.c:51
float MPL3115A2_ReadTemperature(void)
Get a temperature reading from the sensor.
Definition: MPL3115A2.c:282
#define MPL3115A2_ADDRESS
The I2C address of the MPL3115A2 barometer altimeter sensor.
Definition: MPL3115A2.h:40
I2C driver header.
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
MPL3115A2 driver header.
void delay_ms(unsigned int ms)
Delay in ms.
Definition: Utilities.c:39
void MPL3115A2_ActiveMode(void)
Puts the sensor in active mode, needed is the sensor is in standby mode.
Definition: MPL3115A2.c:82