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

Committer:
caseyquinn
Date:
Wed May 20 22:44:57 2015 +0000
Revision:
12:8c00a7f5d483
Parent:
11:2297d364af61
Child:
13:a8e096e715bd
Replaced BMP280 library with BME280 library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
caseyquinn 0:14d46ef4b6cb 1 #include "mbed.h"
caseyquinn 0:14d46ef4b6cb 2 #include "SDFileSystem.h"
caseyquinn 0:14d46ef4b6cb 3 #include "Adafruit_ADS1015.h"
caseyquinn 1:37babeb68ab9 4 #include "MCP40D17.h"
caseyquinn 10:f9cb61b29340 5 #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.
caseyquinn 7:a24d7156bc02 6 #include "STC3100.h"
caseyquinn 10:f9cb61b29340 7 #include "LSM303.h"
caseyquinn 12:8c00a7f5d483 8 #include "BME280.h"
caseyquinn 1:37babeb68ab9 9
caseyquinn 1:37babeb68ab9 10 #define SERIAL_BAUD_RATE 9600
caseyquinn 7:a24d7156bc02 11 #define SCL 20
caseyquinn 7:a24d7156bc02 12 #define SDA 22
caseyquinn 7:a24d7156bc02 13 #define Crono 0xD0 //D0 for the chronoDot
caseyquinn 0:14d46ef4b6cb 14
caseyquinn 0:14d46ef4b6cb 15 I2C i2c(p22, p20);
caseyquinn 0:14d46ef4b6cb 16 Adafruit_ADS1115 ads(&i2c);
caseyquinn 1:37babeb68ab9 17 MCP40D17 DigPot(&i2c);
caseyquinn 12:8c00a7f5d483 18 BME280 bmesensor(p22, p20);
caseyquinn 7:a24d7156bc02 19 STC3100 gasG(p22, p20);
caseyquinn 2:e596e685eb39 20 Serial pc(USBTX, USBRX);
caseyquinn 8:204c21adf693 21 DigitalOut blower(p29, 0);
caseyquinn 8:204c21adf693 22 AnalogIn Honeywell(P0_2);
caseyquinn 10:f9cb61b29340 23 LSM303 movementsensor(p22, p20);
caseyquinn 0:14d46ef4b6cb 24
caseyquinn 7:a24d7156bc02 25 //Timer t;
caseyquinn 4:69bd7e8a994c 26
caseyquinn 7:a24d7156bc02 27 //float battAmps;
caseyquinn 7:a24d7156bc02 28 //float battVolts;
caseyquinn 7:a24d7156bc02 29 //float battGG;
caseyquinn 8:204c21adf693 30
caseyquinn 10:f9cb61b29340 31 float accel_x;
caseyquinn 10:f9cb61b29340 32 float accel_y;
caseyquinn 10:f9cb61b29340 33 float accel_z;
caseyquinn 10:f9cb61b29340 34 float mag_x;
caseyquinn 10:f9cb61b29340 35 float mag_y;
caseyquinn 10:f9cb61b29340 36 float mag_z;
caseyquinn 10:f9cb61b29340 37
caseyquinn 8:204c21adf693 38 float Honeywell_value;
caseyquinn 0:14d46ef4b6cb 39 int omronReading;
caseyquinn 0:14d46ef4b6cb 40 int vInReading;
caseyquinn 0:14d46ef4b6cb 41 int vBlowerReading;
caseyquinn 0:14d46ef4b6cb 42 int omronDiff;
caseyquinn 8:204c21adf693 43 int digital_pot_setpoint = 0x07; //min = 0x7F, max = 0x00
caseyquinn 3:2d059d88582b 44 char filename[] = "/sd/UPASLOG00.txt";
caseyquinn 7:a24d7156bc02 45
caseyquinn 7:a24d7156bc02 46 TwoWire Wire = TwoWire(NRF_TWI0);
caseyquinn 7:a24d7156bc02 47 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)
caseyquinn 7:a24d7156bc02 48
caseyquinn 7:a24d7156bc02 49 uint8_t Seconds = 0;//Seconds
caseyquinn 7:a24d7156bc02 50 uint8_t Minutes = 0;//Minutes
caseyquinn 7:a24d7156bc02 51 uint8_t Hour = 0;//Hour
caseyquinn 7:a24d7156bc02 52 uint8_t Date = 0;//Date
caseyquinn 7:a24d7156bc02 53 uint8_t Month = 0;//Month
caseyquinn 7:a24d7156bc02 54 uint8_t Year = 0;//Year
caseyquinn 11:2297d364af61 55 double secondsD = 0;
caseyquinn 7:a24d7156bc02 56
caseyquinn 7:a24d7156bc02 57 void get_time()
caseyquinn 7:a24d7156bc02 58 {
caseyquinn 7:a24d7156bc02 59 Wire.beginTransmission(Crono); // address DS3231
caseyquinn 7:a24d7156bc02 60 Wire.write(0x0E); // select register
caseyquinn 7:a24d7156bc02 61 Wire.write(0x1C); // write register bitmap, bit 7 is /EOSC
caseyquinn 7:a24d7156bc02 62 Wire.endTransmission();
caseyquinn 7:a24d7156bc02 63 wait(0.05);
caseyquinn 7:a24d7156bc02 64 Wire.beginTransmission(Crono);
caseyquinn 7:a24d7156bc02 65 Wire.write(0x00);
caseyquinn 7:a24d7156bc02 66 Wire.endTransmission();
caseyquinn 7:a24d7156bc02 67 Wire.requestFrom(Crono+1, 7);
caseyquinn 2:e596e685eb39 68
caseyquinn 7:a24d7156bc02 69 while( Wire.available() > 0 )
caseyquinn 7:a24d7156bc02 70 {
caseyquinn 7:a24d7156bc02 71 Seconds = Wire.read();
caseyquinn 7:a24d7156bc02 72 Minutes = Wire.read();
caseyquinn 7:a24d7156bc02 73 Hour = Wire.read();
caseyquinn 7:a24d7156bc02 74 uint8_t day =Wire.read(); // we don't uses this, it's just day of the week
caseyquinn 7:a24d7156bc02 75 Date = Wire.read();
caseyquinn 7:a24d7156bc02 76 Month = Wire.read();
caseyquinn 7:a24d7156bc02 77 Year = Wire.read();
caseyquinn 7:a24d7156bc02 78 //pc.printf("%f", sec); pc.printf("\n");//this is still in bit form
caseyquinn 7:a24d7156bc02 79 //pc.printf("%f", min); pc.printf("\n");
caseyquinn 7:a24d7156bc02 80 //pc.printf("%f", hr); pc.printf("\n");
caseyquinn 7:a24d7156bc02 81 }
caseyquinn 7:a24d7156bc02 82 Year = ((Year&0xF0)>>4)*10 + (Year&0x0F); //Year
caseyquinn 7:a24d7156bc02 83 Month = ((Month&0x10)>>4)*10 + (Month&0x0F); //Month
caseyquinn 7:a24d7156bc02 84 Date = ((Date&0x30)>>4)*10 + (Date&0x0F); //Date
caseyquinn 9:2057c3779b6a 85 Hour = ((Hour&0x30)>>4)*10 + (Hour&0x0F); //Hour
caseyquinn 7:a24d7156bc02 86 Minutes = ((Minutes&0x70)>>4)*10 + (Minutes&0x0F); //Minutes
caseyquinn 7:a24d7156bc02 87 Seconds = ((Seconds&0x70)>>4)*10 + (Seconds&0x0F); //Seconds
caseyquinn 7:a24d7156bc02 88 }
caseyquinn 2:e596e685eb39 89
caseyquinn 0:14d46ef4b6cb 90 int main()
caseyquinn 0:14d46ef4b6cb 91 {
caseyquinn 2:e596e685eb39 92
caseyquinn 7:a24d7156bc02 93 //t.start();
caseyquinn 2:e596e685eb39 94 // create a new file
caseyquinn 8:204c21adf693 95
caseyquinn 8:204c21adf693 96 DigPot.writeRegister(digital_pot_setpoint);
caseyquinn 8:204c21adf693 97 Wire.begin(SCL, SDA, TWI_FREQUENCY_100K);//
caseyquinn 7:a24d7156bc02 98 wait(1);
caseyquinn 8:204c21adf693 99 blower = 1;
caseyquinn 8:204c21adf693 100 wait (1);
caseyquinn 7:a24d7156bc02 101
caseyquinn 7:a24d7156bc02 102
caseyquinn 3:2d059d88582b 103 for (uint8_t i = 0; i < 100; i++) {
caseyquinn 3:2d059d88582b 104 filename[11] = i/10 + '0';
caseyquinn 3:2d059d88582b 105 filename[12] = i%10 + '0';
caseyquinn 2:e596e685eb39 106 FILE *fp = fopen(filename, "r");
caseyquinn 2:e596e685eb39 107 if (fp == NULL) {
caseyquinn 2:e596e685eb39 108 // only open a new file if it doesn't exist
caseyquinn 2:e596e685eb39 109 FILE *fp = fopen(filename, "w");
caseyquinn 2:e596e685eb39 110 fclose(fp);
caseyquinn 2:e596e685eb39 111 break; // leave the loop!
caseyquinn 7:a24d7156bc02 112 }
caseyquinn 2:e596e685eb39 113 }
caseyquinn 7:a24d7156bc02 114
caseyquinn 2:e596e685eb39 115
caseyquinn 1:37babeb68ab9 116
caseyquinn 0:14d46ef4b6cb 117 while(1){
caseyquinn 7:a24d7156bc02 118
caseyquinn 8:204c21adf693 119 get_time();
caseyquinn 10:f9cb61b29340 120
caseyquinn 11:2297d364af61 121 secondsD = Seconds;
caseyquinn 11:2297d364af61 122
caseyquinn 11:2297d364af61 123 if(fmod(secondsD,10)==0){
caseyquinn 11:2297d364af61 124
caseyquinn 10:f9cb61b29340 125 movementsensor.getACCEL();
caseyquinn 10:f9cb61b29340 126 movementsensor.getCOMPASS();
caseyquinn 10:f9cb61b29340 127 accel_x = movementsensor.AccelData.x;
caseyquinn 10:f9cb61b29340 128 accel_y = movementsensor.AccelData.y;
caseyquinn 10:f9cb61b29340 129 accel_z = movementsensor.AccelData.z;
caseyquinn 10:f9cb61b29340 130 mag_x = movementsensor.MagData.x;
caseyquinn 10:f9cb61b29340 131 mag_y = movementsensor.MagData.y;
caseyquinn 10:f9cb61b29340 132 mag_z = movementsensor.MagData.z;
caseyquinn 8:204c21adf693 133 Honeywell_value = Honeywell.read();
caseyquinn 6:2328feb48792 134 omronReading = ads.readADC_SingleEnded(0, 0xC583); // read channel 0 PGA = 2 : Full Scale Range = 2.048V
caseyquinn 6:2328feb48792 135 //omronReading = ads.readADC_SingleEnded(0, 0xC183); // read channel 0 PGA = 1 : Full Scale Range = 4.096V
caseyquinn 0:14d46ef4b6cb 136 vInReading = ads.readADC_SingleEnded(1, 0xD583); // read channel 0
caseyquinn 0:14d46ef4b6cb 137 vBlowerReading = ads.readADC_SingleEnded(2, 0xE783); // read channel 0
caseyquinn 0:14d46ef4b6cb 138 omronDiff = ads.readADC_Differential(0x8583); // differential channel 2-3
caseyquinn 7:a24d7156bc02 139 //battAmps = gasG.getAmps();
caseyquinn 7:a24d7156bc02 140 //battVolts = gasG.getVolts();
caseyquinn 7:a24d7156bc02 141 //battGG = gasG.getCharge();
caseyquinn 7:a24d7156bc02 142 //pc.printf("%d Amps, %d Volts, %d GG\n", gasG.getAmps(), gasG.getVolts(), gasG.getCharge());
caseyquinn 2:e596e685eb39 143 //Mount the filesystem
caseyquinn 2:e596e685eb39 144 sd.mount();
caseyquinn 3:2d059d88582b 145 FILE *fp = fopen(filename, "a");
caseyquinn 12:8c00a7f5d483 146 fprintf(fp, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%2.2f,%04.2f,%2.2f,%f,%.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(),Honeywell_value,accel_x, accel_y, accel_z, mag_x, mag_y, mag_z);
caseyquinn 2:e596e685eb39 147 fclose(fp);
caseyquinn 2:e596e685eb39 148 //Unmount the filesystem
caseyquinn 2:e596e685eb39 149 sd.unmount();
caseyquinn 11:2297d364af61 150 DigPot.writeRegister(digital_pot_setpoint);
caseyquinn 2:e596e685eb39 151
caseyquinn 11:2297d364af61 152 wait(1);
caseyquinn 2:e596e685eb39 153
caseyquinn 11:2297d364af61 154 }
caseyquinn 2:e596e685eb39 155
caseyquinn 2:e596e685eb39 156
caseyquinn 0:14d46ef4b6cb 157 }
caseyquinn 0:14d46ef4b6cb 158 }
caseyquinn 0:14d46ef4b6cb 159
caseyquinn 0:14d46ef4b6cb 160
caseyquinn 0:14d46ef4b6cb 161