Electronic – arduino – Do you always need to clock out the old pixels when reading from a camera

adcarduinocameradelaysensor

I'm writing a program to work with a TSL1401R-LF Linescan Module. It works by reading in a 1 X 128 array of pixels. I've gotten the camera to work properly and my readPixels() method is able to read in the pixels accurately.

However, I'm forced to run a timming() method prior to my readPixels() method or else the program fails. The timming() pretty much does exactly the same thing as the readPixels() method except it doesn't store the outputted values. When I comment it out and only use readPixels() my image becomes saturated and I only get values of 1023 even when a dark object is in the way of the cameras.

This might make more sense when looking at the actual code:

void timming()
{

  digitalWriteFast(SI, HIGH);
  delayMicroseconds(10);
  digitalWriteFast(CLK, HIGH);
  delayMicroseconds(10);
  digitalWriteFast(SI, LOW);
  delayMicroseconds(10);
  digitalWriteFast(CLK, LOW);
  delayMicroseconds(10);

  for(int i = 0; i < 129; i++)
  {
    digitalWriteFast(CLK, HIGH);
    delayMicroseconds(delayTime);
    digitalWriteFast(CLK, LOW);
    delayMicroseconds(delayTime);
  }

}

void readPixels()  
{
  digitalWriteFast(SI, HIGH);
  delayMicroseconds(10);
  digitalWriteFast(CLK, HIGH);
  delayMicroseconds(10);
  digitalWriteFast(SI, LOW);
  delayMicroseconds(10);
  digitalWriteFast(CLK, LOW);
  delayMicroseconds(10);

  for(int i = 0; i < 128; i++)
  { 
    digitalWriteFast(CLK, HIGH);
    pixelsArray1[i]=analogRead(Cam1Aout);
    pixelsArray2[i]=analogRead(Cam2Aout);
    pixelsArray3[i]=analogRead(Cam3Aout);
    delayMicroseconds(delayTime);
    digitalWriteFast(CLK, LOW);
    delayMicroseconds(delayTime);
  }

  digitalWriteFast(CLK, HIGH);
  delayMicroseconds(delayTime);
  digitalWriteFast(CLK, LOW);
  delayMicroseconds(delayTime);

  delayMicroseconds(20);
}

TL;DR

Basically what I'm asking if there is a way to get my program to work without having to use the timming() method.

Datasheet: http://datasheet.elcodis.com/pdf/58/61/586128/tsl1401r-lf.pdf

Best Answer

I suspect that the answer is quite simple: run readPixels() twice in quick succession. As it stands, if you don't run timing(), when you run readPixels() the 1401 has been sitting there integrating for some unknown (but very long) time, so of course your pixel values are saturated. So timing() resets the pixel integrators to zero, and then readPixels() can properly acquire data. However, running readPixels() the first time will have the same effect.

Of course, when you do this you'll need to disregard the first set of values produced by readPixels(), since they will be a uniform 1023.

So the answer to your title question is - of course.