I know that there is a lot in internet about OV7670 and I read a lot about it, but seems something is missing.
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: http://www.voti.nl/docs/OV7670.pdf. 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.
So at this point I thought that the functionality of such camera would be covered by wiring the following pins:
D0..D7
for data (pixel)
connected to arduino digital pins 0 to 7
as INPUT on arduino board
XCLK
for camera clock
connected to arduino digital pin 8
as OUTPUT from arduino board
PCLK
for pixel clock
connected to arduino digital pin 9
as INPUT on arduino board
HREF
to define when a line starts / ends
connected to arduino digital pin 10
as INPUT on arduino board
VSYCH
to define when a frame starts / ends
connected to arduino digital pin 11
as INPUT on arduino board
GRD
groud
connected to arduino GRD
3V3
3,3 INPUT
connected to arduino 3,3v
RESET
connected to arduino RESET
PWDN
connected to arduino GRD
The implementation for such approach from my point of view would be something like:
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
My readPixelFromDataPins() 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:
byte readPixelFromDataPins() {
byte result = 0;
for (int i = 0; i < 8; i++) {
result = result << 1 | digitalRead(data_p[i]);
}
return result;
}
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: OV7670 Snapshot Test Code · GitHub.
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?
I searched a lot and I didn't found any SSCCE (http://sscce.org/) for this camera using arduino, if somebody have it please let me know.
Thanks for your quick response. I alredy read the topic before implementing it and it isn't clear how to proceed since it doesn't comment how XCLK is handled. I alredy tried to use the infos from there but is somehow messy to grab all needed things to test it.
Have you alredy implemented somethong with ov7670? Would you be able to provide a minimal working sampl for it?
XCLK is easy to generate just use PWM to generate an 8mhz clock. No need to mess with fuse bits or anything The AVR hardware has a mode of PWM that lets you output frequencies using this formula F_CPU/((x+1)*2).
I saw you had a repository associated to your answer, the problem is I'm a bit confusing what is really necessary to run the snapshot of ov7670 and what is code from other stuff. My idea is get an SSCCE for the camera.
You commented I can generate the frequency using a PWM, which one may I use? Is there a schematic or reference therefore?
Hi Francisco:
I've been working with the OV7670 camera for a few days and I've reached to a code very similar to yours, except that I'm trying to use an external CLK of 20MHz connected to XCLK, but I liked the idea of using a PWM (I just read it).
The main issue in information and all the libraries I've found is that in all of them they have a SHIELD or a GLCD connected to the camera, and I just have the camera sensor.
About this line you posted
if last PCLOCK was HIGH and current PCLOCK is LOW
I was thinking in connecting the PCLOCK as an external interrupt. The code in setup would be: attachinterrupt(2,clock,RISING); (interrupt 2 is connected to PIN 0 in my Arduino Leonardo).
I'm also having problems in the I2C communication. When I use the function "Wire.endTransmission()" it returns 2, that means that the acknowledge was not received.
Please, if you have reached to any solutions let me know, I would appreciate it.
Sorry for my English and thanks.
Hello francisco-spaeth,
If you still want to find solution to run OV7670 I propose to collaborate in order to get an SSCCE.
I tried to find some support on thread of Mr. Arduino several months ago in order to create SSCCE but it was not easy.
Also, I wrote email to Shenzhen LC Technology Co., Ltd. who is the producer of my ov7670. They provided me some materials which I also can't process due to poor comments in the code/documentation, usage of LCD, SD card, etc which I'm not planning to use.
Documents are here: Dropbox - Error