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

Revision:
22:8dd7e0d4c21c
Parent:
21:765896ebd61c
Child:
23:3647fecd3cef
--- a/main.cpp	Sat May 30 06:32:11 2015 +0000
+++ b/main.cpp	Sat May 30 16:48:23 2015 +0000
@@ -50,9 +50,10 @@
 float massflow; //g/min
 float volflow; //L/min
 float volflowSet = 1.0; //L/min
+float massflowSet; 
 float deltaflow;
 
-int digital_pot_setpoint = 117; //min = 0x7F, max = 0x00
+int digital_pot_setpoint; //min = 0x7F, max = 0x00
 char filename[] = "/sd/UPASLOG000000000000.txt";
 
 TwoWire Wire = TwoWire(NRF_TWI0);    
@@ -99,9 +100,13 @@
   
 int main()
 {
-
-//t.start();
-    // create a new file
+    press = bmesensor.getPressure();
+    temp = bmesensor.getTemperature();
+    rh = bmesensor.getHumidity();
+    
+    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));
+    massflowSet = volflowSet*atmoRho;
+    digital_pot_setpoint = (int)floor(10.627*pow(massflowSet,4)-102.89*pow(massflowSet,3)+375.8*pow(massflowSet,2)-635.59*massflowSet+446.61); //min = 0x7F, max = 0x00
    
    DigPot.writeRegister(digital_pot_setpoint);
    Wire.begin(SCL, SDA, TWI_FREQUENCY_100K);// 
@@ -122,7 +127,7 @@
     if(fmod(secondsD,10)==0){
     
     omronVolt = (omronReading*4.096)/(32768*2);
-    massflow = -1.0147*pow(omronVolt,(float)4)+4.5045*pow(omronVolt,(float)3)-7.1369*pow(omronVolt,(float)2)+8.9857*omronVolt-2.6157;
+    massflow = 2.7143*pow(omronVolt,(float)4)-12.323*pow(omronVolt,(float)3)+22.121*pow(omronVolt,(float)2)-16.71*omronVolt+5.162;
     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));
     volflow = massflow/atmoRho;
     deltaflow = volflow-volflowSet;
@@ -155,7 +160,7 @@
     //Mount the filesystem
     sd.mount();
     FILE *fp = fopen(filename, "a");
-    fprintf(fp, "%d,%d,%d,%d,%d,%d,%f,%f,%f,%f,%2.2f,%04.2f,%2.2f,%.0f,%.0f,%.0f,%.0f,%.0f,%.0f,%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() );
+    fprintf(fp, "%d,%d,%d,%d,%d,%d,%f,%f,%f,%f,%2.2f,%04.2f,%2.2f,%.0f,%.0f,%.0f,%.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 );
     fclose(fp);
     //Unmount the filesystem
     sd.unmount();