Nucleo based high altitude balloon computer

Dependencies:   SDFileSystem Venus838 mbed MS5611 TinyGPS

Committer:
ethanharstad
Date:
Tue Jun 24 15:20:54 2014 +0000
Revision:
4:96539c6e50c0
Parent:
3:552319ab5341
Child:
5:1facb0e83e62
Fix printf formats

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);
ethanharstad 1:678ba5aa45fc 10 Serial pc(USBTX, USBRX);
ethanharstad 3:552319ab5341 11 Venus838 venus(GPS_TX, GPS_RX);
ethanharstad 3:552319ab5341 12 TinyGPS gps;
ethanharstad 2:244d3912b449 13 MS5611I2C pres(I2C_SDA, I2C_SCL, false);
ethanharstad 1:678ba5aa45fc 14 SDFileSystem sd(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, "sd");
ethanharstad 3:552319ab5341 15 Timer tick;
ethanharstad 1:678ba5aa45fc 16
ethanharstad 1:678ba5aa45fc 17 void init() {
ethanharstad 1:678ba5aa45fc 18 pc.baud(115200);
ethanharstad 3:552319ab5341 19 grn = LED_OFF;
ethanharstad 3:552319ab5341 20 ylw = LED_OFF;
ethanharstad 1:678ba5aa45fc 21
ethanharstad 3:552319ab5341 22 venus.setUpdateRate(10);
ethanharstad 3:552319ab5341 23 venus.setNavigationMode(4);
ethanharstad 3:552319ab5341 24 venus.setNmeaMessages(true, false, false, false, true, false);
ethanharstad 1:678ba5aa45fc 25
ethanharstad 1:678ba5aa45fc 26 printf("Attempting to open SD card...\n");
ethanharstad 1:678ba5aa45fc 27 mkdir("/sd/mydir", 0777);
ethanharstad 1:678ba5aa45fc 28
ethanharstad 1:678ba5aa45fc 29 printf("Attempting to open file...\n");
ethanharstad 1:678ba5aa45fc 30 FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
ethanharstad 1:678ba5aa45fc 31 if(fp == NULL) {
ethanharstad 1:678ba5aa45fc 32 error("Could not open file for write\n");
ethanharstad 3:552319ab5341 33 ylw = LED_ON;
ethanharstad 1:678ba5aa45fc 34 }
ethanharstad 1:678ba5aa45fc 35 fprintf(fp, "Hello fun SD Card World!");
ethanharstad 1:678ba5aa45fc 36
ethanharstad 1:678ba5aa45fc 37 printf("Closing file...\n");
ethanharstad 1:678ba5aa45fc 38 fclose(fp);
ethanharstad 1:678ba5aa45fc 39
ethanharstad 3:552319ab5341 40 pres.printCoefficients();
ethanharstad 3:552319ab5341 41
ethanharstad 3:552319ab5341 42 tick.start();
ethanharstad 1:678ba5aa45fc 43 pc.printf("Atlas Ready!\n");
ethanharstad 1:678ba5aa45fc 44 }
ethanharstad 1:678ba5aa45fc 45
ethanharstad 1:678ba5aa45fc 46 int main() {
ethanharstad 3:552319ab5341 47 unsigned long date, time, ttf;
ethanharstad 3:552319ab5341 48 double latitude, longitude, altitude;
ethanharstad 3:552319ab5341 49 float pressure, temperature;
ethanharstad 3:552319ab5341 50 unsigned int writeCount = 0;
ethanharstad 3:552319ab5341 51
ethanharstad 1:678ba5aa45fc 52 init();
ethanharstad 3:552319ab5341 53 FILE *fp = fopen("/sd/atlas.txt", "a");
ethanharstad 3:552319ab5341 54
ethanharstad 1:678ba5aa45fc 55 while(true) {
ethanharstad 3:552319ab5341 56 if(venus.readable()) {
ethanharstad 3:552319ab5341 57 char c = venus.getc();
ethanharstad 3:552319ab5341 58 //pc.putc(c);
ethanharstad 3:552319ab5341 59 gps.encode(c);
ethanharstad 3:552319ab5341 60 }
ethanharstad 3:552319ab5341 61 if(tick.read_ms() >= 500) {
ethanharstad 3:552319ab5341 62 tick.reset();
ethanharstad 3:552319ab5341 63 grn = !grn;
ethanharstad 3:552319ab5341 64
ethanharstad 3:552319ab5341 65 gps.get_datetime(&date, &time, &ttf);
ethanharstad 3:552319ab5341 66 gps.f_get_position(&latitude, &longitude, &ttf);
ethanharstad 3:552319ab5341 67 altitude = gps.f_altitude();
ethanharstad 3:552319ab5341 68 pressure = pres.getPressure();
ethanharstad 3:552319ab5341 69 temperature = pres.getTemperature();
ethanharstad 4:96539c6e50c0 70 pc.printf("%u, %u, %f, %f, %f, %f, %f\n",
ethanharstad 3:552319ab5341 71 date, time, longitude, latitude, altitude,
ethanharstad 3:552319ab5341 72 pressure, temperature
ethanharstad 3:552319ab5341 73 );
ethanharstad 4:96539c6e50c0 74 fprintf(fp, "%u, %u, %f, %f, %f, %f, %f\n",
ethanharstad 3:552319ab5341 75 date, time, longitude, latitude, altitude,
ethanharstad 3:552319ab5341 76 pressure, temperature
ethanharstad 3:552319ab5341 77 );
ethanharstad 3:552319ab5341 78 writeCount++;
ethanharstad 3:552319ab5341 79 if(writeCount > 100) {
ethanharstad 3:552319ab5341 80 writeCount = 0;
ethanharstad 3:552319ab5341 81 fclose(fp);
ethanharstad 3:552319ab5341 82 FILE *fp = fopen("/sd/atlas.txt", "a");
ethanharstad 3:552319ab5341 83 }
ethanharstad 1:678ba5aa45fc 84 }
ethanharstad 1:678ba5aa45fc 85 }
ethanharstad 1:678ba5aa45fc 86 }