The Arduino Eye Shield October 2009
The Arduino Eye Shield is a circuit board that can be plugged on top of the Arduino allowing it to interpret analogue video (PAL or NTSC) from a camera or other source. It gives the Arduino the power of sight.
There are many applications for this. In the example below the video information from the camera is used to drive an 8×8 LED matrix (with a MAX7219 and the Arduino Matrix library).
Video Formats
The PAL and NTSC formats have a relatively straightforward structure. For each line we see a negative-going pulse, then a colour burst, followed by the picture information - where the brightness is determined by the voltage of the signal. Lines follow sequentially to make up a full picture, with additional synchronisation pulses to indicate a new frame. In the example below we see two lines (and the pulse and sync of the next), where there will be two darker vertical features against a brighter background. For a more complete description see: PAL video timing specification.

The Circuit
In the circuit below the LM1881 (IC1) separates the synchronisation pulses from the video signal, allowing the Arduino to identify a specific line of the picture. To read the information we need to sample the changing voltage along the line, which for PAL takes 52µs. The Arduino's analogRead is too slow (taking about 100µs per sample). The solution used here is to digitise the video signal using a simple comparator circuit, which can then be read by a digitalRead operation that takes about 4µs, allowing for operations to store the read value — this allows at least 8 samples to be made per line for the picture. The comparator (AD811, IC3) sets its output either high or low depending on whether the video signal is above or below the reference level. The reference-level is set dynamically by the Arduino. To obtain grey-level information, the same line can be successively sampled with changing reference-levels, or IC4 can also be used to set a second reference level and the two outputs can be read in parallel. Using lower-level code Peter Knight suggests tens of samples should be possible per line, using the same hardware. IC2 is a simple unity gain buffer.
While the Eye Shield can take a colour input, only grey-level information can be processed.

Diagram excludes decoupling capacitors and power for the op-amps (0v,5v)
In the current version, Analog0–Analog3 are set as extra digital inputs to free up the digital pins to drive LEDs etc. In the next version there will be the option to set the reference voltages with a potentiometer. The shield is currently built on a protoshield, but a PCB design is in progress. It is also currently only tested with a PAL signal.
The Code
The basic code structure is shown below. Here picture data is read in on the even frames and processed on the odd frames. This results in a frame-rate of 25 fps for PAL.
int picture[8][8];
void setup() {
pinMode(compSyncPin,INPUT);
pinMode(vertSyncPin,INPUT);
pinMode(burstPin,INPUT);
pinMode(oddEvenPin,INPUT);
pinMode(videoPin,INPUT);
pinMode(refVoltagePin,OUTPUT);
setRefVoltage(3.4f);
}
void loop(){
int y=0;
if(!digitalRead(oddEvenPin)){
while(!digitalRead(oddEvenPin));
while(!digitalRead(vertSyncPin));
while(digitalRead(oddEvenPin)){
if((lineCount%38)==0){
for(int x=0;x<8;++x){
picture[x][y]=digitalRead(videoPin);
}
++y;
}
++lineCount;
while(digitalRead(burstPin));
}
//this now happens on the odd frame...
//process picture data here
lineCount=1;
}
}
void setRefVoltage(float v){
if(v>=0 && v<=5.0){
analogWrite(refVoltagePin,(255*v)/5);
}
}
(download the full code from the GitHub repository)
Applications and Ideas
The Eye Shield was used for my Reflections in Cider installation. This illuminates a matrix of LEDs inside cider bottles in a window display, to create a video-mirror of the passersby.
Featured on the MAKE blog.
I've got a bunch of things I want to do with the Eye Shield now and I'd love to hear what you think of it too. Please contribute to this thread on the Arduino forum. Thanks.
The wonderful Video Experimenter Shield is based on this design, but makes many significant improvements. It is available commercially at a very reasonable price.