diff --git a/arduino_c12880ma_example/arduino_c12880ma_example.ino b/arduino_c12880ma_example/arduino_c12880ma_example.ino new file mode 100644 index 0000000..4d6748c --- /dev/null +++ b/arduino_c12880ma_example/arduino_c12880ma_example.ino @@ -0,0 +1,129 @@ +/* + * Macro Definitions + */ +#define SPEC_TRG A0 +#define SPEC_ST A1 +#define SPEC_CLK A2 +#define SPEC_VIDEO A3 +#define WHITE_LED A4 +#define LASER_404 A5 + +#define SPEC_CHANNELS 288 // New Spec Channel +uint16_t data[SPEC_CHANNELS]; + +void setup(){ + + //Set desired pins to OUTPUT + pinMode(SPEC_CLK, OUTPUT); + pinMode(SPEC_ST, OUTPUT); + pinMode(LASER_404, OUTPUT); + pinMode(WHITE_LED, OUTPUT); + + digitalWrite(SPEC_CLK, HIGH); // Set SPEC_CLK High + digitalWrite(SPEC_ST, LOW); // Set SPEC_ST Low + + Serial.begin(115200); // Baud Rate set to 115200 + +} + +/* + * This functions reads spectrometer data from SPEC_VIDEO + * Look at the Timing Chart in the Datasheet for more info + */ +void readSpectrometer(){ + + int delayTime = 1; // delay time + + // Start clock cycle and set start pulse to signal start + digitalWrite(SPEC_CLK, LOW); + delayMicroseconds(delayTime); + digitalWrite(SPEC_CLK, HIGH); + delayMicroseconds(delayTime); + digitalWrite(SPEC_CLK, LOW); + digitalWrite(SPEC_ST, HIGH); + delayMicroseconds(delayTime); + + //Sample for a period of time + for(int i = 0; i < 15; i++){ + + digitalWrite(SPEC_CLK, HIGH); + delayMicroseconds(delayTime); + digitalWrite(SPEC_CLK, LOW); + delayMicroseconds(delayTime); + + } + + //Set SPEC_ST to low + digitalWrite(SPEC_ST, LOW); + + //Sample for a period of time + for(int i = 0; i < 85; i++){ + + digitalWrite(SPEC_CLK, HIGH); + delayMicroseconds(delayTime); + digitalWrite(SPEC_CLK, LOW); + delayMicroseconds(delayTime); + + } + + //One more clock pulse before the actual read + digitalWrite(SPEC_CLK, HIGH); + delayMicroseconds(delayTime); + digitalWrite(SPEC_CLK, LOW); + delayMicroseconds(delayTime); + + //Read from SPEC_VIDEO + for(int i = 0; i < SPEC_CHANNELS; i++){ + + data[i] = analogRead(SPEC_VIDEO); + + digitalWrite(SPEC_CLK, HIGH); + delayMicroseconds(delayTime); + digitalWrite(SPEC_CLK, LOW); + delayMicroseconds(delayTime); + + } + + //Set SPEC_ST to high + digitalWrite(SPEC_ST, HIGH); + + //Sample for a small amount of time + for(int i = 0; i < 7; i++){ + + digitalWrite(SPEC_CLK, HIGH); + delayMicroseconds(delayTime); + digitalWrite(SPEC_CLK, LOW); + delayMicroseconds(delayTime); + + } + + digitalWrite(SPEC_CLK, HIGH); + delayMicroseconds(delayTime); + +} + +/* + * The function below prints out data to the terminal or + * processing plot + */ +void printData(){ + + for (int i = 0; i < SPEC_CHANNELS; i++){ + + Serial.print(data[i]); + Serial.print(','); + + } + + Serial.print("\n"); +} + +void loop(){ + + readSpectrometer(); + printData(); + delay(10); + +} + + diff --git a/processing_plot/processing_plot_c12880ma.pde b/processing_plot/processing_plot_c12880ma.pde new file mode 100644 index 0000000..9ca9851 --- /dev/null +++ b/processing_plot/processing_plot_c12880ma.pde @@ -0,0 +1,110 @@ +import processing.serial.*; + +Serial myPort; +String val; +int[] data; +double[] summed; +int draw_sum=0; + +double find_max(double[] input) +{ + double max = 0; + for (int i = 0; i < input.length; i++) + { + if (input[i] > max) + { + max = input[i]; + } + } + return max; +} + +void plotdata() +{ + + double summed_max = (find_max(summed))/875; + + background(0); + + if (draw_sum !=0) + { + for (int i=0; i 0) + { + val = myPort.readStringUntil('\n'); // read it and store it in val + if (val != null) + { + data = int(split(val, ',')); + + for (int i = 0; i < data.length; i++) + { + if (i