Implementaion of a weather station using the BMP180 sensor, nokia N5110 lcd screen and the mbed NXP CPC1768 microcontroller

Dependencies:   BMP180 N5110 PowerControl mbed

Fork of DocTest by Craig Evans

Committer:
FFLopes
Date:
Mon May 11 21:35:53 2015 +0000
Revision:
3:f7036017b319
Parent:
2:afdc5d6ca47f
Really finished

Who changed what in which revision?

UserRevisionLine numberNew contents of line
eencae 0:b85460bc73b9 1 /**
eencae 0:b85460bc73b9 2 @file main.h
eencae 1:6fc14cd8ccf1 3 @brief Header file containing functions prototypes, defines and global variables.
FFLopes 3:f7036017b319 4 @brief Implementantion of a weather station using the BMP180 sensor, the N5110 LCD screen and the mbed NXP LPC1768 microcontroller
FFLopes 3:f7036017b319 5 @brief to do that the libraries developed by Dr. Craig Evans are going to be used to control the BMP180 sensor and the N5110 LCD screen
FFLopes 3:f7036017b319 6 @brief a power saving feature was enabled by user the powerControl library by Michael Wei
FFLopes 2:afdc5d6ca47f 7 @brief Revision 1.5.
FFLopes 2:afdc5d6ca47f 8 @author Felipe F. Lopes
FFLopes 2:afdc5d6ca47f 9 @date May 2015
eencae 0:b85460bc73b9 10 */
eencae 0:b85460bc73b9 11
eencae 0:b85460bc73b9 12 #ifndef MAIN_H
eencae 0:b85460bc73b9 13 #define MAIN_H
eencae 0:b85460bc73b9 14
eencae 0:b85460bc73b9 15
eencae 0:b85460bc73b9 16 #include "mbed.h"
FFLopes 2:afdc5d6ca47f 17 #include "N5110.h"
FFLopes 2:afdc5d6ca47f 18 #include "BMP180.h"
FFLopes 2:afdc5d6ca47f 19 #include "PowerControl/PowerControl.h"
FFLopes 2:afdc5d6ca47f 20 #include "PowerControl/EthernetPowerControl.h"
eencae 0:b85460bc73b9 21
FFLopes 2:afdc5d6ca47f 22 //Here the initial values for the data are stored, maybe it can be possible to use them though the entire program
FFLopes 2:afdc5d6ca47f 23 //The temperatures are stored in Celsius
FFLopes 2:afdc5d6ca47f 24 #define maxThresTemp 50
FFLopes 2:afdc5d6ca47f 25 #define minThresTemp 0
FFLopes 2:afdc5d6ca47f 26
FFLopes 2:afdc5d6ca47f 27 //Constants that will be used to define states
FFLopes 2:afdc5d6ca47f 28 #define changeMaxTemp 10
FFLopes 2:afdc5d6ca47f 29 #define changeMinTemp 3
FFLopes 2:afdc5d6ca47f 30 #define dontChangeTemp 20
FFLopes 2:afdc5d6ca47f 31 #define mediumGood 5
FFLopes 2:afdc5d6ca47f 32 #define highGood 6
FFLopes 2:afdc5d6ca47f 33 #define mediumBad 7
FFLopes 2:afdc5d6ca47f 34 #define highBad 8
FFLopes 2:afdc5d6ca47f 35 #define notDefined 9
FFLopes 2:afdc5d6ca47f 36
FFLopes 2:afdc5d6ca47f 37 //Pins for the Leds
FFLopes 2:afdc5d6ca47f 38 #define maxTempAlertPin p23
FFLopes 2:afdc5d6ca47f 39 #define minTempAlertPin p22
FFLopes 2:afdc5d6ca47f 40
FFLopes 2:afdc5d6ca47f 41 //Pin values for the SDA and SCL lines of the BMP180 sensor. The data and clock lines respectivly
FFLopes 2:afdc5d6ca47f 42 #define sdaPin p9
FFLopes 2:afdc5d6ca47f 43 #define sclPin p10
FFLopes 2:afdc5d6ca47f 44
FFLopes 2:afdc5d6ca47f 45 //Pins to connect the LCD Screen
FFLopes 2:afdc5d6ca47f 46 #define pwrPin p5
FFLopes 2:afdc5d6ca47f 47 #define scePin p6
FFLopes 2:afdc5d6ca47f 48 #define rstPin p7
FFLopes 2:afdc5d6ca47f 49 #define dcPin p8
FFLopes 2:afdc5d6ca47f 50 #define mosiPin p11
FFLopes 2:afdc5d6ca47f 51 #define sclkPin p13
FFLopes 2:afdc5d6ca47f 52 #define ledPin p24
FFLopes 2:afdc5d6ca47f 53
FFLopes 2:afdc5d6ca47f 54 //Pin to turn the LCD on/off
FFLopes 2:afdc5d6ca47f 55 #define LCDStatePin p18
FFLopes 2:afdc5d6ca47f 56
FFLopes 2:afdc5d6ca47f 57 //pin to turn loggin on/off
FFLopes 2:afdc5d6ca47f 58 #define dataLoggingPin p29
FFLopes 2:afdc5d6ca47f 59
FFLopes 2:afdc5d6ca47f 60 //pin to read from the potentiometer
FFLopes 2:afdc5d6ca47f 61 #define potentiometerPin p20
FFLopes 2:afdc5d6ca47f 62
FFLopes 2:afdc5d6ca47f 63 //pin for button to change Threshold
FFLopes 2:afdc5d6ca47f 64 #define trhesPinButton p25
FFLopes 2:afdc5d6ca47f 65
FFLopes 2:afdc5d6ca47f 66 //pin to buzzer
FFLopes 2:afdc5d6ca47f 67 #define buzzerPin p21
FFLopes 2:afdc5d6ca47f 68
FFLopes 2:afdc5d6ca47f 69 //pin for button for change of units shown
FFLopes 2:afdc5d6ca47f 70 #define changeUnitsPin p26
FFLopes 2:afdc5d6ca47f 71
FFLopes 2:afdc5d6ca47f 72 /**
FFLopes 2:afdc5d6ca47f 73 @brief Variable to store the value of the forecasted weather
FFLopes 2:afdc5d6ca47f 74 */
FFLopes 2:afdc5d6ca47f 75 int chanceOfWeather = notDefined;
FFLopes 2:afdc5d6ca47f 76
FFLopes 2:afdc5d6ca47f 77 /**
FFLopes 2:afdc5d6ca47f 78 @brief Counter for the amount of times that the measurement was get on the minute
FFLopes 2:afdc5d6ca47f 79 */
FFLopes 2:afdc5d6ca47f 80 int minuteCounter = 0;
FFLopes 2:afdc5d6ca47f 81 /**
FFLopes 2:afdc5d6ca47f 82 @brief Counter for the amount of times that the measurement was taken on the hour
FFLopes 2:afdc5d6ca47f 83 */
FFLopes 2:afdc5d6ca47f 84 int hourCounter = 0;
FFLopes 2:afdc5d6ca47f 85 /**
FFLopes 2:afdc5d6ca47f 86 @brief Counter for the hours
eencae 1:6fc14cd8ccf1 87 */
FFLopes 2:afdc5d6ca47f 88 int hoursCounter = 0;
FFLopes 2:afdc5d6ca47f 89
FFLopes 2:afdc5d6ca47f 90 /**
FFLopes 2:afdc5d6ca47f 91 @brief values for initial the threshold temperatures
FFLopes 2:afdc5d6ca47f 92 */
FFLopes 2:afdc5d6ca47f 93 float maxTemp = 30;
FFLopes 2:afdc5d6ca47f 94 float minTemp = 10;
FFLopes 2:afdc5d6ca47f 95
FFLopes 2:afdc5d6ca47f 96 /**
FFLopes 2:afdc5d6ca47f 97 @brief This variable will track with the embed should show the temperature in celcius or farenheight and change the pressure as well
FFLopes 2:afdc5d6ca47f 98 */
FFLopes 2:afdc5d6ca47f 99 bool changeUnits=false;
FFLopes 2:afdc5d6ca47f 100
FFLopes 2:afdc5d6ca47f 101 /**
FFLopes 2:afdc5d6ca47f 102 @brief Variable to see if the lcd is on or not
FFLopes 2:afdc5d6ca47f 103 */
FFLopes 2:afdc5d6ca47f 104 bool isOn= false;
FFLopes 2:afdc5d6ca47f 105
FFLopes 2:afdc5d6ca47f 106 /**
FFLopes 2:afdc5d6ca47f 107 @brief Variable to track if the temperature threshold is going to be changed
FFLopes 2:afdc5d6ca47f 108 */
FFLopes 2:afdc5d6ca47f 109
FFLopes 2:afdc5d6ca47f 110 int option = dontChangeTemp;
FFLopes 2:afdc5d6ca47f 111
FFLopes 2:afdc5d6ca47f 112 /**
FFLopes 2:afdc5d6ca47f 113 @brief Struct variable that will store the value of the temperature and pressure, initiali the temperature is in celcis and the pressure in mbar
FFLopes 2:afdc5d6ca47f 114 */
FFLopes 2:afdc5d6ca47f 115
FFLopes 2:afdc5d6ca47f 116 Measurement measurement;
eencae 0:b85460bc73b9 117
FFLopes 2:afdc5d6ca47f 118 /**
FFLopes 2:afdc5d6ca47f 119 @brief This vector we will store the measurements of pressure over a minute
FFLopes 2:afdc5d6ca47f 120 */
FFLopes 2:afdc5d6ca47f 121 Measurement measurementMinute[60];
FFLopes 2:afdc5d6ca47f 122
FFLopes 2:afdc5d6ca47f 123 /**
FFLopes 2:afdc5d6ca47f 124 @brief This vector we will store the measurements of pressure over a hour
FFLopes 2:afdc5d6ca47f 125 */
FFLopes 2:afdc5d6ca47f 126 Measurement measurementHour[60];
FFLopes 2:afdc5d6ca47f 127
FFLopes 2:afdc5d6ca47f 128 /**
FFLopes 2:afdc5d6ca47f 129 @brief This vector we will store the measurements of pressure over four hours
FFLopes 2:afdc5d6ca47f 130 */
FFLopes 2:afdc5d6ca47f 131 Measurement measurementHours[4];
FFLopes 2:afdc5d6ca47f 132
FFLopes 2:afdc5d6ca47f 133 /**
FFLopes 2:afdc5d6ca47f 134 @brief Pins to conect the leds for the visual warmings
FFLopes 2:afdc5d6ca47f 135 */
FFLopes 2:afdc5d6ca47f 136 DigitalOut maxTempAlert (maxTempAlertPin);
FFLopes 2:afdc5d6ca47f 137 DigitalOut minTempAlert (minTempAlertPin);
FFLopes 2:afdc5d6ca47f 138
FFLopes 2:afdc5d6ca47f 139 /**
FFLopes 2:afdc5d6ca47f 140 @brief Buzzer to be fired when the temperature is not in the range defined by the thresholds
FFLopes 2:afdc5d6ca47f 141 */
FFLopes 2:afdc5d6ca47f 142 PwmOut buzzer(buzzerPin);
FFLopes 2:afdc5d6ca47f 143
FFLopes 2:afdc5d6ca47f 144 /**
FFLopes 2:afdc5d6ca47f 145 @brief Creating of the LCD Object
FFLopes 2:afdc5d6ca47f 146 */
FFLopes 2:afdc5d6ca47f 147 N5110 lcd(pwrPin, scePin, rstPin, dcPin, mosiPin, sclkPin, ledPin);
FFLopes 2:afdc5d6ca47f 148
FFLopes 2:afdc5d6ca47f 149 /**
FFLopes 2:afdc5d6ca47f 150 @brief main part of the project, the sensor
FFLopes 2:afdc5d6ca47f 151 */
FFLopes 2:afdc5d6ca47f 152 BMP180 sensor (sdaPin,sclPin);
eencae 0:b85460bc73b9 153
eencae 1:6fc14cd8ccf1 154 /**
FFLopes 2:afdc5d6ca47f 155 @brief Button to change units
FFLopes 2:afdc5d6ca47f 156 */
FFLopes 2:afdc5d6ca47f 157 InterruptIn unitsButton(changeUnitsPin);
FFLopes 2:afdc5d6ca47f 158
FFLopes 2:afdc5d6ca47f 159 /**
FFLopes 2:afdc5d6ca47f 160 @brief Button for Trheshold change
FFLopes 2:afdc5d6ca47f 161 */
FFLopes 2:afdc5d6ca47f 162 DigitalIn thresholdButton (trhesPinButton);
FFLopes 2:afdc5d6ca47f 163
FFLopes 2:afdc5d6ca47f 164 /**
FFLopes 2:afdc5d6ca47f 165 @brief Button to turn LCD on/off
FFLopes 2:afdc5d6ca47f 166 */
FFLopes 2:afdc5d6ca47f 167 DigitalIn LCDState(LCDStatePin);
FFLopes 2:afdc5d6ca47f 168
FFLopes 2:afdc5d6ca47f 169 /**
FFLopes 2:afdc5d6ca47f 170 @brief Button to turn logging on/off
FFLopes 2:afdc5d6ca47f 171 */
FFLopes 2:afdc5d6ca47f 172 DigitalIn logging(dataLoggingPin);
FFLopes 2:afdc5d6ca47f 173
FFLopes 2:afdc5d6ca47f 174 /**
FFLopes 2:afdc5d6ca47f 175 @brief Potentiometer read
FFLopes 2:afdc5d6ca47f 176 */
FFLopes 2:afdc5d6ca47f 177 AnalogIn pot (potentiometerPin);
FFLopes 2:afdc5d6ca47f 178
FFLopes 2:afdc5d6ca47f 179 /**
FFLopes 2:afdc5d6ca47f 180 @brief Local file system
FFLopes 2:afdc5d6ca47f 181 */
FFLopes 2:afdc5d6ca47f 182 LocalFileSystem local("file");
FFLopes 2:afdc5d6ca47f 183
FFLopes 2:afdc5d6ca47f 184 /**
FFLopes 2:afdc5d6ca47f 185 @brief serial interface
FFLopes 2:afdc5d6ca47f 186 */
FFLopes 2:afdc5d6ca47f 187 Serial serial(USBTX,USBRX);
FFLopes 2:afdc5d6ca47f 188
FFLopes 2:afdc5d6ca47f 189 /**
FFLopes 2:afdc5d6ca47f 190 @brief Ticker to get new temperature and pressure readings
FFLopes 2:afdc5d6ca47f 191 */
FFLopes 2:afdc5d6ca47f 192 Ticker readUpdates;
FFLopes 2:afdc5d6ca47f 193
FFLopes 2:afdc5d6ca47f 194 /**
FFLopes 2:afdc5d6ca47f 195 @brief Ticker to update the IO
FFLopes 2:afdc5d6ca47f 196 */
FFLopes 2:afdc5d6ca47f 197 Ticker iO;
FFLopes 2:afdc5d6ca47f 198
FFLopes 2:afdc5d6ca47f 199 /**
FFLopes 2:afdc5d6ca47f 200 @brief Interupt to enable the change on the values of the threshold
FFLopes 2:afdc5d6ca47f 201 */
FFLopes 2:afdc5d6ca47f 202 InterruptIn enableChange(trhesPinButton);
FFLopes 2:afdc5d6ca47f 203
FFLopes 2:afdc5d6ca47f 204 /**
FFLopes 2:afdc5d6ca47f 205 @brief String to be shown on the LCD
FFLopes 2:afdc5d6ca47f 206 */
FFLopes 2:afdc5d6ca47f 207 char buffer[14];
FFLopes 2:afdc5d6ca47f 208
FFLopes 2:afdc5d6ca47f 209 /**
FFLopes 2:afdc5d6ca47f 210 @brief contains the time string
FFLopes 2:afdc5d6ca47f 211 */
FFLopes 2:afdc5d6ca47f 212 char rxString[14];
FFLopes 2:afdc5d6ca47f 213 char date[14];
FFLopes 2:afdc5d6ca47f 214
FFLopes 2:afdc5d6ca47f 215 /**
FFLopes 2:afdc5d6ca47f 216 @brief function to update and check the IO
FFLopes 2:afdc5d6ca47f 217 */
FFLopes 2:afdc5d6ca47f 218 void ioUpdate();
FFLopes 2:afdc5d6ca47f 219 /**
FFLopes 2:afdc5d6ca47f 220 @brief function to change the date received to a format easily for a human to read
eencae 1:6fc14cd8ccf1 221 */
FFLopes 2:afdc5d6ca47f 222 void formatData();
FFLopes 2:afdc5d6ca47f 223
FFLopes 2:afdc5d6ca47f 224 /**
FFLopes 2:afdc5d6ca47f 225 @brief Function to be called to received the UNIX time when sent over the USB
FFLopes 2:afdc5d6ca47f 226 */
FFLopes 2:afdc5d6ca47f 227 void getTimeUpdate();
FFLopes 2:afdc5d6ca47f 228
FFLopes 2:afdc5d6ca47f 229 /**
FFLopes 2:afdc5d6ca47f 230 @brief This function gets the UNIX time received over the USB and store as an integer on the RAM memory
FFLopes 2:afdc5d6ca47f 231 */
FFLopes 2:afdc5d6ca47f 232 void setTime();
FFLopes 2:afdc5d6ca47f 233
FFLopes 2:afdc5d6ca47f 234 /**
FFLopes 2:afdc5d6ca47f 235 @brief Function to save power on the mbed by disabling the ethernet port
FFLopes 2:afdc5d6ca47f 236 */
FFLopes 2:afdc5d6ca47f 237 void powerSaving();
FFLopes 2:afdc5d6ca47f 238
FFLopes 2:afdc5d6ca47f 239 /**
FFLopes 2:afdc5d6ca47f 240 @brief this function reads the temperature and pressure value detected on the BMP180 sensor and store in the RAM memory
FFLopes 2:afdc5d6ca47f 241 */
FFLopes 2:afdc5d6ca47f 242 void getMeasurements();
FFLopes 2:afdc5d6ca47f 243
FFLopes 2:afdc5d6ca47f 244 /**
FFLopes 2:afdc5d6ca47f 245 @brief This function gets the temperature in celcius, pressure in mbar and the time formated and store in a .csv file
FFLopes 2:afdc5d6ca47f 246 */
FFLopes 2:afdc5d6ca47f 247 void writeOnFile();
FFLopes 2:afdc5d6ca47f 248
FFLopes 2:afdc5d6ca47f 249 /**
FFLopes 2:afdc5d6ca47f 250 @brief Function to check if the temperature is within the threshold defined, if not it call another function to alert the user.
FFLopes 2:afdc5d6ca47f 251 */
FFLopes 2:afdc5d6ca47f 252 void checkValues();
FFLopes 2:afdc5d6ca47f 253
FFLopes 2:afdc5d6ca47f 254 /**
FFLopes 2:afdc5d6ca47f 255 @brief Function to be called when the temperature is over the maximun defined threshold
FFLopes 2:afdc5d6ca47f 256 */
FFLopes 2:afdc5d6ca47f 257 void highTempAction();
FFLopes 2:afdc5d6ca47f 258
FFLopes 2:afdc5d6ca47f 259 /**
FFLopes 2:afdc5d6ca47f 260 @brief Function to be called in case the temperature is lower than the minimum defined threshold
FFLopes 2:afdc5d6ca47f 261 */
FFLopes 2:afdc5d6ca47f 262 void lowTempAction();
FFLopes 2:afdc5d6ca47f 263
FFLopes 2:afdc5d6ca47f 264 /**
FFLopes 2:afdc5d6ca47f 265 @brief If the temperature is within the define threshold this function is called
FFLopes 2:afdc5d6ca47f 266 */
FFLopes 2:afdc5d6ca47f 267 void normalTempAction();
FFLopes 2:afdc5d6ca47f 268
FFLopes 2:afdc5d6ca47f 269 /**
FFLopes 2:afdc5d6ca47f 270 @brief After the user decided to change the temperature threshold this function will see which of the threshold need to be changed and read the potentiomenter input
FFLopes 2:afdc5d6ca47f 271 @param option - option to which threshold is going to be changed
FFLopes 2:afdc5d6ca47f 272 */
FFLopes 2:afdc5d6ca47f 273 void changeThreshold(int op);
FFLopes 2:afdc5d6ca47f 274
FFLopes 2:afdc5d6ca47f 275 /**
FFLopes 2:afdc5d6ca47f 276 @brief Change the units shown in the LCD, from celcius to farenheight and from mbar to atm
FFLopes 2:afdc5d6ca47f 277 */
FFLopes 2:afdc5d6ca47f 278 void unitsChanger();
FFLopes 2:afdc5d6ca47f 279
FFLopes 2:afdc5d6ca47f 280 /**
FFLopes 2:afdc5d6ca47f 281 @brief function to start the change of the threshold
FFLopes 2:afdc5d6ca47f 282 */
FFLopes 2:afdc5d6ca47f 283 void enableThresChange();
FFLopes 2:afdc5d6ca47f 284
FFLopes 2:afdc5d6ca47f 285 /**
FFLopes 2:afdc5d6ca47f 286 @brief this function will store the measurements taken every second up to 4 hours, take the average of the readings and call the function to make the weather predictions
FFLopes 2:afdc5d6ca47f 287 */
FFLopes 2:afdc5d6ca47f 288 void storeMeasurement();
FFLopes 2:afdc5d6ca47f 289
FFLopes 2:afdc5d6ca47f 290 /**
FFLopes 2:afdc5d6ca47f 291 @brief based on the values stored and their average this function will make a basic weather prediction
FFLopes 2:afdc5d6ca47f 292 */
FFLopes 2:afdc5d6ca47f 293 void makePrediction();
eencae 0:b85460bc73b9 294
eencae 0:b85460bc73b9 295 #endif