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
Diff: main.cpp
- Revision:
- 16:210e5eaeb89b
- Parent:
- 15:3d1322f05b8e
- Child:
- 17:1baf7cab694e
--- a/main.cpp Fri May 29 23:21:21 2015 +0000 +++ b/main.cpp Sat May 30 00:17:13 2015 +0000 @@ -20,7 +20,6 @@ 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,8 +40,8 @@ int vInReading; int vBlowerReading; int omronDiff; -int digital_pot_setpoint = 0x46; //min = 0x7F, max = 0x00 -char filename[] = ""; +int digital_pot_setpoint = 0x07; //min = 0x7F, max = 0x00 +char filename[] = "/sd/UPASLOG00.txt"; 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) @@ -99,17 +98,20 @@ wait(1); blower = 1; wait (1); - - get_time(); - sprintf(filename, "/sd/temp%02d%02d%02d%02d%02d%02d.txt", Year,Month,Date,Hour,Minutes,Seconds); + + + 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 FILE *fp = fopen(filename, "w"); fclose(fp); - - 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); - - + break; // leave the loop! + } + } + while(1){ @@ -119,7 +121,7 @@ secondsD = Seconds; if(fmod(secondsD,10)==0){ - pc.printf("hi"); + movementsensor.getACCEL(); movementsensor.getCOMPASS(); accel_x = movementsensor.AccelData.x; @@ -140,17 +142,13 @@ //Mount the filesystem 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()); - + 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); //Unmount the filesystem sd.unmount(); DigPot.writeRegister(digital_pot_setpoint); wait(1); - - }