print page - ov7670 with both arduino uno and now mega

Upload: ahmad-arif-sakti

Post on 16-Oct-2015

2.227 views

Category:

Documents


11 download

DESCRIPTION

adadsasdasd

TRANSCRIPT

  • 3/15/2014 Print Page - ov7670 with both arduino uno and now mega

    http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0 1/60

    Arduino Forum

    Using Arduino => Sensors => Topic started by: Mr_arduino on April 09, 2013, 10:50:06 pm

    Title: ov7670 with both arduino uno and now megaPost by: Mr_arduino on April 09, 2013, 10:50:06 pm

    Edit: I now recommend the fifo version over the non-fifo version.If you have the fifo version lots of this is still relevant all except the external ram part.The reason for using the fifo version is because of faster readout and you can capture a 640x480 images without breaking it up into pieces.Also I have since figured out how to generate an 8mhz clock using PWM that way you don't have to set fuse bits you can read more about that in my laterposts.Using PWM to generate XCLK has several advantages including: You don't need a special programmer to set the fuse bits. You can change the output clockspeed the fastest it goes is F_CPU/2 which results in 8mhz in the case of the arduino. Also I have since found out that bayer rgb is half the size of yuv422 whichmy old writing below recommends. Raw bayer appears to be about the same level of quality. I would recommend you use it instead of yuv422 I have posted newversions that use raw bayer data. Here is an FAQ of some questions that may come up:Q: The arduino outputs a 5v clock but the arduino will only accept 3.3v what should I doA: use a buffer of some sort it just needs to be fast enough to pass the 8mhz signal.Q: Will the ov7670 accept twi/sccb/i2c (same thing different names) commands without the PCLK runningA: NoQ: Will I need to buffer any other pins besides the PCLKA: No but be sure you have the i2c/twi/sccb lines pulled up to 3.3v instead of 5v or you risk damage to the ov7670Also don't set any of the pins that go to the ov7670 as output.Q: where can I get current registers and useful functions for the ov7670?A: On my github page https://github.com/ComputerNerd/arduino-camera-tftMore specifically here is some stat-up registers here https://github.com/ComputerNerd/arduino-camera-tft/blob/master/ov7670_regs.hAnd here are some useful functions here https://github.com/ComputerNerd/arduino-camera-tft/blob/master/twicam.c also don't forget the header filehttps://github.com/ComputerNerd/arduino-camera-tft/blob/master/twicam.hAnd you will notice that I have vga qvga rgb565 yuv422 defined somewhere else that is here https://github.com/ComputerNerd/arduino-camera-tft/blob/master/config.hQ: the code you posted runs on the arduino mega but I have an arduino uno what can I do?A; The functions that setup the camera will also work on the arduino uno and I have posted some code for the arduino uno see the pastebin links belowQ: The FAQ does not answer my question what should I doA: try reading through this topic your question might be answered if not post a reply I'd rather that you not send a pm because someone else may have the samequestion that you do later on. Here is the my old original post below kept for historical reasons:I have recently been working with the ov7670 unfortunately I made the mistake of cheeping out and buying the cheaper one without the fifo. At first I though itwould be a challenge to get this to work but it turns out not to be that hard at all. The problems: the arudino does not have enough ram and is slow additionallyit runs on 5v when both the ov7670 and the sd card need 3.3v. The solutions. Break the image into smaller pieces and transfer the smaller pieces into spi ram inthis case I have the 23LC1024 128kb of ram that means if I want a vga image 640*480*2 bytes per pixel. I must divide it into 5 equal parts. So I transfer part ofthe image and save that part into the sd card and do this for a total of 5 times each time skipping different regions and saving others. The sensor can outputboth rgb565 or yuv422 I found that yuv422 is better quality so I made a converter for that and you can get the source code herehttps://github.com/ComputerNerd/RawCamera-data-converter. Here is code for the capture program. http://pastebin.com/1nnRc5qL I used sdfatlib to write andbased my code off of his fastlogger code. Note that by defining useLed using #define useLed will assume you have an led on pin 0 and a button on pin 1 to stopthe capture hold down the button and wait for the led to blink very fast make sure that the button sinks the pin to grounnd. If you do not define useLed then ituses serial to start stop image send one letter to the arduino and it will save 1 image you can send more for more images. Also Note that I found some registersonline somewhere and I could not find documentation on those registers. The only ov7670 datasheet that I could find online does not explain all the registers itgives the name but the description is blank. If someone could explain with a reply or PM what these:Code:

    wrReg(AWBC7,0x88); wrReg(AWBC8,0x88); wrReg(AWBC9,0x44); wrReg(AWBC10,0x67); wrReg(AWBC11,0x49); wrReg(AWBC12,0x0e); wrReg(REG_GFIX,0x00); //wrReg(GGAIN,0x40);

    wrReg(AWBCTR3,0x0a); wrReg(AWBCTR2,0x55); wrReg(AWBCTR1,0x11); wrReg(AWBCTR0,0x9f); wrReg(0xb0,0x84);//not sure what this does

    registers do that would be awesome.To solve the 5v issue I use a buffer. To solve the fact that the arduino is slow I set the divider to 9 also I am getting the clock with the CLKOUT pin you willhave to change your fuse settings for that. Also for twi communication the ov7670 is picky about what pullup resistor values you use I found 4.7k and 10k towork. I tried 1k and 2.2k and those do NOT work. You will need twi to write to the registers the image out is parallel. Here are some images taken with theov7670.(http://img812.imageshack.us/img812/696/v5w6.png)(http://img51.imageshack.us/img51/7659/blinds.png)Here is the arduino uno itself. Image is very large click here to view http://imageshack.com/a/img849/4632/zuvj.jpg

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: nonzung on April 11, 2013, 01:21:02 am

    Hello, I would like to see your connection in detail. I want the camera to be used in image processing by arduino.

    Thanks for answer and sorry for my English. Nice job.

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Mr_arduino on April 11, 2013, 07:30:22 pm

    The connections are simple. Start by plugging in SIO_C to A5 and SIO_D to A4 since this is i2c/twi you must have a 4k7 resistor 10k also works. Make sure youhave the resistor to pull up 3.3v not 5v. Also edit twi.c in the arduino ide folder/libraries/Wire/utility search for these lines and comment them out or removethemCode:

    // activate internal pullups for twi. digitalWrite(SDA, 1); digitalWrite(SCL, 1);

    This is to remove the internel pullup resistor by not removing these 2 lines you could cause damage to the sensor. Then plug d7 to digital pin 7 d6 to 6 d5 to 5 d4to 4 d3 to A3 d2 to A2 d1 to A1 and d0 to A0 now plug in VSYNC to digital pin 3 and PCLK to pin 2. Now change the fuse bits to be exacly the same exceptenable the CLKOUT pin. This will output a clock run this through a buffer or level shifter to 3.3v if you do not get the 5v signal down to 3.3v it could damage thesensor. The sd card and spi ram is just standard spi wiring nothing special.

  • 3/15/2014 Print Page - ov7670 with both arduino uno and now mega

    http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0 2/60

    sensor. The sd card and spi ram is just standard spi wiring nothing special.

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: nonzung on April 12, 2013, 01:10:57 am

    Thanks for the answer, I will try. :) :)

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Mr_arduino on April 12, 2013, 04:06:02 pm

    I wish you the best of luck if anything does not work right just reply and I will help you.

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: michinyon on April 13, 2013, 01:57:23 am

    Could you post a photo of your device sometime ? I got one of these and the connections were so tiny thatI could not see then with a magnifying glass and certainly not actually connect anything to them.

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Saren on April 13, 2013, 06:20:47 pm

    Hi, I'm working on a project at university about computer vision and Arduino.I'm trying to capture an image using Arduino Uno and OV7670 camera without FIFO. Other components like SD card, LCD, additional RAM, shields, etc. areunfortunately not available at this time (I've read some tutorials about this, but they were using special shields or some stuff I don't have or camera withFIFO...).Is it possible to directly communicate with camera from Arduino and get some images? It doesn't have to be fast, the point is to get some results.

    Since I'm just a beginner with Arduino, I'm a little bit confused about how to connect my camera to it, when I don't use RAM that was mentioned above. I reallydon't want to damage it... Could you please describe it or provide some connection schema for a case like mine? Could you please also give me some advice how to change the code for thecapture program?

    Any help is appreciated.

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Mr_arduino on April 13, 2013, 09:03:23 pm

    michinyon I bought an ov7670 camera module that means some of the pins are routed to a 2.54mm pitch header I think you have bought just the sensor. I ambusy right now I will take a picture soon.Saren it is possible I will have to get back with you on this one though. I am busy right now and don't have any code written right now for using no ram. I dohowever have a program that is compiled with avr-gcc that sends the image to a frame grabber program that I wrote.Here is the sender program it is in 3 files main.c ov7670.h ov7670.cmain.c:http://pastebin.com/dF3pc23TI will warn you that I made some changes to the code but forgot to change the comments like the captureImg function says it missed a byte but now it does notI posted it to paste bin before realising this.ov7670.hhttp://pastebin.com/CqYTwNqnov7670.chttp://pastebin.com/T1nN5Ni4Here is the frame grabber source codehttp://pastebin.com/dxMJhZTqThis one is only one file. If on Gnu/Linux you will need to install the development package of SDL or if gentoo just emerge sdl. If on windows get the developmentlibrary from http://www.libsdl.org/download-1.2.phpAlso I made an update to my program that captures an image to the sd card it nows saves raw bayer data.http://pastebin.com/zV0ahzPvThe link is different than the previous code that I posted.Here is a program to debayer/demosaic the data it is still in very beta needs workIt will also convert yuv422 to rgb (the old image to sd card program saved data in that format)Code:

    //to compile type gcc -Wall -Wextra -lm -lpng -o yuv main.c#include #include #include #include #include #include #include #define img_w 640#define img_w_2 1280#define img_h 480#define CLIP(X) ( (X) > 255 ? 255 : (X) < 0 ? 0 : X)#define C(Y) ( (Y) - 16 )#define D(U) ( (U) - 128 )#define E(V) ( (V) - 128 )#define YUV2R(Y, U, V) CLIP(( 298 * C(Y) + 409 * E(V) + 128) >> 8)#define YUV2G(Y, U, V) CLIP(( 298 * C(Y) - 100 * D(U) - 208 * E(V) + 128) >> 8)#define YUV2B(Y, U, V) CLIP(( 298 * C(Y) + 516 * D(U) + 128) >> 8)char buf[1024];void showHelp(){

    puts("Yuv422 raw image data to png"); puts("-n x replace x with the image number you want to convert"); puts("-h shows this help file"); puts("-o x replace x with a real integer between 0 and 7 this sets the offset");}int savePNG(char * fileName,uint32_t width,uint32_t height,void * ptr){ //saves a 24bit png with rgb byte order png_byte * dat=ptr;//convert to uint8_t //png_byte **row_pointers = malloc(height*sizeof(png_byte)); //if (row_pointers==0) // return 1; FILE * fp=fopen(fileName,"wb"); if (fp==0) return 1; png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (png_voidp)0,0,0);

  • 3/15/2014 Print Page - ov7670 with both arduino uno and now mega

    http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0 3/60

    png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (png_voidp)0,0,0); if (!png_ptr) return 1; png_infop info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { png_destroy_write_struct(&png_ptr,(png_infopp)NULL); return 1; } if (setjmp(png_jmpbuf(png_ptr))) { png_destroy_write_struct(&png_ptr, &info_ptr); fclose(fp); return 1; } png_init_io(png_ptr, fp);

    png_set_IHDR(png_ptr, info_ptr, width, height,8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);//must be called beforeother png_set_*() functions //png_set_compression_level(png_ptr,Z_BEST_COMPRESSION);//since we are doing timelapses we may be dealing with many files it is good to keep disk space usage down uint32_t y; //for (y=0;y

  • 3/15/2014 Print Page - ov7670 with both arduino uno and now mega

    http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0 4/60

    out[((x+img_w)*3)+3]=in[x];//red out[((x+img_w)*3)+4]=in[x+img_w];//green out[((x+img_w)*3)+5]=in[x+img_w+1];//blue }*/ } out+=img_w*6; in+=img_w*2; }}uint8_t readImg(uint32_t num,uint8_t * dat){ sprintf(buf,"F%d.YUV",num); FILE * myfile = fopen(buf,"rb"); if (myfile==0) {

    printf("Cannot open file %s\n",buf); return 1; } fread(dat,2,img_w*img_h,myfile); fclose(myfile); return 0;}uint8_t processImg(uint8_t * in,uint8_t * out,uint32_t num,uint8_t alg,uint16_t offset){ if (readImg(num,in)) return 1; uint32_t w,h; switch (alg) { case 2: deBayerL(in+offset,out);//linear break; case 1: deBayerN(in+offset,out);//nearest neighboor low quality try to avoid using break; case 0: yuv2rgb(in+offset,out); break; default: puts("You must pick an algorithm to save the image as"); return 1; } sprintf(buf,"frame %d.png",num); if (savePNG(buf,img_w,img_h,out)) { return 1; puts("Error while saving PNG"); } return 0;}int main(int argc,char ** argv){ uint8_t useNum=0; uint32_t useImg; uint16_t offset=0; uint8_t debayer=1; if (argc>1) { //handle arguments int arg; for (arg=0;argimg_w) { printf("you must specify a number between 0 and %d for argument -o\n",img_w); showHelp(); return 1; } continue; } if (strcmp(argv[arg],"-h") == 0) { showHelp(); continue; } } } uint8_t * Dat;//in case some of the file was not saved we use calloc instead of malloc to garentte that the unsaved pixels are set to 0 if (debayer!=0) Dat = calloc(img_w*img_h+img_w,1);

    else Dat = calloc(img_w*img_h+img_w,2); uint8_t * outImg = malloc(img_w*img_h*3);//all bytes in the array will be overwritten no need for calloc if (useNum) { processImg(Dat,outImg,useImg,debayer,offset); } else { uint32_t imgC; for (;;imgC++) { printf("Saving image %d\n",imgC); if (processImg(Dat,outImg,imgC,debayer,offset)) return 1; } } free(Dat); free(outImg); return 0;}

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: nonzung on April 16, 2013, 01:49:37 am

    I forget that. I bought the camera ov7670 fifo.Sorry and thank you so much.

  • 3/15/2014 Print Page - ov7670 with both arduino uno and now mega

    http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0 5/60

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Mr_arduino on April 16, 2013, 05:53:08 pm

    Quote from: nonzung on April 16, 2013, 01:49:37 am

    I forget that. I bought the camera ov7670 fifo.Sorry and thank you so much.

    Smart choice the one with the fifo is much better I wish I would have bought it but I bought the one without the fifo.

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Saren on April 23, 2013, 01:01:18 pm

    Mr_arduino: I didn't have much time lately, but now I'm going to try it. I have some questions about connection: 1. You mentioned that it's necessary to get the 5V signal down to 3.3V. Is it possible to do this without level shifter/buffer or do I have to get this stuff?2. Are connections the same (as in one of your posts) even in my case (without RAM, etc)?

    Thanks for your effort to help. I really appreciate it :)

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Mr_arduino on April 26, 2013, 04:32:11 pm

    The connections will be mostly the same but it could be abit different as I do not own the one with the fifo I am not sure but I think instead of PCLK you useRCLK and and RCLK is output you strobe that to get data. Check you this for more info about the fifo versionhttp://wiki.beyondlogic.org/index.php/OV7670_Camera_Module_with_AL422_FIFO_Theory_of_Operation Also you could try a resistor divider but I have heard thatthey are too slow you may need a buffer/level-shiftier. Also this would not require the ram as you have the fifo.

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Mr_arduino on April 27, 2013, 10:28:20 am

    A recent discovery that I made is you can get an F_CPU/2 (8mhz in the arduino's case) clock output with pwm this removes the need to edit fuse bits. Note thatthis is for the arduino mega 2560 I switched to from the uno to the mega recently. This will work with the arduino uno also just change the timer number.Code:

    DDRL|=8; ASSR &= ~(_BV(EXCLK) | _BV(AS2)); //generate 8mhz clockTCCR5A =67;TCCR5B=17;

    Also change DDRL to proper port and pin or be lazy and replace with pinMode();

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: emueyes on April 27, 2013, 08:24:40 pm

    There's a good page on generating clock signals at http://hekilledmywire.wordpress.com/2011/05/28/introduction-to-timers-tutorial-part-6/#more-57

    I too have the question about level shifting; what sort of buffers are needed, would a 74HC245 do?

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Mr_arduino on April 28, 2013, 02:18:29 pm

    I think the 74HC245 would work just fine also a unidirectional one would work too. Pretty much any buffer that is fast enough to handle a 16mhz signal and canaccept 3.3v as a supply voltage which the 74HC245 can. You do not need to shift the d7-d0 as those are always output from the sensor and never input. Onlythe clock signal needs to go though the buffer as that is an input and the sd card if you are using it. From twi just disable internal pullup resistors and have themto 3.3v instead of 5v. Also I think I may have forgot to mention that RESET needs to be tided to 3.3v and PWDN to ground or you could use more GPIO pins ifyou need to use the PWDN and RESET features although a reset can also be triggered by writing to a register so driving that pin with the arduino has littlepurpose.

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: emueyes on April 29, 2013, 03:42:43 am

    Thanks, that's very helpful. I'd thought that the D0..D7 signals would need shifting and so lots of converters would be needed, but that's simplified things a lot.Still waiting for my camera to turn up.

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Saren on April 30, 2013, 02:54:07 pm

    Quote from: Mr_arduino on April 26, 2013, 04:32:11 pm

    The connections will be mostly the same but it could be abit different as I do not own the one with the fifo I am not sure but I think instead of PCLK you use RCLK and and RCLK is output youstrobe that to get data. Check you this for more info about the fifo version http://wiki.beyondlogic.org/index.php/OV7670_Camera_Module_with_AL422_FIFO_Theory_of_Operation Also youcould try a resistor divider but I have heard that they are too slow you may need a buffer/level-shiftier. Also this would not require the ram as you have the fifo.

    I think there has been a misunderstanding. My camera is without fifo...

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Mr_arduino on April 30, 2013, 08:39:04 pm

    Quote from: Saren on April 30, 2013, 02:54:07 pm

    I think there has been a misunderstanding. My camera is without fifo...

    So is mine so will need the same connections as I use and the external sram. Also the reason d0-d7 not need shifting is the arduino will never drive those pins soit is up to you to make sure that those pins are always set to input on the arduino.

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: sherry254 on May 11, 2013, 08:30:16 am

    Hi, i have the ov7670 camera, an arduino uno rev 3 and ST M27C512-12F1 Eprom. Is it possible to take pictures with these components? and if so, how do iconnect them together. i have seen that you used the spi ram, can i replace that with the eprom??Please assist me on how to connect the arduino, camera and the eprom together to give me a picture.

  • 3/15/2014 Print Page - ov7670 with both arduino uno and now mega

    http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0 6/60

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Mr_arduino on May 11, 2013, 09:43:09 am

    This is the old school eprom with UV erase. There are several reason why this would not work. First of all how are you going to erase it in a reasonable time. Evenif you had a UV led driven by the arduino it would still take awhile to erase and UV is bad for your eyes so you would need to cover it with something. Also youwould not have enough pins are the eprom is parallel. Also how fast are the write speed will it even accept data fast enough. Another problem is that you wouldwear it out fast. Eproms only have a certain amount of writes (They do have unlimited reads though). Also this Eprom has only 64kb of memory you would haveto break the frame up even more which would reduce performance even more. In short the Eprom would not work for this purpose save it for repairing a bios ormake your own NES cartridge or do something fun with it but not in a camera. Just buy or sample the 23LC1024 it is kinda cheap at $2.59 if you only order one atdigi-key and you will not regret it. It is even in dip package. The dip package one is called 23LC1024-I/P by the way

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: sherry254 on May 11, 2013, 11:28:08 am

    Clearly getting the eprom was a wrong move. My other option(or idea, but might not be a very good one) is to connect the camera to a SIM5216E 3g shield. thedatasheet indicates that its possible to connect the camera pins on the shield but the pins are marked 'NC'.this is the shield i have ftp://imall.iteadstudio.com/Shield/IM121026002/DS_IM121026002_3G_Shield.pdfthis is its schematic ftp://imall.iteadstudio.com/Shield/IM121026002/SCH_IM121026002_3G_Shield.pdfCould i connect the camera to the shield instead of using the arduino directly?

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: hlankoande on May 11, 2013, 06:10:49 pm

    Hello Mr_arduinoI have planed to use the OV7670 camera module to capture picture with arduino mega 2560 R3. I m using it to drive robot and get few data from robot. I m using arduino programming IDE to write code. The code you gave is compiled with another compiler and as I do not have deep kwnowledge on this it is liltle bit hard for me. Is it possible to give us(I guess I m not alone in that case) a hello world example to capture picture and store it in an array( in order to save it in SD card or sendit other serial) written with arduino IDE. Thanks lot in advance.

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: isaiful on May 16, 2013, 11:36:48 pm

    hye...i wanna ask if this camera is same with JPEG TTL CMOS camera???

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Mr_arduino on May 17, 2013, 06:59:24 pm

    @hlankoandeI made some code for the arduino mega awhile ago check it out it uses the arduino idehttp://www.youtube.com/watch?v=sEsZeDC6co0@isaifulIt is no were near the jpeg TTL camera. The Jpeg TTL CMOS camera is way easier to use but cost more money.

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: rebelion on May 22, 2013, 06:20:40 am

    Hello

    I have the same problem with OV7670 v2 + Mega R3, a lack of experience stops me to get those things work together..Mr_arduino it would be really great if could share the code and wiring with us?

    Thank you.

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: drkblog on May 24, 2013, 07:27:59 am

    Quote from: Mr_arduino on April 28, 2013, 02:18:29 pm

    I think the 74HC245 would work just fine also a unidirectional one would work too. Pretty much any buffer that is fast enough to handle a 16mhz signal and can accept 3.3v as a supply voltagewhich the 74HC245 can. ... Only the clock signal needs to go though the buffer as that is an input and the sd card if you are using it. From twi just disable internal pullup resistors and havethem to 3.3v instead of 5v...

    Hello, I'm trying too to get the ov7670 communicate with Arduino UNO.

    I read this post a week ago, I bought some 74HC245 but I realized they are not fully bidirectional, you have to choose the direction using a pin. So they can't beused with SIO_D and SIO_C, as far as I know. As I'm reading this post again, I guess A5 and A4 pins, using the code supplied, will output 3.3V instead of 5V(assuming internal pullup is OFF). Am I right?

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Mr_arduino on May 25, 2013, 12:24:25 pm

    It said in the post it does not matter if they are bidirectional or not. Also you do not need a buffer for i2c if you disable the internal pull-up and make sure thatyou have the pull-up resistor to 3.3v.

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: drkblog on May 26, 2013, 09:44:20 am

    Mr_Arduino, thank you for your response. I managed to connect SIO_C and SIO_D, I also changed atmega fuses to get the CLKOUT at pin 8. Yet, I don't have extra RAM chip and right now the only thingI want to do is checking if the ov7670 is responding.

    What's the simplest way to know? Let's say using and oscilloscope.Is it possible to capture an image from the sensor right into the SD (without a RAM)?

  • 3/15/2014 Print Page - ov7670 with both arduino uno and now mega

    http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0 7/60

    Thank you again!

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Mr_arduino on May 28, 2013, 08:07:23 pm

    First verify that CLKOUT is correct connected to the buffer and the output from the buffer does not exceed 3.3v and is correctly connected to XCLK then verifythat with an osciloscope (you should see a square wave) after that see if SIO_C and SIO_D work it may just be a quick burst but that is normal. Then see if youget a most square wave from PCLK there should be a very brief burst where PCLK stops every so often. This is because by default the ov7670 outputs unwanteddummy pixels that serve no good we don't want those dummy pixels. If PCLK never stops it may not be communicating properly but the part where it stops maybe too fast to see I can not remember off the top of my head.

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: drkblog on May 31, 2013, 07:21:35 pm

    Thank you!

    I'm doing better now. Yet it isn't working. I had a communication problem between Arduino and the sensor. Now that's working and I'm able to configure thesensor. I'm having a somewhat coherent reading. I read 512 bytes blocks from the sensor, but I get blocks of zeroes every two or three blocks.

    I'm configuring a 3MHz PCLK but I guess it's too fast for arduino. What do you think?

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Mr_arduino on June 01, 2013, 10:48:20 am

    I set the divider to 4 see this code wrReg(0x11,4);//using pre-scaler for divider Also what you can do to verify communication is increment the divider and waitawhile and increment again in a loop and see if the OUTPUT PCLK changes on an oscilopsoce. Also you MUST have this registerCode:

    wrReg(0x15,32);//pclk does not toggle on HBLANK COM10 vsync falling

    That may another reason why you are getting invalid data. If you don't have it just use all registers from my sample code would be best.

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: drkblog on June 16, 2013, 11:47:37 am

    Ok, I have been working and I see some advances now. Yet I'm not done.

    I've incremented the prescaler and I realized there is a point (as I incremente PCLK frequency) where I start missing bytes. So I'm using the slower PCLK possiblenow. I have got a 23LC1024 chip and removed the SD card. My test program reads 50 lines of 640 from the sensor and puts the in the chip. Then dumps it inbase64 to the PC through the USB. I'm setting the sensor to output a color bar pattern.

    Here is my YUV output for that image's portion. And what I see when I convert it using ffmpeg

    Code:

    $ ./ffmpeg -f rawvideo -s 640*50 -pix_fmt yuvj422p -i frame0.yuv -f image2 -vcodec png img.png

    I think I may be getting valid data from the sensor, and my problem could be in the ffmpeg conversion. But I'm not sure how to check that.

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Mr_arduino on June 17, 2013, 10:51:24 am

    Good job the only thing is that you have the sensor configured for raw bayer data. I attached the image I got.Here is the source code to the program that converts the image it does both yuv422 and raw bayer data and saves it to a png file.https://github.com/ComputerNerd/RawCamera-data-converter/blob/master/main.cTo compile it simply typeCode:

    gcc -Wall -Wextra -lm -lpng -o yuv main.c

    As you may have noticed you need libpng installed.The only thing is that the file name must be called F(x).YUV replace (x) with a number this was because I made it for time lapses originally and need to maypictures at once. If you don't specify which number x is when running the program it will start from 0 and count up until a file is not found note that if you haveF0.YUV and F2.YUV it will stop at F0.YUV as F1.YUV does not exist so in this case if you wanted to convert F2.YUV you would need to use the -n x argument soin this case do ./yuv -n 2 to convert it. Also speaking of missing a byte glitch I found out that sometimes at the beginning of capture a byte would be missed Ifixed this by waiting for PCLK to go low read the pixel then wait for it to go high and then loop. I previously had it backwards.

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: drkblog on June 17, 2013, 06:40:00 pm

    Wow... thank you.

    I thought I was configuring the sensor for YUV output. After reading your reply I went to check that. I think I'm misreading the documentation or the document iswrong. Because I can't manage to change the output.

    What I'm doing now:Code:

    // Max prescaler divider ovcam.toggle(REG_CLKRC, NONE, CLKRC_PRESCALER_MASK & 31); ovcam.toggle(REG_DBLV, NONE, DBLV_PLL_BYPASS);

    // No PCLK during HBLANK

    ovcam.toggle(REG_COM10, NONE, COM10_PCLK_NO_TOGGLE);

    // Set up camera ovcam.write(REG_COM7, 0x00); // YUV ovcam.write(REG_COM15, 0xC0); // Set normal rgb with Full range ovcam.toggle(REG_ABLC1, NONE, ABLC_ENABLE); // Auto black level

    ovcam.write(REG_COM13, 0x88); ovcam.write(REG_TSLB, 0x05);

    The problem is no matter what I put in COM7, COM13 and TSLB. I can't manage to change to YUV. I have a PDF dated "Version 1.3, April 5, 2006" but I see someregisters do not act according to the configuration. Do you know where is the last document for this sensor?

  • 3/15/2014 Print Page - ov7670 with both arduino uno and now mega

    http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0 8/60

    registers do not act according to the configuration. Do you know where is the last document for this sensor?

    Anyway, I guess I can live with RAW Bayer data by now.

    What is the clock frequency you are sending to the module?What is the max PCLK frequency you are able to read from Ardunino UNO or Mega?Is you conversion program discarding color information? Or is it me doing something wrong?

    By the way: I just noticed I had a byte in zero at the start. I fixed it waiting for the high state of the HREF signal, before starting to read the line. But then, as Ichange from bar pattern to the image, I start getting zeroes again. :/

    Thank you very much!

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: drkblog on June 17, 2013, 07:49:34 pm

    Here is a picture taken in three stages of 640x100 pixels:

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Mr_arduino on June 17, 2013, 09:05:46 pm

    Ok I think you were configuring the output for yuv however here is what I use for yuv also I am having the same problem with raw bayer data it lacks color. Yuvis much more colorful Here is what I use for yuv422. Also the documentation for the ov7670 is very bad don't blame yourself. Although here is a newer version 1.4that may help abithttp://www.haoyuelectronics.com/Attachment/OV7670%20+%20AL422B%28FIFO%29%20Camera%20Module%28V2.0%29/OV7670%20datasheet%28V1.4%29.pdfIf you noticed in the changelog of the 1.4 from 1.3 they changed the TSLB and COM13 documentation.Code:

    wrReg(0xb0,0x84);//Undocumented but writing this fixes colors I do not know why wrReg(REG_COM7, 0x00); // YUV wrReg(REG_COM15, 0xC0); //Full range wrReg(REG_TSLB,0x04); // 0D = UYVY 04 = YUYV wrReg(REG_COM13,0xC8); // connect to REG_TSLB

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: drkblog on June 17, 2013, 09:39:51 pm

    I keep getting the RAW data. I will keep trying tomorrow morning (it's 11:40PM here). Thank you again.

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Mr_arduino on June 17, 2013, 10:04:11 pm

    Also did you look at the linux driver it has a complete register configuration which has parts based on official registers provided by omnivisonhttp://dev.openaos.org/browser/trunk/buildroot/gen7/linux/drivers/media/video/ov7670.cAlso at the bottom of the page click download as plain text to copy paste without the line numbers. And with my program are you telling it to yuv422 conversiontry passing the argument '-c y' without the quotes.

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: drkblog on June 18, 2013, 08:33:51 am

    I'm going to check that link with the registers.

    I tried your program with "-c y" and "-c d". I only get a reasonable image with D (debayer). But I don't like having something like this sensor, and not be able toconfigure it correctly.

    As a mater of fact, RAW bayer could be the best choice for my project. I don't need color information and I see bayer format is one byte per pixel, which takeshalf space and time.

    Have you tried the FIFO version of this module? I'm going to buy one, because I will save a lot of space if the RAM is on the sensor itself.

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Mr_arduino on June 18, 2013, 09:06:26 am

    There are several advantages of the fifo version however it is the same exact sensor the ov7670 so you will still have the same register issues.Here are someadvantages of the fifo version you control when pixels are read out and you have enough ram to read the entire pixel at once. What I would do is just use thelinux driver registers copy paste the entire large structbefore the large struct add Code:

    struct regval_list { uint8_t reg_num; uint8_t value;};

    After that replaceCode:

    static struct regval_list ov7670_default_regs[] = {

    withCode:

    const struct regval_list ov7670_default_regs[] PROGMEM = {

    Also make sure you #include and use this function to write the registersCode:

    void wrSensorRegs8_8(const struct regval_list reglist[]){ uint8_t reg_addr,reg_val; const struct regval_list *next = reglist; while ((reg_addr != 0xff) | (reg_val != 0xff)){ reg_addr = pgm_read_byte(&next->reg_num); reg_val = pgm_read_byte(&next->value); //wrReg(reg_addr, reg_val); ovcam.write(reg_addr,reg_val); next++; }}

  • 3/15/2014 Print Page - ov7670 with both arduino uno and now mega

    http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0 9/60

    }

    After writing all those registers configure PCLK and make sure the PCLK does not toggle during HBLANK.

    Then in the file that you downloaded (the linux driver) look forCode:

    static struct regval_list ov7670_fmt_yuv422[] = {

    And adapt it to your codeAlso if you want changeCode:

    { REG_COM9, 0x18 }, /* 4x gain ceiling; 0x8 is reserved bit */

    toCode:

    { REG_COM9, 0x6A }, /* 128x gain ceiling; 0x8 is reserved bit */

    Note that it does not mean gain will always be 128x it just means it can go up there if needs to

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: drkblog on June 19, 2013, 07:31:33 pm

    I copied the configuration from the driver, pretty much in the way you suggested me. But I see voltage levels in the signaling change. And that messes up withmy electrical interface, so the Arduino can't read the signals. I didn't connect the sensor to the arduino because I was afraid I could damage the sensor and ittakes 25 days to arrive from Hong Kong. So I used a bidirectional 3.3V to 5V interface using FET. I made an article, it's in Spanish but you will be able to see thecircuit and some waveforms. And there is a link to the application note in english too: http://blog.drk.com.ar/2013/interfaz-logica-bidireccional-entre-5v-y-3-3v

    I guess I could make it work spending some time in it. But I have to go on with other parts of this project. I'm going to work in other stuff as I wait for the FIFOversion I bought yesterday, to arrive. Then I will have to build the circuit again, and I could give it another try.

    Do you have any document/information about the interface with the FIFO memory?

    I hope that memory is going to let me read the bytes at any given speed. Because timing with this sensor is a pain.

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Mr_arduino on June 19, 2013, 08:59:51 pm

    Sorry I forgot to mention that it changes CLCK speed. I have uploaded the registers I use herehttps://github.com/ComputerNerd/arduino-camera-tft/blob/master/twicam.cThey are pretty much the ones from the linux driver with some slight changes that may help what you described.Note that init_cam() takes one parameter uint8_t useBayer what this means is if you pass 1 to it then it will set the camera to use raw bayer data Note thatwhen useing bayer after this function add a 200 millosecond delay and rewrite the clock value (register 0x11).pass 0 to make it use something other than bayerdata. You can use setColor() to pick what you want. SetRes() sets what resolution you want. SetRes() changes the clock divider speed (register 0x11). Youmay need to change that.Also for setRes() and setColor() you will some of the #defines here https://github.com/ComputerNerd/arduino-camera-tft/blob/master/config.hor you could just addCode:

    #define vga 0#define qvga 1#define qqvga 2#define yuv422 0#define rgb565 1#define bayerRGB 2

    to your code.Also here is documentation on the fifo version http://wiki.beyondlogic.org/index.php/OV7670_Camera_Module_with_AL422_FIFO_Theory_of_Operation

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: drkblog on June 19, 2013, 10:21:17 pm

    Great!

    The default configuration was changing register 0x6B (DBLV) which has control over the PLL afecting the PCLK output. Which was causing all the problem withthe clock. Now it seems to be working. And the output format has clearly changed. But now I can't convert the image using neither "-c d" nor "-c y" flags. MaybeI'm misreading the second byte. According to the datasheet, each byte is to be read during the high stage of PCLK. Which is what I am doing, as far as I know.

    I'm attaching the frame read from the sensor (Just 640x200) and the PNG I get.

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: drkblog on June 19, 2013, 10:33:58 pm

    Update. I was missing a fix, in the reading logic... yet it isn't done...

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: drkblog on June 19, 2013, 10:45:29 pm

    Sorry for the repeated posting. But there are great news... it's working now.

    I'm getting just 640x200 portion of the frame for the sake of speed in the tests :)

    THANK YOU!

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Mr_arduino on June 19, 2013, 10:47:37 pm

    Wow I am glad to see that it is working it makes me happy too. The colors look nice.

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: drkblog on June 19, 2013, 10:53:58 pm

    I'm sure that could be improved. I didn't setup filter for 50Hz, and the camera is pointing a little towards the light. But what I really wanted was to be able toconfigure the sensor. So it's great. Thank you again!

  • 3/15/2014 Print Page - ov7670 with both arduino uno and now mega

    http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0 10/60

    configure the sensor. So it's great. Thank you again!

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Mr_arduino on June 19, 2013, 10:56:45 pm

    You could disable digital gain. For some reason your image reminds me of what digital gain enabled looks like.

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: drkblog on June 19, 2013, 11:01:02 pm

    Ok! I will try that tomorrow and will let you know.

    I have to get some sleep now :)

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Mr_arduino on June 20, 2013, 10:00:04 am

    Hint to disable digital gain change register 0x74 to 0x10I just edited the struct https://github.com/ComputerNerd/arduino-camera-tft/commit/7809cb37eb072d6325f33b6491284c6615a13bff

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: drkblog on June 20, 2013, 11:16:46 am

    Digital gain was disabled already. Now I'm using day light and commented the Gamma matrix setting from the linux driver code...

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Mr_arduino on June 20, 2013, 05:07:50 pm

    I am glad to see that it is working well for you. Something seems different about the image noise/artifacts you posted I just cannot place my finger on it. Did youchange some registers or something?

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: drkblog on June 20, 2013, 07:48:27 pm

    Nope. I mean, I copied the basic configuration and the YUV configuration sets, from the source you posted. Here is what I'm running:

    Code:

    static struct regval_list ov7670_default_regs[] = {// { REG_COM7, COM7_RESET },//// Clock scale: 3 = 15fps// 2 = 20fps// 1 = 30fps

    { REG_CLKRC, 20 }, // OV: clock scale (30 fps) [26 funciona] { REG_TSLB, 0x04 }, // OV { REG_COM7, 0 }, // VGA // // Set the hardware window. These values from OV don't entirely // make sense - hstop is less than hstart. But they work... // { REG_HSTART, 0x13 }, { REG_HSTOP, 0x01 }, { REG_HREF, 0xb6 }, { REG_VSTART, 0x02 }, { REG_VSTOP, 0x7a }, { REG_VREF, 0x0a },

    { REG_COM3, 0 }, { REG_COM14, 0 }, // Mystery scaling numbers { 0x70, 0x3a }, { 0x71, 0x35 }, { 0x72, 0x11 }, { 0x73, 0xf0 }, { 0xa2, 0x02 }, { REG_COM10, COM10_PCLK_HB }, // No PCLK during HBLANK

    // Gamma curve values //

    { 0x7a, 0x20 }, { 0x7b, 0x10 }, { 0x7c, 0x1e }, { 0x7d, 0x35 }, { 0x7e, 0x5a }, { 0x7f, 0x69 }, { 0x80, 0x76 }, { 0x81, 0x80 }, { 0x82, 0x88 }, { 0x83, 0x8f }, { 0x84, 0x96 }, { 0x85, 0xa3 }, { 0x86, 0xaf }, { 0x87, 0xc4 }, { 0x88, 0xd7 }, { 0x89, 0xe8 },

    // AGC and AEC parameters. Note we start by disabling those features, // then turn them only after tweaking the values. { REG_COM8, COM8_FASTAEC | COM8_AECSTEP | COM8_BFILT }, { REG_GAIN, 0 }, { REG_AECH, 0 }, { REG_COM4, 0x40 }, // magic reserved bit { REG_COM9, 0x18 }, // 4x gain + magic rsvd bit { REG_BD50MAX, 0x05 }, { REG_BD60MAX, 0x07 }, { REG_AEW, 0x95 }, { REG_AEB, 0x33 }, { REG_VPT, 0xe3 }, { REG_HAECC1, 0x78 }, { REG_HAECC2, 0x68 }, { 0xa1, 0x03 }, // magic { REG_HAECC3, 0xd8 }, { REG_HAECC4, 0xd8 }, { REG_HAECC5, 0xf0 }, { REG_HAECC6, 0x90 }, { REG_HAECC7, 0x94 }, { REG_COM8, COM8_FASTAEC|COM8_AECSTEP|COM8_BFILT|COM8_AGC|COM8_AEC },

    // Almost all of these are magic "reserved" values. { REG_COM5, 0x61 }, { REG_COM6, 0x4b }, { 0x16, 0x02 }, { REG_MVFP, 0x07 }, { 0x21, 0x02 }, { 0x22, 0x91 }, { 0x29, 0x07 }, { 0x33, 0x0b }, { 0x35, 0x0b }, { 0x37, 0x1d }, { 0x38, 0x71 }, { 0x39, 0x2a }, { REG_COM12, 0x78 }, { 0x4d, 0x40 }, { 0x4e, 0x20 }, { REG_GFIX, 0 }, { REG_DBLV, 0x00 }, { 0x74, 0x10 }, // DVL 0x4A ?? { 0x8d, 0x4f }, { 0x8e, 0 }, { 0x8f, 0 }, { 0x90, 0 }, { 0x91, 0 }, { 0x96, 0 }, { 0x9a, 0 }, { 0xb0, 0x84 }, { 0xb1, 0x0c }, { 0xb2, 0x0e }, { 0xb3, 0x82 }, { 0xb8, 0x0a },

  • 3/15/2014 Print Page - ov7670 with both arduino uno and now mega

    http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0 11/60

    { 0xb3, 0x82 }, { 0xb8, 0x0a },

    // More reserved magic, some of which tweaks white balance { 0x43, 0x0a }, { 0x44, 0xf0 }, { 0x45, 0x34 }, { 0x46, 0x58 }, { 0x47, 0x28 }, { 0x48, 0x3a }, { 0x59, 0x88 }, { 0x5a, 0x88 }, { 0x5b, 0x44 }, { 0x5c, 0x67 }, { 0x5d, 0x49 }, { 0x5e, 0x0e }, { 0x6c, 0x0a }, { 0x6d, 0x55 }, { 0x6e, 0x11 }, { 0x6f, 0x9f }, // "9e for advance AWB" { 0x6a, 0x40 }, { REG_BLUE, 0x40 }, { REG_RED, 0x60 }, { REG_COM8, COM8_FASTAEC|COM8_AECSTEP|COM8_BFILT|COM8_AGC|COM8_AEC|COM8_AWB },

    // Matrix coefficients { 0x4f, 0x80 }, { 0x50, 0x80 }, { 0x51, 0 }, { 0x52, 0x22 }, { 0x53, 0x5e }, { 0x54, 0x80 }, { 0x58, 0x9e },

    { REG_COM16, COM16_AWBGAIN }, { REG_EDGE, 0 }, { 0x75, 0x05 }, { 0x76, 0xe1 }, { 0x4c, 0 }, { 0x77, 0x01 }, { REG_COM13, 0xc3 }, { 0x4b, 0x09 }, { 0xc9, 0x60 }, { REG_COM16, 0x38 }, { 0x56, 0x40 },

    { 0x34, 0x11 }, { REG_COM11, COM11_EXP|COM11_HZAUTO|COM11_50HZ }, { 0xa4, 0x88 }, { 0x96, 0 }, { 0x97, 0x30 }, { 0x98, 0x20 }, { 0x99, 0x30 }, { 0x9a, 0x84 }, { 0x9b, 0x29 }, { 0x9c, 0x03 }, { 0x9d, 0x4c }, { 0x9e, 0x3f }, { 0x78, 0x04 },

    // Extra-weird stuff. Some sort of multiplexor register { 0x79, 0x01 }, { 0xc8, 0xf0 }, { 0x79, 0x0f }, { 0xc8, 0x00 }, { 0x79, 0x10 }, { 0xc8, 0x7e }, { 0x79, 0x0a }, { 0xc8, 0x80 }, { 0x79, 0x0b }, { 0xc8, 0x01 }, { 0x79, 0x0c }, { 0xc8, 0x0f }, { 0x79, 0x0d }, { 0xc8, 0x20 }, { 0x79, 0x09 }, { 0xc8, 0x80 }, { 0x79, 0x02 }, { 0xc8, 0xc0 }, { 0x79, 0x03 }, { 0xc8, 0x40 }, { 0x79, 0x05 }, { 0xc8, 0x30 }, { 0x79, 0x26 },/* */

    { 0xff, 0xff },};

    static struct regval_list ov7670_fmt_yuv422[] = { { REG_COM7, 0x0 }, /* Selects YUV mode */ { REG_RGB444, 0 }, /* No RGB444 please */ { REG_COM1, 0 }, { REG_COM15, COM15_R00FF }, { REG_COM9, 0x18 }, /* 4x gain ceiling; 0x8 is reserved bit */ { 0x4f, 0x80 }, /* "matrix coefficient 1" */ { 0x50, 0x80 }, /* "matrix coefficient 2" */ { 0x51, 0 }, /* vb */ { 0x52, 0x22 }, /* "matrix coefficient 4" */ { 0x53, 0x5e }, /* "matrix coefficient 5" */ { 0x54, 0x80 }, /* "matrix coefficient 6" */ { REG_COM13, COM13_GAMMA|COM13_UVSAT }, { 0xff, 0xff },};

    My changes are for PCLK speed only...

    Code:

    { REG_CLKRC, 20 }, // OV: clock scale (30 fps) [26 funciona] { REG_DBLV, 0x00 }

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Mr_arduino on June 20, 2013, 08:51:50 pm

    Your problem is writting 0x38 to COM16 that is a very bad idea.It should be 0x08 instead. Here is why that is bad is because it enables edge enhancement andde-noising this sounds good but it actually makes the image worse it makes it blurry and gives it hard edges. Another problem is you left in the 4x gain ceiling.You want 128x. Check out my tweaked structs here https://github.com/ComputerNerd/arduino-camera-tft/blob/master/twicam.c

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: drkblog on June 21, 2013, 06:19:21 pm

    Nice! Now it's much better. I copied your values for YUV422

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Mr_arduino on June 21, 2013, 06:50:40 pm

    It does look better. No more outline on the edges. I noticed the drawing on the music stand changed colors. Is that because it is a different picture or is itbecause of the camera?

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: drkblog on June 21, 2013, 07:08:38 pm

    No, it's the same book. I guess the change in colors has to do with commenting COM13_GAMMA.

    I'm feeding the OV7670 with 16MHz clock from Arduino, but that implies modifying fuse configuration. How are you feeding the XCLK (clock in) of your sensor?

    Here is another take.

  • 3/15/2014 Print Page - ov7670 with both arduino uno and now mega

    http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0 12/60

    Here is another take.

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Mr_arduino on June 21, 2013, 10:21:54 pm

    On the arduino uno version I am feeding it with the CLKOUT from the avr (modified fuse setting). However after I posted this topic I found an easier way to giveit an 8mhz clock using pwm this is half of the 16mhz clock you are getting out right now if you modified your fuse settingsOn the mega vs uno it is slightly different.Here is what I have in my code for the arduino mega with tft screen versionCode:

    DDRL|=8; ASSR &= ~(_BV(EXCLK) | _BV(AS2)); //generate 8mhz clock TCCR5A =67; TCCR5B=17; OCR5A = 0;

    You will have to modify this abit though.Here is what I did for the uno.Code:

    DDRB|=(1

  • 3/15/2014 Print Page - ov7670 with both arduino uno and now mega

    http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0 13/60

    }

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: drkblog on June 22, 2013, 11:40:50 am

    Well. That's pretty much what I'm doing right now. But, with the 16MHz clock. During the initial tests I tried the "software" clock but later I found out the sensordatasheet said the minimum clock had to be 10MHz. Now I see it works with 8MHz too. At that moment I had other problems and blamed the clock. So I went tothe 16MHz again, and I made it work using that clock, in the end.I have to use a divider of at least 20 for the PCLK out put, or else I'm unable to read the image. That makes sense, because I'm using a 16MHz clock, so dividingby 20 in my scheme is like dividing by 10 in your case.

    Right now I left the sensor because I have to go on with another part of my project. With the tests I've made I know I will be able to meet the requirements. All Ineed is to take gray scale images at five FPS, maybe eight FPS but no more, for the space of five seconds. I'll be using the FIFO version and will store the frameson an SD card. I'm going to use the ArduinoMEGA instead of the UNO version. Because I ran out of digital outputs now.

    Most probably I will be back here, within a couple of weeks, as I start testing it again with the ArduinoMEGA and the FIFO version of the sensor. :)

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Mr_arduino on June 22, 2013, 12:37:00 pm

    You can go faster than 20. I got 8 in the old 16mhz version. Also once the fifo version arives you will not have to worry about the XCLK because it has a built inone and you can read at any speed you want. I think your goal of 5-8fps is possible but I do not currently own the fifo version I got another sensor to play withright now the MT9D111 it outputs jpeg data but it does not any fifo versions and I am going to try to get it to work with my raspberry pi anyways as it is muchfaster.

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: drkblog on June 22, 2013, 12:57:50 pm

    I'm trying to stay within the Arduino because I have already solved other requirements with it. And it would be a lot of work migrating other stuff to Raspberry Pi,for example. I want to keep this as simple as possible, also. Raspberry Pi is awesome but it's a complexity level above Arduino, you have a whole operatingsystem there, as far as I know. And that leads to some side effects.So, for this project I'm trying to stay in this platform, even knowing that Raspberry would solve the camera issue with ease. Anyway, I would like to knowwhatever comes out of your testing. You never know when you will have to implement the Plan B. :)

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Mr_arduino on June 22, 2013, 01:30:52 pm

    The problem with the raspberry pi is interrupts the arduino has nothing going other than what the program does. Also the arduino takes less power and does notget hot. For MT9D11 that I am working on I have tried getting it to work but I keep missing pixels. I will have to write a linux driver that way I can disableinterrupts while taking the picture but I still have a whiles away to go before doing that. Also what I meant by my previous post is that I do not have the fifoversion as I already have enough sensors to play with though I am still willing to help with the fifo version. But I think your goal of 5-8fps is possible. Usingsdfatlib you get write to the sd card really fast if you create a contiguous file first then using the writeData() function that saves 512 bytes at a time.

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: drkblog on June 22, 2013, 06:09:11 pm

    Yes. I read the program you wrote, which creates the contiguous block first, the writes down the information. I don't even have to worry about the format, as Iwill have to write the software which is going to read the SD on the PC for downloading information from my device. That will save me some overhead that couldhave if I were to write an AVI or MPEG file.I will post here as soon as I start testing the FIFO version. By the way, where are you from?

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Mr_arduino on June 22, 2013, 07:05:37 pm

    I am from the USA. Why do you ask is it related to my posting abilities? I did just notice a mistake in my previous post that made it not make sense. Alsospeaking of contiguous files actually creating the contiguous file is slow so try creating a big file then re-sizing it.

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: drkblog on June 22, 2013, 07:38:57 pm

    haha no, I just asked out of curiosity. Don't worry I didn't see any non-sense in your posts. And, in the end, It's a forum. We aren't writing a book here :)

    Besides, knowing the place you are from, I have an idea how easy is to access technology for you. For example, here in Argentina it is hard to get somecomponents. I had to buy the RAM 23LC1024 at Mouser in USA and send it to a friend who was vacationing in Boston. So he brought it back here. Otherwise Iwould have paid 100USD shipping for an order of 20 bucks, which is senseless.Fortunately, we have a several big shops here were you can find a lot of stuff. Even some rare pieces. But there is some stuff we have to buy in USA, HongKong, China. Specially for testing purposes.

    Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesomePost by: Mr_arduino on June 22, 2013, 08:06:56 pm

    International shipping can be expensive It is annoying when shipping cost make up a high percentage of the order. Lots of chinese ebay sellers offer free shippingis that you mean by buying from Hong Kong? I do that alot for modules also they have much better deals on zif sockets.

    Title: Re: ov7670 with both arduino uno and now megaPost by: xKoldFuzionx on July 10, 2013, 11:37:14 pm

    I'm new to all this electronics stuff and finally coming to terms with my inner nerd. Lol, I've fallen in love with the idea of creating things that anyone can use . Ibought an ov7670 on ebay a few weeks back and after reading this thread, I'm completely in the dark. So, I was hoping you could shed some light on somethings for me?

    Obviously, you're using C to code all this, but do you know of any tutorials that will help me learn about registers? I get that you call them with hex, though hexand bin math are way over my head, I kinda sorta follow it.

    Im absorbing as much as i can through google/wikipedia as often as i can and picking up any book i can find on arduino and coding it. I understand the basics ofit and it feels very comfortable, so switching over to C right now would be a bit much.

  • 3/15/2014 Print Page - ov7670 with both arduino uno and now mega

    http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0 14/60

    it and it feels very comfortable, so switching over to C right now would be a bit much.

    I've only been doing the whole electronics thing for about a month, so I really don't understand a lot of the components, so bare with me.

    You mentioned early on that you added the ram to speed up the data transfer. How long did it take to write to the SD card without the memory? Breaking it upinto 5 blocks was still faster? How can that be?

    Thanks in advance for the help and patience. So many people I've seen online said it was impossible to use this camera, but then I found one Guy who shared alink, but it was in Russian or something, so I couldn't even read it to find out more. I've seen in this thread and another one that not only have you gotten it towork, you understand how it works. Teach me, oh great and powerful Oz!

    EDIT-- I should add, I understand I can just use your code, but it does me no good if I don't understand why it does what it does. I'm sure it would get me by,

    and I might even plug it all in tomorrow just to see if the thing works, but I'd really like to understand it so I can write my own code. I seem to learn better bydoing.

    Title: Re: ov7670 with both arduino uno and now megaPost by: drkblog on July 11, 2013, 09:35:20 am

    Hello xKoldFuzionx, welcome to the electronics world. :)

    Your questions is a little too broad to cover it up in one reply, so I guess I'm going to start with some basic stuff:

    To really understand what's going on here, you will have to give it a lot of time. And you will have to start from the beginning. This module is really hard to getworking, and is too complex if you don't even know about C. My first recommendation would be that you start experimenting with simpler circuits.

    As you should know by now, Arduino is an experimental board with a microcontroller. Even when the specific microcontroller may vary, as well as its machinecode. The Arduino family share an interface for programming it using C or C++. I haven't seen anyone using another language for Arduino, which doesn't meanthere isn't. But all the stuff I came across is written in C/C++. So, for the sake of simplicity let's say that you program Ardunio in C/C++.

    Here are the terms what I think you should start learning about:

    Ohm law, diode, transistor (as a switch, at least), power dissipationBinary logic (from the logical and electrical point of view)Logical gatesMicrocontroller (or microprocessor, or CPU) and DSPMemoriesParallel interfaceSerial interfaceI2C and SPI interfaces

    And then, you will learn about registers when reading about microcontrollers and memories.

    Title: Re: ov7670 with both arduino uno and now megaPost by: xKoldFuzionx on July 11, 2013, 10:22:56 am

    Sorry for such a broad question. But, greatly appreciate the input.

    I understand ohm's law, the fTransistors e books I started to read drilled it into me, though I don't entirely understand it's use. Let me clarify. I understand theV=IR, I=V/R, R=V/I, but I don't get the power part of it(the Watts).

    I understand simple diodes that block current, but zener diodes confuse me as to how they work.

    Transistors, I get the idea of them, but they confuse me and no text I've read so far seems to simplify it enough.

    By binary logic, you just mean the basic 1 == high, 0 == low? I get that it's like a switch(1 is on, 0 is off), sending a pulse of 5v for high, 0v for low. I was alsojust reading the math of the base 2 system. Is there more behind the logic?

    Logic gates was something I was also just trying to read about, but I felt like it was completely over my head. The problem I have with reading this stuff is Idon't see it in action. I'm a very mechanically inclined person. I can usually look at something, watch it function and figure out how it works.Computers/electronics are hidden, so I use EveryCircuit on my phone a lot to simulate circuits to see how they function. I haven't experimented with that stuffon there yet, but I may start today after seeing some of the stuff I was reading.

    I don't want to buy another camera module as they're all so dang expensive. I was excited to buy this one for less than $4. I'm unemployed right now, so moneyis a big issue. But, I was hoping throwing myself into this would help me learn. I don't expect to get it working overnight, but within a year would be great.

    As for the other stuff to look up, thanks. I'll be reading up on that stuff very soon.

    I guess, I was just really hoping(as I've read so far) that the Arduino language was all I needed to learn, but I guess knowing c/c++ is needed in almost all ofArduino, huh?

    Title: Re: ov7670 with both arduino uno and now megaPost by: drkblog on July 11, 2013, 01:40:06 pm

    In the first place you have to accept that learning electronics isn't easy. Specially if you want to really know what is going on there. A degree in electronicstakes 5 or 6 years, at least in Argentina. Being realistic and pragmatic, you have to accept some things as they are given. You won't be able to see a circuitworking like a mechanical device. You have to learn what components do under certain circumstances and then apply that knowledge. Having that in mind:

    All you mind about power is P = V x I ~~ P [Watt]= V [Volt] x I [Ampere]

    And you have to check that your components have a standard power dissipation. If you place the under certain current and voltage, and that multiplicationresults in more Watts than this component tolerates, you will break it. You can even forget about power dissipation until you start breaking components :)

    You have to learn about the transistor as a switch [http://en.wikipedia.org/wiki/Transistor#Transistor_as_a_switch](http://upload.wikimedia.org/wikipedia/commons/thumb/5/5d/Transistor_as_switch.svg/150px-Transistor_as_switch.svg.png)

    When you make a small current flow through the base, the collector-emitter juncture behaves like a cable (conducting). When the base current disappears, thecollector-emitter is like an open switch (not conducting). You can think of it like a switch controlled by an electrical signal, instead of a human hand. Don't even

  • 3/15/2014 Print Page - ov7670 with both arduino uno and now mega

    http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0 15/60

    try to understand why the transistor do this. At least by now.

    Yes, logic is implemented in circuits using 5V or zero volt. But that's a convention and depends whether you are using TTL or CMOS, you can use a differentvalue, like 3.3V (very common today). And you can't easily mix this kind of signals, if you connect a 5V output to a 3.3V input you will likely damage the device.Unless otherwise stated in the datasheet.

    Logical gates are predecessors to microprocessors, but of course, they are widely used today. Again, you have to learn its behavior as an enclosed unit. Youdon't need to learn how they work inside. If you have an two-input AND gate, you will get a 1 at the output if and only if you have 1 at the two inputs. Apractical use could be: "You have a digital output from arduino and another digital output from a light sensor. You have a 1 from the sensor if there is lightdetected. And you want to turn a LED on and off according to the sensor BUT, you want to turn the LED off from the Arduni at any given time. If you connectthe led to the sensor it will work all the time, and Arduni won't be able to turn the LED off. Then you place a AND gate connecting the sensor and the arduinooutput to its input and the LED to the gate output. Now, if the Arduino output is 1, the LED will turn on and off according to the sensor. But if Arudino's output is0, then the LED will be off no matter if the sensor outputs a 1 or a 0".

    You can connect the module you bought according to the circuits and code from this post. Making it work isn't easy anyway. And you are working with a 3.3Vmodule, so be careful about the outputs from Arduino going into the camera inputs. You could damage the sensor forever. If money is an issue, I wouldrecommend you start playing with cheaper stuff. So you can understand what you are doing. And you start by breaking cheaper things. It's really unusual youstart learning electronics without burning some stuff.

    Do you have an oscilloscope?

    Title: Re: ov7670 with both arduino uno and now megaPost by: xKoldFuzionx on July 11, 2013, 02:50:11 pm

    Ok, I understand that, but with an Arduino, why would I ever need to use a transistor or a gate. Through code, I can program the same actions. For instance:

    Quote

    if ((12 == HIGH) && (10 == HIGH)){ digitalWrite(13, HIGH);}else{ digitalWrite(13, LOW);}

    [/tt]

    Obviously, you would have to program something to trigger 12 or ten to go high, but you get it. In essence, isn't that the whole point of having a Microcontroller? One component does the job of many?

    No, I don't have an oscilloscope. Used one once, but that's the closest I've gotten. I know it would be invaluable, but just can't swing it right now.

    Title: Re: ov7670 with both arduino uno and now megaPost by: drkblog on July 11, 2013, 05:11:32 pm

    First note that a transistor is not a logical gate, and you can't replace one by another because they have different functionality. Of course, you can build alogical gate using one or more transistors and resistors, but stick to the idea that they aren't the same.

    Said that, I placed an example (an excuse) for using a logical gate, it doesn't matter if you can solve it with an Arduino. But if you want to play hard, let's saythat you have all I/O pins used in your arduino and you have only one left for the problem I presented before. Will you buy another Arduino for doing somethingyou can solve with a single logical gate of USD 0.50?

    And for the transistor as a switch, let's say you have to turn a DC motor on and off with an arduino output. You have two motors A and B. Motor A works with5V and uses 150mA, and motor B works with 12V and uses 30mA. You can't connect A to an output because Arduino supports 40mA (maximum) current per IOpin. If you connect motor A you will break the IO or the whole Arduino. You can't connect motor B neither because you have to provide it with 12V and IO pinoutputs 5V. Both cases can be solved using a transistor suited for the work. Transistor have parameters of maximum current also. So you have to check that.

    There is a couple of projects for building a low-budget oscilloscope using an Arduino, you can google that but here is a link: http://code.google.com/p/xoscillo/

    Title: Re: ov7670 with both arduino uno and now megaPost by: xKoldFuzionx on July 11, 2013, 05:41:39 pm

    Ok, that makes complete sense. All the example sketches I've worked through so far have just been really basic as far as components. So, say motor A has atransistor hooked up to it(just so I can get this straight) the 5v pin would connect to the base, 12v supply to the collector and motor's positive wire connectedto the emitter? Then, when high, it electrically flips the switch allowing the 12v through? Then in that case, would you hook up a 12v supply to a regulator thenthe Arduino, and and a lead from +12v to the collector?

    And yeah, I see what you mean with the gate. It makes a lot more sense to use that rather than buy another Arduino just to do the same thing.

    Ok, so one more thing, can you recommend any good beginner's electronics books that are simple but cover everything in a good amount of detail?

    Title: Re: ov7670 with both arduino uno and now megaPost by: drkblog on July 11, 2013, 06:46:12 pm

    You will have to do something like this:

    (http://embedded-lab.com/blog/wp-content/uploads/2010/12/Circuit_SingleTransistorDCMotor.png)

    The base resistor limits the base current when there is 5V on it. The base current will be (Vcc - Vbe) / R, in this case (5V - 0.7V) / 1k = 4.3mA which is enoughfor 100mA current between collector and emitter. How much current you need in the base for a given collector-emitter current, comes out from figute 3 in thisdatasheet: http://pdf.datasheetcatalog.com/datasheet/mcc/548B.pdf

    The diode is a protection which prevents the inverse current generated inside the motor when it's turned on. Such diode is needed when you are switching aninductor/coil on and off (a motor, a relay, etc), to protect the transistor.

    Title: Re: ov7670 with both arduino uno and now megaPost by: sampullman on July 15, 2013, 10:07:27 pm

  • 3/15/2014 Print Page - ov7670 with both arduino uno and now mega

    http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0 16/60

    Hey all,

    I've been using this thread to try and get my OV7670 working, and I seem to have hit a roadblock. Currently, my images mostly look similar to this:http://imgur.com/SoKGYNP

    I'm using this to get my 8Mhz clock down to 3.3v https://www.sparkfun.com/products/8745 (generated on pin 10 using fast pwm).

    I'm setting reg. 0x11 to 0x03, which is giving me a 250khz PCLK, although I have tried other values - 0x01 to 0x09

    I'm using this code to set up the camera for QCIF (176x144) mode with YUYV422 color.Code:

    writeReg(0x15, 32); // PCLK does not toggle on HBLANK COM10 vsync falling

    writeReg(REG_TSLB, 0x04); // 0D = UYVY, 04 = YUYV writeReg(REG_COM13, 0x88); // with REG_TSLB

    writeReg(REG_COM7, 0x08); writeReg(REG_COM17, 0x00); writeReg(REG_COM15, 0xC0); writeReg(REG_COM3, 0x08);

    The full test code for image capture I'm using is here:http://pastebin.com/0tPSt4Kp

    I should note that at the moment I'm attempting to capture the image and send it over serial using only the 2k sram on the arduino (this is just a proof ofconcept until I can get ahold of some external ram). Therefore, I have to break the image up into 36 chunks or so, but I don't see any reason why it shouldn't bepossible - just really slow.

    Any help would be greatly appreciated. I can provide more detail as well if necessary.

    Title: Re: ov7670 with both arduino uno and now megaPost by: drkblog on July 15, 2013, 10:22:28 pm

    In the first place you have to be sure your cam is working. If you have a problem with the clock you are feeding, you will waste a lot of time. In my case, I usedthe 16MHz clock from Arduino and I feed it right into the camera, because at 16MHz you don't have 5V signal. You should check with an oscilloscope to seewhat's the real amplitude of your 8MHz clock. To see if the camera is working you have to check the PCLK output.If you don't have an oscilloscope, I would recommend you check PCLK using a frequency meter. You have to be sure the module is working. After that, capturecovering the camera lens to get a frame of a black image. You should see these chain of bytes: 80 00 80 00 80....

    Title: Re: ov7670 with both arduino uno and now megaPost by: sampullman on July 15, 2013, 11:15:08 pm

    Thanks for the response.I do think the camera is working. I'm able to read and write to registers, and from my oscilloscope it seems like VSYNC is going high at a reasonable rate. I'm alsoable to see the PCLK output, which is 250khz when reg 0x11 is set to 0x03. Here is a picture of the oscilloscope when measuring the PCLK:http://imgur.com/YQhWI8d

    Actually, I just noticed the peak to peak is ~5v, and the min/max are -1.8v/3.6v - is that bad?

    Here is the signal going into the OV7670 XCLK: http://imgur.com/syTEAat

    When I try to capture with the lens covered I get mostly 00 00 00... and sometimes some garbage.

    Out of curiosity, how would I go about getting the 16Mhz arduino clock output? I've never burned a bootloader and I only have a usb connector, can I do it withjust that?

    Title: Re: ov7670 with both arduino uno and now megaPost by: drkblog on July 16, 2013, 08:51:29 am

    Ok, if the module is working, and you are able to read/write registers you are almost done. The next hard-to-do thing is, configuring all the undocumentedregisters. If you fail to do that, you won't get the camera working. You can be sure about that.

    You MUST write all the registers in ov7670_default_regs[] and then those in ov7670_fmt_yuv422[] :

    http://dev.openaos.org/browser/trunk/buildroot/gen7/linux/drivers/media/video/ov7670.c

    Also, start by getting PCLK as low as possible first. As far as I remember I wasn't able to get a good reading with REG_CLKRC under 20 (decimal). But, I'm feeding16MHz clock and you have half this clock, which makes you PCLK half mine when using the same divider in REG_CLKRC. So (I'm totally guessing here), you shouldbe able to make it work with REG_CLKRC set at 10. The reading code has to be as quick as possible and you have to use cli() before start reading. Please postthe portion of code you are using to read from the camera.

    For burning fuses I needed a second Ardunio, with a program called ISP http://arduino.cc/en/Tutorial/ArduinoISP but I wouldn't recommend that approach for thisproject. Using 8MHz clock is simpler and better. Yet, it's the limit for OV7670, you won't be able to make it work with less than that. As the datasheet says theminimum clock should be 10MHz.

    Title: Re: ov7670 with both arduino uno and now megaPost by: Mr_arduino on July 16, 2013, 11:48:30 am

    About the 10mhz limit. I don't think that is true I have left the ov7670 on with an 8mhz clock for hours and nothing bad has happened. Also I have looked atother new sensors from omnivision datasheets to see if I can figure out what the undocumented registers mean and most of the newer datasheets say 6mhz isthe lower limit for the clock. Usually overclocking is more dangerous than under-clocking.Actually I made some corrections to the linux driver registers. Also the code I have on my github page uses divider settings is for people with the 8mhz clock. Ihave posted about the registers on my github page before but I have sense made some changes. Here are the files you need.https://github.com/ComputerNerd/arduino-camera-tft/blob/master/config.h change #define MT9D111 to #define ov7670https://github.com/ComputerNerd/arduino-camera-tft/blob/master/twicam.c update the function void errorD(uint8_t err) for your hardware for example send thestring error over serial instead of displaying it on the lcd screen or you can just remove that function. Also remove the code that hflips the image. That is specificto the tft screen I am using if you are not sending it to the seeedstudio v1 lcd screen you don't want the image hfliped.https://github.com/ComputerNerd/arduino-camera-tft/blob/master/twicam.h can be used as is but must be used if you use twicam.c

  • 3/15/2014 Print Page - ov7670 with both arduino uno and now mega

    http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0 17/60

    https://github.com/ComputerNerd/arduino-camera-tft/blob/master/twicam.h can be used as is but must be used if you use twicam.chttps://github.com/ComputerNerd/arduino-camera-tft/blob/master/captureimage.c Here is an example of how to capture an image there are many differentfunctions for different resolutions. change PINE&32 to where ever your VSYNC pin is also change PINE&16 to where ever the PCLK output is also change the codethat sends the data to the tft screen to were ever you are sending it. Once you have adapted those files to your system you can call the function setRes(); anduse the defines in config.h for example setRes(qvga); sets the resolution to 320x240. When calling initCam() You also have a choice of 3 different registerpresets (0 1 and 2). I would recommend doing initCam(0); that seems to work best. Also you have setColor() I would recommend yuv422 for qvga and qqvga bycalling it with setColor(yuv422);. For vga I would recomend bayer call it with setColor(bayerRGB). rgb565 is very low quality only use it if you are sending to a tftscreen that uses rgb565 data.

    Title: Re: ov7670 with both arduino uno and now megaPost by: sampullman on July 16, 2013, 02:20:25 pm

    @drkblog

    Ok, I'm going to spend some time making sure my register setup is correct. I saw a few tutorials that didn't seem to bother with the defaults (such as thishttp://embeddedprogrammer.blogspot.com/2012/07/hacking-ov7670-camera-module-sccb-cheat.html ), which is why I didn't spend too much time on it before.

    Here is the code I'm using to capture very small chunks from the camera (small enough to fit in arduino SRAM, so ~4 QCIF lines at a time).

    Code:

    void captureChunk(unsigned long wait, unsigned long chunk, uint8_t *pixels) { unsigned int n = 0; while(!(PIND & 8)) {} // Wait for VSYNC high while(PIND & 8) {} // Wait for VSYNC low

    while(wait--) { while(!(PIND & 4)) {}; while(PIND & 4) {}; } while(chunk--) { while(!(PIND & 4)) {}; pixels[n++] = (uint8_t)((PINC & 0x0F) | (PIND & 0xF0)); while(PIND & 4) {}; } //.... write to serial }

    @Mr_arduinoI'll look through that, thanks for the link. Is there any particular reason to use custom twi functions instead of the built in Wire library? I'm able to read and writeregisters using that at the moment. Also, would you happen to have a link for a newer version of the datasheet? I'm using this one right now:http://www.eleparts.co.kr/data/design/product_file/Board/OV7670_CMOS.pdf

    Title: Re: ov7670 with both arduino uno and now megaPost by: Mr_arduino on July 16, 2013, 04:04:59 pm

    ^^^ I made my own twi functions because I am not using the arduion ide. I don't like the arduion ide. Note that I am not forcing you to avoid using the arduinoide. Most likely the code that I posted will work just fine with the arduino ide. Here is a newer version of the datasheethttp://www.haoyuelectronics.com/Attachment/OV7670%20+%20AL422B%28FIFO%29%20Camera%20Module%28V2.0%29/OV7670%20datasheet%28V1.4%29.pdfAlso looking at your code using an unsigned long is bad. The avr is an 8bit processor but it does have some 16bit math support. Try to use the typedefs fromstdint.hfor example uint16_t is a 16bit unsigned variable. In C an int could be either 16bit or 32bit depending on the compiler. int16_t will always be 16bit so that isbetter to use.What I do is have two loops one that reads a line and another that tells how many lines to read.

    Title: Re: ov7670 with both arduino uno and now megaPost by: technonewb on July 17, 2013, 12:09:06 pm

    Hello Mr_arduino, drkblog, and sampullman!

    I am working on a project for one of my university proffesors and I am ran into a problem with the OV7670 camera. I have been trying to read some registers onthe module but without luck. It appears that all three of you are able to use the Wire library but I had no luck with it.

    When I try using the Wire commands, the endTransmission returns 2 meaning the camera could not be addressed properly.Code:

    Wire.beginTransmission(sensor_addr >> 1); Wire.write(0x01 & 0x00FF); Serial.println(Wire.endTransmission());

    Also, the following code (which sampullman provided) returns the address of the register instead of the actual value stored inside the register:Code:

    #include

    uint8_t sensor_addr = 0x42;

    void setup(){ Wire.begin(); Serial.begin(115200);}

    void loop(){ uint8_t* dat; readReg8(0x01, dat); Serial.println(*dat); delay(1000);}

    /* Write 2 byte value regDat to the camera register addressed by regID */byte writeReg(int regID, int regDat) { Wire.beginTransmission(sensor_addr >> 1); Wire.write(regID & 0x00FF); Wire.write(regDat & 0x00FF); byte result = Wire.endTransmission(); delay(1); return result;} /* Read a 2 byte value from the camera addressed at regID, and store it at * memory location pointed to by regDat. Return 1 on success, 0 on failure. */byte readReg8(uint8_t regID, uint8_t* regDat) { Wire.beginTransmission(sensor_addr >> 1); Wire.write(regID & 0x00FF);

  • 3/15/2014 Print Page - ov7670 with both arduino uno and now mega

    http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0 18/60

    Wire.endTransmission(); Wire.requestFrom((sensor_addr >> 1),1); if(Wire.available()) { *regDat = Wire.read(); delay(1); return 1; } else { return 0; }}

    Could you please give me a hand?

    Title: Re: ov7670 with both arduino uno and now megaPost by: Mr_arduino on July 17, 2013, 12:49:30 pm

    Actully my latest code does not use the wire library see https://github.com/ComputerNerd/arduino-camera-tft/blob/master/twicam.c or if you feel the need touse the Wire library my very old code uses it see http://pastebin.com/1nnRc5qLAlso the ov7670 is picky about which pullup resitors you use. I found that 4.7k and 10k work but 1k and 2.2k do NOT work. And make sure that you are using thepullup resistor to 3.3v and if you use the Wire library you must edit twi.c which is located in (arduino ide folder)/libraries/Wire/UtilityAnd remove these lines:Code:

    // activate internal pullups for twi. digitalWrite(SDA, 1); digitalWrite(SCL, 1);

    By not doing that you could damage the ov7670 although when I first got the ov7670 I made the mistake of not removing those lines and nothing happenedhowever your millage may vary. After removing those lines be sure to recompile your program.

    Title: Re: ov7670 with both arduino uno and now megaPost by: giantsfan3 on July 18, 2013, 09:40:08 am

    @Mr_Arduino, Terrific effort by you on this code, as well as answering people's questions! I see you are also adding support for the MT9D111. I'm definitely goingto try the Omnivision module with this code.

    Here is a suggestion: Perhaps you could take a few minutes and turn this into a standard structured Arduino-importable library (along with an example usagesketch of .INO filetype).Along with that, you could make a few lines of tutorial out of your build including the hardware connections, and put it on the first post of the thread, so thatothers can reproduce your setup (there will also be fewer code-troubleshooting questions that way).

    Also, here's a cool video by someone in Japan who made a TFT-camera out of it (this is where I first learned about the OV7670):Not sure how they got this kind of almost real-time video from it using just the Atmega:http://www.youtube.com/watch?v=RYh1389IEng

    Quote from: Mr_arduino on July 17, 2013, 12:49:30 pm

    Actully my latest code does not use the wire library see https://github.com/ComputerNerd/arduino-camera-tft/blob/master/twicam.c or if you feel the need to use the Wire library my very oldcode uses it see http://pastebin.com/1nnRc5qL

    Title: Re: ov7670 with both arduino uno and now megaPost by: Mr_arduino on July 18, 2013, 04:06:00 pm

    ^^^ About creating an *.ino file Everyone has different needs I like to keep my files organized so that if someone has trouble with something for examplecommunicating with the camera I can point them to the right file and they don't have to look through lots of code to find what they need. I try to keep thefilename related to what the functions in it do see https://github.com/ComputerNerd/arduino-camera-tft Also I don't use the arduino ide anymore. I have deletedit a long time ago and never looked back(I know I can always re-download it but I don't ever want to use it again) My code should just be copy pastable into thearduino ide. It is just standard C. I do have older code that does use the arduino ide you can find that on the first page. I think I did already explain the hardwareconnections in the first few posts or do you mean make a video? Also what that person from Japan did was have the arduino configure the ov7670 but instead ofplugging the video signals into the arduino they plugged it into the tft screen. What I had to do for my tft project was read the data with the arduino and send itto the tft screen or send it external ram. Speaking of which I now recommend the fifo version version over the non-fifo version. I would have done it with my tftscreen but it needs to be configured with the arduino uno as well. The tft they have just needs to be powered on and it starts working. A disadvantage ofdirectly plugging in the ov7670 into the tft screen is that you can't have a menu that allows you to configure the camera. My program includes a menu toconfigure the ov7670.

    Title: Re: ov7670 with both arduino uno and now megaPost by: sampullman on July 18, 2013, 05:23:34 pm

    @technonewb

    I'm not sure if you posted all of your code, but you need to add something like this after the Wire.begin() call in order to set up TWI communication so that itworks with the OV7670:Code:

    TWSR &= ~3; // Disable TWI prescaler TWBR = 72; // CLOCK / (16 + 2*TWBR*Prescaler)

    This should set up the wire library to transmit at ~100Khz.

    Other than that, it's important to follow Mr_arduino's advice for disabling the internal pull up resistors for twi. You need to add your own (4.7Kohm or 10k shouldwork like he said) to pull up to 3.3v instead of 5v.

    I still haven't pulled a reasonable image off the module, but hopefully with some external spi ram coming in today and switching from QCIF to QQVGA I'll havebetter luck.

    Title: Re: ov7670 with both arduino uno and now megaPost by: Mr_arduino on July 18, 2013, 08:12:35 pm

    I have the same values here that sampullman posted. https://github.com/ComputerNerd/arduino-camera-tft/blob/master/main.cAlso if you are using my register read and write code you don't want to use Wire.begin() if you are using the wire library you don't need to use the code thatsampullman posted (I think).

    Title: Re: ov7670 with both arduino uno and now mega

  • 3/15/2014 Print Page - ov7670 with both arduino uno and now mega

    http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0 19/60

    Title: Re: ov7670 with both arduino uno and now megaPost by: Mr_arduino on July 24, 2013, 06:23:54 pm

    I am sorry for the double post but I would like add that if you have a question about the ov7670 please don't PM me post it in this topic instead that wayeveryone will benefit.

    Title: Re: ov7670 with both arduino uno and now megaPost by: vichaz on August 09, 2013, 03:14:43 pm

    Hi guys!

    I'm new in Arduino and electronics but with 10 years of PHP programing experience. Not long ago I bought Arduino UNO with different modules and started to playwith it as a hobby.

    Unfortunately, I bought OV7670 camera without FIFO and now try to get an image to SD card. Furthermore, my camera module has only 8*2 pins (I think withoutRESET and PWDN pins. Also there are no marks of pins so I'm not sure from where I have to start counting pins.)Here is my cam - http://dx.com/p/ov7670-30fps-vga-camera-module-for-arduino-blue-147415

    It was not easy to find this thread in order to get s