Atlas data logger
Dependencies: MPU9150 SDFileSystem mbed
Atlas.cpp@0:a896760ee53b, 2014-06-20 (annotated)
- Committer:
- ethanharstad
- Date:
- Fri Jun 20 19:59:59 2014 +0000
- Revision:
- 0:a896760ee53b
Test code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ethanharstad | 0:a896760ee53b | 1 | #include "mbed.h" |
ethanharstad | 0:a896760ee53b | 2 | #include "Atlas.h" |
ethanharstad | 0:a896760ee53b | 3 | #include "SDFileSystem.h" |
ethanharstad | 0:a896760ee53b | 4 | |
ethanharstad | 0:a896760ee53b | 5 | DigitalOut grn(LED_GRN); |
ethanharstad | 0:a896760ee53b | 6 | DigitalOut ylw(LED_YLW); |
ethanharstad | 0:a896760ee53b | 7 | Serial pc(USBTX, USBRX); |
ethanharstad | 0:a896760ee53b | 8 | Serial gps(GPS_TX, GPS_RX); |
ethanharstad | 0:a896760ee53b | 9 | SDFileSystem sd(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, "sd"); |
ethanharstad | 0:a896760ee53b | 10 | |
ethanharstad | 0:a896760ee53b | 11 | void init() { |
ethanharstad | 0:a896760ee53b | 12 | pc.baud(115200); |
ethanharstad | 0:a896760ee53b | 13 | gps.baud(115200); |
ethanharstad | 0:a896760ee53b | 14 | grn = LED_ON; |
ethanharstad | 0:a896760ee53b | 15 | ylw = LED_ON; |
ethanharstad | 0:a896760ee53b | 16 | |
ethanharstad | 0:a896760ee53b | 17 | printf("Attempting to open SD card...\n"); |
ethanharstad | 0:a896760ee53b | 18 | mkdir("/sd/mydir", 0777); |
ethanharstad | 0:a896760ee53b | 19 | |
ethanharstad | 0:a896760ee53b | 20 | printf("Attempting to open file...\n"); |
ethanharstad | 0:a896760ee53b | 21 | FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); |
ethanharstad | 0:a896760ee53b | 22 | if(fp == NULL) { |
ethanharstad | 0:a896760ee53b | 23 | error("Could not open file for write\n"); |
ethanharstad | 0:a896760ee53b | 24 | ylw = LED_OFF; |
ethanharstad | 0:a896760ee53b | 25 | } |
ethanharstad | 0:a896760ee53b | 26 | fprintf(fp, "Hello fun SD Card World!"); |
ethanharstad | 0:a896760ee53b | 27 | |
ethanharstad | 0:a896760ee53b | 28 | printf("Closing file...\n"); |
ethanharstad | 0:a896760ee53b | 29 | fclose(fp); |
ethanharstad | 0:a896760ee53b | 30 | |
ethanharstad | 0:a896760ee53b | 31 | pc.printf("Atlas Ready!\n"); |
ethanharstad | 0:a896760ee53b | 32 | } |
ethanharstad | 0:a896760ee53b | 33 | |
ethanharstad | 0:a896760ee53b | 34 | int main() { |
ethanharstad | 0:a896760ee53b | 35 | init(); |
ethanharstad | 0:a896760ee53b | 36 | while(true) { |
ethanharstad | 0:a896760ee53b | 37 | if(gps.readable()) { |
ethanharstad | 0:a896760ee53b | 38 | pc.putc(gps.getc()); |
ethanharstad | 0:a896760ee53b | 39 | } |
ethanharstad | 0:a896760ee53b | 40 | } |
ethanharstad | 0:a896760ee53b | 41 | } |