Commit d5a13a0e authored by saberioon's avatar saberioon
Browse files

init

parents
File added
/*
* 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);
}
This image diff could not be displayed because it is too large. You can view the blob instead.
This image diff could not be displayed because it is too large. You can view the blob instead.
This image diff could not be displayed because it is too large. You can view the blob instead.
This image diff could not be displayed because it is too large. You can view the blob instead.
## How to build a spectrometer at home
### Hardware
To build a spectrometer, you need :
1. Arduino Uno Rev3 : [https://store.arduino.cc/arduino-uno-rev3](https://store.arduino.cc/arduino-uno-rev3)
2. Hamamatsu C12880MA MEMS Micro-spectrometer: [https://www.hamamatsu.com/eu/en/product/type/C12880MA/index.html](https://www.hamamatsu.com/eu/en/product/type/C12880MA/index.html)
3. C12880MA Breakout Board [https://groupgets.com/manufacturers/getlab/products/c12880ma-breakout-board-v2](https://groupgets.com/manufacturers/getlab/products/c12880ma-breakout-board-v2)
4. Breadboard and jumpers
#### How to assebmle the Hardware :
Since all signal pins are broken out, you can easily use jumpers and breadboard for connecting breakout board to Arduino Uno. Just follow as below :
| Breaking board | Arduino Uno Rev3 |
| -------------- | ---------------- |
| SPEC_TRG | A0 |
| SPEC_ST | A1 |
| SPEC_CLK | A2 |
| SPEC_VIDEO | A3 |
| WHITE_LED | A4 |
| LASER_404 | A5 |
| EOS | Don't connect it |
| GND | GND |
| GND | GND |
| 5V | 5V |
| 3V3 | 3.3V |
Breaking board attached to breadboard
![IMG_5671](/Users/mms/Documents/Arduino/Hypernets_Outreach/Pics/IMG_5672.png)
Arduino UNO Rev 3 and jumpers
![IMG_5672](/Users/mms/Documents/Arduino/Hypernets_Outreach/Pics/IMG_5671.png)
Arduino UNO Rev 3 and Breaking board connected using jumpers and breadboard
![IMG_5673](/Users/mms/Documents/Arduino/Hypernets_Outreach/Pics/IMG_5673.png)
Now you can connect your Arduino UNO Rev3 to your computer using USB-C connector.
### Software
First Download and install Arduino IDE based on your operation system from here : [https://www.arduino.cc/en/software](https://www.arduino.cc/en/software)
You can refer to [this page](https://www.arduino.cc/en/Guide) for how to install the IDE in your computer.
You also need Processing to show the outputs. You can install it from here : [https://processing.org/download/](https://processing.org/download/)
### Setup the Arduino IDE
1. Copy and past this code in your Arduino IDE
2. Upload it to your Arduino by click on Upload Icon on top right corner
![fig1](/Users/mms/Documents/Arduino/Hypernets_Outreach/Pics/Fig1.png)
Wait till your sketch uploaded to your Arduino and see the following commend in bottom of IDE :
![fig2](/Users/mms/Documents/Arduino/Hypernets_Outreach/Pics/Fig2.png)
3. Go to Tools > Board and select Arduino UNO from the list
4. Go to Tools > port and select /dev/cu.usbmodel1101(Arduino Uno) from the list and when you open the Tools, you should have something like this :
![fig3](/Users/mms/Documents/Arduino/Hypernets_Outreach/Pics/Fig3.png)
5. Open the processing application and copy and past this code
6. Go to line 50 in processing and change the number 0 according to your system ``` String portName = Serial.list()[0] ```
> Tip : If you have only one port, leav it as 0
7. Click on Run
Now you can have reflectance
![Outreach_v1](/Users/mms/Documents/Arduino/Hypernets_Outreach/Pics/Outreach_v1.gif)
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<summed.length-1; i++)
{
line(i, 0, i, 875-(int)(summed[i]/summed_max));
}
} else
{
for (int i=0; i<data.length-1; i++)
{
line(i, 0, i, 875-data[i]);
}
}
stroke(255);
}
void setup()
{
println(Serial.list());
String portName = Serial.list()[2]; //This is the index into the serial list, if you only have one serial device the index is 0
myPort = new Serial(this, portName, 115200);
summed = new double[288];
for (int i = 0; i < 288; i++)
{
summed[i] = 0;
}
size(288, 750);
}
void draw()
{
if ( myPort.available() > 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<summed.length)
{
summed[i] += data[i];
}
//print(data[i]);
// print(' ');
}
// println( ' ');
plotdata();
}
}
}
void keyPressed() {
if (key == 'c' )
{
for (int i = 0; i < summed.length; i++)
{
summed[i] = 0;
}
}
else if (key == 't' )
{
if(draw_sum==1)
{
draw_sum = 0;
}
else
{
draw_sum = 1;
}
}
else
{
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment