![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Thermal wake pod program
Dependencies: DS1820 ExtendedTimer SDFileSystem mbed
Fork of FindingTemp by
main.cpp@2:98ae1b36758e, 2017-07-31 (annotated)
- Committer:
- htompkins20
- Date:
- Mon Jul 31 22:53:20 2017 +0000
- Revision:
- 2:98ae1b36758e
- Parent:
- 1:a036633bc3c2
- Child:
- 3:1d8fca358781
Problem with SD card dismount
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jabbott19 | 0:da5b15595769 | 1 | /* |
jabbott19 | 0:da5b15595769 | 2 | SD pins: DI = p5, DO = p6, SCK = p7, CS = p8 |
jabbott19 | 0:da5b15595769 | 3 | */ |
jabbott19 | 0:da5b15595769 | 4 | |
jabbott19 | 0:da5b15595769 | 5 | |
jabbott19 | 0:da5b15595769 | 6 | #define MULTIPLE_PROBES |
jabbott19 | 0:da5b15595769 | 7 | #define ARM1_DATA_PIN p19 |
jabbott19 | 0:da5b15595769 | 8 | #define TAIL_DATA_PIN p20 |
jabbott19 | 0:da5b15595769 | 9 | #define ARM2_DATA_PIN p30 |
jabbott19 | 0:da5b15595769 | 10 | |
jabbott19 | 0:da5b15595769 | 11 | #include "mbed.h" |
jabbott19 | 0:da5b15595769 | 12 | #include "DS1820.h" |
jabbott19 | 0:da5b15595769 | 13 | #include "ExtendedTimer.h" |
jabbott19 | 0:da5b15595769 | 14 | #include "SDFileSystem.h" |
jabbott19 | 0:da5b15595769 | 15 | |
jabbott19 | 0:da5b15595769 | 16 | #define MAX_PROBES 45 |
jabbott19 | 0:da5b15595769 | 17 | |
jabbott19 | 0:da5b15595769 | 18 | |
jabbott19 | 0:da5b15595769 | 19 | DS1820* probe1[20]; |
jabbott19 | 0:da5b15595769 | 20 | DS1820* probe2[20]; |
jabbott19 | 0:da5b15595769 | 21 | DS1820* probeTail[20]; |
jabbott19 | 0:da5b15595769 | 22 | SDFileSystem fs(p5, p6, p7, p8, "fs"); |
jabbott19 | 0:da5b15595769 | 23 | Serial pc(USBTX,USBRX); |
htompkins20 | 2:98ae1b36758e | 24 | DigitalIn stopMeOrElse(p21); |
jabbott19 | 0:da5b15595769 | 25 | |
jabbott19 | 0:da5b15595769 | 26 | int main() |
jabbott19 | 0:da5b15595769 | 27 | { |
jabbott19 | 0:da5b15595769 | 28 | float lastFlush = 0; |
jabbott19 | 0:da5b15595769 | 29 | float flushInterval = 5*60; |
jabbott19 | 0:da5b15595769 | 30 | float lastMeasurement = 0; |
jabbott19 | 0:da5b15595769 | 31 | float measurementInterval = 30; |
jabbott19 | 0:da5b15595769 | 32 | |
htompkins20 | 2:98ae1b36758e | 33 | pc.printf("Let's do science!\r\n"); |
jabbott19 | 0:da5b15595769 | 34 | // Mount the filesystem |
jabbott19 | 0:da5b15595769 | 35 | bool mountFailure = fs.mount(); |
jabbott19 | 0:da5b15595769 | 36 | if (mountFailure != 0) { |
jabbott19 | 0:da5b15595769 | 37 | pc.printf("Mount failure!\r\n"); |
jabbott19 | 0:da5b15595769 | 38 | return -1; // ends program with error status |
jabbott19 | 0:da5b15595769 | 39 | } |
jabbott19 | 0:da5b15595769 | 40 | pc.printf("Mount success!\r\n"); |
jabbott19 | 0:da5b15595769 | 41 | |
jabbott19 | 0:da5b15595769 | 42 | //File for arm 1 data |
jabbott19 | 0:da5b15595769 | 43 | FILE * output1; |
jabbott19 | 0:da5b15595769 | 44 | //file for arm 2 data |
jabbott19 | 0:da5b15595769 | 45 | FILE* output2; |
jabbott19 | 0:da5b15595769 | 46 | //file for tail data |
jabbott19 | 0:da5b15595769 | 47 | FILE* outputt; |
jabbott19 | 0:da5b15595769 | 48 | |
jabbott19 | 0:da5b15595769 | 49 | output1 = fopen("/fs/Arm1.txt", "a"); |
jabbott19 | 0:da5b15595769 | 50 | output2 = fopen("/fs/Arm2.txt", "a"); |
jabbott19 | 0:da5b15595769 | 51 | outputt = fopen("/fs/Tail.txt", "a"); |
jabbott19 | 0:da5b15595769 | 52 | |
jabbott19 | 0:da5b15595769 | 53 | ExtendedTimer t; |
jabbott19 | 0:da5b15595769 | 54 | //start the timer |
jabbott19 | 0:da5b15595769 | 55 | t.start(); |
jabbott19 | 0:da5b15595769 | 56 | |
jabbott19 | 0:da5b15595769 | 57 | //Find Arm1 Probes |
jabbott19 | 0:da5b15595769 | 58 | // Initialize the probe array to DS1820 objects |
jabbott19 | 0:da5b15595769 | 59 | int num_devices1 = 0; |
jabbott19 | 0:da5b15595769 | 60 | //Iterator for stepping through name[] |
jabbott19 | 0:da5b15595769 | 61 | //int count = 0; |
jabbott19 | 0:da5b15595769 | 62 | pc.printf("Searching on arm 1...\r\n"); |
jabbott19 | 0:da5b15595769 | 63 | while(DS1820::unassignedProbe(ARM1_DATA_PIN)) { |
jabbott19 | 0:da5b15595769 | 64 | probe1[num_devices1] = new DS1820(ARM1_DATA_PIN); |
jabbott19 | 0:da5b15595769 | 65 | num_devices1++; |
jabbott19 | 0:da5b15595769 | 66 | //count ++; |
jabbott19 | 0:da5b15595769 | 67 | if (num_devices1 == MAX_PROBES) |
jabbott19 | 0:da5b15595769 | 68 | break; |
jabbott19 | 0:da5b15595769 | 69 | } |
jabbott19 | 0:da5b15595769 | 70 | pc.printf("Found %d device(s)\r\n\n", num_devices1); |
jabbott19 | 0:da5b15595769 | 71 | |
jabbott19 | 0:da5b15595769 | 72 | pc.printf("Searching on arm 2...\r\n"); |
jabbott19 | 0:da5b15595769 | 73 | //Find Arm2 Probes |
jabbott19 | 0:da5b15595769 | 74 | // Initialize the probe array to DS1820 objects |
jabbott19 | 0:da5b15595769 | 75 | int num_devices2 = 0; |
jabbott19 | 0:da5b15595769 | 76 | //Iterator for stepping through name[] |
jabbott19 | 0:da5b15595769 | 77 | //int count = 0; |
jabbott19 | 0:da5b15595769 | 78 | while(DS1820::unassignedProbe(ARM2_DATA_PIN)) { |
jabbott19 | 0:da5b15595769 | 79 | probe2[num_devices2] = new DS1820(ARM2_DATA_PIN); |
jabbott19 | 0:da5b15595769 | 80 | num_devices2++; |
jabbott19 | 0:da5b15595769 | 81 | //count ++; |
jabbott19 | 0:da5b15595769 | 82 | if (num_devices2 == MAX_PROBES) |
jabbott19 | 0:da5b15595769 | 83 | break; |
jabbott19 | 0:da5b15595769 | 84 | } |
jabbott19 | 0:da5b15595769 | 85 | pc.printf("Found %d device(s)\r\n\n", num_devices2); |
jabbott19 | 0:da5b15595769 | 86 | |
jabbott19 | 0:da5b15595769 | 87 | pc.printf("Searching on tail...\r\n"); |
jabbott19 | 0:da5b15595769 | 88 | //Find Tail Probes |
jabbott19 | 0:da5b15595769 | 89 | // Initialize the probe array to DS1820 objects |
jabbott19 | 0:da5b15595769 | 90 | int num_devicest = 0; |
jabbott19 | 0:da5b15595769 | 91 | //Iterator for stepping through name[] |
jabbott19 | 0:da5b15595769 | 92 | //int count = 0; |
jabbott19 | 0:da5b15595769 | 93 | while(DS1820::unassignedProbe(TAIL_DATA_PIN)) { |
jabbott19 | 0:da5b15595769 | 94 | probeTail[num_devicest] = new DS1820(TAIL_DATA_PIN); |
jabbott19 | 0:da5b15595769 | 95 | num_devicest++; |
jabbott19 | 0:da5b15595769 | 96 | //count ++; |
jabbott19 | 0:da5b15595769 | 97 | if (num_devicest == MAX_PROBES) |
jabbott19 | 0:da5b15595769 | 98 | break; |
jabbott19 | 0:da5b15595769 | 99 | } |
jabbott19 | 0:da5b15595769 | 100 | pc.printf("Found %d device(s)\r\n\n", num_devicest); |
jabbott19 | 0:da5b15595769 | 101 | |
JLarkin | 1:a036633bc3c2 | 102 | |
JLarkin | 1:a036633bc3c2 | 103 | unsigned long long fullName; |
JLarkin | 1:a036633bc3c2 | 104 | unsigned int firstName; |
JLarkin | 1:a036633bc3c2 | 105 | unsigned int lastName; |
jabbott19 | 0:da5b15595769 | 106 | // Write header row to each file with device IDs |
jabbott19 | 0:da5b15595769 | 107 | //tail |
jabbott19 | 0:da5b15595769 | 108 | fprintf(outputt,"Time\t"); |
jabbott19 | 0:da5b15595769 | 109 | for(int count = 0; count < num_devicest; count ++) { |
JLarkin | 1:a036633bc3c2 | 110 | fullName = probeTail[count]->whoAmI(); |
JLarkin | 1:a036633bc3c2 | 111 | firstName = fullName >> 32; |
JLarkin | 1:a036633bc3c2 | 112 | lastName = fullName; |
JLarkin | 1:a036633bc3c2 | 113 | fprintf(outputt, "%x%x\t", firstName, lastName); |
jabbott19 | 0:da5b15595769 | 114 | } |
jabbott19 | 0:da5b15595769 | 115 | //Arm1 |
jabbott19 | 0:da5b15595769 | 116 | fprintf(output1,"Time\t"); |
jabbott19 | 0:da5b15595769 | 117 | for(int count = 0; count < num_devices1; count++) { |
JLarkin | 1:a036633bc3c2 | 118 | fullName = probe1[count]->whoAmI(); |
JLarkin | 1:a036633bc3c2 | 119 | firstName = fullName >> 32; |
JLarkin | 1:a036633bc3c2 | 120 | lastName = fullName; |
JLarkin | 1:a036633bc3c2 | 121 | fprintf(output1, "%x%x\t", firstName, lastName); |
jabbott19 | 0:da5b15595769 | 122 | } |
jabbott19 | 0:da5b15595769 | 123 | fprintf(output2,"Time\t"); |
jabbott19 | 0:da5b15595769 | 124 | //Arm2 |
jabbott19 | 0:da5b15595769 | 125 | for(int count = 0; count < num_devices2; count++) { |
JLarkin | 1:a036633bc3c2 | 126 | fullName = probe2[count]->whoAmI(); |
JLarkin | 1:a036633bc3c2 | 127 | firstName = fullName >> 32; |
JLarkin | 1:a036633bc3c2 | 128 | lastName = fullName; |
JLarkin | 1:a036633bc3c2 | 129 | fprintf(output2, "%x%x\t", firstName, lastName); |
jabbott19 | 0:da5b15595769 | 130 | } |
jabbott19 | 0:da5b15595769 | 131 | fprintf(outputt,"\r\n"); |
jabbott19 | 0:da5b15595769 | 132 | fprintf(output1,"\r\n"); |
jabbott19 | 0:da5b15595769 | 133 | fprintf(output2,"\r\n"); |
jabbott19 | 0:da5b15595769 | 134 | |
jabbott19 | 0:da5b15595769 | 135 | //start collecting data |
jabbott19 | 0:da5b15595769 | 136 | |
htompkins20 | 2:98ae1b36758e | 137 | while((t.read()<4*60*60) && (!stopMeOrElse)) { |
jabbott19 | 0:da5b15595769 | 138 | //conditional statement to trigger sensor readings |
jabbott19 | 0:da5b15595769 | 139 | if ((t.read()-lastMeasurement)>measurementInterval) { |
jabbott19 | 0:da5b15595769 | 140 | lastMeasurement = t.read(); |
jabbott19 | 0:da5b15595769 | 141 | //Tail sensors being read |
jabbott19 | 0:da5b15595769 | 142 | probeTail[0]->convertTemperature(true, DS1820::all_devices); //Start temperature conversion, wait until ready |
jabbott19 | 0:da5b15595769 | 143 | fprintf(outputt,"%3.1f \t",t.read()); |
jabbott19 | 0:da5b15595769 | 144 | for(int i = 0; i < num_devicest; i++) { |
jabbott19 | 0:da5b15595769 | 145 | fprintf(outputt,"%3.1f \t",probeTail[i]->temperature()); |
jabbott19 | 0:da5b15595769 | 146 | } |
jabbott19 | 0:da5b15595769 | 147 | probe1[0]->convertTemperature(true, DS1820::all_devices); |
jabbott19 | 0:da5b15595769 | 148 | fprintf(output1,"%3.1f \t",t.read()); |
jabbott19 | 0:da5b15595769 | 149 | for(int i = 0; i < num_devices1; i++) { |
jabbott19 | 0:da5b15595769 | 150 | fprintf(output1,"%3.1f \t",probe1[i]->temperature()); |
jabbott19 | 0:da5b15595769 | 151 | } |
jabbott19 | 0:da5b15595769 | 152 | probe2[0]->convertTemperature(true, DS1820::all_devices); |
jabbott19 | 0:da5b15595769 | 153 | fprintf(output2,"%3.1f \t",t.read()); |
jabbott19 | 0:da5b15595769 | 154 | for(int i = 0; i < num_devices2; i++) { |
jabbott19 | 0:da5b15595769 | 155 | fprintf(output2,"%3.1f \t",probe2[i]->temperature()); |
jabbott19 | 0:da5b15595769 | 156 | } |
jabbott19 | 0:da5b15595769 | 157 | fprintf(outputt,"\r\n"); |
jabbott19 | 0:da5b15595769 | 158 | fprintf(output1,"\r\n"); |
jabbott19 | 0:da5b15595769 | 159 | fprintf(output2,"\r\n"); |
jabbott19 | 0:da5b15595769 | 160 | } |
jabbott19 | 0:da5b15595769 | 161 | |
jabbott19 | 0:da5b15595769 | 162 | if((t.read()-lastFlush)>flushInterval) { |
jabbott19 | 0:da5b15595769 | 163 | lastFlush = t.read(); |
jabbott19 | 0:da5b15595769 | 164 | pc.printf("Wrote block of data at %3.1f s after power-up\r\n",lastFlush); |
jabbott19 | 0:da5b15595769 | 165 | fclose(outputt); |
jabbott19 | 0:da5b15595769 | 166 | fclose(output1); |
jabbott19 | 0:da5b15595769 | 167 | fclose(output2); |
jabbott19 | 0:da5b15595769 | 168 | output1 = fopen("/fs/Arm1.txt", "a"); |
jabbott19 | 0:da5b15595769 | 169 | output2 = fopen("/fs/Arm2.txt", "a"); |
jabbott19 | 0:da5b15595769 | 170 | outputt = fopen("/fs/Tail.txt", "a"); |
jabbott19 | 0:da5b15595769 | 171 | } |
jabbott19 | 0:da5b15595769 | 172 | //fprintf(output, "Device %d returns %3.1fo\r\n", i, probe[i]->temperature()); |
jabbott19 | 0:da5b15595769 | 173 | //flushing io buffer |
jabbott19 | 0:da5b15595769 | 174 | |
jabbott19 | 0:da5b15595769 | 175 | } |
htompkins20 | 2:98ae1b36758e | 176 | pc.printf("It has been good to do science.\r\n"); |
jabbott19 | 0:da5b15595769 | 177 | fclose(outputt); |
jabbott19 | 0:da5b15595769 | 178 | fclose(output1); |
jabbott19 | 0:da5b15595769 | 179 | fclose(output2); |
jabbott19 | 0:da5b15595769 | 180 | fs.unmount(); |
jabbott19 | 0:da5b15595769 | 181 | } |