asdf

Dependencies:   SDFileSystem mbed

Fork of All_Combined_Real by JanPaul Bergeson

Revision:
1:5fa445bd14a6
Parent:
0:26713d1db198
Child:
2:146625d6992d
--- a/main.cpp	Thu Mar 10 17:27:10 2016 +0000
+++ b/main.cpp	Thu Mar 10 17:40:58 2016 +0000
@@ -1,13 +1,35 @@
 #include "mbed.h"
 #include "nmea.h"
 #include "SDFileSystem.h"
+#include "SPI.h"
 
+#define NUM_PIXELS 2048
 #define BUF_SIZE 1024
+#define OUTPUT_FILE "/sd/data.csv"
 
-DigitalOut gpo(D0);
+// pinout for spectrometer
+
+// Mosi (#8) -> PTD2
+// Miso (#7) -> PTD3
+// Sclk (#9) -> PTD1
+
+// Pixel_rdy (#6) -> PTA1
+// Fifo_cs (#3) -> PTB23
+// Trigger (#13) -> PTA2
+ 
+SPI spi(PTD2, PTD3, PTD1); // mosi, miso, sclk
+
+DigitalIn pixel_rdy(PTA1);
+DigitalOut fifo_cs(PTB23);
+DigitalOut trigger(PTA2);
+
+// Blinking red LED
 DigitalOut led(LED_RED);
 
+// GPS connection (through arduino)
 Serial duino(PTC4, PTC3);
+
+// USB serial to PC
 Serial pc(USBTX, USBRX);
 
 /**************************************************
@@ -16,17 +38,47 @@
 SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd");
 FILE *fpData;
 
+void read_pixels() {
+    int data[NUM_PIXELS];
+    for (int i = 0; i < NUM_PIXELS; i++) {
+        
+        while (!pixel_rdy);
+        
+        fifo_cs = 0;
+        data[i] = spi.write(0x00); // write a dummy byte just to read the data
+        fifo_cs = 1;
+        
+    }
+    
+    // write to file and pc
+    fpData = fopen(OUTPUT_FILE, "a");
+    for (int i = 0; i < NUM_PIXELS; i++)
+    {
+        pc.printf(",%d", data[i]);
+        fprintf(fpData, ",%d", data[i]);
+    }
+    pc.printf("\r\n");
+    fprintf(fpData, "\r\n");
+    fclose(fpData);
+}
+
 int main()
 {
     pc.baud(115200); // make sure to set computer TERA Term or whatever to 115200 baud!!!
     duino.baud(9600);
     pc.printf("Initializing ...\r\n");
+    
+    fifo_cs = 1;
+    trigger = 0;
+    wait(0.5f);
+    
     char buffer[BUF_SIZE];
     
     while (true) {
         
         led = !led;
         
+        // --- gps stuff --- //
         get_nmea(&duino, buffer, BUF_SIZE);
         
         struct NMEA_data nmea = parse_line(buffer);
@@ -40,7 +92,7 @@
             
         // assemble data into summary string
         char status_str[BUF_SIZE];
-        sprintf(status_str, "%02d:%02d:%02d, %d/%d/%d, %dd %lf' %c %dd %lf' %c, %s\r\n", 
+        sprintf(status_str, "%02d:%02d:%02d,%d/%d/%d,%dd %lf' %c %dd %lf' %c,%s", 
             nmea.hours, nmea.minutes, nmea.seconds, 
             nmea.month, nmea.day, nmea.year,
             nmea.latitude, nmea.latitude_minutes, nmea.latitude_direction,
@@ -49,9 +101,22 @@
         // print to pc, sd card
         pc.printf("%s", status_str);
         
-        fpData = fopen("/sd/data.txt", "a");
+        fpData = fopen(OUTPUT_FILE, "a");
         fprintf(fpData, "%s", status_str);
         fclose(fpData);
+        
+        // --- end of gps stuff --- //
+        
+        
+        
+        // Trigger an acquisition from spectrometer
+        trigger = 1;
+        wait_ms(1);
+        trigger = 0;
+        read_pixels();
+        
+        
+        
         wait(0.5f);
     }
 }
\ No newline at end of file