Nucleo based high altitude balloon computer

Dependencies:   SDFileSystem Venus838 mbed MS5611 TinyGPS

Committer:
matgyver
Date:
Mon Jun 30 04:02:08 2014 +0000
Revision:
7:308ab9062b76
Parent:
6:f91db4a7acf1
Fixed lockup issue and swapped from Timer to Ticker.  Moved logging function to separate function.  Added more info to debug file and added placeholders for additional information.  Other minor bugfixes.

Who changed what in which revision?

UserRevisionLine numberNew 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");
matgyver 7:308ab9062b76 16 Ticker tick;
matgyver 7:308ab9062b76 17
matgyver 7:308ab9062b76 18 unsigned int logCount = 0;
matgyver 7:308ab9062b76 19
matgyver 7:308ab9062b76 20 //Function to log data
matgyver 7:308ab9062b76 21 void datalog(void) {
matgyver 7:308ab9062b76 22 unsigned long date, time, ttf;
matgyver 7:308ab9062b76 23 double latitude, longitude, altitude;
matgyver 7:308ab9062b76 24 float pressure, temperature, battery;
matgyver 7:308ab9062b76 25 //unsigned int writeCount = 0;
matgyver 7:308ab9062b76 26 //unsigned int logCount = 0;
matgyver 7:308ab9062b76 27
matgyver 7:308ab9062b76 28 grn = !grn;
matgyver 7:308ab9062b76 29 gps.get_datetime(&date, &time, &ttf);
matgyver 7:308ab9062b76 30 gps.f_get_position(&latitude, &longitude, &ttf);
matgyver 7:308ab9062b76 31 altitude = gps.f_altitude();
matgyver 7:308ab9062b76 32 pressure = pres.getPressure();
matgyver 7:308ab9062b76 33 temperature = pres.getTemperature();
matgyver 7:308ab9062b76 34 battery = (batt.read()*3.3f) * 4.0f;
matgyver 7:308ab9062b76 35 //wait_ms(1);
matgyver 7:308ab9062b76 36 pc.printf("%u, %u, %u, %f, %f, %f, %f, %f, %f\r\n",
matgyver 7:308ab9062b76 37 logCount, date, time, longitude, latitude, altitude,
matgyver 7:308ab9062b76 38 pressure, temperature, battery);
matgyver 7:308ab9062b76 39 FILE *fp = fopen("/sd/atlas.txt", "a");
matgyver 7:308ab9062b76 40 fprintf(fp, "%u, %u, %u, %f, %f, %f, %f, %f %f\r\n",
matgyver 7:308ab9062b76 41 logCount, date, time, longitude, latitude, altitude,
matgyver 7:308ab9062b76 42 pressure, temperature, battery);
matgyver 7:308ab9062b76 43 logCount++;
matgyver 7:308ab9062b76 44 fclose(fp);
matgyver 7:308ab9062b76 45 }
ethanharstad 1:678ba5aa45fc 46
ethanharstad 1:678ba5aa45fc 47 void init() {
ethanharstad 1:678ba5aa45fc 48 pc.baud(115200);
ethanharstad 3:552319ab5341 49 grn = LED_OFF;
ethanharstad 3:552319ab5341 50 ylw = LED_OFF;
matgyver 6:f91db4a7acf1 51 printf("Configuring Venus GPS...\r\n");
matgyver 6:f91db4a7acf1 52 //venus.setUpdateRate(1);
ethanharstad 3:552319ab5341 53 venus.setNavigationMode(4);
ethanharstad 3:552319ab5341 54 venus.setNmeaMessages(true, false, false, false, true, false);
ethanharstad 1:678ba5aa45fc 55
matgyver 6:f91db4a7acf1 56 printf("Attempting to open SD card...\r\n");
matgyver 5:1facb0e83e62 57 mkdir("/sd/debug", 0777);
ethanharstad 1:678ba5aa45fc 58
matgyver 6:f91db4a7acf1 59 printf("Attempting to open file...\r\n");
matgyver 5:1facb0e83e62 60 FILE *fp = fopen("/sd/debug/debug.txt", "w");
ethanharstad 1:678ba5aa45fc 61 if(fp == NULL) {
matgyver 6:f91db4a7acf1 62 error("Could not open file for write\r\n");
ethanharstad 3:552319ab5341 63 ylw = LED_ON;
ethanharstad 1:678ba5aa45fc 64 }
matgyver 7:308ab9062b76 65 fprintf(fp, "Atlas Debug File\r\n");
matgyver 7:308ab9062b76 66 fprintf(fp, "====================\r\n");
matgyver 7:308ab9062b76 67 fprintf(fp, "Atlas Firmware: 0.1\r\n");
matgyver 7:308ab9062b76 68 //TODO Add calls to query GPS for fimrware and other info
matgyver 7:308ab9062b76 69 fprintf(fp, "GPS Firmware: Update rate: Mode: \r\n");
matgyver 7:308ab9062b76 70 //fprintf(fp, pres.printCoefficients());
matgyver 6:f91db4a7acf1 71 printf("Closing file...\r\n");
ethanharstad 1:678ba5aa45fc 72 fclose(fp);
ethanharstad 1:678ba5aa45fc 73
ethanharstad 3:552319ab5341 74 pres.printCoefficients();
ethanharstad 3:552319ab5341 75
matgyver 7:308ab9062b76 76 //tick.start();
matgyver 6:f91db4a7acf1 77 pc.printf("Atlas Ready!\r\n");
ethanharstad 1:678ba5aa45fc 78 }
ethanharstad 1:678ba5aa45fc 79
ethanharstad 1:678ba5aa45fc 80 int main() {
ethanharstad 3:552319ab5341 81
ethanharstad 1:678ba5aa45fc 82 init();
matgyver 7:308ab9062b76 83 tick.attach(&datalog,1.0);
ethanharstad 3:552319ab5341 84 FILE *fp = fopen("/sd/atlas.txt", "a");
matgyver 5:1facb0e83e62 85 fprintf(fp, "Atlas Logger\r\n");
matgyver 7:308ab9062b76 86 fprintf(fp, "Count Date Time Lon Lat Alt Pressure Temp Battery\r\n");
matgyver 7:308ab9062b76 87 fprintf(fp, "-------------------------------------------------------------------------\r\n");
matgyver 6:f91db4a7acf1 88 fclose(fp);
ethanharstad 1:678ba5aa45fc 89 while(true) {
ethanharstad 3:552319ab5341 90 if(venus.readable()) {
ethanharstad 3:552319ab5341 91 char c = venus.getc();
ethanharstad 3:552319ab5341 92 //pc.putc(c);
ethanharstad 3:552319ab5341 93 gps.encode(c);
ethanharstad 3:552319ab5341 94 }
matgyver 7:308ab9062b76 95
matgyver 7:308ab9062b76 96 /*
ethanharstad 3:552319ab5341 97 if(tick.read_ms() >= 500) {
ethanharstad 3:552319ab5341 98 tick.reset();
ethanharstad 3:552319ab5341 99 grn = !grn;
ethanharstad 3:552319ab5341 100 gps.get_datetime(&date, &time, &ttf);
ethanharstad 3:552319ab5341 101 gps.f_get_position(&latitude, &longitude, &ttf);
ethanharstad 3:552319ab5341 102 altitude = gps.f_altitude();
ethanharstad 3:552319ab5341 103 pressure = pres.getPressure();
ethanharstad 3:552319ab5341 104 temperature = pres.getTemperature();
matgyver 5:1facb0e83e62 105 battery = (batt.read()*3.3f) * 4.0f;
matgyver 5:1facb0e83e62 106 wait_ms(1);
matgyver 7:308ab9062b76 107 pc.printf("%u %u, %u, %f, %f, %f, %f, %f, %f\r\n",
matgyver 7:308ab9062b76 108 logCount, date, time, longitude, latitude, altitude,
matgyver 5:1facb0e83e62 109 pressure, temperature, battery
ethanharstad 3:552319ab5341 110 );
matgyver 6:f91db4a7acf1 111 FILE *fp = fopen("/sd/atlas.txt", "a");
matgyver 7:308ab9062b76 112 fprintf(fp, "%u %u, %u, %f, %f, %f, %f, %f %f\r\n",
matgyver 7:308ab9062b76 113 logCount, date, time, longitude, latitude, altitude,
matgyver 5:1facb0e83e62 114 pressure, temperature, battery
ethanharstad 3:552319ab5341 115 );
matgyver 7:308ab9062b76 116 logCount++;
matgyver 6:f91db4a7acf1 117 fclose(fp);
ethanharstad 3:552319ab5341 118 writeCount++;
matgyver 7:308ab9062b76 119 if(writeCount > 100) {
matgyver 7:308ab9062b76 120 writeCount = 0;
matgyver 7:308ab9062b76 121 fclose(fp);
matgyver 7:308ab9062b76 122 FILE *fp = fopen("/sd/atlas.txt", "a");
matgyver 7:308ab9062b76 123 }
ethanharstad 1:678ba5aa45fc 124 }
matgyver 7:308ab9062b76 125 */
ethanharstad 1:678ba5aa45fc 126 }
ethanharstad 1:678ba5aa45fc 127 }