Jun 21, 2016

Arduvision (II): OV7670 + FIFO module and arduino Mega

After several people asking for instructions to use an Arduino Mega to interface the ov7670 sensor, I decided to publish a tutorial about it...


- Voltage level translator: To properly connect a 3.3v sensor to a 5v microcontroller you need bi-directional voltage level translators, for example like this:
There is already a lot of info on how these work, so I won't get into that.

- Arduino Mega or compatible development board. In this tutorial I use a Mega2560 clone.

- A CMOS module with FIFO and an ov7670 or an ov7725 sensor (I've tried both, and setup the register parameters). At the moment I'm working only through the FIFO, but may try synchronize the microcontroller clock directly with the CMOS sensor, as int the AVRcam project.
For this setup the module must have the following available pins (numbering may differ):

                      GND --- 1     2 --- VCC3.3
                   OV_SCL --- 3     4 --- FIFO_WRST
                   OV_SDA --- 5     6 --- FIFO_RRST
                  FIFO_D0 --- 7     8 --- FIFO_OE
                  FIFO_D2 --- 9    10 --- FIFO_D1
                  FIFO_D4 --- 11   12 --- FIFO_D3
                  FIFO_D6 --- 13   14 --- FIFO_D5
                FIFO_RCLK --- 15   16 --- FIFO_D7
                 FIFO_WEN --- 17   18 --- OV_VSYNC

Some other modules have these pin numbers/labeling:

                      VCC --- 1     2 --- GND
                    SIO_C --- 3     4 --- SIO_D
                    VSYNC --- 5     6 --- HREF
                  FIFO_D7 --- 7     8 --- FIFO_D4
                  FIFO_D5 --- 9    10 --- FIFO_D2
                  FIFO_D3 --- 11   12 --- FIFO_D0
                  FIFO_D1 --- 13   14 --- FIFO_D6
                    RESET --- 15   16 --- PWDN
                   STROBE --- 17   18 --- FIFO_RCK
                  FIFO_WR --- 19   20 --- FIFO_OE
                FIFO_WRST --- 21   22 --- FIFO_RRST


                      VCC --- 1     2 --- GND
                    SIO_C --- 3     4 --- SIO_D
                    VSYNC --- 5     6 --- HREF
                      WEN --- 7     8 --- XCLK
                FIFO_RRST --- 9    10 --- FIFO_OE
                  RCLK/WR --- 11   12 --- GND
                  FIFO_D0 --- 13   14 --- FIFO_D1
                  FIFO_D2 --- 15   16 --- FIFO_D3
                  FIFO_D4 --- 17   18 --- FIFO_D5
                  FIFO_D6 --- 19   20 --- FIFO_D7

I've tested an ELH 30w FIFO module and the Alientek OV7670 v2.2 module. Both use a 12MHz clock. Other modules use a 24MHz clock. While this affects only the framerate selection parameters, some newer versions have a different schematic/pinout which need VSYNC signal to be inverted, these will not work with this setup.

- Jumper wires and breadboard to make the connections.


Connect the boards as follows:

          OV+FIFO                           MEGA2560
                  GND ----------------------- GND
                 3.3V ----------------------- 3.3V
              FIFO_OE ----------------------- GND
     FIFO_WR/FIFO_WEN --> level tranlator --> PH5 / D8
   FIFO_RCK/FIFO_RCLK --> level tranlator --> PH6 / D9
            FIFO_WRST --> level tranlator --> PB6 / D12
            FIFO_RRST --> level tranlator --> PB7 / D13
         SIO_D/OV_SDA <-> level tranlator <-> PD1 / SDA
         SIO_C/OV_SCL <-> level tranlator <-> PD0 / SCL
             OV_VSYNC <-- level tranlator <-- PE4 / D2
              FIFO_D3 <-- level tranlator <-- PF3 / A3
              FIFO_D4 <-- level tranlator <-- PF4 / A4
              FIFO_D5 <-- level tranlator <-- PF5 / A5
              FIFO_D6 <-- level tranlator <-- PF6 / A6
              FIFO_D7 <-- level tranlator <-- PF7 / A7
  (some modules) PWDN ----------------------- GND / not connected
 (some modules) RESET ----------------------- 3.3V / not connected
  (some modules) HREF ----------------------- not connected
(some modules) STROBE ----------------------- not connected

You may edit the file IO_config.h of the arduino sketch if you want to make some changes, just pay attention on the VSYNC pin, that is tied to INT0 interruption.


You can download from this repo the arduino sketch and the processing code to communicate with the arduino via USB:

The code will either stream a 80x60 pixels image, in different pixel depths, or detect the boundaries of the brightest/darkest blob within a threshold.

Edit: you get too much garbage in the processing console you may need to change the baudrate to match your system capabilities.

In the arduino sketch look for the line:
   static const unsigned long _BAUDRATE = 500000;

And in the processing sketch, in the globalDefinitions.java tab:
   public final static int BAUDRATE = 500000;

Try with substituting the 500000 for 115200.

Some people have added pullup resistors to the SDA and SCL lines and disabled the internal pullups. However, in this setup things worked straight away without these steps.

You will have to change the serial port name to match your system. In the processing code, look for the line:

   serialPort = new Serial(this, "/dev/ttyUSB0", G_DEF.BAUDRATE);

And chage the port name "/dev/ttyUSB0".

This is a video of the demo:


I'll try that all the information published here is related only to 100% open hardware and software.

Two inspiring fully open hardware and software embedded computer vision projects:

AVRcam by John Orlando
One of the pioneers pushing the little microcontroller capabilities.

OpenMV by Ibrahim Abdelkader 
Currently in development, it will be an amazing and affordable platform with outstanding capabilities, and the only one in its class completely open.

Useful documentation

Source code related to microcontrollers and CMOS sensors/modules:

Forum discussion threads about microcontrollers and CMOS sensors/modules


  1. Hi, thank you so much, as it is a long time I am searching for something serious on the subject.
    Best regards from Paris !

  2. Im your little fans form Arduvision(I) and in this following my problem while I test with Arduino Mega is like this screenshot
    I have try to setup baudrate as 19200, 38400 and 115200 and 5000000..
    How can I receive the fresh image like you ??
    I really need your support to remake the final project of my school
    Hope and thank you so much :D

    1. Hmmm... maybe something with the wiring?
      I guess you are using the voltage level tranlators like indicated, right?
      The strange thing is that the arduino is communicating with the sensor...
      Some other guy had problems with his sensor, have you some other ov7670 module to test?

    2. ok, in the graphic schematic there is a missing line from FIFO_OE to GND, I'll correct it right now...

    3. Im have ov7670 none fifo and my Ov+Fifo is this device
      I also use it on the previous project (your Arduvision (I)) and I think It'll work well with this project :D

  3. Ah I solve the problem of this project, but It still have a darkness than your demo & fps too low than you :D
    But it work stable with all baudrate. Thank you

  4. I got it but the pixel is too low :D

    1. This is my problem
      how to make it brightness :D Thank you

    2. Hehe, I was asking what was the problem before (why did you got this: https://postimg.org/image/mz45gou69/ and how did you solved it)

      For the dark image you probably need to play with the sensor settings.
      First try commenting line 58 in sensor.cpp :
      // sensor_writeRegs(common_reglist);

      If that doesn't help, in ov7670_regs.h check the values of:


      Look for other registers configurations in the internet or have a look at the sensor datasheet.

  5. hey My best result :)
    but still need light enought to see the image better :D

    1. hey, nice fps :)
      at least there are improvements

    2. why did you got this?:


      how did you solved it?

    3. https://postimg.org/image/mz45gou69/
      This just my wiring problem of OE pin (I haven't connect OE to GND !! lol
      Can I get some knowledge if the Arduino send the image stream data to the Bluetooth or Wifi via UART (Like some SmartHome streaming project which receive video stream to smartphone) ? The Init and mechanism method on Arduino is coding like your project .uno + library ? Need some advice :D
      Thank you

    4. This comment has been removed by the author.

    5. Look for info about the HC-05 serial BT module. You will have to increase the module's baudrate via AT commands. It should work straight away with your current setup.
      On the android side you can try to use the processing sketch with the APDE app.

  6. Can I re-define the pin config (from your define pin library) pin_config.h to change the function of any pin-config ?
    _Haven't any pin which must be standand & can not change to another pin (like SCL SDA on ArduinoMega)?

    1. You can change the pins in IO_config.h, the names correspond to the chip ports and pins
      SDA and SCL pins have to match your board's hardware SDA and SCL
      OV_VSYNC pin has to be the one corresponding to the interrupt number specified by VSYNC_INT
      All data pins have to be in the same port, and data pin numbers have to be the same as the bit positions:
      data bit 7 - pin 7 of the X port
      data bit 6 - pin 6 of the X port

  7. okay got it!! thank your support too much :D

  8. Can you write a post to interpret your code in Arduino Mega
    or comment more in your code for user easy to understand your code :D thank you

  9. Thank you for your post. Only a question, it is posible to do it with an arduino UNO clone? Or is mandatory the use of arduino Mega?

    1. Hi!
      You can do it with an UNO, with the same voltage level translators but using the code/pins of this post:

    2. I will try using Arduino Pro Mini (3.3V) so the final result could be smaller and more compact.

      Thanks for your help!

  10. Hi friend! Do you have any schematic for connecting this module in a TFT display 3.2" or larger? Thanks

  11. How do you use Arduino UNO with this code? What do I change?

    1. You can use the following info/code code, but with the voltage level translators:

  12. why my arduino tell me

    Initializing sensor...
    PANIC! sensor init keeps failing!

    1. There is a problem in the communication with the sensor:
      a) the wiring is not right
      b) the arduino is a 16MHz 5v version

      Are you using a 8MHz (3.3v) arduino?

    2. sorry, I don't understand you mean ..8 MHz(3.3v)

      but I use 3.3v between mega 2560 and ov7670-fifo,

      is that worng?

      I'm from Taiwan, so my English translation use of may be wrong...

    3. Sorry, I mixed posts... if you are using

      MEGA <-> voltage level translator <-> sensor

      you a right.

      Check the wirings.

    4. I checked the wirings two times , but still tell me

      PANIC! sensor init keeps failing!

      there are ways to detect whether ov7670-fifo can operate ?
      I worry that ov7670 is bad...

      Thanks :)

  13. why my arduino tell me

    Initializing sensor...
    PANIC! sensor init keeps failing!

    Is camera burned ??

  14. First of all, thank you very much for sharing your code and for the tutorial you have written. I was trying to compile (verify) the code from arduvision_01 folder, but I am getting the following error message (I did not modify any file):

    "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10611 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "C:\Users\Little\AppData\Local\Temp\build4b980085cde7535f83d731951fbb0ae6.tmp\sketch\ov_fifo_test.ino.cpp" -o "C:\Users\Little\AppData\Local\Temp\build4b980085cde7535f83d731951fbb0ae6.tmp\sketch\ov_fifo_test.ino.cpp.o"
    C:\Users\Little\Documents\Arduino\ov_fifo_test\ov_fifo_test.ino: In function 'void vsyncIntFunc()':

    ov_fifo_test:164: error: ambiguating new declaration of 'void vsyncIntFunc()'

    void static __inline__ vsyncIntFunc() {


    C:\Users\Little\Documents\Arduino\ov_fifo_test\ov_fifo_test.ino:164:19: note: old declaration 'int vsyncIntFunc()'

    void static __inline__ vsyncIntFunc() {


    Using library Wire at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire
    exit status 1
    ambiguating new declaration of 'void vsyncIntFunc()'

    Any idea of what is happening? Thank you!

    1. Hi,

      Can you please try removing the "static" from the function declaration?

      void __inline__ vsyncIntFunc()

    2. Hello David! I thought I had done removing "static" before, but now, I tried it again and it worked (maybe I had removed "__inline__" also! Thank you very much! Would you explain the reason why I had to remove "static" and why it's compiling now?

    3. Glad it works now! I'll change the github sources.
      Sincerely no idea why :)
      It might have to do with changes in different versions of the Arduino core libraries.

  15. Hi, I have the newer version with inverted VSYNS. How can I get this code to work with it. I have read that you have to put one into COM10 register. But i can not seem two find out how I do it in your code.
    Best Regards.

    1. Can you try changing, in the file ov_fifo_test_mega.ino, lines 148 and 178, the interrupt to RISING instead of FALLING

      attachInterrupt(VSYNC_INT, (void(*)())&vsyncIntFunc, FALLING);


      attachInterrupt(VSYNC_INT, (void(*)())&vsyncIntFunc, RISING);

      and see what happens?

  16. Hi, I have the newer version with inverted VSYNS. How can I get this code to work with it. I have read that you have to put one into COM10 register. But i can not seem two find out how I do it in your code.
    Best regards.

  17. Hi, i used that ov_fifo_test.ino & got some op
    Initializing sensor...
    inited OK, sensor PID: 7673

    How to stream image?
    how to use that receive_stream_mega.pde?
    Can you help me saving image file in sdcard?
    i interfaced sdcard.But how to save image.

    1. solved streaming.
      Need help with storing in sd card

    2. Good to hear the streaming worked. At the moment I'm quite busy so I wont be able to help you with the SD card stuff.

  18. Replies
    1. To reduce the amount of data to be transferred in the streaming.

  19. I was wondering if the Arduvision (II): OV7670 + FIFO module and arduino
    Mega is capable of taking a picture.

  20. I would use this camera to view the picture on a 7" LCD screen, for example! Or via Wi-Fi Module!

  21. How to get raw image data without processing software.may be on arduino serial monitor.
    How to get still image instead of video stream

  22. hi there. I`d like to know what should be the name of the serial port to match with my system?
    thank you for helping me

    1. hi, what OS are you using? OSX, Windows, Linux?
      The serial port should be the same as the one selected in the Arduino IDE (under Tools -> Port )

  23. hi,thank you for great tutorial
    I need a little help with something
    I don't know how to match my port name in my computer with the processing code.
    what should I chane it to?

    1. what OS are you using? OSX, Windows, Linux?
      The serial port should be the same as the one selected in the Arduino IDE (under Tools -> Port )