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:
- 20:ad9883973d86
- Parent:
- 19:addd6c99c970
- Child:
- 21:765896ebd61c
diff -r addd6c99c970 -r ad9883973d86 main.cpp --- a/main.cpp Sat May 30 03:59:24 2015 +0000 +++ b/main.cpp Sat May 30 06:26:52 2015 +0000 @@ -24,11 +24,13 @@ LSM303 movementsensor(p22, p20); SI1145 lightsensor(p22, p20); -//Timer t; +float press; +float temp; +float rh; -//float battAmps; -//float battVolts; -//float battGG; +int uv; +int vis; +int ir; float accel_x; float accel_y; @@ -37,11 +39,20 @@ float mag_y; float mag_z; -int omronReading; + int vInReading; int vBlowerReading; int omronDiff; -int digital_pot_setpoint = 0x07; //min = 0x7F, max = 0x00 + +int omronReading; +float omronVolt; //V +float atmoRho; //g/L +float massflow; //g/min +float volflow; //L/min +float volflowSet = 1.0; //L/min +float deltaflow; + +int digital_pot_setpoint = 117; //min = 0x7F, max = 0x00 char filename[] = "/sd/UPASLOG000000000000.txt"; TwoWire Wire = TwoWire(NRF_TWI0); @@ -76,9 +87,7 @@ Date = Wire.read(); Month = Wire.read(); Year = Wire.read(); - //pc.printf("%f", sec); pc.printf("\n");//this is still in bit form - //pc.printf("%f", min); pc.printf("\n"); - //pc.printf("%f", hr); pc.printf("\n"); + } Year = ((Year&0xF0)>>4)*10 + (Year&0x0F); //Year Month = ((Month&0x10)>>4)*10 + (Month&0x0F); //Month @@ -96,24 +105,9 @@ DigPot.writeRegister(digital_pot_setpoint); Wire.begin(SCL, SDA, TWI_FREQUENCY_100K);// - wait(1); - blower = 1; - wait (1); + wait(1); + blower = 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 - FILE *fp = fopen(filename, "w"); - fclose(fp); - break; // leave the loop! - } - } - */ - get_time(); sprintf(filename, "/sd/UPASLOG_%02d%02d%02d%02d%02d%02d.txt",Year,Month,Date,Hour,Minutes,Seconds); FILE *fp = fopen(filename, "w"); @@ -123,11 +117,20 @@ while(1){ get_time(); - secondsD = Seconds; if(fmod(secondsD,10)==0){ + omronVolt = 0.1+(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; + 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; + + /*if(abs(deltaflow)>.05*volflowSet){ + DigPot.writeRegister(digital_pot_setpoint); + } + */ movementsensor.getACCEL(); movementsensor.getCOMPASS(); accel_x = movementsensor.AccelData.x; @@ -137,28 +140,33 @@ mag_y = movementsensor.MagData.y; mag_z = movementsensor.MagData.z; omronReading = ads.readADC_SingleEnded(0, 0xC583); // read channel 0 PGA = 2 : Full Scale Range = 2.048V - //omronReading = ads.readADC_SingleEnded(0, 0xC183); // read channel 0 PGA = 1 : Full Scale Range = 4.096V vInReading = ads.readADC_SingleEnded(1, 0xD583); // read channel 0 vBlowerReading = ads.readADC_SingleEnded(2, 0xE783); // read channel 0 omronDiff = ads.readADC_Differential(0x8583); // differential channel 2-3 - //battAmps = gasG.getAmps(); - //battVolts = gasG.getVolts(); - //battGG = gasG.getCharge(); - //pc.printf("%d Amps, %d Volts, %d GG\n", gasG.getAmps(), gasG.getVolts(), gasG.getCharge()); - //Mount the filesystem + press = bmesensor.getPressure(); + temp = bmesensor.getTemperature(); + rh = bmesensor.getHumidity(); + uv = lightsensor.getUV(); + vis = lightsensor.getVIS(); + ir = lightsensor.getIR(); + + + //Mount the filesystem sd.mount(); FILE *fp = fopen(filename, "a"); - fprintf(fp, "%d,%d,%d,%d,%d,%d,%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,bmesensor.getTemperature(), bmesensor.getPressure(),bmesensor.getHumidity(),accel_x, accel_y, accel_z, mag_x, mag_y, mag_z,lightsensor.getUV(), lightsensor.getVIS(), lightsensor.getIR(), 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\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() ); fclose(fp); //Unmount the filesystem sd.unmount(); - DigPot.writeRegister(digital_pot_setpoint); - + wait(1); } + + + } }