Nucleo based high altitude balloon computer

Dependencies:   SDFileSystem Venus838 mbed MS5611 TinyGPS

Committer:
matgyver
Date:
Thu Jun 26 14:43:31 2014 +0000
Revision:
6:f91db4a7acf1
Parent:
5:1facb0e83e62
Child:
7:308ab9062b76
Fixed issue with logging to the SD Card

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