Exam week is here and I finally had to get my butt on the ball to finish this. here are the two codes. one is arduino the other is processing. I can't test this yet because I haven't built the CCD circuit yet. Any tips or suggestions would be great!
int vout = 26; // sample this pin to get image data
int shsw = 5; // sample hold. GND cuts on vdd2 cuts off
int clk = 6; // clock timer pin. controls the timing.
int vdd2 = 7; // camera needs 5volts supplied to vdd2 to function
int shut = 8; // shutter function. for use, leave high then 1ms prior to sampling, drop voltage to ground for 1mn then back up to high.
int rog = 9; // pulse rog low once to start sequence
int sample =
0; // this will be used as a serial data output of the samples.
void setup()
{
Serial.begin(9600); // start serial. Is baud rate correct?
pinMode (vout,INPUT); // reads data from ccd to give us samples inbetween clock pulses
pinMode (shsw,OUTPUT);// some of these pin's functions are optional.
pinMode (clk,OUTPUT);
pinMode (vdd2,OUTPUT);
pinMode (shut,OUTPUT);
pinMode (rog,OUTPUT);
}
void loop()
{
//clk initialization
Serial.println("start"); // just for kicks
digitalWrite(clk,HIGH); // these next few steps starts the clk, this must be done each time prior to a 2087 cycle
digitalWrite(rog,HIGH);
delayMicroseconds(1);
digitalWrite(rog,LOW);
delayMicroseconds(1.01);
digitalWrite(rog,HIGH);
delayMicroseconds(1);
for(int i = 0; i < 2087; i++ )
{
digitalWrite(clk,LOW); // the 2087 cycle begins here.
delayMicroseconds(1);
digitalWrite(clk,HIGH);
sample = analogRead(vout); // output the ccd's data into a serial sample that can then be read by a processing programing and written to a file
Serial.println(sample); // ^^^^^^^^^^^
delayMicroseconds(1);
}
}
here is the processing code
import processing.serial.*;
Serial mySerial; // start a serial called mySerial
PrintWriter output; // calls the writer output
void setup()
{
mySerial = new Serial( this, Serial.list() [0], 9600);// sets up mySerial
output = createWriter( "SampleData.txt" ); // sets output to a txt file
}
void draw()
{
if (mySerial.available() > 0 ) //check is serial data is there
{
String value = mySerial.readString();
if (value != null) // if null then something is broke. otherwise...
{
output.println( value );// print the serial to output which uses createWriter to place into a new txt file.
}
}
}