title: Arduino + OV7670 - Without FIFO - Reading Snapshot
body: <p>I know that there is a lot in internet (<a href="http://forum.arduino.cc/index.php?topic=159557.0">http://forum.arduino.cc/index.php?topic=159557.0</a> for example) about OV7670 and I read a lot about it, but seems something is missing.</p>
  
  <p>First of all I took a look into the way how can we read pixel by pixel from the camera to build the rectangular 600 X 480 image, and this was quite easy to understand considering HREF, VSYNCH and PCLOCK described on documentation here: <a href="http://www.voti.nl/docs/OV7670.pdf">http://www.voti.nl/docs/OV7670.pdf</a>. I understand XCLOCK as an input I need to give to OV7670 as a kind of cycle controller and RESET would be something to reset it.</p>
  
  <p>So at this point I thought that the functionality of such camera would be covered by wiring the following pins:</p>
  
  <ul>
  <li><strong>D0..D7</strong> - for data (pixel) connected to arduino digital pins 0 to 7 as INPUT on arduino board</li>
  <li><strong>XCLK</strong> - for camera clock connected to arduino digital pin 8 as OUTPUT from arduino board</li>
  <li><strong>PCLK</strong> - for pixel clock connected to arduino digital pin 9 as INPUT on arduino board</li>
  <li><strong>HREF</strong> - to define when a line starts / ends connected to arduino digital pin 10   as INPUT on arduino board</li>
  <li><strong>VSYCH</strong> - to define when a frame starts / ends connected to arduino digital pin 11 as INPUT on arduino board</li>
  <li><strong>GRD</strong> - groud connected to arduino GRD </li>
  <li><strong>3V3</strong> - 3,3 INPUT connected to arduino 3,3v    </li>
  <li><strong>RESET</strong> - connected to arduino RESET   </li>
  <li><strong>PWDN</strong> - connected to arduino GRD  </li>
  </ul>
  
  <p>The implementation for such approach from my point of view would be something like:
  Code:</p>
  
  <pre><code>for each loop function do
     write high to XCLK
  
     if VSYNCH is HIGH 
        return;
  
     if HREF is LOW 
        return;
  
     if lastPCLOCK was HIGH and currentPCLOCK is LOW 
        readPixelFromDataPins();
  
  end for
  </code></pre>
  
  <p>My <code>readPixelFromDataPins()</code> basically read just the first byte (as I'm just testing if I can even read something from the camera), and it is written as follows:</p>
  
  <p>Code:</p>
  
  <pre><code>byte readPixelFromDataPins() {
    byte result = 0;
    for (int i = 0; i &lt; 8; i++) {
      result = result &lt;&lt; 1 | digitalRead(data_p[i]);
    }
    return result;
  }
  </code></pre>
  
  <p>In order to check if something is being read from the camera I just print it to the Serial 9600, the byte read from data pins as a number. But currently I'm receiving only zero values. The code I'm using to retrieve an image is stored here: <a href="https://gist.github.com/franciscospaeth/8503747">https://gist.github.com/franciscospaeth/8503747</a>.</p>
  
  <p>Did somebody that makes OV7670 work with Arduino already figure out what am I doing wrong? I suppose I'm using the XCLOCK wrongly right? What shall I do to get it working?</p>
  
  <p>I searched a lot and I didn't found any SSCCE (<a href="http://sscce.org/">http://sscce.org/</a>) for this camera using arduino, if somebody have it please let me know.</p>
  
  <hr>
  
  <p>This question is present on arduino forum (<a href="http://forum.arduino.cc/index.php?topic=211741.0">http://forum.arduino.cc/index.php?topic=211741.0</a>) too.</p>