Nucleo based high altitude balloon computer
Dependencies: SDFileSystem Venus838 mbed MS5611 TinyGPS
Atlas.cpp@5:1facb0e83e62, 2014-06-25 (annotated)
- Committer:
- matgyver
- Date:
- Wed Jun 25 15:02:14 2014 +0000
- Revision:
- 5:1facb0e83e62
- Parent:
- 4:96539c6e50c0
- Child:
- 6:f91db4a7acf1
Added reading in the battery voltage and displaying and logging the data
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ethanharstad | 1:678ba5aa45fc | 1 | #include "mbed.h" |
ethanharstad | 1:678ba5aa45fc | 2 | #include "Atlas.h" |
ethanharstad | 1:678ba5aa45fc | 3 | #include "SDFileSystem.h" |
ethanharstad | 1:678ba5aa45fc | 4 | #include "Venus838.h" |
ethanharstad | 3:552319ab5341 | 5 | #include "TinyGPS.h" |
ethanharstad | 2:244d3912b449 | 6 | #include "MS5611I2C.h" |
ethanharstad | 1:678ba5aa45fc | 7 | |
ethanharstad | 1:678ba5aa45fc | 8 | DigitalOut grn(LED_GRN); |
ethanharstad | 1:678ba5aa45fc | 9 | DigitalOut ylw(LED_YLW); |
matgyver | 5:1facb0e83e62 | 10 | AnalogIn batt(PC_2); |
ethanharstad | 1:678ba5aa45fc | 11 | Serial pc(USBTX, USBRX); |
ethanharstad | 3:552319ab5341 | 12 | Venus838 venus(GPS_TX, GPS_RX); |
ethanharstad | 3:552319ab5341 | 13 | TinyGPS gps; |
ethanharstad | 2:244d3912b449 | 14 | MS5611I2C pres(I2C_SDA, I2C_SCL, false); |
ethanharstad | 1:678ba5aa45fc | 15 | SDFileSystem sd(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, "sd"); |
ethanharstad | 3:552319ab5341 | 16 | Timer tick; |
ethanharstad | 1:678ba5aa45fc | 17 | |
ethanharstad | 1:678ba5aa45fc | 18 | void init() { |
ethanharstad | 1:678ba5aa45fc | 19 | pc.baud(115200); |
ethanharstad | 3:552319ab5341 | 20 | grn = LED_OFF; |
ethanharstad | 3:552319ab5341 | 21 | ylw = LED_OFF; |
ethanharstad | 1:678ba5aa45fc | 22 | |
ethanharstad | 3:552319ab5341 | 23 | venus.setUpdateRate(10); |
ethanharstad | 3:552319ab5341 | 24 | venus.setNavigationMode(4); |
ethanharstad | 3:552319ab5341 | 25 | venus.setNmeaMessages(true, false, false, false, true, false); |
ethanharstad | 1:678ba5aa45fc | 26 | |
ethanharstad | 1:678ba5aa45fc | 27 | printf("Attempting to open SD card...\n"); |
matgyver | 5:1facb0e83e62 | 28 | mkdir("/sd/debug", 0777); |
ethanharstad | 1:678ba5aa45fc | 29 | |
ethanharstad | 1:678ba5aa45fc | 30 | printf("Attempting to open file...\n"); |
matgyver | 5:1facb0e83e62 | 31 | FILE *fp = fopen("/sd/debug/debug.txt", "w"); |
ethanharstad | 1:678ba5aa45fc | 32 | if(fp == NULL) { |
ethanharstad | 1:678ba5aa45fc | 33 | error("Could not open file for write\n"); |
ethanharstad | 3:552319ab5341 | 34 | ylw = LED_ON; |
ethanharstad | 1:678ba5aa45fc | 35 | } |
matgyver | 5:1facb0e83e62 | 36 | fprintf(fp, "Hooray, we can write to the SD Card. Go get a cookie."); |
ethanharstad | 1:678ba5aa45fc | 37 | |
ethanharstad | 1:678ba5aa45fc | 38 | printf("Closing file...\n"); |
ethanharstad | 1:678ba5aa45fc | 39 | fclose(fp); |
ethanharstad | 1:678ba5aa45fc | 40 | |
ethanharstad | 3:552319ab5341 | 41 | pres.printCoefficients(); |
ethanharstad | 3:552319ab5341 | 42 | |
ethanharstad | 3:552319ab5341 | 43 | tick.start(); |
ethanharstad | 1:678ba5aa45fc | 44 | pc.printf("Atlas Ready!\n"); |
ethanharstad | 1:678ba5aa45fc | 45 | } |
ethanharstad | 1:678ba5aa45fc | 46 | |
ethanharstad | 1:678ba5aa45fc | 47 | int main() { |
ethanharstad | 3:552319ab5341 | 48 | unsigned long date, time, ttf; |
ethanharstad | 3:552319ab5341 | 49 | double latitude, longitude, altitude; |
matgyver | 5:1facb0e83e62 | 50 | float pressure, temperature, battery; |
ethanharstad | 3:552319ab5341 | 51 | unsigned int writeCount = 0; |
ethanharstad | 3:552319ab5341 | 52 | |
ethanharstad | 1:678ba5aa45fc | 53 | init(); |
ethanharstad | 3:552319ab5341 | 54 | FILE *fp = fopen("/sd/atlas.txt", "a"); |
matgyver | 5:1facb0e83e62 | 55 | fprintf(fp, "Atlas Logger\r\n"); |
matgyver | 5:1facb0e83e62 | 56 | fprintf(fp, "Date Time Lon Lat Alt Pressure Temp Battery\r\n"); |
matgyver | 5:1facb0e83e62 | 57 | fprintf(fp, "------------------------------------------------------------------\r\n"); |
matgyver | 5:1facb0e83e62 | 58 | //fclose(fp); |
ethanharstad | 1:678ba5aa45fc | 59 | while(true) { |
ethanharstad | 3:552319ab5341 | 60 | if(venus.readable()) { |
ethanharstad | 3:552319ab5341 | 61 | char c = venus.getc(); |
ethanharstad | 3:552319ab5341 | 62 | //pc.putc(c); |
ethanharstad | 3:552319ab5341 | 63 | gps.encode(c); |
ethanharstad | 3:552319ab5341 | 64 | } |
ethanharstad | 3:552319ab5341 | 65 | if(tick.read_ms() >= 500) { |
ethanharstad | 3:552319ab5341 | 66 | tick.reset(); |
ethanharstad | 3:552319ab5341 | 67 | grn = !grn; |
ethanharstad | 3:552319ab5341 | 68 | |
ethanharstad | 3:552319ab5341 | 69 | gps.get_datetime(&date, &time, &ttf); |
ethanharstad | 3:552319ab5341 | 70 | gps.f_get_position(&latitude, &longitude, &ttf); |
ethanharstad | 3:552319ab5341 | 71 | altitude = gps.f_altitude(); |
ethanharstad | 3:552319ab5341 | 72 | pressure = pres.getPressure(); |
ethanharstad | 3:552319ab5341 | 73 | temperature = pres.getTemperature(); |
matgyver | 5:1facb0e83e62 | 74 | battery = (batt.read()*3.3f) * 4.0f; |
matgyver | 5:1facb0e83e62 | 75 | wait_ms(1); |
matgyver | 5:1facb0e83e62 | 76 | pc.printf("%u, %u, %f, %f, %f, %f, %f, %f\n", |
ethanharstad | 3:552319ab5341 | 77 | date, time, longitude, latitude, altitude, |
matgyver | 5:1facb0e83e62 | 78 | pressure, temperature, battery |
ethanharstad | 3:552319ab5341 | 79 | ); |
matgyver | 5:1facb0e83e62 | 80 | fprintf(fp, "%u, %u, %f, %f, %f, %f, %f %f\n", |
ethanharstad | 3:552319ab5341 | 81 | date, time, longitude, latitude, altitude, |
matgyver | 5:1facb0e83e62 | 82 | pressure, temperature, battery |
ethanharstad | 3:552319ab5341 | 83 | ); |
ethanharstad | 3:552319ab5341 | 84 | writeCount++; |
ethanharstad | 3:552319ab5341 | 85 | if(writeCount > 100) { |
ethanharstad | 3:552319ab5341 | 86 | writeCount = 0; |
ethanharstad | 3:552319ab5341 | 87 | fclose(fp); |
ethanharstad | 3:552319ab5341 | 88 | FILE *fp = fopen("/sd/atlas.txt", "a"); |
ethanharstad | 3:552319ab5341 | 89 | } |
ethanharstad | 1:678ba5aa45fc | 90 | } |
ethanharstad | 1:678ba5aa45fc | 91 | } |
ethanharstad | 1:678ba5aa45fc | 92 | } |