
Simple Weather Station. Data Logger and gives primitive weather predictions.
Dependencies: BMP180 N5110 PowerControl beep mbed
Revision 5:cae171557246, committed 2015-05-09
- Comitter:
- el13nsp
- Date:
- Sat May 09 15:10:14 2015 +0000
- Parent:
- 4:1fc40db4c19c
- Child:
- 6:7271c1e8e348
- Commit message:
- Main.h added and doxygen used to document code.; Code refined.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
main.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon May 04 21:20:17 2015 +0000 +++ b/main.cpp Sat May 09 15:10:14 2015 +0000 @@ -1,59 +1,11 @@ -#include "mbed.h" -#include "N5110.h" -#include "BMP180.h" -#include "beep.h" -#include "PowerControl/PowerControl.h" -#include "PowerControl/EthernetPowerControl.h" - -#define USR_POWERDOWN (0x104) - -#define celcius 0 -#define fahrenheit 1 - -int semihost_powerdown() -{ - uint32_t arg; - return __semihost(USR_POWERDOWN, &arg); -} - -BMP180 bmp180(p28,p27); // SDA, SCL - -BusOut leds(LED4,LED3,LED2,LED1); // on-boards LEDs for visual feedback - -LocalFileSystem local("local"); // create local filesystem - -AnalogIn POT1(p20); - -DigitalIn logSwitch(p21); +/** +@file main.cpp + +@brief Program implementation + +*/ -DigitalOut redled(p25); -DigitalOut greenled(p24); - -Beep buzzer(p22); - -Ticker timer; -Ticker stateTimer; -Ticker alarmTimer; -Ticker writingTimer; -Ticker graphTimer; - -int timerFlag=0; -int stateTimerFlag=0; -int alarmTimerFlag=0; -int writingTimerFlag=0; -int graphTimerFlag=0; -int setTimeFlag = 0; // flag for ISR -int buttonAFlag = 0; //initialize flag A -int buttonBFlag = 0; //initialize flag B -int buttonCFlag = 0; //initialize flag C -int initFlag = 0; - -int alarm = 0; // Initially no alarm will sound; -int state = 0; // State for weather prediction -int prediction = 0; // Flag to see if prediction is possible or not -int i = 0; -int j = 0; -int unit = celcius; // Initially unit is celcius +#include "main.h" // Interrupt Service Routine void timerExpired() @@ -80,29 +32,6 @@ graphTimerFlag = 1; } -InterruptIn buttonA(p15); -InterruptIn buttonB(p18); -InterruptIn buttonC(p17); -InterruptIn buttonD(p16); - -Serial serial(USBTX,USBRX); - -void serialISR(); // ISR that is called when serial data is received -void setTime(); // function to set the UNIX time -void setState(); // Function that checks the state for weather prediction -void writeDataToFile(float temp,float press,char* time); - -char rxString[16]; // buffer to store received string for time - -// VCC,SCE,RST,D/C,MOSI,SCLK,LED -N5110 lcd(p7,p8,p9,p10,p11,p13,p26); -// Can also power (VCC) directly from VOUT (3.3 V) - -// Can give better performance due to current limitation from GPIO pin - -float temparray[84]; //Array to hold temperature readings -float pressarray[84]; //Array to hold pressure readings -float presscompare[12]; - //Interrupt service routine void buttonAPressed() { @@ -131,14 +60,6 @@ unit = !unit; } -void sunny(); -void cloudySun(); -void clouds(); -void rainy(); -void stormy(); - - - int main() { @@ -158,7 +79,7 @@ //set_time(0); // initialise time to 1st January 1970 PHY_PowerDown(); - int result = semihost_powerdown(); + //int result = semihost_powerdown(); buttonB.mode(PullUp); buttonC.mode(PullUp); @@ -337,14 +258,14 @@ } - if(writingTimerFlag) { + if(writingTimerFlag) { // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< writingTimerFlag = 0; // read values (T in Celsius and P in mb) and print over serial port measurement = bmp180.readValues(); - if(logSwitch) { + if(logSwitch) { // If data logging switch is turned ON writeDataToFile(measurement.temperature, measurement.pressure, timebuffer); // write current value to disk } @@ -605,10 +526,8 @@ { greenled = 1; // turn on LEDs for feedback FILE *fp = fopen("/local/Datalog.csv", "a"); // open 'log.txt' for appending -// if the file doesn't exist it is created, if it exists, data is appended to the end + // if the file doesn't exist it is created, if it exists, data is appended to the end fprintf(fp,"T = %f C, P = %f mb, Time = %s\n",temp, press, time); // print string to file fclose(fp); // close file greenled = 0; // turn off LEDs to signify file access has finished } - -//Need to add weather predictions, weather warning, data logging and other power saving features \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.h Sat May 09 15:10:14 2015 +0000 @@ -0,0 +1,184 @@ +/** +@file main.h +@brief Header file containing functions prototypes, defines and global variables. +@brief Revision 1.0. +@author Nikhil Suresh Pillai +@date May 2015 +*/ + +#ifndef MAIN_H +#define MAIN_H + +#include "mbed.h" +#include "N5110.h" +#include "BMP180.h" +#include "beep.h" +#include "PowerControl/PowerControl.h" +#include "PowerControl/EthernetPowerControl.h" + +#define celcius 0 +#define fahrenheit 1 + +/** +@namespace bmp180 +@brief I2C Bus for barometric pressure sensor chip's SDA and SCL +*/ +BMP180 bmp180(p28,p27); + +/** +@namespace leds +@brief GPIO bus output for onboard status leds +*/ +BusOut leds(LED4,LED3,LED2,LED1); + +/** +@namespace local +@brief Create local filesystem +*/ +LocalFileSystem local("local"); + +/** +@namespace POT1 +@brief Analog GPIO for potentiometer +*/ +AnalogIn POT1(p20); + +/** +@namespace logSwitch +@brief GPIO for logging switch +*/ +DigitalIn logSwitch(p21); + +/** +@namespace redled +@brief GPIO for warning led +*/ +DigitalOut redled(p25); + +/** +@namespace greenled +@brief GPIO for logging status led +*/ +DigitalOut greenled(p24); + +/** +@namespace buzzer +@brief GPIO for warning buzzer +*/ +Beep buzzer(p22); + +/** +@namespace buttonA +@brief GPIO for temperature graph button A +*/ +InterruptIn buttonA(p15); + +/** +@namespace buttonB +@brief GPIO for pressure graph button B +*/ +InterruptIn buttonB(p18); + +/** +@namespace buttonC +@brief GPIO for weather prediction button C +*/ +InterruptIn buttonC(p17); + +/** +@namespace buttonD +@brief GPIO for unit change button D +*/ +InterruptIn buttonD(p16); + +/** +@namespace lcd +@brief GPIO for LCD display +*/ +N5110 lcd(p7,p8,p9,p10,p11,p13,p26); + +/** +@namespace serial +@brief GPIO for serial reading and writing +*/ +Serial serial(USBTX,USBRX); + +Ticker timer; /*!< timer Ticker initialised */ +Ticker stateTimer; /*!< state timer Ticker initialised */ +Ticker alarmTimer; /*!< alarm timer Ticker initialised */ +Ticker writingTimer; /*!< writing timer Ticker initialised */ +Ticker graphTimer; /*!< graph timer Ticker initialised */ + +int timerFlag=0; /*!< timer flag set in ISR */ +int stateTimerFlag=0; /*!< state timer flag set in ISR */ +int alarmTimerFlag=0; /*!< alarm timer flag set in ISR */ +int writingTimerFlag=0; /*!< writing timer flag set in ISR */ +int graphTimerFlag=0; /*!< graph timer flag set in ISR */ +int setTimeFlag = 0; /*!< set time flag set in ISR */ +int buttonAFlag = 0; /*!< button A flag set in ISR */ +int buttonBFlag = 0; /*!< button B flag set in ISR */ +int buttonCFlag = 0; /*!< button C flag set in ISR */ +int initFlag = 0; /*!< init flag set in ISR */ + +int alarm = 0; /*!< alarm flag set in ISR */ +int state = 0; /*!< state flag set in ISR */ +int prediction = 0; /*!< prediction flag set in ISR */ +int i = 0; /*!< Initialise increment variable i */ +int j = 0; /*!< Initialise increment variable j*/ +int unit = celcius; /*!< unit flag set in ISR */ + +char rxString[16]; /*!< buffer to store received string for time */ + +float temparray[84]; /*!< Array to hold temperature readings */ +float pressarray[84]; /*!< Array to hold pressure readings */ +float presscompare[12]; /*!< Array to hold pressure readings for prediction*/ + +/** +ISR that is called when serial data is received +*/ +void serialISR(); + +/** +Sets the UNIX time +*/ +void setTime(); + +/** +Checks the state for weather prediction +*/ +void setState(); + +/** +Logs data to csv file on the flash memory +@param temp - Temperature to log +@param press - Pressure to log +@param time - Time to log +*/ +void writeDataToFile(float temp,float press,char* time); + +/** +Sets pixels to display sunny weather +*/ +void sunny(); + +/** +Sets pixels to display mild cloudy weather +*/ +void cloudySun(); + +/** +Sets pixels to display cloudy weather +*/ +void clouds(); + +/** +Sets pixels to display rainy weather +*/ +void rainy(); + +/** +Sets pixels to display stormy weather +*/ +void stormy(); + +#endif \ No newline at end of file