Code supports writing to the SD card as well as working with the Volckens group smartphone apps for the mbed HRM1017

Dependencies:   ADS1115 BLE_API BME280 Calibration CronoDot EEPROM LSM303 MCP40D17 NCP5623BMUTBG SDFileSystem SI1145 STC3100 mbed nRF51822

Fork of UPAS_BLE_and_USB by Volckens Group Sensors

Committer:
joshuasmth04
Date:
Tue Jun 09 20:54:03 2015 +0000
Revision:
41:1fb3e0ac6f87
Parent:
40:ef7e1dcb3780
Child:
42:fc2f2b9f07ae
Replaced wire.h library with CronoDot library.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
caseyquinn 0:14d46ef4b6cb 1 #include "mbed.h"
caseyquinn 0:14d46ef4b6cb 2 #include "SDFileSystem.h"
caseyquinn 0:14d46ef4b6cb 3 #include "Adafruit_ADS1015.h"
caseyquinn 1:37babeb68ab9 4 #include "MCP40D17.h"
caseyquinn 7:a24d7156bc02 5 #include "STC3100.h"
caseyquinn 10:f9cb61b29340 6 #include "LSM303.h"
caseyquinn 12:8c00a7f5d483 7 #include "BME280.h"
caseyquinn 14:ad550174db8b 8 #include "SI1145.h"
joshuasmth04 40:ef7e1dcb3780 9 #include "NCP5623BMUTBG.h"
joshuasmth04 41:1fb3e0ac6f87 10 #include "CronoDot.h"
caseyquinn 1:37babeb68ab9 11
caseyquinn 1:37babeb68ab9 12 #define SERIAL_BAUD_RATE 9600
joshuasmth04 41:1fb3e0ac6f87 13 #define SCL 20
caseyquinn 7:a24d7156bc02 14 #define SDA 22
lionberg 37:838824df3f5f 15 #define Crono 0xD0 //D0 for the chronoDot
caseyquinn 0:14d46ef4b6cb 16
caseyquinn 0:14d46ef4b6cb 17 I2C i2c(p22, p20);
caseyquinn 0:14d46ef4b6cb 18 Adafruit_ADS1115 ads(&i2c);
caseyquinn 1:37babeb68ab9 19 MCP40D17 DigPot(&i2c);
caseyquinn 12:8c00a7f5d483 20 BME280 bmesensor(p22, p20);
caseyquinn 7:a24d7156bc02 21 STC3100 gasG(p22, p20);
caseyquinn 2:e596e685eb39 22 Serial pc(USBTX, USBRX);
caseyquinn 8:204c21adf693 23 DigitalOut blower(p29, 0);
caseyquinn 17:1baf7cab694e 24 DigitalOut pbKill(p18, 1);
caseyquinn 10:f9cb61b29340 25 LSM303 movementsensor(p22, p20);
caseyquinn 14:ad550174db8b 26 SI1145 lightsensor(p22, p20);
joshuasmth04 40:ef7e1dcb3780 27 NCP5623BMUTBG RGB_LED(p22, p20);
joshuasmth04 41:1fb3e0ac6f87 28 CronoDot RTC(p22, p20);
caseyquinn 0:14d46ef4b6cb 29
caseyquinn 20:ad9883973d86 30 float press;
caseyquinn 20:ad9883973d86 31 float temp;
caseyquinn 20:ad9883973d86 32 float rh;
caseyquinn 4:69bd7e8a994c 33
caseyquinn 20:ad9883973d86 34 int uv;
caseyquinn 20:ad9883973d86 35 int vis;
caseyquinn 20:ad9883973d86 36 int ir;
caseyquinn 8:204c21adf693 37
caseyquinn 10:f9cb61b29340 38 float accel_x;
caseyquinn 10:f9cb61b29340 39 float accel_y;
caseyquinn 10:f9cb61b29340 40 float accel_z;
caseyquinn 10:f9cb61b29340 41 float mag_x;
caseyquinn 10:f9cb61b29340 42 float mag_y;
caseyquinn 10:f9cb61b29340 43 float mag_z;
caseyquinn 10:f9cb61b29340 44
caseyquinn 20:ad9883973d86 45
caseyquinn 0:14d46ef4b6cb 46 int vInReading;
caseyquinn 0:14d46ef4b6cb 47 int vBlowerReading;
caseyquinn 0:14d46ef4b6cb 48 int omronDiff;
caseyquinn 20:ad9883973d86 49
caseyquinn 20:ad9883973d86 50 int omronReading;
caseyquinn 20:ad9883973d86 51 float omronVolt; //V
caseyquinn 20:ad9883973d86 52 float atmoRho; //g/L
caseyquinn 20:ad9883973d86 53 float massflow; //g/min
caseyquinn 20:ad9883973d86 54 float volflow; //L/min
caseyquinn 20:ad9883973d86 55 float volflowSet = 1.0; //L/min
joshuasmth04 41:1fb3e0ac6f87 56 float massflowSet;
caseyquinn 20:ad9883973d86 57 float deltaflow;
caseyquinn 20:ad9883973d86 58
caseyquinn 22:8dd7e0d4c21c 59 int digital_pot_setpoint; //min = 0x7F, max = 0x00
lionberg 37:838824df3f5f 60 char filename[] = "/sd/UPAS0010LOG000000000000.txt";
caseyquinn 7:a24d7156bc02 61
caseyquinn 7:a24d7156bc02 62 SDFileSystem sd(SPIS_PSELMOSI, SPIS_PSELMISO, SPIS_PSELSCK, SPIS_PSELSS, "sd"); // I believe this matches Todd's pinout, let me know if this doesn't work. (p12, p13, p15, p14)
caseyquinn 7:a24d7156bc02 63
joshuasmth04 41:1fb3e0ac6f87 64 char Seconds = 0; //Seconds
joshuasmth04 41:1fb3e0ac6f87 65 char Minutes = 0; //Minutes
joshuasmth04 41:1fb3e0ac6f87 66 char Hour = 0; //Hour
joshuasmth04 41:1fb3e0ac6f87 67 char Date = 0; //Date
joshuasmth04 41:1fb3e0ac6f87 68 char Month = 0; //Month
joshuasmth04 41:1fb3e0ac6f87 69 char Year = 0; //Year
caseyquinn 7:a24d7156bc02 70
joshuasmth04 41:1fb3e0ac6f87 71 double secondsD = 0;
joshuasmth04 41:1fb3e0ac6f87 72 char * RTCtime;
caseyquinn 20:ad9883973d86 73
joshuasmth04 41:1fb3e0ac6f87 74
caseyquinn 0:14d46ef4b6cb 75 int main()
caseyquinn 0:14d46ef4b6cb 76 {
joshuasmth04 40:ef7e1dcb3780 77 RGB_LED.set_led(1,1,1);
caseyquinn 22:8dd7e0d4c21c 78 press = bmesensor.getPressure();
caseyquinn 22:8dd7e0d4c21c 79 temp = bmesensor.getTemperature();
caseyquinn 22:8dd7e0d4c21c 80 rh = bmesensor.getHumidity();
joshuasmth04 41:1fb3e0ac6f87 81
caseyquinn 22:8dd7e0d4c21c 82 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));
caseyquinn 22:8dd7e0d4c21c 83 massflowSet = volflowSet*atmoRho;
lionberg 26:9cf8e76d8274 84 //Digtal pot tf from file: UPAS v2 OSU-PrimaryFlowData FullSet 2015-05-29 CQ mods.xlsx
lionberg 33:bc73a2493821 85 digital_pot_setpoint = (int)floor(9.2456*pow(massflowSet,4)-89.538*pow(massflowSet,3)+329.03*pow(massflowSet,2)-566.12*massflowSet+412.72); //min = 0x7F, max = 0x00
joshuasmth04 35:bd978e6ccd82 86
joshuasmth04 41:1fb3e0ac6f87 87 DigPot.writeRegister(digital_pot_setpoint);
joshuasmth04 41:1fb3e0ac6f87 88 wait(1);
joshuasmth04 41:1fb3e0ac6f87 89 blower = 1;
joshuasmth04 41:1fb3e0ac6f87 90
joshuasmth04 41:1fb3e0ac6f87 91 RTCtime = RTC.get_time();
joshuasmth04 41:1fb3e0ac6f87 92 sprintf(filename, "/sd/UPAS0010LOG_%02d-%02d-%02d_%02d-%02d-%02d.txt",RTCtime[5],RTCtime[4],RTCtime[3],RTCtime[2],RTCtime[1],RTCtime[0]);
caseyquinn 17:1baf7cab694e 93 FILE *fp = fopen(filename, "w");
caseyquinn 17:1baf7cab694e 94 fclose(fp);
caseyquinn 2:e596e685eb39 95
joshuasmth04 41:1fb3e0ac6f87 96
joshuasmth04 41:1fb3e0ac6f87 97 while(1) {
joshuasmth04 41:1fb3e0ac6f87 98
joshuasmth04 41:1fb3e0ac6f87 99 RGB_LED.set_led(0,1,0);
joshuasmth04 41:1fb3e0ac6f87 100 RTCtime = RTC.get_time(); // the way the variable RTCtime works you must save the variables in normal chars or weird things happen
joshuasmth04 41:1fb3e0ac6f87 101 Seconds = RTCtime[0];//Seconds
joshuasmth04 41:1fb3e0ac6f87 102 Minutes = RTCtime[1];//Minutes
joshuasmth04 41:1fb3e0ac6f87 103 Hour = RTCtime[2];//Hour
joshuasmth04 41:1fb3e0ac6f87 104 Date = RTCtime[3];//Date
joshuasmth04 41:1fb3e0ac6f87 105 Month = RTCtime[4];//Month
joshuasmth04 41:1fb3e0ac6f87 106 Year = RTCtime[5];//Year
lionberg 37:838824df3f5f 107
joshuasmth04 41:1fb3e0ac6f87 108 secondsD = (double)RTCtime[0];
joshuasmth04 41:1fb3e0ac6f87 109
joshuasmth04 41:1fb3e0ac6f87 110 if(fmod(secondsD,10)==0) {
joshuasmth04 41:1fb3e0ac6f87 111 omronVolt = (omronReading*4.096)/(32768*2);
joshuasmth04 41:1fb3e0ac6f87 112
joshuasmth04 41:1fb3e0ac6f87 113 //Mass Flow tf from file: UPAS v2 OSU-PrimaryFlowData FullSet
joshuasmth04 41:1fb3e0ac6f87 114 //UPAS0001=-2.8112*L14^4+15.636*L14^3-30.192*L14^2+25.945*L14-7.6599
joshuasmth04 41:1fb3e0ac6f87 115 //massflow = -2.8112*pow(omronVolt,(float)4)+15.636*pow(omronVolt,(float)3)-30.192*pow(omronVolt,(float)2)+25.945*omronVolt-7.6599;
joshuasmth04 41:1fb3e0ac6f87 116 //UPAS0002=-1.4365*L14^4+8.4231*L14^3-16.754*L14^2+15.071*L14-4.5382
joshuasmth04 41:1fb3e0ac6f87 117 //massflow = -1.4365*pow(omronVolt,(float)4)+8.4231*pow(omronVolt,(float)3)-16.754*pow(omronVolt,(float)2)+15.071*omronVolt-4.5382;
joshuasmth04 41:1fb3e0ac6f87 118 //UPAS0003=-2.7391*L14^4+15.215*L14^3-29.522*L14^2+25.424*L14-7.5516
joshuasmth04 41:1fb3e0ac6f87 119 //massflow = -2.7391*pow(omronVolt,(float)4)+15.215*pow(omronVolt,(float)3)-29.522*pow(omronVolt,(float)2)+25.424*omronVolt-7.5516;
joshuasmth04 41:1fb3e0ac6f87 120 //UPAS0004 =-1.5374*L14^4+9.2898*L14^3-18.894*L14^2+17.112*L14-5.1938
joshuasmth04 41:1fb3e0ac6f87 121 //massflow = -1.5374*pow(omronVolt,(float)4)+9.2898*pow(omronVolt,(float)3)-18.894*pow(omronVolt,(float)2)+17.112*omronVolt-5.1938;
joshuasmth04 41:1fb3e0ac6f87 122 //UPAS0005 =-0.4654*L14^4+3.507*L14^3-7.7254*L14^2+7.8831*L14-2.4317
joshuasmth04 41:1fb3e0ac6f87 123 //massflow = -0.4654*pow(omronVolt,(float)4)+3.507*pow(omronVolt,(float)3)-7.7254*pow(omronVolt,(float)2)+7.8831*omronVolt-2.4317;
joshuasmth04 41:1fb3e0ac6f87 124 //UPAS0006=-0.0507*L14^4+1.2322*L14^3-2.9659*L14^2+3.9118*L14-1.0765
joshuasmth04 41:1fb3e0ac6f87 125 //massflow = -0.0507*pow(omronVolt,(float)4)+1.2322*pow(omronVolt,(float)3)-2.9659*pow(omronVolt,(float)2)+3.9118*omronVolt-1.0765;
joshuasmth04 41:1fb3e0ac6f87 126 //UPAS0007=-1.5303*L14^4+10.411*L14^3-24.002*L14^2+24.321*L14-8.4713
joshuasmth04 41:1fb3e0ac6f87 127 //massflow = -1.5303*pow(omronVolt,(float)4)+10.411*pow(omronVolt,(float)3)-24.002*pow(omronVolt,(float)2)+24.321*omronVolt-8.4713;
joshuasmth04 41:1fb3e0ac6f87 128 //UPAS0008=-1.1291*L14^4+7.701*L14^3-17.501*L14^2+17.754*L14-6.073
joshuasmth04 41:1fb3e0ac6f87 129 //massflow = -1.1291*pow(omronVolt,(float)4)+7.701*pow(omronVolt,(float)3)-17.501*pow(omronVolt,(float)2)+17.754*omronVolt-6.073;
joshuasmth04 41:1fb3e0ac6f87 130 //UPAS0009=-2.662*L14^4+16.421*L14^3-35.797*L14^2+34.579*L14-11.77
joshuasmth04 41:1fb3e0ac6f87 131 //massflow = -2.662*pow(omronVolt,(float)4)+16.421*pow(omronVolt,(float)3)-35.797*pow(omronVolt,(float)2)+34.579*omronVolt-11.77;
joshuasmth04 41:1fb3e0ac6f87 132 //UPAS0010=-3.6933*L14^4+21.633*L14^3-44.694*L14^2+40.387*L14-12.82
joshuasmth04 41:1fb3e0ac6f87 133 massflow = -3.6933*pow(omronVolt,(float)4)+21.633*pow(omronVolt,(float)3)-44.694*pow(omronVolt,(float)2)+40.387*omronVolt-12.82;
joshuasmth04 41:1fb3e0ac6f87 134
joshuasmth04 41:1fb3e0ac6f87 135 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));
joshuasmth04 41:1fb3e0ac6f87 136 volflow = massflow/atmoRho;
joshuasmth04 41:1fb3e0ac6f87 137 deltaflow = volflow-volflowSet;
joshuasmth04 41:1fb3e0ac6f87 138
joshuasmth04 41:1fb3e0ac6f87 139 /*if(abs(deltaflow)>.05*volflowSet){
joshuasmth04 41:1fb3e0ac6f87 140 digital_pot_setpoint = f(Vsetpoint);
joshuasmth04 41:1fb3e0ac6f87 141 DigPot.writeRegister(digital_pot_setpoint);
joshuasmth04 41:1fb3e0ac6f87 142 }
joshuasmth04 41:1fb3e0ac6f87 143 */
joshuasmth04 41:1fb3e0ac6f87 144 movementsensor.getACCEL();
joshuasmth04 41:1fb3e0ac6f87 145 movementsensor.getCOMPASS();
joshuasmth04 41:1fb3e0ac6f87 146 accel_x = movementsensor.AccelData.x;
joshuasmth04 41:1fb3e0ac6f87 147 accel_y = movementsensor.AccelData.y;
joshuasmth04 41:1fb3e0ac6f87 148 accel_z = movementsensor.AccelData.z;
joshuasmth04 41:1fb3e0ac6f87 149 mag_x = movementsensor.MagData.x;
joshuasmth04 41:1fb3e0ac6f87 150 mag_y = movementsensor.MagData.y;
joshuasmth04 41:1fb3e0ac6f87 151 mag_z = movementsensor.MagData.z;
joshuasmth04 41:1fb3e0ac6f87 152 omronReading = ads.readADC_SingleEnded(0, 0xC583); // read channel 0 PGA = 2 : Full Scale Range = 2.048V
joshuasmth04 41:1fb3e0ac6f87 153 vInReading = ads.readADC_SingleEnded(1, 0xD583); // read channel 0
joshuasmth04 41:1fb3e0ac6f87 154 vBlowerReading = ads.readADC_SingleEnded(2, 0xE783); // read channel 0
joshuasmth04 41:1fb3e0ac6f87 155 omronDiff = ads.readADC_Differential(0x8583); // differential channel 2-3
joshuasmth04 41:1fb3e0ac6f87 156 press = bmesensor.getPressure();
joshuasmth04 41:1fb3e0ac6f87 157 temp = bmesensor.getTemperature()-5;
joshuasmth04 41:1fb3e0ac6f87 158 rh = bmesensor.getHumidity();
joshuasmth04 41:1fb3e0ac6f87 159 uv = lightsensor.getUV();
joshuasmth04 41:1fb3e0ac6f87 160 vis = lightsensor.getVIS();
joshuasmth04 41:1fb3e0ac6f87 161 ir = lightsensor.getIR();
joshuasmth04 41:1fb3e0ac6f87 162
joshuasmth04 41:1fb3e0ac6f87 163
joshuasmth04 41:1fb3e0ac6f87 164 //Mount the filesystem
joshuasmth04 41:1fb3e0ac6f87 165 sd.mount();
joshuasmth04 41:1fb3e0ac6f87 166 FILE *fp = fopen(filename, "a");
joshuasmth04 41:1fb3e0ac6f87 167 fprintf(fp, "%02d,%02d,%02d,%02d,%02d,%02d,%f,%f,%f,%f,%2.2f,%04.2f,%2.2f,%1.4f,%1.4f,%1.4f,%.0f,%.0f,%.0f,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\r\n", Year,Month,Date,Hour,Minutes,Seconds,omronVolt,atmoRho,volflow,massflow,temp,press,rh,accel_x, accel_y, accel_z, mag_x, mag_y, mag_z, uv, vis, ir, omronReading,vInReading, vBlowerReading, omronDiff, gasG.getAmps(), gasG.getVolts(), gasG.getCharge(), digital_pot_setpoint);
joshuasmth04 41:1fb3e0ac6f87 168 fclose(fp);
joshuasmth04 41:1fb3e0ac6f87 169 //Unmount the filesystem
joshuasmth04 41:1fb3e0ac6f87 170 sd.unmount();
joshuasmth04 41:1fb3e0ac6f87 171
joshuasmth04 41:1fb3e0ac6f87 172 wait(1);
joshuasmth04 41:1fb3e0ac6f87 173
caseyquinn 34:481403146690 174 }
caseyquinn 0:14d46ef4b6cb 175 }
caseyquinn 0:14d46ef4b6cb 176 }
caseyquinn 0:14d46ef4b6cb 177
caseyquinn 0:14d46ef4b6cb 178
caseyquinn 0:14d46ef4b6cb 179