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:
15:3d1322f05b8e
Parent:
14:ad550174db8b
Child:
16:210e5eaeb89b
--- a/main.cpp	Fri May 29 14:21:23 2015 +0000
+++ b/main.cpp	Fri May 29 23:21:21 2015 +0000
@@ -20,6 +20,7 @@
 STC3100 gasG(p22, p20);
 Serial  pc(USBTX, USBRX);
 DigitalOut blower(p29, 0);
+DigitalOut pbKill(p18, 1);
 LSM303 movementsensor(p22, p20);
 SI1145 lightsensor(p22, p20);
 
@@ -41,7 +42,7 @@
 int vBlowerReading;
 int omronDiff;
 int digital_pot_setpoint = 0x46; //min = 0x7F, max = 0x00
-char filename[] = "/sd/UPASLOG00.txt";
+char filename[] = "";
 
 TwoWire Wire = TwoWire(NRF_TWI0);    
 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)
@@ -98,20 +99,17 @@
     wait(1);
   blower = 1;
   wait (1);
-    
- 
-  for (uint8_t i = 0; i < 100; i++) {
-      filename[11] = i/10 + '0';
-      filename[12] = i%10 + '0';
-      FILE *fp = fopen(filename, "r");
-      if (fp == NULL) {
-      // only open a new file if it doesn't exist
+
+      get_time();
+      sprintf(filename, "/sd/temp%02d%02d%02d%02d%02d%02d.txt", Year,Month,Date,Hour,Minutes,Seconds);
       FILE *fp = fopen(filename, "w");
       fclose(fp);
-      break;  // leave the loop!
-                    } 
-    }
- 
+     
+    fp = fopen(filename, "a");
+    fprintf(fp, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%2.2f,%04.2f,%2.2f,%.0f,%.0f,%.0f,%.0f,%.0f,%.0f,%d,%d,%d\r\n", Year,Month,Date,Hour,Minutes,Seconds,omronReading,vInReading, vBlowerReading, omronDiff, gasG.getAmps(), gasG.getVolts(), gasG.getCharge(), bmesensor.getTemperature(), bmesensor.getPressure(),bmesensor.getHumidity(),accel_x, accel_y, accel_z, mag_x, mag_y, mag_z, lightsensor.getUV(), lightsensor.getVIS(), lightsensor.getIR());
+    fclose(fp);
+                    
+    
 
          
     while(1){
@@ -121,7 +119,7 @@
     secondsD = Seconds;
     
     if(fmod(secondsD,10)==0){
-    
+    pc.printf("hi");
     movementsensor.getACCEL();
     movementsensor.getCOMPASS();
     accel_x = movementsensor.AccelData.x;
@@ -143,12 +141,16 @@
     sd.mount();
     FILE *fp = fopen(filename, "a");
     fprintf(fp, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%2.2f,%04.2f,%2.2f,%.0f,%.0f,%.0f,%.0f,%.0f,%.0f,%d,%d,%d\r\n", Year,Month,Date,Hour,Minutes,Seconds,omronReading,vInReading, vBlowerReading, omronDiff, gasG.getAmps(), gasG.getVolts(), gasG.getCharge(), bmesensor.getTemperature(), bmesensor.getPressure(),bmesensor.getHumidity(),accel_x, accel_y, accel_z, mag_x, mag_y, mag_z, lightsensor.getUV(), lightsensor.getVIS(), lightsensor.getIR());
+    //fprintf(fp, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%2.2f,%04.2f,%2.2f,%.0f,%.0f,%.0f,%.0f,%.0f,%.0f,%d,%d,%d\r\n", Year,Month,Date,Hour,Minutes,Seconds,omronReading,vInReading, vBlowerReading, omronDiff,  bmesensor.getTemperature(), bmesensor.getPressure(),bmesensor.getHumidity(),accel_x, accel_y, accel_z, mag_x, mag_y, mag_z, lightsensor.getUV(), lightsensor.getVIS(), lightsensor.getIR());
+    
     fclose(fp);
     //Unmount the filesystem
     sd.unmount();
     DigPot.writeRegister(digital_pot_setpoint);
    
     wait(1);
+    
+    
    
     }