OV7670 with both arduino uno and now mega

I updated my code with some of the suggestion stoney reported and indeed I got some improvements.

  1. vsync edge detection is not influent in my case. I got the same image so I think it depends on how the code is written so for now I let it be as it was but I might consider changing this behavior accordingly to the code as it comes out. Thanks for pointing out and clarifying this issue.

  2. I implemented HREF functionality but I couldn't get it working with interrupts; the same goes for PCLK so I needed to poll with a while loop (DAMN! :D)

  3. I tryed to wait either for PCLK low and high before reading the pixel and I got these two versions; the first waiting for low as MrArduino did and the second waiting for high accordingly to my interpretation of the scheme I found on the DS which I post herein. (I'd go for the second version). the third one is what I got by converting the raw datas with MrArduino's converter.



  1. @stoney: why you think Hstart/Hend and Vstart/Vend are relevant? It's just to check if the resolution is ok, isn't it? Would you mind giving a shot to my updated code? maybe we can figure something else out and close this!

I really hope I'm only missing some color settings and someone can point out some error(s) or a stupid register setting because it looks to me I'm quite there but I can't grasp the last handhold.

You all can find the updated code on the usual repo on github!

edit: problem is mostly due to the fact that I'm using default color scheme values which is YUV but I'm reading as RGB. Anyway I got wrong colors anyway with half height colorbars; at least I'm getting the right amount of bars now... I'll post an updated screenshot soon

EvIl_DeViL:
I updated my code with some of the suggestion stoney reported and indeed I got some improvements.
...

We should probably start a new thread for OV7670 use on a due within the arduino IDE instead of hijacking Mr Arduino's mega thread.

Done .. continued on the due thread over at .. ..new thread

I don't know... I think people won't help us there and there's no much left to talk about uno and mega. Anyway If that thread will fail we could come back here so let's see...

edit: I GOT IT WORKING ON DUE! REPO ALREADY UPDATED! I'll post optimization soon but at least you can now study even on this board! there were issues related to registry configurations. I imported MrArduino's list and now it's working :wink:

Hello to all.
Have a nice day! :smiley:
My name is Jim.

I got a school project, i should take pictures with OV7670 camera using my computer and an arduino pro mini.

Searching on the internet i found this site, that is doing the same project

The guy is connecting the ov7670 camera and arduino pro mini in using below diagram

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

So here is the problem when i was connecting the camera on the arduino, i find out that my camera hasnt the following 4 pins: WEN, RCLK, SCL, SDA so cant continue with my project.

here is the camera:

What to do now? Any ideas? Thanks

SCL and SDA are SIDC and SIOD

Not sure about the other pins.

But you are seriously going to have your work cut out getting this to work as school project.

I'd recommend that you look for another camera module, e.g. one that has built in JPEG compression, possibly one of the ones that has on board frame buffer and communicates via serial

The one you have is ultra difficult to get working.

Thank you for the answer.

For the project i should use a OV7670 CMOS VGA camera, and aruino pro mini 5v 16mhz.

The point is taking pictures 128Χ128 pixel or less.

I got another camera without FIFO. picture below.

i got problem with my project i think :cold_sweat:

Hi everyone,

Noob here, I was hoping someone could help me. I think now I have read through 38 pages of conversation. I am hoping my questions are not repeated. I have modified the last attempt @TaylanPince used before giving up on the ov7670+FIFO. I modified it to connect to an arduino MEGA (1280) i know its old. I removed the on-arduino rgb to yuv conversion as per Mr. Arduino's suggestion in a post after that. Besides I only need a grayscale image over serial. after changing what the arduino yields over serial I get a list of values. I then created a small MatLab script to change this list into a matrix and then into a grayscale image. If I enable the colorbar in my setup I do get that but if I go with regular YUV I get weird data. Please help.

Current code: ov7670/ov7670.ino at master · FJSaenz/ov7670 · GitHub

the text i get back from the camera is here : https://dl.dropboxusercontent.com/u/38422921/rn.txt

the image after the matlab conversion is here: https://dl.dropboxusercontent.com/u/38422921/bwbars.jpg

the text after enabling only YUV and QQVGA: https://dl.dropboxusercontent.com/u/38422921/zz.txt

the image after matlab conversion: https://dl.dropboxusercontent.com/u/38422921/bwyuv.jpg
Regards,

@cjjm

For the project i should use a OV7670 CMOS VGA camera, and aruino pro mini 5v 16mhz.

ummm

It doesnt make much difference if you have a fifo or not.

The issue(s) with this camera is

  1. You code needs to be able to read in data very quickly, as I think it only works on a 8Mhz or faster clock (not sure about the fifo but I thought it used the same data clock)

  2. Setting up the hundreds of registers that control the picture colour / gamma/ brightness/ contrast etc etc, is an art in its self.

  3. The camera doesnt use I2C it uses a modified version called SCCB, I guess this may work with the Pro Mini using I2C but on many other devices the differences between SCCB and I2C are too great for people simply to use I2C.

  4. Generation of an 8Mhz clock isnt easy, I thought you needed to blow special fuses using a different program (not the IDE) in order to get that signal - but I'm a bit out of touch with this on the AVR arduinos, as I use a 72Mhz STM32 Maple Mini board for this.

@Edantes87

Hardly anyone has actually got this to work.

I have had mixed results even on a STM32 running at 72Mhz, with 48kb ram.

I can get images from the camera but the line length stuff is still all wrong for me :frowning:

@rogerClark

I know TaylanPince some pages ago got it working but he went for the no FIFO version and an external chip instead. I only have the FIFO version and an old MEGA. I do have two non-FIFO versions of the camera but I would need to get me a chip. According to Mr. Arduino the code im using is too slow. he did mention however that the main (or most terrible as he put it) flaw of the code was that it was doing YUV to RGB conversion on the arduino itself. I deleted this lines because I do not need them I would be happy with grayscale. I reallyo hope someone can help me...school project.

ED87

So i need to buy another camera? is possible do this project? I got over 2 weeks for this project.

What i need to do? What u suggest?

If you only have 2 weeks, (presuming you don't intend to work on it 8 hours a day for 2 weeks), I'd recommend you use a camera that has better support and is easier to interface

See

e.g

or

perhaps

Note. I've not used any of these, but both Sparkfun and Adafruit will give you far more support than you are likely to get with the OV7670 and they both have example code and say their camera's work on the Uno

There are also these cameras


you can find some of them on eBay.
For example this one.

@Edantes87
MrArduino suggest to perform every conversion in a computer so you can convert your image to get a colour image.
The gray image is not a true gray image, an image with colors removed, because of the Bayer filter.

Edantes87:
@rogerClark

I know TaylanPince some pages ago got it working but he went for the no FIFO version and an external chip instead. I only have the FIFO version and an old MEGA. I do have two non-FIFO versions of the camera but I would need to get me a chip. According to Mr. Arduino the code im using is too slow. he did mention however that the main (or most terrible as he put it) flaw of the code was that it was doing YUV to RGB conversion on the arduino itself. I deleted this lines because I do not need them I would be happy with grayscale. I reallyo hope someone can help me...school project.

ED87

Hi @Edantes87

I am currently working with the FIFO version and Arduino Nano. I'm also new to this microcontroller and have been working with the OV+FIFO for about a month now. I got VGA mode working recently but my colors are still a little off.

Anyways, you don't have to worry about the speed of your code execution when working with the FIFO version. The FIFO version has an external 12MHz oscillator that feeds directly into the XCLK of the OV7670. The onboard DRAM controller takes care of the esoteric processes of getting the camera data into the FIFO memory. After that, you can read bytes from the FIFO over UART as slow as you want regardless of the resolution.

I took a look at your code and it is quite a mess. I don't have time to coach you on your programming style but I can offer a few hints about the routines you will need to get a good image from the camera.

The most important question to ask you is which version of the OV7670+FIFO module you have? Some versions come with the OV VSYNC pin directly tied to the Write Reset pin of the FIFO. This has a huge impact on the code you need to write.

If you have the version that exposes the camera VSYNC output to you, then take a look at the VSYNC interrupt handler below and adapt it to your code. This part captures the camera image data into the FIFO memory.

// *****************************************************
//               VSYNC INTERRUPT HANDLER
// *****************************************************
void static __inline__ vsyncIntFunc() {
      DISABLE_WREN;  // disable writing to fifo
          
      if (bRequestPending && bNewFrame) {   /*  if a new frame is ready and I want that frame... */
        detachInterrupt(VSYNC_INT);
        processRequest();    /*  read the data out of the fifo here */
        bRequestPending = false;    /*  reset states */
        bNewFrame = false;
        attachInterrupt(VSYNC_INT, &vsyncIntFunc, FALLING);
      }
      else {  */  load a new frame into the fifo */
          
          ENABLE_WREN;   /* enable writing to fifo (active LOW)*/
          // reset write pointer of the fifo 
          ENABLE_WRST;  /*  write reset (active LOW) */
          //_delay_cycles(500);

          DISABLE_WRST;
          //_delay_cycles(100);   /* Disabled by me.  5/18/2015 */
         
          
          bNewFrame = true;
          
      }
}

I added a lot of comments for you. If you still don't understand what is going on here, then you should read the AL422b and OV7670 datasheets. Specifically the timing diagrams.

After you get the image from the camera into the FIFO, reading it out is as simple as resetting the FIFO read pointer address...

// Reset the fifo read pointer 
void fifo_rrst(void)
{
      ENABLE_RRST;
    //_delayNanoseconds(5);
    SET_RCLK_H;
    //_delayNanoseconds(5);
    SET_RCLK_L;
    DISABLE_RRST;
}

and then pulsing the FIFO read clock for each byte you want.

// Read one byte from the fifo
uint8_t fifo_readByte(void)
{
    uint8_t val;
    SET_RCLK_H;
    val = (DATA_PINS) /* & B11111000); // |B00000111; */
    //_delay_cycles(10);
    SET_RCLK_L;
    //_delay_cycles(10);

    return val;
}

Remember, YUV is 2bytes per pixel. QQVGA YUV = 1601202pixels = 38,400bytes to read out of the FIFO.

Good luck and keep us posted on your progress.

Hi @engenex,

I am very grateful for your response. I am working with what I assume is V3 of the 0v7670+FIFO module.

The pinout can be seen here: g4qkdO.png

I am currently working on making my code a little less of a mess. specifically moving registry definitions and other things into header files. I hope that will make it better.

After that since vsync is exposed to me, I will change my vsync handlers to what you just told me, I will keep you posted. Is there anything else I need to do?

Regards

-Ed87

@Edantes87

I am working with the same 22-pin module. Attached are the schematics.

Make sure you have SDA and SCL pulled up to 3.3v per Mr.Arduino's instructions (This includes disabling the internal pullups in the Wire library). On the OV+FIFO side: PWDN → GND; RESET# → 3.3v; OE → GND.

I think the biggest pitfall most people encounter are the register settings. Just use Mr.Arduino's settings and everything will be ok.

57-OV7670LD0.pdf (297 KB)

i am using mr arduino's code from this( GitHub - ComputerNerd/ov7670-no-ram-arduino-uno: Allows you to use a non fifo ov7670 on the arudino uno without external spi ram like other examples. Sends the data to UART.) on arduino IDE ,i have made the required changes but i have a confusion what is that util/delay and util/twi library that he has used? is it the one from avr or the one inside wire library on arduino IDE? or are both of them same?

Sorry if this is a newbie question but are d(0-7) each representing the corresponding bit in a byte?
If I'm reading these pins, do I need pull-up resistors?

Yes ChromeBit,each d pin of the camera represents a bit.no you dont need any pullup resistors with them you just directly connect them from arduino pins

i have connected my ov7670 +non fifo to arduino mega ,i am trying to read default register values from the camera using wire lib , i have diabled the pullup registers as mr arduino said, but everytime i read i get a different value, sometimes correct sometime wrong.what can be the problem?