OV7670 experiment

For past many days, I was working to “port” my project to a LPC1769 (LPCXpresso) using a real compiler and writing the code from scratch, with almost zero libraries available. The most important part, after got my “image processing” working smooth (almost 20 fps for processing and extract blob details for a test image) without any optimization, I started working to the second part of the story: connect a OV7670 camera to my project. This should bring me a decent resolution with a decent frame rate at a very low price (targeting somewhere around 10-15 FPS) if everything works as it should…

Anyway, at the moment I got the SCCB protocol working by the book (will take few good seconds to initialize the camera with the current settings, (need to see if can do some tuning cause is too long), then I’m using an external interrupt to check VSYNC signal, to detect when a frame is finishing/starting, then with this will manipulate the rest o the signals that controls the camera. Basically, is a OV7670 with a FIFO chip, which give me the freedom to control the speed of “draining” data out of the camera.

Anyway, so far, so good: I got the entire setup spitting data, with everything in sync. For now is no image processing or storing, I am just monitoring the signals and few of the DATA lines. Will try to read again the SCCB manual for this camera and use a proper configuration for my application (QCIF, YCrCb, etc) then, will start to tune more on the data fetching (use Fast GPIO) and processing.

Since I am just learning about ARM microcontrollers, I think is not too bad ^_^


26 thoughts on “OV7670 experiment

  1. hello

    I am currently working with that 0v7670 + fifo buffer chip. but I can’t configure fifo buffer successively. PLZ kindly help me. If you could send expand code ,it will be more helpful to me.
    PLZ reply !

    • Hi NASK, can you please explain your problem? Not really sure what do you mean by “configure FIFO”, is actually nothing to configure, if you have the manual for AL422B just go and check the timing diagrams on page 9 and 10. All you need to do is to enable an external interrupt that listen on VSYNC, and on rising edge, trigger the WRST and WEN (based on the version of the module you are using the code may be different) and the rest of the signals in a proper sequence. Will be hepful if you have a logic analyser and have an uderstanding how video signal looks like (timing diagram is in OV7670 manual).
      Hope this help, cheers!

  2. Fist I would like to Thank for your reply !

    I bought cammera module is in below link.


    below shows, my c code for reading and writing task of fifo buffer Ic (not fully). WE CLR set and clear time, Is it enough for readding task?

    /* this is for the external interrupt to VSYNC Pin . */

    void __attribute__((__interrupt__)) _INT0Interrupt(void)

    IFS0bits.INT0IF = 0; //Clear the INT0 interrupt flag or else

    //the CPU will keep vectoring back to the ISR






    void main (void)
    FIFO_READ(); //clean






    void FIFO_READ(void)



    I am just storing data in buffer 'k' and watch, I can see some data is filling. but I'm not sure its reliability since I dont have a Logic analyser to check it. so , I would like to send that data to my computer to see video, is it possible ? and I only know RS232 interface. using this interface can I do it? any other posible methods ?

    PLZ reply !

    • For a start, WEN is active high, while WRST is active LOW. Not sure what you try to do in here, but if you check the video signal timing diagram you will see that VSYNC is LOW withing the frame and HIGH between frames. As such, you can trigger your WRST on falling edge (active LOW) and set WEN (active HIGH) when capturing the first frame. On the follwing VSYNC raising edge, you clear WEN and can start reading the data from FIFO using RRST, OE and RCLK signals (all active LOW). So basically, you can set a flag or use a counter incremented by VSYNC and based on the state will decide the operation you are doing.

      You can dump the data over serial port, that is why you use FIFO in the first place, right? so you capture an image, and slowly read the data from the FIFO and either process it or send it out using SPI or UART. I am using Processing to receive, process and display the data in real time. Can write your own client to handle this also.

  3. Hi,
    Did you debounce your ex interrupt ? if it is yes, How did you do it ? actually, my interrupt is not being working. but I am sure about my code for the intterupt.

    can this be happen, interrupt making voltage is not enough for wanted voltage for the PIC. (my PIC is dsPIC30F4011)

    PLZ replay !

  4. hi my friend.you have a great progress with ov7670.

    I am also working with it but i have a problem.

    I am using stm32f4 to communicate with camera.i tried with my own sccb library and standart i2c library but i cant get it work.i am using 0x42 for writing but i cant get ACK bit.I dont belive it is a hardware problem.

    Do you have any idea to make me happy :)


    • Hi Baris, I will look for my SCCB library which is generic (using the same code on ATmega8/328/644/1024 and also on LPC1768/1769). Also can find the STM32 dedicated ones online. Will try to post it soon. Sorry for delay, I’m a bit busy with some stuff.

  5. Hi Claudiu,

    This is a very interesting project you have described and you have done well. Part of my project requires software to track a moving light so the image need be no more than B/W, effectively tracking a blob. There is a camera on sale “640×480 VGA CMOS Camera Module OV7670 FIFO Buffer AL422B SCCB compatible wit I2C”. Is this the one you are using?

    Secondly. Did you write your own libraries or are there libraries out there that I can use to get me started?

    Kind regards,

    • Hi Ric, thank you! Yes, that is the module, even if may not look exactly the same, as seems to be some new very cheap versions available lately, all works the same.
      I actually started by using the SCCB (i2c) library available online (just google OV7670 SCCB and you will find many versions available) and modify it as was not working well for me. Will strongly suggest to get the manual for OV7670 SCCB as you will need to “pre-configure” the camera with the desired settings or else may not be able to communicate with it.
      I prefer to use macros to handle the IO ports as will allow to write portable code on various micro controllers. Most of my libraries are pretty generic except the UART ones which are low level and dedicated to the respective microcontroller in order to get maximum available speed, especially that in my current version i am over clocking the microcontroller by 20% (from 20 Mhz to 24 Mhz).
      Also, will be good if you can use a logic analyzer to determine the timing introduced by different code implementations which sometime will make a big difference (e.g.: using while instead or for…next, etc).
      Good luck if your project, do let me know if need any help.

  6. Hi Claudiu

    Good job …!
    what’s your idea about OV7670 without FIFO buffer ?
    is it easy as same as another one to do?

    • @Sharin: Thank you! Without FIFO will not be that simple, but can be done. However, need to optimize the code pretty much to get a high framerate. I am considering to look into this, but I have not much time at the moment…

  7. Tanx.

    If we have 24MHz on XCLK , how much will be received on PCLK ? ( Approximately )
    This level is before FIFO ( On my side -> NO FIFO )

    I use AT91SAM7X256 ! MCK = 48MHz

    Best regards

    • @sharin: you can inject your own XCLK (you mention 24 MHz) then can program OV7670 to select the PLCK you want using the divider registries (e.g.: COM14). Also, can choose to go with lower XCLK and use PLL (e.g.: DBLV).

  8. Tanx for your useful replies

    My MCU frequency is 55MHz , XCLK is 13.8MHz also we have output on PCLK & HREF.

    The problem –> D0~D7 always are 0 !
    I can read & write by SCCB and it’s OK

    Is the value of registers incorrect?!

    void InitQQVGA565(char flipv,char fliph) {
    // QQVGA RGB565
    sccb_write(REG_COM11,0x0A) ;
    sccb_write(REG_COM7,0x04) ;
    sccb_write(REG_RGB444, 0x00);
    sccb_write(REG_COM15, 0xd0);
    sccb_write(REG_HSTART,0x16) ;
    sccb_write(REG_HSTOP,0x04) ;
    sccb_write(REG_HREF,0x24) ;
    sccb_write(REG_VSTART,0x02) ;
    sccb_write(REG_VSTOP,0x7a) ;
    sccb_write(REG_VREF,0x0a) ;
    sccb_write(REG_COM10,0x02) ;
    sccb_write(REG_COM3, 0x04);
    sccb_write(REG_COM14, 0x1a);

    flipv = flipv ? 0x10:0; fliph = fliph ? 0x20:0;
    // sccb_write(REG_MVFP,0x07 | (flipv ? 0x10:0) | (fliph ? 0x20:0)) ;
    sccb_write(REG_MVFP,0x07 | (flipv) | (fliph)) ;

    sccb_write(0x72, 0x22);
    sccb_write(0x73, 0xf2);



    Best regards,

    • @Sharin: you should have something on D0-D7 even if your initial setup is not correct. Unfortunately, I need to cleanup my desk to start my desktop to access the code i used. I am trying to do this over the weekend, sorry, I am traveling quite a bit lately and also lots of work, no time for other things.

  9. Excuse me !!
    I got it.
    It is my last question! :D

    It is ok now , but max voltage on D0~D7 is 1.2v .
    Because of this issue, the MCU can’t recognize the 0 & 1 logic & consider all of them in 0.

    What must i do ?
    Is it normal?
    Any suggestion?

    finally, excuse me because of my silly questions


  10. Hi Claudio. .
    spent 2 hours in your website reading your progress. . and i’m very exited :D

    I’m new to this “camera / image accuisition & processing” thing

    But i’m planning to make (study) a project similiar like yours. . . cam+quadcopter+android_app+atmega328

    i’ve just finished the quadcopter subproject and moving to this subproject “the cam parts” :D. .
    But i never handle any image related project before, so i want to ask you for a newbie like me which camera module is suitable for me?

    2 kind of OV7670 module i see in ebay said some module equipped with FIFO buffer chip, and some others not. What does FIFO chip do? ( sorry i’m newbie :'( )

    Which module is suitable for me? with fifo ones or the ones without? and why?

    is atmega328 suitable for this trial? im not expecting 30fps. . 1 fps just fine for start and study. . :’)
    thanks for your replies in advance :)

    • @Alfiansyah: in your case, why not consider a serial camera module (e.g.: uCam from 4D Systems, I used one also, see here), so you won’t need to handle the camera signals. Is plenty of documentation on this already available. Not sure how will you manage to do image processing, image acquisition and also handle the quadrocopter navigation but wish you good luck!

  11. uCam that u suggest Cost $59 I cannot affort that much TT. . .

    Instead I’m looking for cheap camera module that suits me. . And I found OV7670 , and then When i look for a related project then i found your blog. ..

    About handling image processing, image acquisition and also handle the quadrocopter navigation, I will not use Atmega328. . Cause My Quadcopter control Board use STM32F4, and i’m pretty sure it will handle those. .

    But for know i’m just want to study a camera module and the background theory behind it(video signal , image, etc) using cheap things If that were possible . .

    So what do you think? . . I’m really cannot afford to buy the camera module you suggest earlier. .

    • @Alfiansyah: There are similar modules on ebay or SparkFun.com which are cheaper. The question is: what you want do do with it? If you just want to stream images use the serial jpeg camera, if you want to do image processing then a you can use OV7670 FIFO module, however, you will need to handle all the signals to control the camera and do the image processing. You may need to use a dedicated core for this application. Also, based on the application you may need more memory than Atmega328p have (2 Kbytes).

  12. I’ve just searched about 3 hours about uart camera module and come up with 38$ as the cheapest on Ebay. . .

    still don’t have passion to buy it :'(. .

    I look in sparkfun an the only available camera module was TCM8230 . . it was cheap only $10. . i read the datasheet for a while and come up with conclusion that this camera was using 8 bit Parallel hsync Vsync interface, which is most likely the same as OV7xxx module. . .

    For the application i plan to study, just streaming low fps low resolution(128×64 or less) video to PC or just to take a picture. No image processing just to bypass it to PC or something. .

    What do you think? Is it not possible using atmega328? if yes then what about migrating to STM32F103? which has 20KB of RAM and run on 72MHZ

    Thanks for your replies :D

    • @Alfiansyah: serial streaming? Why not just use a xBee module with any serial camera, no need to go through atmega328p.

  13. Is it Possible? I really don’t know. .

    But The total Cost is still more cheap to Implement [Micro+Parralel Camera +Xbee] Than [Serial Camera + Xbee]. . .

    So i still wondering is it possible to build to accomplished my needs? (low fps low resolution(128×64 or less) video to PC or just to take a picture) It’s not just displaying but i want to study video basic trough this project. . .

    • @Alfiansyah: not sure about the cost, but I find the total cost of using a cheap jpeg serial camera a cheaper option. Anyway, to answer your question, yes, you can build a system able to stream images using the OV7670.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s