Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ADS1115 BME280 CronoDot SDFileSystem mbed
Fork of Outdoor_UPAS_v1_2_Tboard by
Revision 29:fd74725294d5, committed 2016-04-24
- Comitter:
- caseyquinn
- Date:
- Sun Apr 24 23:37:50 2016 +0000
- Parent:
- 28:42932d3b105d
- Child:
- 30:aa6324845a84
- Commit message:
- sets the serial # using the sample id string. If a 2 digit sample id is set then that value will be used for the serial number. If sample name > 2 will use existing. samplers 1-17 will have MS and >17 will be PS. SD file will use designation too
Changed in this revision
--- a/Calibration.lib Sat Apr 23 00:10:57 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://developer.mbed.org/teams/Vockens-Group-Sensors/code/Calibration/#cef76c1bfcdb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TboardSampler_Calibration.lib Sun Apr 24 23:37:50 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/Vockens-Group-Sensors/code/TboardSampler_Calibration/#28df51864355
--- a/main.cpp Sat Apr 23 00:10:57 2016 +0000
+++ b/main.cpp Sun Apr 24 23:37:50 2016 +0000
@@ -157,7 +157,7 @@
float gainFlow;
float sampledVol; //L, total sampled volume
-int digital_pot_setpoint = 100; //min = 0x7F, max = 0x00
+int digital_pot_setpoint = 30; //min = 0x7F, max = 0x00
int digital_pot_set;
int digital_pot_change;
int digitalpotMax = 127;
@@ -317,6 +317,7 @@
uint8_t subjectLabelOriginal[9] = {0x02,0x52,0x45,0x53,0x45,0x54,0x5F,0x5F,0x5f};
uint8_t dataLogOriginal[2] = {0x03,0x0A,};
uint8_t flowRateOriginal[5] = {0x04,0x00,0x00,0x80,0x3F};
+ uint8_t serialBytes[3] = {0x07,0x00,0x00};
uint8_t latLongSchoolOriginal[17] = {0x0A,0x00,0x00,0x80,0x3F,0x00,0x00,0x80,0x3F,0x00,0x00,0x80,0x3F,0x00,0x00,0x80,0x3F};
// Latitude School EEPROM = 0x50-0x53
// Longitude School EEPROM = 0x54-0x57
@@ -332,6 +333,7 @@
E2PROM.read(0x00001, subjectLabelOriginal+1,8);
E2PROM.read(0x00014,dataLogOriginal+1,1);
E2PROM.read(0x00010,flowRateOriginal+1,4);
+ E2PROM.read(0x00034,serialBytes+1,2);
E2PROM.read(0x00050,latLongSchoolOriginal+1,16);
}else{
NEW_EEPROM_CHECK[0] = 0x0A;
@@ -340,6 +342,7 @@
E2PROM.write(0x00001, subjectLabelOriginal+1,8);
E2PROM.write(0x00014,dataLogOriginal+1,1);
E2PROM.write(0x00010,flowRateOriginal+1,4);
+ E2PROM.write(0x00034,serialBytes+1,2);
E2PROM.write(0x00050,latLongSchoolOriginal+1,16);
}
@@ -452,7 +455,7 @@
amps = gasG.getAmps();
bVolt = gasG.getVolts();
bFuel = gasG.getCharge();
-
+ /*
//Check for fully charged battery
if(bVolt > 1750 && amps > 8191) {
RGB_LED.set_led(0,1,0);
@@ -470,7 +473,7 @@
RGB_LED.set_led(0,0,0);
}
-
+ */
// Get GPS Data
//////////////////////////////
//if(gpsEN ==1){
@@ -486,6 +489,7 @@
if(gpsFix){
workDistance = GPSdistanceCalc (work_lat, work_lon);
homeDistance = GPSdistanceCalc (home_lat, home_lon);
+ RGB_LED.set_led(0,0,0);
if(workDistance < 50) {
location = 1;
@@ -646,9 +650,10 @@
//////////////////////////////////////////////////////////////
int main(){
+
RGB_LED.set_led(0,0,1);
- /*
+ /*
while(1){
if(sdCD == 0){
RGB_LED.set_led(0,1,0);
@@ -665,9 +670,9 @@
transitF3.getFault();
blankF4.getFault();
- schoolF1.drive(253); //closed = 253, open = 254
+ schoolF1.drive(254); //closed = 253, open = 254
homeF2.drive(253); //closed = 253, open = 254
- transitF3.drive(254); //closed = 253, open = 254
+ transitF3.drive(253); //closed = 253, open = 254
blankF4.drive(253); //closed = 253, open = 254
wait(1);
@@ -690,24 +695,36 @@
pc.printf("\f\n\r-------------Startup-------------\n\r");
wait(0.5);
- uint8_t serialNumberAndType[6] = {0x50,0x53,}; //ex) PS0018 // 0x50,0x53 <- ASCII 80 + 83 (PS) //0x4d,0x53 <- ASCII + 83 (MS)
+
+
+ uint8_t serialNumberAndType[6] = {0x50,0x53,}; //ex) PS0018 // 0x50,0x53 <- ASCII 80 + 83 (PS) //0x4d,0x53 <- ASCII 77 + 83 (MS)
+ E2PROM.read(0x00034,serialNumberAndType+2,2);
+
+ int tempSerialNum = ((serialNumberAndType[2]-48)*10 + serialNumberAndType[3]-48);
+ if(tempSerialNum < 18){
+ serialNumberAndType[0] = 0x4D;
+ }
- E2PROM.read(0x00034,serialNumberAndType+2,2);
-
- int tempSerialNum = serialNumberAndType[2]+serialNumberAndType[3];
int serialNumDigits[4];
serialNumDigits[0] = tempSerialNum / 1000 % 10;
serialNumDigits[1] = tempSerialNum / 100 % 10;
serialNumDigits[2] = tempSerialNum / 10 % 10;
serialNumDigits[3] = tempSerialNum % 10;
+
serialNumberAndType[2] = serialNumDigits[0]+48;
serialNumberAndType[3] = serialNumDigits[1]+48;
serialNumberAndType[4] = serialNumDigits[2]+48;
serialNumberAndType[5] = serialNumDigits[3]+48;
-
- RGB_LED.set_led(0,1,0);
+ /*
+ serialNumberAndType[2] = serialNumDigits[0];
+ serialNumberAndType[3] = serialNumDigits[1];
+ serialNumberAndType[4] = serialNumDigits[2];
+ serialNumberAndType[5] = serialNumDigits[3];
+ */
+
+ RGB_LED.set_led(0,1,0);
pc.attach(pc_recv);
microChannel.attach(uartMicro,microChannel.RxIrq);
@@ -775,13 +792,35 @@
}
-
+ //Get the subject line information
+ uint8_t subjectLabelOriginal[8] = {0,};
+ E2PROM.read(0x00001, subjectLabelOriginal,8);
//Get the proper serial number
uint8_t serialBytes[2] = {0,};
- E2PROM.read(0x00034, serialBytes,2);
- serial_num = ((uint16_t)serialBytes[1] << 8) | serialBytes[0];
+ E2PROM.read(0x00034,serialBytes,2);
+ serial_num = (uint16_t)(((serialBytes[0]-48)*10 + serialBytes[1]-48));
+
+
+////////////////////////////////////////////////////////////////////
+ //Temporary fix for setting serial_num
+////////////////////////////////////////////////////////////////////
+ //uint8_t serialsubjectLabelOriginal[2] = {0,};
+ //E2PROM.read(0x00001, serialsubjectLabelOriginal,2);
+ //uint8_t newserialBytes[2] = {0,};
+
+ if(subjectLabelOriginal[2] == 95){
+ E2PROM.write(0x00034,subjectLabelOriginal,2);
+ serial_num = (uint16_t)(((subjectLabelOriginal[0]-48)*10 + subjectLabelOriginal[1]-48));
+ }
+
+ //----------------------------------------------
calibrations.initialize(serial_num);
+ pc.printf("%d\r\n", serial_num);
+ pc.printf("%f\r\n",calibrations.MF4);
+ //----------------------------------------------
+////////////////////////////////////////////////////////////////////
+
uint8_t logByte[1] = {0,};
E2PROM.read(0x00014,logByte,1);
@@ -791,7 +830,8 @@
uint8_t flowRateBytes[4] = {0,};
E2PROM.read(0x00010,flowRateBytes,4);
E2PROM.byteToFloat(flowRateBytes, &volflowSet);
-
+
+
if(volflowSet<=1.0) {
gainFlow = 100;
} else if(volflowSet>=2.0) {
@@ -813,15 +853,50 @@
pumps = 1;
//pumpOn = 1;
- uint8_t subjectLabelOriginal[8] = {0,};
- E2PROM.read(0x00001, subjectLabelOriginal,8);
+/* Add this chunk back in once calibrated.
+ if(volflowSet<=1.0) {
+ gainFlow = 100;
+ } else if(volflowSet>=2.0) {
+ gainFlow = 25;
+ } else {
+ gainFlow = 25;
+ }
+
+ RGB_LED.set_led(1,0,0);
+ press = bmesensor.getPressure();
+ temp = bmesensor.getTemperature();
+ rh = bmesensor.getHumidity();
+
+ 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));
+ massflowSet = volflowSet*atmoRho;
+
+ //Digtal pot tf from file: UPAS v2 OSU-PrimaryFlowData FullSet 2015-05-29 CQ mods.xlsx
+ digital_pot_setpoint = (int)floor(calibrations.DP4*pow(massflowSet,4)+calibrations.DP3*pow(massflowSet,3)+calibrations.DP2*pow(massflowSet,2)+calibrations.DP1*massflowSet+calibrations.DP0); //min = 0x7F, max = 0x00
+
+ if(digital_pot_setpoint>=digitalpotMax) {
+ digital_pot_setpoint = digitalpotMax;
+ } else if(digital_pot_setpoint<=digitalpotMin) {
+ digital_pot_setpoint = digitalpotMin;
+ }
+
+ pc.printf("%d\r\n", digital_pot_setpoint);
+ DigPot.writeRegister(digital_pot_setpoint);
+ wait(1);
+ blower = 1;
+ */
+
time_t seconds = time(NULL);
strftime(timestr, 32, "%y-%m-%d-%H=%M=%S", localtime(&seconds));
-
- sprintf(filename, "/sd/AMAS%04dLOG_%02d-%02d-%02d_%02d=%02d=%02d_%c%c%c%c%c%c%c%c.txt",serial_num,RTC_UPAS.year,RTC_UPAS.month,RTC_UPAS.date,RTC_UPAS.hour,RTC_UPAS.minutes,RTC_UPAS.seconds,subjectLabelOriginal[0],subjectLabelOriginal[1],subjectLabelOriginal[2],subjectLabelOriginal[3],subjectLabelOriginal[4],subjectLabelOriginal[5],subjectLabelOriginal[6],subjectLabelOriginal[7]);
+ if(tempSerialNum < 18){
+ sprintf(filename, "/sd/MS%04dLOG_%02d-%02d-%02d_%02d=%02d=%02d_%c%c%c%c%c%c%c%c.txt",serial_num,RTC_UPAS.year,RTC_UPAS.month,RTC_UPAS.date,RTC_UPAS.hour,RTC_UPAS.minutes,RTC_UPAS.seconds,subjectLabelOriginal[0],subjectLabelOriginal[1],subjectLabelOriginal[2],subjectLabelOriginal[3],subjectLabelOriginal[4],subjectLabelOriginal[5],subjectLabelOriginal[6],subjectLabelOriginal[7]);
+
+ }
+ else{
+ sprintf(filename, "/sd/PS%04dLOG_%02d-%02d-%02d_%02d=%02d=%02d_%c%c%c%c%c%c%c%c.txt",serial_num,RTC_UPAS.year,RTC_UPAS.month,RTC_UPAS.date,RTC_UPAS.hour,RTC_UPAS.minutes,RTC_UPAS.seconds,subjectLabelOriginal[0],subjectLabelOriginal[1],subjectLabelOriginal[2],subjectLabelOriginal[3],subjectLabelOriginal[4],subjectLabelOriginal[5],subjectLabelOriginal[6],subjectLabelOriginal[7]);
+ }
//sprintf(filename, "/sd/UPAS_TboardtestLog_%s_%c%c%c%c%c%c%c%c.txt", timestr,subjectLabelOriginal[0],subjectLabelOriginal[1],subjectLabelOriginal[2],subjectLabelOriginal[3],subjectLabelOriginal[4],subjectLabelOriginal[5],subjectLabelOriginal[6],subjectLabelOriginal[7]);
//sprintf(filename, "/sd/UPAS_TboardtestLog_%s.txt", timestr);
FILE *fp = fopen(filename, "w");
@@ -878,6 +953,7 @@
}
*/
+
sampledVol = 0.0;
RGB_LED.set_led(0,1,0);
wait(1);
@@ -886,8 +962,81 @@
stop.attach(&check_stop, 9); // check if we should shut down every 9 number seconds, starting after the start.
logg.attach(&log_data, logInerval);
//flowCtl.attach(&flowControl, 3);
+/*
+ wait(60);
+
+ schoolF1.getFault();
+ homeF2.getFault();
+ transitF3.getFault();
+ blankF4.getFault();
+
+ schoolF1.drive(254); //closed = 253, open = 254
+ homeF2.drive(253); //closed = 253, open = 254
+ transitF3.drive(253); //closed = 253, open = 254
+ blankF4.drive(253); //closed = 253, open = 254
+
+ wait(1);
+ schoolF1.stop();
+ homeF2.stop();
+ transitF3.stop();
+ blankF4.stop();
+wait(60);
+
+ schoolF1.getFault();
+ homeF2.getFault();
+ transitF3.getFault();
+ blankF4.getFault();
+
+ schoolF1.drive(253); //closed = 253, open = 254
+ homeF2.drive(254); //closed = 253, open = 254
+ transitF3.drive(253); //closed = 253, open = 254
+ blankF4.drive(253); //closed = 253, open = 254
+
+ wait(1);
+ schoolF1.stop();
+ homeF2.stop();
+ transitF3.stop();
+ blankF4.stop();
+
+ wait(60);
+
+ schoolF1.getFault();
+ homeF2.getFault();
+ transitF3.getFault();
+ blankF4.getFault();
+
+ schoolF1.drive(253); //closed = 253, open = 254
+ homeF2.drive(253); //closed = 253, open = 254
+ transitF3.drive(254); //closed = 253, open = 254
+ blankF4.drive(253); //closed = 253, open = 254
+
+ wait(1);
+ schoolF1.stop();
+ homeF2.stop();
+ transitF3.stop();
+ blankF4.stop();
+
+ wait(60);
+
+ schoolF1.getFault();
+ homeF2.getFault();
+ transitF3.getFault();
+ blankF4.getFault();
+
+ schoolF1.drive(253); //closed = 253, open = 254
+ homeF2.drive(253); //closed = 253, open = 254
+ transitF3.drive(253); //closed = 253, open = 254
+ blankF4.drive(254); //closed = 253, open = 254
+
+ wait(1);
+ schoolF1.stop();
+ homeF2.stop();
+ transitF3.stop();
+ blankF4.stop();
+*/
+
//** end of initalization **//
//---------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------//
