all working version 2.0

Dependencies:   ADS1115 BME280 CronoDot SDFileSystem mbed

Fork of Outdoor_UPAS_v1_2_powerfunction by scott kelleher

Committer:
caseyquinn
Date:
Mon Feb 29 20:43:07 2016 +0000
Revision:
5:c3252e5d45ca
Parent:
4:5d004fd997d5
Child:
6:a738dcd53bf8
Changed RN4677 pins to D8 and D2 to match what Jake had previously and try to troubleshoot app issues first, then will need to address the potential pin conflict from nucleo pinout and the tboard pinout assignments.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jelord 0:2cb2b2ea316f 1 #include "mbed.h"
jelord 2:88fcbfadec6a 2 #include "SDFileSystem.h"
jelord 2:88fcbfadec6a 3 #include "Adafruit_ADS1015.h"
jelord 2:88fcbfadec6a 4 #include "MCP40D17.h"
jelord 2:88fcbfadec6a 5 #include "STC3100.h"
jelord 2:88fcbfadec6a 6 #include "LSM303.h"
jelord 2:88fcbfadec6a 7 #include "BME280.h"
jelord 2:88fcbfadec6a 8 #include "SI1145.h"
jelord 2:88fcbfadec6a 9 #include "NCP5623BMUTBG.h"
jelord 2:88fcbfadec6a 10 #include "CronoDot.h"
jelord 2:88fcbfadec6a 11 #include "EEPROM.h"
jelord 2:88fcbfadec6a 12 #include "Calibration.h"
caseyquinn 4:5d004fd997d5 13 //Serial pc(USBTX, USBRX);
caseyquinn 5:c3252e5d45ca 14 //Serial microChannel(D0, D1); // tx, rx Appears there is a conflict in the mbed code (possibly already assigned to SERIAL_TX, SERIAL_RX, USBTX, USBRX need to reassign these values)
caseyquinn 5:c3252e5d45ca 15 // However still an issue with the BLE not reading the EEPROM with the old pin assignments Jake had.
caseyquinn 5:c3252e5d45ca 16 Serial microChannel(D8, D2); // tx, rx
jelord 1:9fbb5b665068 17 Timer t;
jelord 1:9fbb5b665068 18 struct tm tt;
jelord 0:2cb2b2ea316f 19
jelord 2:88fcbfadec6a 20 I2C i2c(D14, D15);
jelord 2:88fcbfadec6a 21 Adafruit_ADS1115 ads(&i2c);
jelord 2:88fcbfadec6a 22 MCP40D17 DigPot(&i2c);
jelord 2:88fcbfadec6a 23 BME280 bmesensor(D14, D15);
jelord 2:88fcbfadec6a 24 STC3100 gasG(D14, D15);
caseyquinn 5:c3252e5d45ca 25 //DigitalOut blower(D8, 0);
caseyquinn 4:5d004fd997d5 26 DigitalOut pbKill(PC_12, 1);
caseyquinn 4:5d004fd997d5 27 DigitalOut bleRTS(PB_14, 0);
caseyquinn 4:5d004fd997d5 28 DigitalOut bleCTS(PB_13, 0);
jelord 2:88fcbfadec6a 29 LSM303 movementsensor(D14, D15);
jelord 2:88fcbfadec6a 30 SI1145 lightsensor(D14, D15);
jelord 2:88fcbfadec6a 31 NCP5623BMUTBG RGB_LED(D14, D15);
jelord 3:122bfc998c4c 32 CronoDot RTC_UPAS(D14, D15);
jelord 2:88fcbfadec6a 33 EEPROM E2PROM(D14, D15);
jelord 2:88fcbfadec6a 34 //DigitalOut GPS_EN(p4,0); //pin 4 is used to enable and disable the GPS, in order to recive serial communications
jelord 2:88fcbfadec6a 35 Calibration calibrations(1); //Default serial/calibration if there are no values for the selected option
jelord 0:2cb2b2ea316f 36
jelord 3:122bfc998c4c 37 Timeout stop; //This is the stop call back object
jelord 3:122bfc998c4c 38 Timeout logg; //This is the logging call back object
jelord 3:122bfc998c4c 39
jelord 3:122bfc998c4c 40 uint16_t serial_num = 1; // Default serial/calibration number
jelord 3:122bfc998c4c 41 int RunReady =0;
jelord 3:122bfc998c4c 42
caseyquinn 4:5d004fd997d5 43 struct tm STtime;
caseyquinn 4:5d004fd997d5 44
caseyquinn 4:5d004fd997d5 45
jelord 3:122bfc998c4c 46
jelord 3:122bfc998c4c 47 float press = 1.1;
jelord 3:122bfc998c4c 48 float temp = 75.5;
jelord 3:122bfc998c4c 49 float rh = 12.1;
jelord 3:122bfc998c4c 50
jelord 3:122bfc998c4c 51 int uv = 8;
jelord 3:122bfc998c4c 52 int vis = 7;
jelord 3:122bfc998c4c 53 int ir = 6;
jelord 3:122bfc998c4c 54
jelord 3:122bfc998c4c 55 float compass = 0.1;
jelord 3:122bfc998c4c 56 float accel_x = 0.2;
jelord 3:122bfc998c4c 57 float accel_y = 0.3;
jelord 3:122bfc998c4c 58 float accel_z = 0.4;
jelord 3:122bfc998c4c 59 float accel_comp = 0.5;
jelord 3:122bfc998c4c 60 float angle_x = 0.6;
jelord 3:122bfc998c4c 61 float angle_y = 0.7;
jelord 3:122bfc998c4c 62 float angle_z = 0.8;
jelord 3:122bfc998c4c 63 float mag_x = 0.9;
jelord 3:122bfc998c4c 64 float mag_y = 1.0;
jelord 3:122bfc998c4c 65 float mag_z = 1.2;
jelord 3:122bfc998c4c 66
jelord 3:122bfc998c4c 67 int vInReading = 18;
jelord 3:122bfc998c4c 68 int vBlowerReading = 19;
jelord 3:122bfc998c4c 69 int omronDiff = 20;
jelord 3:122bfc998c4c 70 float omronVolt = 1.2; //V
jelord 3:122bfc998c4c 71 int omronReading = 100;
jelord 3:122bfc998c4c 72 float atmoRho = 1.5; //g/L
jelord 3:122bfc998c4c 73
jelord 3:122bfc998c4c 74 float massflow = 87.6; //g/min
jelord 3:122bfc998c4c 75 float volflow = 88.8; //L/min
jelord 3:122bfc998c4c 76 float volflowSet = 1.0; //L/min
jelord 3:122bfc998c4c 77 int logInerval = 10; //seconds
jelord 3:122bfc998c4c 78 double secondsD = 0;
jelord 3:122bfc998c4c 79 double lastsecondD = 0;
jelord 3:122bfc998c4c 80 float massflowSet = 19.2;
jelord 3:122bfc998c4c 81 float deltaVflow = 0.0;
jelord 3:122bfc998c4c 82 float deltaMflow = 0.0;
jelord 3:122bfc998c4c 83 float gainFlow = 98.1;
jelord 3:122bfc998c4c 84 float sampledVol = 2.0; //L, total sampled volume
jelord 3:122bfc998c4c 85
jelord 3:122bfc998c4c 86 int digital_pot_setpoint = 5 ; //min = 0x7F, max = 0x00
jelord 3:122bfc998c4c 87 int digital_pot_set = 6;
jelord 3:122bfc998c4c 88 int digital_pot_change = 7;
jelord 3:122bfc998c4c 89 int digitalpotMax = 127;
jelord 3:122bfc998c4c 90 int digitalpotMin = 2;
jelord 3:122bfc998c4c 91
jelord 3:122bfc998c4c 92 int dutyUp = 4;
jelord 3:122bfc998c4c 93 int dutyDown = 3;
jelord 3:122bfc998c4c 94
jelord 3:122bfc998c4c 95 // variables are only place holders for the US_Menu //
jelord 3:122bfc998c4c 96 int refreshtime = 6;
jelord 3:122bfc998c4c 97 float home_lat, home_lon, work_lat, work_lon;
jelord 3:122bfc998c4c 98 //*************************************************//
jelord 3:122bfc998c4c 99
jelord 3:122bfc998c4c 100 //int refresh_Time = 10; // refresh time in s, note calling read_GPS()(or similar) will still take how ever long it needs(hopefully < 1s)
jelord 3:122bfc998c4c 101
jelord 3:122bfc998c4c 102 char filename[] = "/sd/XXXX0000LOG000000000000---------------.txt";
jelord 3:122bfc998c4c 103
caseyquinn 4:5d004fd997d5 104 SDFileSystem sd(D4, D5, D3, D10, "sd"); // I believe this matches Todd's pinout, let me know if this doesn't work. (MOSI, MISO, SCK, SEL)
jelord 3:122bfc998c4c 105
jelord 2:88fcbfadec6a 106 void sendData();
jelord 2:88fcbfadec6a 107
jelord 3:122bfc998c4c 108 //int timeout = 2;
jelord 2:88fcbfadec6a 109
jelord 3:122bfc998c4c 110 //void pc_recv(void){
jelord 3:122bfc998c4c 111 // while(pc.readable()){
jelord 3:122bfc998c4c 112 // pc.getc();
jelord 3:122bfc998c4c 113 // }
jelord 3:122bfc998c4c 114 //}
jelord 0:2cb2b2ea316f 115
jelord 0:2cb2b2ea316f 116 static uint8_t rx_buf[20];
jelord 0:2cb2b2ea316f 117 static uint8_t rx_len=0;
jelord 1:9fbb5b665068 118 static int haltBLE = 1;
jelord 1:9fbb5b665068 119 static int transmissionValue = 0;
jelord 2:88fcbfadec6a 120 uint8_t writeData[20] = {0,};
jelord 2:88fcbfadec6a 121 static uint8_t dataLength = 0;
jelord 3:122bfc998c4c 122 static int runReady = 0;
jelord 3:122bfc998c4c 123 static uint8_t startAndEndTime[12] = {0,};
caseyquinn 5:c3252e5d45ca 124
jelord 0:2cb2b2ea316f 125 void uartMicro(void){
jelord 3:122bfc998c4c 126 if(runReady!=1){
jelord 3:122bfc998c4c 127 haltBLE = 2;
jelord 3:122bfc998c4c 128 while(microChannel.readable()){
jelord 3:122bfc998c4c 129 rx_buf[rx_len++] = microChannel.getc();
jelord 2:88fcbfadec6a 130
jelord 3:122bfc998c4c 131 //Code block to verify what is being transmitted. To function correctly, all data must terminate with \0 or \n
jelord 3:122bfc998c4c 132 if(transmissionValue==0){
jelord 3:122bfc998c4c 133
caseyquinn 4:5d004fd997d5 134 if (rx_buf[0] == 0x01)transmissionValue = 1; //rtc
jelord 3:122bfc998c4c 135 else if(rx_buf[0] == 0x02)transmissionValue = 2; //sample start and end times
jelord 3:122bfc998c4c 136 else if(rx_buf[0] == 0x03)transmissionValue = 3; //sample name
jelord 3:122bfc998c4c 137 else if(rx_buf[0] == 0x04)transmissionValue = 4; //Send Data Check
jelord 3:122bfc998c4c 138
jelord 3:122bfc998c4c 139 else if(rx_buf[0] == 0x05)transmissionValue = 5; //log interval
jelord 3:122bfc998c4c 140 else if(rx_buf[0] == 0x06)transmissionValue = 6; //Flow Rate
jelord 3:122bfc998c4c 141 else if(rx_buf[0] == 0x07)transmissionValue = 7; //Serial Number
jelord 3:122bfc998c4c 142 else if(rx_buf[0] == 0x08)transmissionValue = 8; //Run Enable
jelord 3:122bfc998c4c 143 else transmissionValue = 100; //Not useful data
jelord 3:122bfc998c4c 144 }
jelord 3:122bfc998c4c 145
jelord 3:122bfc998c4c 146 if(rx_buf[rx_len-1]=='\0' || rx_buf[rx_len-1]=='\n' || rx_buf[rx_len-1] == 0xff){
jelord 3:122bfc998c4c 147 if((transmissionValue == 1 || transmissionValue == 2 || transmissionValue == 3 || transmissionValue == 4 || transmissionValue == 5 ||
jelord 3:122bfc998c4c 148 transmissionValue == 6 || transmissionValue == 7) && rx_buf[rx_len-1] != 0xff)
jelord 3:122bfc998c4c 149 {}else{
jelord 3:122bfc998c4c 150 if(transmissionValue == 4 ) sendData();
jelord 3:122bfc998c4c 151 if(transmissionValue == 8){
jelord 3:122bfc998c4c 152 runReady = 1;
jelord 3:122bfc998c4c 153 microChannel.attach(NULL,microChannel.RxIrq);
jelord 3:122bfc998c4c 154 }
jelord 3:122bfc998c4c 155 haltBLE = 1;
jelord 3:122bfc998c4c 156 transmissionValue = 0;
jelord 3:122bfc998c4c 157 dataLength = 0;
jelord 2:88fcbfadec6a 158
jelord 3:122bfc998c4c 159 }
jelord 2:88fcbfadec6a 160 }
jelord 1:9fbb5b665068 161 }
jelord 3:122bfc998c4c 162 if(haltBLE!=1){
jelord 2:88fcbfadec6a 163
jelord 3:122bfc998c4c 164 if((transmissionValue!=100) && (dataLength!= 0)) writeData[dataLength-1] = rx_buf[0];
jelord 3:122bfc998c4c 165
jelord 3:122bfc998c4c 166 if(transmissionValue ==100){
jelord 3:122bfc998c4c 167 //pc.putc(rx_buf[0]);
jelord 2:88fcbfadec6a 168
jelord 3:122bfc998c4c 169 }else if(transmissionValue ==1){ //process and store RTC values
jelord 3:122bfc998c4c 170
jelord 3:122bfc998c4c 171 if(dataLength==6)RTC_UPAS.set_time(writeData[0],writeData[1],writeData[2],writeData[3],writeData[3],writeData[4],writeData[5]);
jelord 3:122bfc998c4c 172
jelord 3:122bfc998c4c 173 }else if(transmissionValue ==2){ //process and store sample start/end
jelord 3:122bfc998c4c 174 if(dataLength ==12)E2PROM.write(0x00015, writeData, 12);
jelord 3:122bfc998c4c 175
jelord 3:122bfc998c4c 176 }else if(transmissionValue ==3){ //process and store sample name
jelord 3:122bfc998c4c 177 if(dataLength ==8)E2PROM.write(0x00001,writeData,8);
jelord 3:122bfc998c4c 178
jelord 3:122bfc998c4c 179 }else if(transmissionValue ==5){ //process and store Log Interval
jelord 3:122bfc998c4c 180 if(dataLength ==1)E2PROM.write(0x00014,writeData,1);
jelord 2:88fcbfadec6a 181
jelord 3:122bfc998c4c 182 }else if(transmissionValue ==6){ //process and store Flow Rate
jelord 3:122bfc998c4c 183 if(dataLength ==4)E2PROM.write(0x00010,writeData,4);
jelord 3:122bfc998c4c 184
jelord 3:122bfc998c4c 185 }else if(transmissionValue ==7){ //process and store Serial Number
jelord 3:122bfc998c4c 186 if(dataLength ==2)E2PROM.write(0x00034,writeData,2);
jelord 3:122bfc998c4c 187 }
jelord 3:122bfc998c4c 188 dataLength++;
jelord 1:9fbb5b665068 189 }
jelord 3:122bfc998c4c 190
jelord 3:122bfc998c4c 191 rx_len = 0;
jelord 3:122bfc998c4c 192 }else{
jelord 3:122bfc998c4c 193 while(microChannel.readable())
jelord 3:122bfc998c4c 194 uint8_t extract = microChannel.getc();
jelord 3:122bfc998c4c 195 }
jelord 2:88fcbfadec6a 196
jelord 2:88fcbfadec6a 197 }
jelord 2:88fcbfadec6a 198 void sendData(){
jelord 2:88fcbfadec6a 199
jelord 2:88fcbfadec6a 200 uint8_t sampleTimePassValues[13] = {0x01,};
jelord 2:88fcbfadec6a 201 uint8_t subjectLabelOriginal[9] = {0x02,};
jelord 2:88fcbfadec6a 202 uint8_t dataLogOriginal[2] = {0x03,};
jelord 2:88fcbfadec6a 203 uint8_t flowRateOriginal[5] = {0x04,};
jelord 2:88fcbfadec6a 204 //uint8_t presetRunModeCheck[1] = {0,}; Commented and currently unused to prevent mem issues
jelord 2:88fcbfadec6a 205 E2PROM.read(0x00015, sampleTimePassValues+1, 12);
jelord 2:88fcbfadec6a 206 E2PROM.read(0x00001, subjectLabelOriginal+1,8);
jelord 2:88fcbfadec6a 207 E2PROM.read(0x00014,dataLogOriginal+1,1);
jelord 2:88fcbfadec6a 208 E2PROM.read(0x00010,flowRateOriginal+1,4);
jelord 2:88fcbfadec6a 209
jelord 2:88fcbfadec6a 210 for(int i=0; i<13; i++){
jelord 2:88fcbfadec6a 211 microChannel.putc(sampleTimePassValues[i]);
jelord 2:88fcbfadec6a 212 }
jelord 2:88fcbfadec6a 213 wait(.25);
jelord 2:88fcbfadec6a 214
jelord 2:88fcbfadec6a 215 for(int i=0; i<9; i++){
jelord 2:88fcbfadec6a 216 microChannel.putc(subjectLabelOriginal[i]);
jelord 2:88fcbfadec6a 217 }
jelord 2:88fcbfadec6a 218 wait(.25);
jelord 2:88fcbfadec6a 219
jelord 2:88fcbfadec6a 220 for(int i=0; i<2; i++){
jelord 2:88fcbfadec6a 221 microChannel.putc(dataLogOriginal[i]);
jelord 2:88fcbfadec6a 222 }
jelord 2:88fcbfadec6a 223 wait(.25);
jelord 2:88fcbfadec6a 224
jelord 2:88fcbfadec6a 225 for(int i=0; i<5; i++){
jelord 2:88fcbfadec6a 226 microChannel.putc(flowRateOriginal[i]);
jelord 2:88fcbfadec6a 227 }
jelord 0:2cb2b2ea316f 228
jelord 2:88fcbfadec6a 229
jelord 2:88fcbfadec6a 230 }
caseyquinn 5:c3252e5d45ca 231
jelord 3:122bfc998c4c 232 void check_stop() // this checks if it's time to stop and shutdown
jelord 3:122bfc998c4c 233 {
jelord 3:122bfc998c4c 234
jelord 3:122bfc998c4c 235 if(RTC_UPAS.compare(startAndEndTime[6], startAndEndTime[7], startAndEndTime[8], startAndEndTime[9], startAndEndTime[10], startAndEndTime[11])) {
jelord 3:122bfc998c4c 236 pbKill = 0; // this is were we shut everything down
caseyquinn 4:5d004fd997d5 237 //pc.printf("If you're reading this something has gone very wrong.");
jelord 3:122bfc998c4c 238 }
jelord 3:122bfc998c4c 239 stop.detach();
jelord 3:122bfc998c4c 240 stop.attach(&check_stop, 9);
jelord 3:122bfc998c4c 241
jelord 3:122bfc998c4c 242 }
caseyquinn 5:c3252e5d45ca 243
jelord 3:122bfc998c4c 244
jelord 3:122bfc998c4c 245 void log_data()
jelord 3:122bfc998c4c 246 {
jelord 3:122bfc998c4c 247
jelord 3:122bfc998c4c 248
jelord 3:122bfc998c4c 249
jelord 3:122bfc998c4c 250 }
jelord 1:9fbb5b665068 251
jelord 1:9fbb5b665068 252 int main(){
caseyquinn 4:5d004fd997d5 253 RGB_LED.set_led(1,1,1);
caseyquinn 4:5d004fd997d5 254 STtime.tm_sec = 10; // 0-59
caseyquinn 4:5d004fd997d5 255 STtime.tm_min = 38; // 0-59
caseyquinn 4:5d004fd997d5 256 STtime.tm_hour = 15; // 0-23
caseyquinn 4:5d004fd997d5 257 STtime.tm_mday = 26; // 1-31
caseyquinn 4:5d004fd997d5 258 STtime.tm_mon = 1; // 0-11
caseyquinn 4:5d004fd997d5 259 STtime.tm_year = 116; // year since 1900
caseyquinn 4:5d004fd997d5 260 time_t STseconds = mktime(&STtime);
caseyquinn 4:5d004fd997d5 261 set_time(STseconds); // Set RTC time to 16 December 2013 10:05:23 UTC
caseyquinn 4:5d004fd997d5 262 char timestr[32];
caseyquinn 4:5d004fd997d5 263 //wait(10);
caseyquinn 4:5d004fd997d5 264 RGB_LED.set_led(0,0,1);
caseyquinn 4:5d004fd997d5 265 //pc.baud(115200); // set what you want here depending on your terminal program speed
caseyquinn 4:5d004fd997d5 266 //pc.printf("\f\n\r-------------Startup-------------\n\r");
jelord 1:9fbb5b665068 267 wait(0.5);
jelord 3:122bfc998c4c 268 //timeout=2;
caseyquinn 5:c3252e5d45ca 269
jelord 3:122bfc998c4c 270 uint8_t serialNumberAndType[6] = {0x50,0x53};
jelord 3:122bfc998c4c 271 E2PROM.read(0x00034,serialNumberAndType+2,2);
caseyquinn 4:5d004fd997d5 272
jelord 3:122bfc998c4c 273 int tempSerialNum = serialNumberAndType[2]+serialNumberAndType[3];
jelord 3:122bfc998c4c 274 int serialNumDigits[4];
jelord 3:122bfc998c4c 275 serialNumDigits[0] = tempSerialNum / 1000 % 10;
jelord 3:122bfc998c4c 276 serialNumDigits[1] = tempSerialNum / 100 % 10;
jelord 3:122bfc998c4c 277 serialNumDigits[2] = tempSerialNum / 10 % 10;
jelord 3:122bfc998c4c 278 serialNumDigits[3] = tempSerialNum % 10;
jelord 3:122bfc998c4c 279
jelord 3:122bfc998c4c 280 serialNumberAndType[2] = serialNumDigits[0]+48;
jelord 3:122bfc998c4c 281 serialNumberAndType[3] = serialNumDigits[1]+48;
jelord 3:122bfc998c4c 282 serialNumberAndType[4] = serialNumDigits[2]+48;
jelord 3:122bfc998c4c 283 serialNumberAndType[5] = serialNumDigits[3]+48;
caseyquinn 5:c3252e5d45ca 284 RGB_LED.set_led(0,1,0);
jelord 3:122bfc998c4c 285 //pc.attach(pc_recv);
jelord 1:9fbb5b665068 286 microChannel.attach(uartMicro,microChannel.RxIrq);
jelord 3:122bfc998c4c 287 microChannel.baud(115200);
caseyquinn 5:c3252e5d45ca 288 RGB_LED.set_led(1,0,0);
jelord 1:9fbb5b665068 289 microChannel.printf("$$$");
jelord 3:122bfc998c4c 290 wait(0.5);
jelord 3:122bfc998c4c 291 microChannel.printf("SN,");
jelord 3:122bfc998c4c 292 for(int i=0;i<6;i++)microChannel.putc(serialNumberAndType[i]);
jelord 3:122bfc998c4c 293 microChannel.printf("\r");
jelord 3:122bfc998c4c 294 wait(0.5);
jelord 1:9fbb5b665068 295 microChannel.printf("A\r");
jelord 3:122bfc998c4c 296 wait(0.5);
jelord 2:88fcbfadec6a 297 microChannel.printf("---\r");
jelord 3:122bfc998c4c 298 wait(0.5);
jelord 2:88fcbfadec6a 299
jelord 2:88fcbfadec6a 300
caseyquinn 4:5d004fd997d5 301
jelord 2:88fcbfadec6a 302
jelord 2:88fcbfadec6a 303 RGB_LED.set_led(1,1,1);
jelord 3:122bfc998c4c 304 while(runReady!=1) {
jelord 3:122bfc998c4c 305 wait(1);
jelord 3:122bfc998c4c 306 //pc.printf("Waiting for BLE instruction");
jelord 3:122bfc998c4c 307
jelord 3:122bfc998c4c 308 }
jelord 3:122bfc998c4c 309
jelord 3:122bfc998c4c 310
jelord 3:122bfc998c4c 311 //wait(1);
jelord 3:122bfc998c4c 312
jelord 3:122bfc998c4c 313 E2PROM.read(0x00015, startAndEndTime, 12); //Grab start and end times from EEPROM
jelord 3:122bfc998c4c 314 RGB_LED.set_led(0,1,0);
jelord 3:122bfc998c4c 315 while(!RTC_UPAS.compare(startAndEndTime[0], startAndEndTime[1], startAndEndTime[2], startAndEndTime[3], startAndEndTime[4], startAndEndTime[5])) { // this while waits for the start time by looping until the start time
jelord 3:122bfc998c4c 316 wait(0.5);
jelord 3:122bfc998c4c 317
jelord 3:122bfc998c4c 318 RTC_UPAS.get_time();
jelord 3:122bfc998c4c 319
jelord 3:122bfc998c4c 320 }
jelord 3:122bfc998c4c 321
jelord 3:122bfc998c4c 322
jelord 3:122bfc998c4c 323 //Get the proper serial number
jelord 3:122bfc998c4c 324 uint8_t serialBytes[2] = {0,};
jelord 3:122bfc998c4c 325 E2PROM.read(0x00034, serialBytes,2);
jelord 3:122bfc998c4c 326 serial_num = ((uint16_t)serialBytes[1] << 8) | serialBytes[0];
jelord 3:122bfc998c4c 327 calibrations.initialize(serial_num);
jelord 3:122bfc998c4c 328
jelord 3:122bfc998c4c 329 uint8_t logByte[1] = {0,};
jelord 3:122bfc998c4c 330 E2PROM.read(0x00014,logByte,1);
jelord 3:122bfc998c4c 331 logInerval = logByte[0];
jelord 3:122bfc998c4c 332
jelord 3:122bfc998c4c 333 stop.attach(&check_stop, 30); // check if we should shut down every 9 seconds, starting 60s after the start.
caseyquinn 4:5d004fd997d5 334
jelord 3:122bfc998c4c 335 //Use the flow rate value stored in eeprom
jelord 3:122bfc998c4c 336 uint8_t flowRateBytes[4] = {0,};
jelord 3:122bfc998c4c 337 E2PROM.read(0x00010,flowRateBytes,4);
jelord 3:122bfc998c4c 338 E2PROM.byteToFloat(flowRateBytes, &volflowSet);
jelord 3:122bfc998c4c 339
jelord 3:122bfc998c4c 340 if(volflowSet<=1.0) {
jelord 3:122bfc998c4c 341 gainFlow = 100;
jelord 3:122bfc998c4c 342 } else if(volflowSet>=2.0) {
jelord 3:122bfc998c4c 343 gainFlow = 25;
jelord 3:122bfc998c4c 344 } else {
jelord 3:122bfc998c4c 345 gainFlow = 25;
jelord 0:2cb2b2ea316f 346 }
jelord 3:122bfc998c4c 347
jelord 3:122bfc998c4c 348 RGB_LED.set_led(1,0,0);
jelord 3:122bfc998c4c 349 press = bmesensor.getPressure();
jelord 3:122bfc998c4c 350 temp = bmesensor.getTemperature();
jelord 3:122bfc998c4c 351 rh = bmesensor.getHumidity();
jelord 3:122bfc998c4c 352
jelord 3:122bfc998c4c 353 atmoRho = ((press-((6.1078*pow((float)10,(float)((7.5*temp)/(237.3+temp))))*(rh/100)))*100)/(287.0531*(temp+273.15))+((6.1078*pow((float)10,(float)((7.5*temp)/(237.3+temp))))*(rh/100)*100)/(461.4964*(temp+273.15));
jelord 3:122bfc998c4c 354 massflowSet = volflowSet*atmoRho;
jelord 3:122bfc998c4c 355 //Digtal pot tf from file: UPAS v2 OSU-PrimaryFlowData FullSet 2015-05-29 CQ mods.xlsx
jelord 3:122bfc998c4c 356
jelord 3:122bfc998c4c 357
jelord 3:122bfc998c4c 358
jelord 3:122bfc998c4c 359
jelord 3:122bfc998c4c 360 DigPot.writeRegister(digital_pot_setpoint);
jelord 3:122bfc998c4c 361 wait(1);
caseyquinn 5:c3252e5d45ca 362 //blower = 1;
jelord 3:122bfc998c4c 363
jelord 3:122bfc998c4c 364 uint8_t subjectLabelOriginal[8] = {0,};
caseyquinn 4:5d004fd997d5 365 E2PROM.read(0x00001, subjectLabelOriginal,8);
caseyquinn 5:c3252e5d45ca 366 //sprintf(filename, "/sd/UPAS%04dLOG_%02d-%02d-%02d_%02d=%02d=%02d_%c%c%c%c%c%c%c%c.txt",serial_num,RTC_UPAS.year,RTC_UPAS.month,RTC_UPAS.date,RTC_UPAS.hour,RTC_UPAS.minutes,RTC_UPAS.seconds,subjectLabelOriginal[0],subjectLabelOriginal[1],subjectLabelOriginal[2],subjectLabelOriginal[3],subjectLabelOriginal[4],subjectLabelOriginal[5],subjectLabelOriginal[6],subjectLabelOriginal[7]);
caseyquinn 5:c3252e5d45ca 367
caseyquinn 4:5d004fd997d5 368 time_t seconds = time(NULL);
caseyquinn 4:5d004fd997d5 369 strftime(timestr, 32, "%y-%m-%d-%H=%M=%S", localtime(&seconds));
caseyquinn 4:5d004fd997d5 370 sprintf(filename, "/sd/UPASboardtest_%s.txt", timestr);
jelord 3:122bfc998c4c 371 FILE *fp = fopen(filename, "w");
jelord 3:122bfc998c4c 372 fclose(fp);
jelord 3:122bfc998c4c 373
jelord 3:122bfc998c4c 374 //---------------------------------------------------------------------------------------------//
jelord 3:122bfc998c4c 375 //Following lines are needed to enter into the initiallization flow control loop
jelord 3:122bfc998c4c 376
jelord 3:122bfc998c4c 377 wait(5);
jelord 3:122bfc998c4c 378
jelord 3:122bfc998c4c 379
jelord 3:122bfc998c4c 380 sampledVol = 0.0;
jelord 3:122bfc998c4c 381 RGB_LED.set_led(0,1,0);
jelord 3:122bfc998c4c 382
jelord 3:122bfc998c4c 383
jelord 3:122bfc998c4c 384
jelord 3:122bfc998c4c 385 //** end of initalization **//
jelord 3:122bfc998c4c 386 //---------------------------------------------------------------------------------------------//
jelord 3:122bfc998c4c 387 //---------------------------------------------------------------------------------------------//
jelord 3:122bfc998c4c 388 // Main Control Loop
jelord 3:122bfc998c4c 389
jelord 3:122bfc998c4c 390
jelord 3:122bfc998c4c 391 //logg.attach(&log_data, 30); // uses callbacks or block Interrupts for anything that uses i2c
caseyquinn 4:5d004fd997d5 392 // while(!RTC_UPAS.compare(startAndEndTime[6], startAndEndTime[7], startAndEndTime[8], startAndEndTime[9], startAndEndTime[10], startAndEndTime[11])){
caseyquinn 4:5d004fd997d5 393 while(1){
jelord 3:122bfc998c4c 394 wait(logInerval);
jelord 3:122bfc998c4c 395 RGB_LED.set_led(1,1,0);
caseyquinn 4:5d004fd997d5 396
caseyquinn 4:5d004fd997d5 397
caseyquinn 4:5d004fd997d5 398 time_t seconds = time(NULL);
caseyquinn 4:5d004fd997d5 399 strftime(timestr, 32, "%y%m%d%H%M%S", localtime(&seconds));
caseyquinn 4:5d004fd997d5 400 press = bmesensor.getPressure();
caseyquinn 4:5d004fd997d5 401 temp = bmesensor.getTemperature()-5.0;
caseyquinn 4:5d004fd997d5 402 rh = bmesensor.getHumidity();
caseyquinn 4:5d004fd997d5 403 uv = lightsensor.getUV();
caseyquinn 4:5d004fd997d5 404
caseyquinn 4:5d004fd997d5 405 FILE *fp = fopen(filename, "a");
caseyquinn 4:5d004fd997d5 406 //fprintf(fp, "Time as a basic string = %s\r\n", ctime(&seconds));
caseyquinn 4:5d004fd997d5 407 //fprintf(fp, "Time as a basic string = %s\r\n", timestr);
caseyquinn 4:5d004fd997d5 408 //fprintf(fp, "%02d,%02d,%02d,%02d,%02d,%02d,",RTC_UPAS.year, RTC_UPAS.month,RTC_UPAS.date,RTC_UPAS.hour,RTC_UPAS.minutes,RTC_UPAS.seconds);
caseyquinn 4:5d004fd997d5 409 fprintf(fp, "%s,", timestr);
caseyquinn 4:5d004fd997d5 410 fprintf(fp, "%1.3f,%1.3f,%2.2f,%4.2f,%2.1f,%1.3f,", omronVolt,massflow,temp,press,rh,atmoRho);
caseyquinn 4:5d004fd997d5 411 fprintf(fp, "%1.3f,%5.1f,%1.1f,%1.1f,%1.1f,%1.1f,", volflow, sampledVol, accel_x, accel_y, accel_z, accel_comp);
caseyquinn 4:5d004fd997d5 412 fprintf(fp, "%.1f,%.1f,%.1f,%.3f,%.3f,%.3f,%.1f,", angle_x,angle_y,angle_z,mag_x, mag_y, mag_z,compass);
caseyquinn 4:5d004fd997d5 413 fprintf(fp, "%d,%d,%d,%d,%d,%d," ,uv,omronReading, vInReading, vBlowerReading, omronDiff,gasG.getAmps());
caseyquinn 4:5d004fd997d5 414 fprintf(fp, "%d,%d,%d,%1.3f,%1.3f\r\n", gasG.getVolts(), gasG.getCharge(),digital_pot_set, deltaMflow, deltaVflow);
caseyquinn 4:5d004fd997d5 415 fclose(fp);
caseyquinn 4:5d004fd997d5 416 free(fp);
caseyquinn 4:5d004fd997d5 417 RGB_LED.set_led(1,0,0);
jelord 3:122bfc998c4c 418 }
caseyquinn 4:5d004fd997d5 419
jelord 3:122bfc998c4c 420
jelord 0:2cb2b2ea316f 421 }