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
main.cpp
- Committer:
- caseyquinn
- Date:
- 2015-05-21
- Revision:
- 13:a8e096e715bd
- Parent:
- 12:8c00a7f5d483
- Child:
- 14:ad550174db8b
File content as of revision 13:a8e096e715bd:
#include "mbed.h" #include "SDFileSystem.h" #include "Adafruit_ADS1015.h" #include "MCP40D17.h" #include "wire.h" //Used with the RTC in this code. Will need to try and remove this, and also create the correct library/update addresses and registers for the RTC. #include "STC3100.h" #include "LSM303.h" #include "BME280.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); BME280 bmesensor(p22, p20); STC3100 gasG(p22, p20); Serial pc(USBTX, USBRX); DigitalOut blower(p29, 0); LSM303 movementsensor(p22, p20); //Timer t; //float battAmps; //float battVolts; //float battGG; float accel_x; float accel_y; float accel_z; float mag_x; float mag_y; float mag_z; int omronReading; int vInReading; int vBlowerReading; int omronDiff; 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) 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 double secondsD = 0; 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); 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&0x30)>>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(); // create a new file DigPot.writeRegister(digital_pot_setpoint); Wire.begin(SCL, SDA, TWI_FREQUENCY_100K);// 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 FILE *fp = fopen(filename, "w"); fclose(fp); break; // leave the loop! } } while(1){ get_time(); secondsD = Seconds; if(fmod(secondsD,10)==0){ movementsensor.getACCEL(); movementsensor.getCOMPASS(); accel_x = movementsensor.AccelData.x; accel_y = movementsensor.AccelData.y; accel_z = movementsensor.AccelData.z; mag_x = movementsensor.MagData.x; 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 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\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); fclose(fp); //Unmount the filesystem sd.unmount(); DigPot.writeRegister(digital_pot_setpoint); wait(1); } } }