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:
- 7:a24d7156bc02
- Parent:
- 6:2328feb48792
- Child:
- 8:204c21adf693
--- a/main.cpp Tue May 05 15:13:06 2015 +0000 +++ b/main.cpp Wed May 06 04:08:03 2015 +0000 @@ -3,33 +3,87 @@ #include "Adafruit_ADS1015.h" #include "MCP40D17.h" #include "BMP280.h" +#include "wire.h" +#include "STC3100.h" #define SERIAL_BAUD_RATE 9600 +#define SCL 20 +#define SDA 22 +#define Crono 0xD0 //D0 for the chronoDot I2C i2c(p22, p20); Adafruit_ADS1115 ads(&i2c); MCP40D17 DigPot(&i2c); BMP280 bmpsensor(p22, p20); +STC3100 gasG(p22, p20); Serial pc(USBTX, USBRX); DigitalOut blower(p29, 1); -Timer t; +//Timer t; +//float battAmps; +//float battVolts; +//float battGG; int omronReading; int vInReading; int vBlowerReading; int omronDiff; -int digital_pot_setpoint = 0x02; //min = 0x7F, max = 0x00 +int digital_pot_setpoint = 0x46; //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) + +uint8_t Seconds = 0;//Seconds +uint8_t Minutes = 0;//Minutes +uint8_t Hour = 0;//Hour +uint8_t Date = 0;//Date +uint8_t Month = 0;//Month +uint8_t Year = 0;//Year + +void get_time() +{ + Wire.beginTransmission(Crono); // address DS3231 + Wire.write(0x0E); // select register + Wire.write(0x1C); // write register bitmap, bit 7 is /EOSC + Wire.endTransmission(); + wait(0.05); + Wire.beginTransmission(Crono); + Wire.write(0x00); + Wire.endTransmission(); + Wire.requestFrom(Crono+1, 7); -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) + while( Wire.available() > 0 ) + { + Seconds = Wire.read(); + Minutes = Wire.read(); + Hour = Wire.read(); + uint8_t day =Wire.read(); // we don't uses this, it's just day of the week + 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 + Date = ((Date&0x30)>>4)*10 + (Date&0x0F); //Date + Hour = ((Hour&0x10)>>4)*10 + (Hour&0x0F); //Hour + Minutes = ((Minutes&0x70)>>4)*10 + (Minutes&0x0F); //Minutes + Seconds = ((Seconds&0x70)>>4)*10 + (Seconds&0x0F); //Seconds +} int main() { -t.start(); +//t.start(); // create a new file + Wire.begin(SCL, SDA, TWI_FREQUENCY_100K);// + wait(1); + + for (uint8_t i = 0; i < 100; i++) { filename[11] = i/10 + '0'; filename[12] = i%10 + '0'; @@ -39,29 +93,32 @@ FILE *fp = fopen(filename, "w"); fclose(fp); break; // leave the loop! + } } - + - } - while(1){ - + + get_time(); 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 sd.mount(); FILE *fp = fopen(filename, "a"); - fprintf(fp, "%f,%d,%d,%d,%d,%2.2f,%04.2f\r\n", t.read(),omronReading,vInReading, vBlowerReading, omronDiff,bmpsensor.getTemperature(), bmpsensor.getPressure()); + fprintf(fp, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%2.2f,%04.2f\r\n", Year,Month,Date,Hour,Minutes,Seconds,omronReading,vInReading, vBlowerReading, omronDiff, gasG.getAmps(), gasG.getVolts(), gasG.getCharge(), bmpsensor.getTemperature(), bmpsensor.getPressure()); fclose(fp); //Unmount the filesystem sd.unmount(); - wait(5); + wait(10); DigPot.writeRegister(digital_pot_setpoint);