Year Two Project ELEC 2645: Embedded Systems Project Portable Weather Station

Dependencies:   BMP180 ConfigFile N5110 PowerControl beep mbed

Committer:
OHstin
Date:
Mon May 11 15:25:52 2015 +0000
Revision:
0:da2b8c7a1ec1
Completed Weather Station

Who changed what in which revision?

UserRevisionLine numberNew contents of line
OHstin 0:da2b8c7a1ec1 1 /**
OHstin 0:da2b8c7a1ec1 2 @file sensors.h
OHstin 0:da2b8c7a1ec1 3 @brief this file contians functions that allow the user to access the sensors used in for the project\n
OHstin 0:da2b8c7a1ec1 4 @brief the sensors are barameter, thermometer and a simple voltage divider that measures voltage\n
OHstin 0:da2b8c7a1ec1 5 @author Augustine K Kizito
OHstin 0:da2b8c7a1ec1 6 @date April 2015
OHstin 0:da2b8c7a1ec1 7 */
OHstin 0:da2b8c7a1ec1 8 #ifndef SENSORS_H
OHstin 0:da2b8c7a1ec1 9 #define SENSORS_H
OHstin 0:da2b8c7a1ec1 10
OHstin 0:da2b8c7a1ec1 11 #include "BMP180.h"
OHstin 0:da2b8c7a1ec1 12
OHstin 0:da2b8c7a1ec1 13 BMP180 bmp180(p28,p27); // SDA, SCL
OHstin 0:da2b8c7a1ec1 14 AnalogIn ain(p20); // connected to PP3 battery, used to measure voltage
OHstin 0:da2b8c7a1ec1 15
OHstin 0:da2b8c7a1ec1 16 /**
OHstin 0:da2b8c7a1ec1 17 Reads the current temperature from the BMP180 sensor and returns the value
OHstin 0:da2b8c7a1ec1 18
OHstin 0:da2b8c7a1ec1 19 @returns float temperature in degrees celsius
OHstin 0:da2b8c7a1ec1 20
OHstin 0:da2b8c7a1ec1 21 */
OHstin 0:da2b8c7a1ec1 22 float getTemperature();
OHstin 0:da2b8c7a1ec1 23 /**
OHstin 0:da2b8c7a1ec1 24 Reads the current pressure from the BMP180 sensor and returns the value
OHstin 0:da2b8c7a1ec1 25
OHstin 0:da2b8c7a1ec1 26 @returns float pressure in mbars
OHstin 0:da2b8c7a1ec1 27
OHstin 0:da2b8c7a1ec1 28 */
OHstin 0:da2b8c7a1ec1 29 float getPressure();
OHstin 0:da2b8c7a1ec1 30 /**
OHstin 0:da2b8c7a1ec1 31 Reads the voltage reading across the potential divider connecte to the PP3 Battery
OHstin 0:da2b8c7a1ec1 32
OHstin 0:da2b8c7a1ec1 33 @returns float battery voltage in Volts
OHstin 0:da2b8c7a1ec1 34 */
OHstin 0:da2b8c7a1ec1 35 float getVoltage();
OHstin 0:da2b8c7a1ec1 36
OHstin 0:da2b8c7a1ec1 37
OHstin 0:da2b8c7a1ec1 38
OHstin 0:da2b8c7a1ec1 39
OHstin 0:da2b8c7a1ec1 40 float getTemperature()
OHstin 0:da2b8c7a1ec1 41 {
OHstin 0:da2b8c7a1ec1 42 float temperature; // stores temperature in deg Cel
OHstin 0:da2b8c7a1ec1 43
OHstin 0:da2b8c7a1ec1 44 if (bmp180.ReadData(&temperature,NULL)) {
OHstin 0:da2b8c7a1ec1 45 // tempeature value is returned successfully
OHstin 0:da2b8c7a1ec1 46
OHstin 0:da2b8c7a1ec1 47 } else {
OHstin 0:da2b8c7a1ec1 48 // sensor failed
OHstin 0:da2b8c7a1ec1 49 temperature = -100;
OHstin 0:da2b8c7a1ec1 50 }
OHstin 0:da2b8c7a1ec1 51
OHstin 0:da2b8c7a1ec1 52 return temperature;
OHstin 0:da2b8c7a1ec1 53 }
OHstin 0:da2b8c7a1ec1 54
OHstin 0:da2b8c7a1ec1 55 float getPressure()
OHstin 0:da2b8c7a1ec1 56 {
OHstin 0:da2b8c7a1ec1 57 float pressure; // stores pressure in hPa
OHstin 0:da2b8c7a1ec1 58
OHstin 0:da2b8c7a1ec1 59 if (bmp180.ReadData(NULL, &pressure)) {
OHstin 0:da2b8c7a1ec1 60 // pressure value is returned successfully
OHstin 0:da2b8c7a1ec1 61
OHstin 0:da2b8c7a1ec1 62 } else {
OHstin 0:da2b8c7a1ec1 63 // sensor failed
OHstin 0:da2b8c7a1ec1 64 pressure = -10;
OHstin 0:da2b8c7a1ec1 65 }
OHstin 0:da2b8c7a1ec1 66
OHstin 0:da2b8c7a1ec1 67 return pressure;
OHstin 0:da2b8c7a1ec1 68
OHstin 0:da2b8c7a1ec1 69 }
OHstin 0:da2b8c7a1ec1 70
OHstin 0:da2b8c7a1ec1 71 float getVoltage()
OHstin 0:da2b8c7a1ec1 72 {
OHstin 0:da2b8c7a1ec1 73 // calculate voltage
OHstin 0:da2b8c7a1ec1 74 float voltage = ain*9.9+1.8;
OHstin 0:da2b8c7a1ec1 75
OHstin 0:da2b8c7a1ec1 76 return voltage;
OHstin 0:da2b8c7a1ec1 77
OHstin 0:da2b8c7a1ec1 78 }
OHstin 0:da2b8c7a1ec1 79
OHstin 0:da2b8c7a1ec1 80 #endif