Ov7670 With Both Arduino Uno and Now Mega

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 96

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Arduino Forum
Using Arduino => Sensors => Topic started by: Mr_arduino on Apr 10, 2013, 04:50 am

Title: ov7670 with both arduino uno and now mega


Post by: Mr_arduino on Apr 10, 2013, 04:50 am
Have you been told by someone that you an external ram of some sort such as a fifo or spi ram. I admit to thinking that was needed and telling people they need one or the other (fifo being the better option) but
if you just want to send data from the camera to your PC using the arduino you don't need external ram.
Check out this https://github.com/ComputerNerd/ov7670-no-ram-arduino-uno
It requires only the ov7670 without fifo and a way to get 5v to 3.3v no other parts such as spi ram or al422.
Edit: As of 2014-07-05 I have decided to try and improve this initial post. I would like to hear your feedback. I want to try and avoid redundant questions and I think a better writeup in the initial post would be
beneficial. Tell me what you think about this post.
When creating this post on the 2013-04-09 I would have never imagined that there would be so much interest in the ov7670.
I am happy that I have enabled so many people to explore the world of image processing introducing people to a valuable and fun concept.

What is the ov7670?

Although I think most people who click on this thread know what the ov7670 is, I think it is still good to have an explanation for the people curious about what all the commotion is.
The ov7670 is an image sensor manufactured by Omnivision.
This image sensor is quite old by image sensor standards. According to Omnivision (http://www.ovt.com/uploads/newsreleases/english/OV7670
%20%20OV9655%20in%20Mass%20Production_release%20FINAL.pdf) they started mass production of the sensor in February of 2006.
The image sensor has a resolution of 640x480 and is an Soc meaning it has built in image processing capabilities.

Why the ov7670?

I am quite surprised that out of all the sensors available this one has the most success.
I like to play with image sensors of all types not just the ov7670 however the ov7670 seems to spark the most interest in people.
I bought the module because at the time it was (and still is) the lowest cost camera module that you can buy.
The quality you can get from it would be be described as just okay. There are nicer modules you can buy for not much more money if you are looking for quality.

What can I do with the ov7670?

The reality is you are limited not only by the sensor but by the processor you are using.
This thread focuses primarily on arduino boards and interfacing the ov7670 to microcontrollers featured on an arduino board. The arduinos that I have used are both based on 8bit AVRs running at 16mhz so that
is quite the limitation. I do however welcome discussion of any microcontroller. Do not expect something ridiculous like 30fps 640x480 on the arduino uno.
The original reason that I wanted to use the ov7670 was time lapse purposes.
I could live with the slow speed as all I need was an image every few seconds. However using a faster microcontroller can mean reading pixels faster but remember unoptimized code on a fast microcontroller
can be slower than well optimized code on a slower device.
So with all that said: What can I actually do with this sensor? The answer is pretty much anything that does not involve subjecting the sensor to unreasonable conditions or expecting something unreasonable
from it like 1000fps full resolution. What attracts me to the idea of a camera module vs just buying a webcam is the fact that I have more control over it. You are able to program it to do various tasks that suite
your needs and lots of the automatic stuff on the ov7670 can be overridden if needed.

How can I get started?

Read the documentation and check out code that I have written. Also check the code to figure out some aspects of wiring. I have already explained many aspects of wiring. Just read the thread.

Where can I get documentation?

http://www.electronicaestudio.com/docs/sht001.pdf
https://github.com/dalmirdasilva/ArduinoCamera/blob/master/CameraAL422B/datasheet/OV7670%20Implementation%20Guide%20%28V1.0%29.pdf
https://github.com/luckasfb/Development_Documents/blob/master/MTK-Mediatek-Alps-Documents/OV7670%20software%20application%20note.pdf
I however would like to expand this list. If you have ANYTHING from Omnivsion that would help me understand undocumented stuff in regards to the ov7670 I will take it. If you cannot or do not want it to be
posted on the internet I will respect that wish fully. I will take anything regarding the ov7670 even a newer version of what I have already. In fact I would take unrelated documentation that comes from Omnivsion.
It is nice to have. You never know seemly unrelated documentation might prove to be relevant in non direct ways.

Where do you keep up to date code

Here https://github.com/ComputerNerd/ov7670-simple/ and here https://github.com/ComputerNerd/arduino-camera-tft also if you don't have any other parts besides the ov7670 check out https://github.com
/ComputerNerd/ov7670-no-ram-arduino-uno it also contains how to enable pwm to get 8mhz.
I also made a data convert that allows you to convert raw data from the camera into a png file
https://github.com/ComputerNerd/RawCamera-data-converter
For windows users who don't want to bother setting up MinGW here is a windows binary.
https://github.com/ComputerNerd/RawCamera-data-converter/blob/master/convert.exe.7z
I also posted some pastebin links that is old code but it covers some stuff that the code above does not

How I can I help the author?

Responding to you all guys does not happen magically. There are some things you can do to help ensure that I will continue to help you.
1. Give back: Know something that I don't know regarding the ov7670? Post it.
2. Avoid asking repeat questions.
3. Write stuff. Maybe you can explain something better than I can. If that is the case please do such. I am always open to suggestions on how I can improving my writing.
The initial post below the line break is the second revision of my initial post. I had to move the first revision down a post to work around a character limit.
Edit: I now recommend the fifo version over the non-fifo version. However if you have the regular version without the fifo you can still get an image using external spi ram.
If you have the fifo version lots of this is still relevant all except the external ram part and reading pixels.
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 however to do such you must use raw bayer data.
Also I have since figured out how to generate an 8mhz clock using PWM
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 clock speed the fastest it goes is F_CPU/2 which results in 8mhz in the case of the arduino. However it is best to set it as max speed and use the divider that the ov7670 has.
Also a good way to keep filesize down thus improving transfer speed is to use raw bayer data.
Raw bayer appears to be about the same or better quality as yuv422 but takes half the speed thus doubling transfer speed.
I would recommend you use it instead of yuv422 I have posted new versions that use raw bayer data.
Here is an FAQ of some questions that may come up:
Q: Some arduino outputs a 5v clock but the OV7670 will only accept 3.3v what should I do
A: 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 XCLK?
A: No

1 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Q: Will I need to buffer any other pins besides the XCLK?


A: 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 ov7670
Also 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-tft
More specifically here is some stat-up registers here https://github.com/ComputerNerd/arduino-camera-tft/blob/master/ov7670_regs.h
And here are some useful functions here https://github.com/ComputerNerd/arduino-camera-tft/blob/master/twicam.c also don't forget the header file https://github.com/ComputerNerd/arduino-camera-tft/blob
/master/twicam.h
And 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.h
Q: 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 below or my github page ov7670-simple (link below)
Q: The code you posted (above) is complex give me something more simple
A: For a while I had this code available I just thought I would make it more obvious that it exists. https://github.com/ComputerNerd/ov7670-simple
Q: The FAQ does not answer my question what should I do
A: 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 same question that you do later on.
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: nonzung on Apr 11, 2013, 07:21 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) = awesome
Post by: Mr_arduino on Apr 12, 2013, 01:30 am
Edit I had to move down the first revision of my inital post to here to work ardound a character limition below that I explained how I conntect the ov7670 to the arduino uno.
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 it would 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 additionally it 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 in this 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 of the 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 output both rgb565 or yuv422 I found that
yuv422 is better quality so I made a converter for that and you can get the source code here https://github.com/ComputerNerd/RawCamera-data-converter. Here is code for the capture program.
http://pastebin.com/1nnRc5qL I used sdfatlib to write and based 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 stop the capture hold down the button and wait for the led to blink very fast make sure that the button sinks the pin to ground. If you do not define useLed then it uses 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 registers online 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 it gives the name but the description is blank. If someone could explain with a reply or PM what these:
Code: [Select]
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 will have 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 to work. 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 the ov7670.
(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
Below here lies my response (the original aspect of the post).
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 you have 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 remove them
Code: [Select]
// 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 d4 to 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 exactly the same except enable 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 the sensor. The sd card and spi ram is just standard spi wiring nothing special.
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: nonzung on Apr 12, 2013, 07:10 am
Thanks for the answer, I will try. :) :)
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: Mr_arduino on Apr 12, 2013, 10:06 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) = awesome
Post by: michinyon on Apr 13, 2013, 07:57 am
Could you post a photo of your device sometime ? I got one of these and the connections were so tiny that
I could not see then with a magnifying glass and certainly not actually connect anything to them.
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: Saren on Apr 14, 2013, 12:20 am
Hi,
I'm working on a project at university about computer vision and Arduino.

2 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

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. are unfortunately 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 with FIFO...).
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 really don'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 the capture program?
Any help is appreciated.
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: Mr_arduino on Apr 14, 2013, 03:03 am
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 am busy 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 do however 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.c
main.c:
http://pastebin.com/dF3pc23T
I 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 not I posted it to paste bin before realising this.
ov7670.h
http://pastebin.com/CqYTwNqn
ov7670.c
http://pastebin.com/T1nN5Ni4
Here is the frame grabber source code
http://pastebin.com/dxMJhZTq
This 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 development library from http://www.libsdl.org/download1.2.php
Also I made an update to my program that captures an image to the sd card it nows saves raw bayer data.
http://pastebin.com/zV0ahzPv
The 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 work
It will also convert yuv422 to rgb (the old image to sd card program saved data in that format)
Code: [Select]
//to compile type gcc -Wall -Wextra -lm -lpng -o yuv main.c
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <png.h>
#include <zlib.h>
#include <sys/stat.h>
#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);
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 before other 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<height;y++)
//
row_pointers[y]=&dat[(y*width*3)];//the rows are contiguous
png_set_user_limits(png_ptr, width, height);
png_write_info(png_ptr, info_ptr);
//puts("saving data 2");
//png_write_image(png_ptr, row_pointers);
for (y=0;y<height;y++)
png_write_row(png_ptr, &dat[(y*width*3)]);
//png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
png_write_end(png_ptr, info_ptr);
png_destroy_write_struct(&png_ptr, &info_ptr);
//free(row_pointers);
fclose(fp);//done with file
return 0;//will return 0 on success non-zero in error
}
void yuv2rgb(uint8_t * yuvDat,uint8_t * out)
{
uint64_t xy;
for (xy=0;xy<(img_w/2)*img_h;xy++)
{
*out++=YUV2R(yuvDat[0],yuvDat[1],yuvDat[3]);
*out++=YUV2G(yuvDat[0],yuvDat[1],yuvDat[3]);
*out++=YUV2B(yuvDat[0],yuvDat[1],yuvDat[3]);
*out++=YUV2R(yuvDat[2],yuvDat[1],yuvDat[3]);
*out++=YUV2G(yuvDat[2],yuvDat[1],yuvDat[3]);
*out++=YUV2B(yuvDat[2],yuvDat[1],yuvDat[3]);
yuvDat+=4;
}
}
void deBayerN(uint8_t * in,uint8_t * out)
{

3 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

uint32_t x,y;
for (y=0;y<img_h;y+=2)
{
for (x=0;x<img_w;x+=2)
{
//this will do a 2x2 pixel rectangle
/*R G
G B*/
out[(x*3)]=in[x];//copy red
out[(x*3)+1]=in[x+1];//green
out[(x*3)+2]=in[x+1+img_w];//blue
out[(x*3)+3]=in[x];//red
out[(x*3)+4]=in[x+1];//green
out[(x*3)+5]=in[x+1+img_w];//blue
out[((x+img_w)*3)]=in[x];//red
out[((x+img_w)*3)+1]=in[x+img_w];//green
out[((x+img_w)*3)+2]=in[x+1+img_w];//blue
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;
}
}
void deBayerL (uint8_t * in,uint8_t * out)
{//this is an implementation of http://www.ipol.im/pub/art/2011/g_mhcd/
uint32_t x,y;
for (y=0;y<img_h;y+=2)
{
for (x=0;x<img_w;x+=2)
{
//this will do a 2x2 pixel rectangle
/* B Gb
Gr R
*/
/*R G THIS IS WRONG BUT STANDARD The rows are reversed on omnivision sensors keep this in mind later just get alg working for now
G B*/
//if (x>=2 && x<=img_w-2 && y>=2 && y<=img_h-2)//see if we are able to grab pixels from neighboors
//{
//printf("X %d Y %d x-img_w %d\n",x,y,x-img_w);
out[x*3]=in[x];//red just needs to be copied
//out[(x*3)+1]=((in[x]*4)+(in[x-1]*2)+(in[x+1]*2)+(*(in+x-img_w)*2)+(in[x+img_w]*2)-(in[x-2])-(in[x+2])-(*(in+x-img_w_2))-in[x+img_w_2])/8;//green at red locations
//out[(x*3)+2]=((in[x]*6)+(*(in+x-1-img_w)*2)+(*(in+x+1-img_w)*2)+(*(in+x-1+img_w)*2)+(in[x+1+img_w]*2)-(in[x-2]/3*2)-(in[x+2]/3*2)-(*(in+x-img_w_2)/3*2)-(in[x+img_w_2]/3*2))/8;//Blue at red
//out[(x*3)+4]=
out[(x*3)+4]=in[x+1];//copy green
out[((img_w+x)*3)+1]=in[x+img_w];//copy green
out[((img_w+x)*3)+5]=in[x+img_w+1];//copy blue
/*}
else//we are on the edge defualt to edge safe algorthim
{
out[(x*3)]=in[x];//copy red
out[(x*3)+1]=in[x+1];//green
out[(x*3)+2]=in[x+1+img_w];//blue
out[(x*3)+3]=in[x];//red
out[(x*3)+4]=in[x+1];//green
out[(x*3)+5]=in[x+1+img_w];//blue
out[((x+img_w)*3)]=in[x];//red
out[((x+img_w)*3)+1]=in[x+img_w];//green
out[((x+img_w)*3)+2]=in[x+1+img_w];//blue
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;arg<argc;arg++)
{
if (strcmp(argv[arg],"-n") == 0)
{
arg++;
useImg=atoi(argv[arg]);
useNum=1;

4 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

continue;
}
if (strcmp(argv[arg],"-o") == 0)
{
arg++;
offset=atoi(argv[arg]);
if (offset>img_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) = awesome


Post by: nonzung on Apr 16, 2013, 07:49 am
I forget that. I bought the camera ov7670 fifo.
Sorry and thank you so much.
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: Mr_arduino on Apr 16, 2013, 11:53 pm
Quote from: nonzung on Apr 16, 2013, 07:49 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) = awesome
Post by: Saren on Apr 23, 2013, 07:01 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) = awesome
Post by: Mr_arduino on Apr 26, 2013, 10:32 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 you strobe 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 you could 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.
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: Mr_arduino on Apr 27, 2013, 04:28 pm
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 that this 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: [Select]
DDRL|=8;
ASSR &= ~(_BV(EXCLK) | _BV(AS2));
//generate 8mhz clock
TCCR5A =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) = awesome
Post by: emueyes on Apr 28, 2013, 02:24 am
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) = awesome
Post by: Mr_arduino on Apr 28, 2013, 08:18 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 voltage which the

5 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

74HC245 can. You do not need to shift the d7-d0 as those are always output from the sensor and never input. 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 have them to 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 if you 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 little purpose.
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: emueyes on Apr 29, 2013, 09:42 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) = awesome
Post by: Saren on Apr 30, 2013, 08:54 pm
Quote from: Mr_arduino on Apr 26, 2013, 10:32 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 you strobe 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 you could 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) = awesome
Post by: Mr_arduino on May 01, 2013, 02:39 am
Quote from: Saren on Apr 30, 2013, 08:54 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 so it 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) = awesome
Post by: sherry254 on May 11, 2013, 02:30 pm
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 i connect 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.
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: Mr_arduino on May 11, 2013, 03:43 pm
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. Even if 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 you would 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 would wear 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 have to 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 or make 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 at digi-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) = awesome
Post by: sherry254 on May 11, 2013, 05:28 pm
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. the datasheet 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.pdf
this is its schematic ftp://imall.iteadstudio.com/Shield/IM121026002/SCH_IM121026002_3G_Shield.pdf
Could i connect the camera to the shield instead of using the arduino directly?
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: hlankoande on May 12, 2013, 12:10 am
Hello Mr_arduino
I 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 send it other serial) written with arduino IDE.
Thanks lot in advance.
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: isaiful on May 17, 2013, 05:36 am
hye...i wanna ask if this camera is same with JPEG TTL CMOS camera???
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: Mr_arduino on May 18, 2013, 12:59 am
@hlankoande
I made some code for the arduino mega awhile ago check it out it uses the arduino ide
http://www.youtube.com/watch?v=sEsZeDC6co0
@isaiful
It 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) = awesome
Post by: rebelion on May 22, 2013, 12:20 pm
Hello

6 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

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) = awesome
Post by: drkblog on May 24, 2013, 01:27 pm
Quote from: Mr_arduino on Apr 28, 2013, 08:18 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 voltage which 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 have them 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 be used 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) = awesome
Post by: Mr_arduino on May 25, 2013, 06:24 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 that you have the pull-up resistor to 3.3v.
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: drkblog on May 26, 2013, 03:44 pm
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 thing I 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)?

Thank you again!


Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: Mr_arduino on May 29, 2013, 02:07 am
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 verify that 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 you get 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 unwanted dummy 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 may be too fast to see I can not remember off the top of my head.
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: drkblog on Jun 01, 2013, 01:21 am
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 the sensor. 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) = awesome
Post by: Mr_arduino on Jun 01, 2013, 04:48 pm
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 wait awhile and increment again in a loop and see if
the OUTPUT PCLK changes on an oscilopsoce. Also you MUST have this register
Code: [Select]
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) = awesome
Post by: drkblog on Jun 16, 2013, 05:47 pm
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 possible now. 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 in base64 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: [Select]
$ ./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) = awesome
Post by: Mr_arduino on Jun 17, 2013, 04:51 pm

7 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

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.c
To compile it simply type
Code: [Select]
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 may pictures 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 have F0.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 so in 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 I fixed 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) = awesome
Post by: drkblog on Jun 18, 2013, 12:40 am
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 is wrong. Because I can't manage to change the
output.
What I'm doing now:
Code: [Select]
// 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 some 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 I change from bar pattern to the image, I start getting
zeroes again. :/
Thank you very much!

Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome


Post by: drkblog on Jun 18, 2013, 01:49 am
Here is a picture taken in three stages of 640x100 pixels:

Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome


Post by: Mr_arduino on Jun 18, 2013, 03:05 am
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. Yuv is 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.4 that may help abit http://www.haoyuelectronics.com/Attachment
/OV7670%20+%20AL422B%28FIFO%29%20Camera%20Module%28V2.0%29/OV7670%20datasheet%28V1.4%29.pdf
If you noticed in the changelog of the 1.4 from 1.3 they changed the TSLB and COM13 documentation.
Code: [Select]
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) = awesome


Post by: drkblog on Jun 18, 2013, 03:39 am
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) = awesome
Post by: Mr_arduino on Jun 18, 2013, 04:04 am
Also did you look at the linux driver it has a complete register configuration which has parts based on official registers provided by omnivison http://dev.openaos.org/browser/trunk/buildroot/gen7/linux/drivers
/media/video/ov7670.c
Also 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 conversion try passing the argument '-c y' without the quotes.
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: drkblog on Jun 18, 2013, 02:33 pm
I'm going to check that link with the registers.

8 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

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 to configure 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 takes half 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) = awesome
Post by: Mr_arduino on Jun 18, 2013, 03:06 pm
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 some advantages 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 the linux driver registers copy paste the entire large struct
before the large struct add
Code: [Select]
struct regval_list {
uint8_t reg_num;
uint8_t value;
};

After that replace


Code: [Select]
static struct regval_list ov7670_default_regs[] = {

with
Code: [Select]
const struct regval_list ov7670_default_regs[] PROGMEM = {

Also make sure you #include <avr/pgmspace.h>


and use this function to write the registers
Code: [Select]
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++;
}
}

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 for
Code: [Select]
static struct regval_list ov7670_fmt_yuv422[] = {

And adapt it to your code


Also if you want change
Code: [Select]
{ REG_COM9, 0x18 }, /* 4x gain ceiling; 0x8 is reserved bit */

to
Code: [Select]
{ 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) = awesome
Post by: drkblog on Jun 20, 2013, 01:31 am
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 with my 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 it takes 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 the circuit and some waveforms. And there is a link to the application note in english too: http://blog.drk.com.ar/2013/interfaz-logica-bidireccional-entre5v-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 FIFO version 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) = awesome


Post by: Mr_arduino on Jun 20, 2013, 02:59 am
Sorry I forgot to mention that it changes CLCK speed. I have uploaded the registers I use here
https://github.com/ComputerNerd/arduino-camera-tft/blob/master/twicam.c
They 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 that when 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 bayer data. You can use setColor() to pick what you want. SetRes() sets what resolution you want.
SetRes() changes the clock divider speed (register 0x11). You may 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.h
or you could just add
Code: [Select]
#define vga 0
#define qvga 1
#define qqvga 2

9 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

#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) = awesome
Post by: drkblog on Jun 20, 2013, 04:21 am
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 with the 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. Maybe I'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) = awesome
Post by: drkblog on Jun 20, 2013, 04:33 am
Update. I was missing a fix, in the reading logic... yet it isn't done...
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: drkblog on Jun 20, 2013, 04:45 am
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) = awesome
Post by: Mr_arduino on Jun 20, 2013, 04:47 am
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) = awesome
Post by: drkblog on Jun 20, 2013, 04:53 am
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 to configure the sensor. So it's great. Thank you again!
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: Mr_arduino on Jun 20, 2013, 04:56 am
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) = awesome
Post by: drkblog on Jun 20, 2013, 05:01 am
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) = awesome
Post by: Mr_arduino on Jun 20, 2013, 04:00 pm
Hint to disable digital gain change register 0x74 to 0x10
I just edited the struct https://github.com/ComputerNerd/arduino-camera-tft/commit/7809cb37eb072d6325f33b6491284c6615a13bff
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: drkblog on Jun 20, 2013, 05:16 pm
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) = awesome
Post by: Mr_arduino on Jun 20, 2013, 11:07 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 you change some registers or something?
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: drkblog on Jun 21, 2013, 01:48 am
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: [Select]
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...

10 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...


//
{ REG_HSTART, 0x13 },
{ REG_HREF, 0xb6 },
{ REG_VSTOP, 0x7a },

http://forum.arduino.cc/index.php?action=printpa...

{ REG_HSTOP, 0x01 },
{ REG_VSTART, 0x02 },
{ 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,
0x7c,
0x7e,
0x80,
0x82,
0x84,
0x86,
0x88,

0x20
0x1e
0x5a
0x76
0x88
0x96
0xaf
0xd7

},
},
},
},
},
},
},
},

{
{
{
{
{
{
{
{

0x7b,
0x7d,
0x7f,
0x81,
0x83,
0x85,
0x87,
0x89,

0x10
0x35
0x69
0x80
0x8f
0xa3
0xc4
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 },
// 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 },
{ 0x51, 0 },
{ 0x53, 0x5e },
{ 0x58, 0x9e },

{ 0x50, 0x80 },
{ 0x52, 0x22 },
{ 0x54, 0x80 },

{
{
{
{
{
{

REG_COM16,
0x75, 0x05
0x4c, 0 },
REG_COM13,
0xc9, 0x60
0x56, 0x40

COM16_AWBGAIN },
{ REG_EDGE, 0 },
},
{ 0x76, 0xe1 },
{ 0x77, 0x01 },
0xc3 },
{ 0x4b, 0x09 },
},
{ REG_COM16, 0x38 },
},

{
{
{
{
{
{
{

0x34,
0xa4,
0x97,
0x99,
0x9b,
0x9d,
0x78,

},
},
},
},
},
},
},

0x11
0x88
0x30
0x30
0x29
0x4c
0x04

// Extra-weird stuff.
{ 0x79, 0x01 },
{ 0x79, 0x0f },
{ 0x79, 0x10 },
{ 0x79, 0x0a },
{ 0x79, 0x0b },
{ 0x79, 0x0c },
{ 0x79, 0x0d },
{ 0x79, 0x09 },
{ 0x79, 0x02 },
{ 0x79, 0x03 },
{ 0x79, 0x05 },
{ 0x79, 0x26 },

{
{
{
{
{
{

REG_COM11,
0x96, 0 },
0x98, 0x20
0x9a, 0x84
0x9c, 0x03
0x9e, 0x3f

COM11_EXP|COM11_HZAUTO|COM11_50HZ },
},
},
},
},

Some sort of multiplexor register


{ 0xc8, 0xf0 },
{ 0xc8, 0x00 },
{ 0xc8, 0x7e },
{ 0xc8, 0x80 },
{ 0xc8, 0x01 },
{ 0xc8, 0x0f },
{ 0xc8, 0x20 },
{ 0xc8, 0x80 },
{ 0xc8, 0xc0 },
{ 0xc8, 0x40 },
{ 0xc8, 0x30 },

/*
*/
{ 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
{ 0x4f, 0x80 },
/* "matrix coefficient
{ 0x50, 0x80 },
/* "matrix coefficient
{ 0x51, 0
},
/* vb */
{ 0x52, 0x22 },
/* "matrix coefficient
{ 0x53, 0x5e },
/* "matrix coefficient
{ 0x54, 0x80 },
/* "matrix coefficient
{ REG_COM13, COM13_GAMMA|COM13_UVSAT },
{ 0xff, 0xff },
};

reserved bit */
1" */
2" */
4" */
5" */
6" */

My changes are for PCLK speed only...


Code: [Select]

11 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

{ REG_CLKRC, 20 },
{ REG_DBLV, 0x00 }

http://forum.arduino.cc/index.php?action=printpa...

// OV: clock scale (30 fps) [26 funciona]

Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome


Post by: Mr_arduino on Jun 21, 2013, 02:51 am
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 and de-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/arduinocamera-tft/blob/master/twicam.c
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: drkblog on Jun 22, 2013, 12:19 am
Nice! Now it's much better. I copied your values for YUV422
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: Mr_arduino on Jun 22, 2013, 12:50 am
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 it because of the camera?
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: drkblog on Jun 22, 2013, 01:08 am
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.
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: Mr_arduino on Jun 22, 2013, 04:21 am
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 give it an 8mhz clock using pwm this is half of the
16mhz clock you are getting out right now if you modified your fuse settings
On the mega vs uno it is slightly different.
Here is what I have in my code for the arduino mega with tft screen version
Code: [Select]
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: [Select]
DDRB|=(1<<3);//pin 11
ASSR &= ~(_BV(EXCLK) | _BV(AS2));
TCCR2A=(1<<COM2A0)|(1<<WGM21)|(1<<WGM20);//this also results in 67 but I wanted to clean up magic numbers
TCCR2B=(1<<WGM22)|(1<<CS20);
OCR2A=0;

Sorry I do not have time right now to test the arduino uno values.
Also what color should the guy on the book be? Edit never mind found it on google images. I wonder why enabling gamma correction makes the image so much worse. I have encountered the same thing too.
That is why I disabled gamma correction. I personally think that it is best to disable as many in camera effects as possible and instead do stuff similar to what the sensor does but better in post production. Lot of
times the sensor's de-noising algorithm is not as good as what you may find on the computer.
Edit2: Also when you asked about XCLK did you mean that you were interested in reading pixels faster if so here is some faster code that may help you. This code is from my original arduino uno + spi ram
setup. I think this will be most relevant to you.
Code: [Select]
inline void spiCSt(void)//selects the RAM chip and resets it
{
//toggles spi CS used for reseting sram
PORTB|=4;//cs high
PORTB&=~4;//cs low
}
inline void spiWrB(uint8_t dat)
{
SPDR = dat;
// Wait for transmission complete
while(!(SPSR & (1<<SPIF))) {}
}
void captureImg(uint16_t ws,uint16_t hs,uint16_t wg,uint8_t hg)
{
//skip 1 multiplies skip 2 same with get1 and get2
//first wait for vsync it is on pin 3 (counting from 0) portD
//start spi ram
uint16_t ls2,lg2;
spiCSt();
spiWrB(2);//sequental write mode
spiWrB(0);//24 bit address
spiWrB(0);
spiWrB(0);
while (!(PIND&8)){}//wait for high
while ((PIND&8)){}//wait for low
if (hs != 0){
while (hs--){
ls2=ws;
while (ls2--){
while ((PIND&4)) {}//wait for low
while (!(PIND&4)) {}//wait for high
}
}
}
while (hg--){
lg2=wg;
while (lg2--){
while ((PIND&4)) {}//wait for low
SPDR=(PINC&15)|(PIND&240);
while (!(PIND&4)) {}//wait for high

12 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

}
}
}

Here is how to enable spi at maximum speed


Code: [Select]
//enable spi
SPCR=80;//spi enable master
SPSR=1;//double speed

To read the full 640x480 image do this


Code: [Select]
captureImg(0,0,1280,96);//each pixel is 2 bytes so 1280 instead of 640 for width
sendRam(1280,96);
captureImg(1280,96,1280,96);
sendRam(1280,96);
captureImg(1280,192,1280,96);
sendRam(1280,96);
captureImg(1280,288,1280,96);
sendRam(1280,96);
captureImg(1280,384,1280,96);
sendRam(1280,96);

The sendRam function just sends the image to the computer


Code: [Select]
void sendRam(uint16_t w,uint16_t h)
{
spiCSt();
spiWrB(3);//sequental read mode
spiWrB(0);//24 bit address
spiWrB(0);
spiWrB(0);
uint16_t wl,hl;
for (hl=0;hl<h;++hl){
for (wl=0;wl<w;++wl){
while ( !( UCSR0A & (1<<UDRE0)) ) {} //wait for byte to transmit
SPDR=0;//send dummy value to get byte back
while(!(SPSR & (1<<SPIF))) {}
UDR0=SPDR;
}
}
while ( !( UCSR0A & (1<<UDRE0)) ) {} //wait for byte to transmit
}

Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome


Post by: drkblog on Jun 22, 2013, 05:40 pm
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 sensor datasheet 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 to the 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 dividing by 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 I need 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 frames on 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) = awesome
Post by: Mr_arduino on Jun 22, 2013, 06:37 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 in one 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 with right 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 much faster.
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: drkblog on Jun 22, 2013, 06:57 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 operating system 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 know whatever 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) = awesome
Post by: Mr_arduino on Jun 22, 2013, 07:30 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 not get 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 disable interrupts 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 fifo version 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. Using sdfatlib
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) = awesome
Post by: drkblog on Jun 23, 2013, 12:09 am
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 I will 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 could have 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) = awesome
Post by: Mr_arduino on Jun 23, 2013, 01:05 am
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. Also speaking 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) = awesome

13 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Post by: drkblog on Jun 23, 2013, 01:38 am


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 some components. 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 I would 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, Hong Kong, China. Specially for testing purposes.
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: Mr_arduino on Jun 23, 2013, 02:06 am
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 shipping is 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 mega
Post by: xKoldFuzionx on Jul 11, 2013, 05:37 am
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 . I bought 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 some things 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 hex and 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 of 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 up into 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 a link, 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 to work, 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 by doing.
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Jul 11, 2013, 03:35 pm
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 get working, 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 machine code. 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 mean there 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 dissipation


Binary logic (from the logical and electrical point of view)
Logical gates
Microcontroller (or microprocessor, or CPU) and DSP
Memories
Parallel interface
Serial interface
I2C 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 mega
Post by: xKoldFuzionx on Jul 11, 2013, 04:22 pm
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 the V=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 also just 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 I don't see it in action. I'm a very mechanically inclined

14 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

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 stuff on 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 money is 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 of Arduino, huh?

Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Jul 11, 2013, 07:40 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 electronics takes 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 circuit working 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 multiplication results 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/150pxTransistor_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, the collector-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 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 different value, 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. You don'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. A practical 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 light detected. 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 connect the 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 arduino output 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 is 0, 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.3V module, 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 would recommend 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 you start learning electronics without burning some stuff.
Do you have an oscilloscope?
Title: Re: ov7670 with both arduino uno and now mega
Post by: xKoldFuzionx on Jul 11, 2013, 08:50 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 mega
Post by: drkblog on Jul 11, 2013, 11:11 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 a logical 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 say that 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 something you 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 with 5V 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 IO pin. 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 pin outputs 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 mega
Post by: xKoldFuzionx on Jul 11, 2013, 11:41 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 a transistor 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 connected to 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 then the 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.

15 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

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 mega
Post by: drkblog on Jul 12, 2013, 12:46 am
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 enough for 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 this datasheet: 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 an inductor/coil on and off (a motor, a relay, etc), to
protect the transistor.
Title: Re: ov7670 with both arduino uno and now mega
Post by: sampullman on Jul 16, 2013, 04:07 am
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: [Select]
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 of concept 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 be possible - 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 mega
Post by: drkblog on Jul 16, 2013, 04:22 am
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 used the 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 see what'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, capture covering 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 mega
Post by: sampullman on Jul 16, 2013, 05:15 am
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 also able 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 with just that?

Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Jul 16, 2013, 02:51 pm
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 undocumented registers. 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 feeding 16MHz 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 should be 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 post the 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 this project. 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 the minimum clock should be 10MHz.

16 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jul 16, 2013, 05:48 pm
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 at other 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 is the 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. I have 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 ov7670
https://github.com/ComputerNerd/arduino-camera-tft/blob/master/twicam.c update the function void errorD(uint8_t err) for your hardware for example send the string 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 specific to 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
https://github.com/ComputerNerd/arduino-camera-tft/blob/master/captureimage.c Here is an example of how to capture an image there are many different functions 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 code that 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(); and use 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
register presets (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 by calling 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 tft screen that uses rgb565 data.
Title: Re: ov7670 with both arduino uno and now mega
Post by: sampullman on Jul 16, 2013, 08:20 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 this http://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: [Select]
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_arduino
I'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 write registers 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 mega
Post by: Mr_arduino on Jul 16, 2013, 10:04 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 arduino ide. Most likely the code that I posted will work just
fine with the arduino ide. Here is a newer version of the datasheet
http://www.haoyuelectronics.com/Attachment/OV7670%20+%20AL422B%28FIFO%29%20Camera%20Module%28V2.0%29/OV7670%20datasheet%28V1.4%29.pdf
Also 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 from stdint.h
for 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 is better 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 mega
Post by: technonewb on Jul 17, 2013, 06:09 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 on the 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: [Select]
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: [Select]
#include <Wire.h>
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;

17 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

}
/* 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);
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 mega
Post by: Mr_arduino on Jul 17, 2013, 06:49 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 old code uses it see
http://pastebin.com/1nnRc5qL
Also 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 the pullup 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/Utility
And remove these lines:
Code: [Select]
// 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 happened however your millage may vary. After removing those
lines be sure to recompile your program.
Title: Re: ov7670 with both arduino uno and now mega
Post by: giantsfan3 on Jul 18, 2013, 03:40 pm
@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 going to 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 usage sketch 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 that others 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 Jul 17, 2013, 06:49 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 old code uses it see http://pastebin.com/1nnRc5qL

Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jul 18, 2013, 10:06 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 example communicating 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 the filename 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 deleted it 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 the
arduino 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 hardware connections 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 of plugging 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 it to 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 tft screen 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 of directly 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 to configure the ov7670.
Title: Re: ov7670 with both arduino uno and now mega
Post by: sampullman on Jul 18, 2013, 11:23 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 it works with the OV7670:
Code: [Select]
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 should work 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 have better luck.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jul 19, 2013, 02:12 am
I have the same values here that sampullman posted. https://github.com/ComputerNerd/arduino-camera-tft/blob/master/main.c
Also 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 that sampullman posted (I think).
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jul 25, 2013, 12:23 am

18 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

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 way everyone will benefit.
Title: Re: ov7670 with both arduino uno and now mega
Post by: vichaz on Aug 09, 2013, 09:14 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 play with 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 without RESET 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 some information how to connect the camera. But even read all 6 pages of your discussions I don't realize finally how to get the image to SD.
What I have now is:
1) Arduino UNO
2) my OV7670 camera module
3) SD card module (I know how it have to be connected to Arduino. No problems with it)
4) some miscellaneous resistors, wires, prototype board
5) using Arduino IDE
That is all.
I would like to ask someone for your help/suggestions which parts I have to buy additionally in order to save image to SD.
Also, I would like to propose to create straightforward instructions with circuit schema, some TODOs list, list of necessary parts or video how to catch image from OV7670 module by Arduino UNO and save to SD
card. I can create this report as soon as I will finish with my little project.
Is there any who can spend some time for me to help with it? Please send me PM. I think it will be better to help me privately and I will create an detailed report after that in order to share knowledge with other.
Thanks, Victor
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Aug 10, 2013, 09:05 pm
Well it appears that we just need to figure out which pin is what then you should be up and running. I looked up their website and did not find the pinout http://www.lctech-inc.com/Hardware
/Detail.aspx?id=7c378661-0fd6-475e-8b63-a874aa6eb4df I guess you are going to have to email them asking for the pinout http://www.lctech-inc.com/About.aspx
Title: Working code example and wiring instructions
Post by: gtsam on Aug 27, 2013, 04:02 pm
That topic was very helpful to get me started with the OV7670 + fifo. I added working code, plus wiring / breadboard instrauctions to github https://github.com/arndtjenssen/ov7670 (https://github.com
/arndtjenssen/ov7670). I use an atmega1284 (lots of i/o pins) running at 3.3V with 16Mhz (works fine for me) which eliminats the trouble with voltage conversion between the camera and uC. Thanks to all the
contributors!!!

Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Sep 02, 2013, 01:59 am
I am very glad to hear that we helped you always glad to see knowledge being shared.
Title: Re: ov7670 with both arduino uno and now mega
Post by: vichaz on Sep 14, 2013, 03:37 pm
Hi,
Mr_arduino, as you suggested I asked LCtech for pin outs.
They provided me the following archive http://ge.tt/2xBvxAs w5th the following answer:
-----It's very glad to receive your letter,much thanks for your interest in our products.
Attached the pin outs of OV7670 Camera Module ,please have a check.
If you have any questions,please feel free to contact us.
-----Actually, the information in this archive is not enough for me to understand how I have to continue with this module.
As I know I have to use at least some crystal for clock...
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: relic1974 on Sep 24, 2013, 04:14 pm
Quote from: Mr_arduino on Apr 12, 2013, 01:30 am
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 you have 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 remove them
Code: [Select]
// 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 d4 to 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 except enable 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 the sensor. The sd card and spi ram is just standard spi wiring
nothing special.

Hi, this is the closest thing I have found to a real library for this module, besides the over-priced arduCam shield/library, so kudos to you first of all.
I am using a Sainsmart 3.2" TFT that depends on the UFTF and UTouch libraries to work. I use TinyFat to store to SD. I am using a mega board, and I'm looking thru your code to see if I need to change any
pin definitions, as the only pins available to me are A0 thru A7 and the i2C bus and a few other digital pins, some with PWM. The shield uses the rest. Plus I'm having a few errors getting main.c, ov7670.h and
ov7570.c to compile. I know no other way so I have all 3 source files tabbed out in the Arduino IDE. I get an error about an undefined wrReg, which I see is a function and IS prototyped in ov7670.h.
Can you explain what changes to code I may need to make for the mega boards, and why I"m getting the compile error. I also have NO idea how to use the frame grabber.

19 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Also, a keyword.txt file would be most useful for the library. And one more question .. I read that the library sets up the camera and grabs frames saving them to SD card (I'll have to use TinyFat somehow, not
sure how) but are there functions in the library to output to a TFT screen? If not, how do you suggest going about displaying on a screen, or would it be faster to send the data over bluetooth to the Processing
IDE.
Sorry if these are noob questions but a lot of these methods are new to me, as so far I've only worked with single .ino files.
Title: Re: ov7670 with both arduino uno and now mega
Post by: relic1974 on Sep 24, 2013, 06:31 pm
OK, I have another question for MrArduino, and first of all I and I'm sure MANY others are most grateful that you took the time to write this library and are providing help.
An idea hit me and since you've had plenty of experience with these camera modules I wanted to ask if this approach would work.
I have a Sainsmart UTFT 3.2 inch + shield + touchscreen + SDCard. The ONLY library that works with the sainsmart shield is the UTFT/UTouch library. But while doing research I found the official arduino page
with great example code and wiring examples. The way I understand this module, all data is sent via SPI, MOSI/MISO. Unlike other TFT displays, mine has a 40 pin header with 16 bit data bus (D0 - D15 plus
all of the other usual CS and SPI lines. It appears that if I connect my TFT without the sainsmart shield, following the default wiring shown here http://arduino.cc/en/Guide/TFTtoBoards (http://arduino.cc
/en/Guide/TFTtoBoards) that it should work
Can I use your library to simply 'direct the traffic' and set registers, and connect the OV7670's DATA (D0-D7) outputs DIRECTLY to the sainsmart TFT's data input bus? It would seem that if it was possible to do
this I could basically stream the data directly from the camera to the TFT. The arduino would just handle setting up the camera, controlling CS and sync signals and SPI.
If this would work, I am guessing that the framerate would be very fluid, and the images from the camera would virtually be displayed on the TFT as if it were streaming. My module DOES have FIFO onboard.
And if all of this is possible in theory, what changes would I need to make to your code and/or library? Here is a pin diagram of the TFT display that I have, and I'd REALLY prefer using this one. image link
below...
http://www.sainsmart.com/media/wysiwyg/Product/PinOut.jpg (http://www.sainsmart.com/media/wysiwyg/Product/PinOut.jpg)
I am hoping that this way I can avoid the sainsmart TFT shield, avoid the UTFT library (and eliminate rewriting a lot of tft code), avoid using something like the arduCam shield, and get great streaming video /
results.
I'd also be more than happy to share in detail my results, I'm just new to these camera modules and interfacing to a not so standard TFT screen. BTW apart from what a lot of people think about Sainsmart
modules/shields, IMO this TFT is of great quality, has a responsive touch screen, and saves to SD just fine. The picture is vivid as well.
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Oct 01, 2013, 03:06 am
Well. I'm back with the OV7670 (now with FIFO). After some work I concluded I have the version 1 (http://wiki.beyondlogic.org/index.php/OV7670_Camera_Module_with_AL422_FIFO_Theory_of_Operation) of
the module. What means I have to reset the write pointer by hand at the start of the frame (as far as I know).
I managed to build a testing program which captures a frame and then dumps it to the serial interface. By dumping the captured frame more than once, I checked the memory reading process is working. Yet, the
captured frame seems of of sync. The capture steps are:

Wait for VSYNC HIGH


Wait for VSYNC LOW
Reset Write pointer
Set Write Enable HIGH
Wait for VSYNC HIGH
Set Write Enable LOW

I tried by inverting VSYNC (and doing the proper changes in the code) as the version 2 of this module need such configuration, but I get the same result. I checked in the module HREF is connected to a NAND
with the Write Enable input pin. So horizontal synchronization should be automatic. But I'm puzzled I get this kind of image:
6 FPS
(http://www.drk.com.ar/images/forum/div9.png)
3 FPS
(http://www.drk.com.ar/images/forum/divF.png)

Title: Re: ov7670 with both arduino uno and now mega
Post by: relic1974 on Oct 01, 2013, 04:53 am
drk I have a question maybe you can answer. I have a TFT/touchscreen 320x240 that has a 40 pin header and uses 16 bit data bus instead of SPI. (at least I don't see any SPI pins labeled). Is this screen
going to work, or is it a waste of time .. and should I just buy a SPI based LCD ?
Also I have found so many different examples that my head is spinning. Are you using a library to set your fuses? Or are you manually writing to registers in your code? I think if I could just get the camera
configured then I would have some luck getting data out to a LCD. My cam also has FIFO. Using an external 16mhz xtal to clock it.
as for your problem, maybe using the two available interrupts for catching the vsync and href signals would help?? I've created many arduino projects, but getting this camera to work has been the biggest
challenge yet.
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Oct 01, 2013, 02:50 pm
The point is according to the documentation I've found, I have nothing to do with HREF signal. I wait for VSYNC pulse (start of a frame) and set Write Enable high until VSYNC goes down. In the AL422 /WE is
the output of a NAND between WE and HREF. That way /WE is low if and only if I set WE high and HREF is high (which is high during 640 PCLK, one horizontal line). Between two HREF pulses, /WE in the
AL22 goes high again which prevents recording of invalid data between two lines. At least in theory.

20 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

About the TFT, I haven't used one of those yet. But I guess the problem with a 16bits parallel interface is you have to spend 16 I/O ports just for interfacing with the display. So you will need an ArduinoMEGA or
any other C with plenty of ports. That's way SPI or IC interfaces are preferred for C --you save a lot of pins.
When I tested the OV7670 (without FIFO) I clocked it with 16MHz clock from Arduino at first. Later I used the code in this post and changed to a Timer library and clocked it at 4MHz (I guess, I don't remember
precisely but you can see my comments in the previous pages) which made easier to read from the non-FIFO module.
Why do you clock your FIFO module externally?
Title: Re: ov7670 with both arduino uno and now mega
Post by: relic1974 on Oct 01, 2013, 04:35 pm
drkblog,
I think you're problem may be the 4mhz clock you are driving the camera with. Obviously I am no expert, as I've only been able to run OV7670 init sketches to ensure that the module is functioning. I really need
to pick up a SPI display!
I've been to every forum I could fine, and even according to at least one datasheet I have seen, the MINIMUM suggested clock speed is 10mhz .. although 8mhz seems to work fine too. I think the max you're
supposed to clock it is like 20mhz.
I'm using an external ocsillator simply to increase the framerate. It could be that @ 4mhz you're missing some horizontal / row data and also possibly missing some vsync triggers. I'd say try your same setup
and code at 8mhz and see what happens.
As for my module / project, like i said I've only had success in initializing the module. So that I'm clear, would you kindly post any links to the libraries and/or code that you're using? While I don't have a
compatible display yet, I could at least get some framework code working and verify that I'm getting data from the cam's data bus, sync signals, etc...
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Oct 01, 2013, 05:07 pm
You are confused about these modules. All the FIFO modules I've seen so far don't support external clocking. Instead they are internally clocked and connected to the FIFO. From outside the module you can
only access the FIFO memory. There you can read the data sequentially at any given speed. As long as you stopped the Write process (From OV7670 to the AL422B).
From what you say I guess you have a non-FIFO version, which you have to clock externally. I have successfully used such a module and you can see the images I've got, if you go back to page 4 of this same
post. There I explained I was using a 16MHz clock, but as MR_Arduino said, you can feed the module with an 8MHz clock (software made, so you don have to change the fuses). And it works too, even then
datasheets says the minimum clock is 10MHz. Can you link to the module you have bought? Or post a picture of it's back side (not the lens side)?
The problem with the non-FIFO version is you have to read at camera's speed and store the data in RAM. The FIFO version comes with a memory chip where you can store a full frame, then read it at the speed
you want/you can.
Title: Re: ov7670 with both arduino uno and now mega
Post by: relic1974 on Oct 01, 2013, 05:34 pm
It looks like I am indeed confused, majorly! the module does have a XCLK pin. I don't have an image of the backside but I can describe what components are there and give a link to where i bought it. It does
not appear to have FIFO onboard. I'm also going to go ahead and buy a SPI display module.
product link http://www.ebay.com/itm/261213033140?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649 (http://www.ebay.com/itm/261213033140?ssPageName=STRK:MEWNX:IT&
_trksid=p3984.m1439.l2649)
On the back of the camera, blank space except for a few caps. Do you have a part number for a FIFO chip? I have some arduino prototype shields I can use to solder it all up. And I really appreciate your help /
responses. You are the first one to reply to the many forums I have posted these questions in.
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Oct 01, 2013, 06:00 pm
Yup! That's the non-FIFO version. You have to feed it with a clock in XCLK which can be as low as 8MHz. And you have to read data at PCLK speed. So you have to setup a slow frame rate and PCLK in order
to read data from Arduino. You won't be able to do it otherwise. You will have to find out if you can do (whatever you want to do) without the FIFO version. In my case, as I have to store to an SD card, storing a
whole frame to RAM is mandatory. My options are using the FIFO version or adding enough RAM externally. Of course, the FIFO module seems the accurate solution.
But I'm stuck now. I think I'm using a wrong signal sequence during the write process.
Title: Re: ov7670 with both arduino uno and now mega
Post by: relic1974 on Oct 01, 2013, 06:35 pm
Thanks for your reply. I can pick up a FIFO chip cheap and TTL convert to 3V. Not sure that I understand the PCLK signal and timing. What I really have a hard time understanding is the large number of
registers / fuses that have to be configured. I guess I need to examine your code from page 4 again. Anyway, just bought a SPI display so maybe I will get somewhere soon.
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Oct 01, 2013, 06:45 pm
The non-FIFO version works with the registers that Mr_Arduino provided, using 16MHz or 8MHz clock. You have to wait for PCLK raising edge and the read one byte from data lines. Then the second byte with
the next PCLK raising edge. That portion of code should be really fast, and you have to disable interrupts in the C for that to work (disable interrupts only when reading the image from the sensor). And you have
to configure the cam to slow PCLK enough. If you have 16MHz clock you have to divide it for a bigger number than having an 8MHz clock. If you don't do that you will never be able to read the image with an
16MHz Arduino. Unless (I'm not sure) you configure interrupts for handling PCLK. But even if you do that, you could have a speed problem if PCLK is too fast.
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Oct 03, 2013, 02:39 am
UPDATE: OV7670 + FIFO is in the end a big disappointment, at least for me.
It is true you can capture a frame in the module's FIFO memory. But you can't read it at any speed you want. AL422B memory datasheet states 1S as the maximum read cycle time. Which means you can't read
less than 1,000,000 bytes per second from the FIFO. Right now I'm testing whether it is possible to read a block, pause and later resume. I'll let you know...
UPDATE II: The OV7670 + FIFO module (three versions checked) have a huge design error. They don't provide access to the /RE pin of the FIFO. Using that pin you can pause reading and then continue,
without stopping the RCLK. The other way (pausing RCLK) you get out of sync eventually.
UPDATE III: I can successfully read a block of data from the FIFO optimizing the code in Arduino Mega2560. I get a 1.3MHz clock which is ok for the AL422B. Of course, I'm limited by RAM to a small block of
bytes. So reading the next block is hard. The only way is resetting the read pointer and discarding the previous block. Which makes the process slow, and yet I'm missing some byte in between blocks. I need to
write the frame to an SD card, so my block size must be 512 bytes, which makes a total of 600 blocks which in turn makes a total of 179,700 skips.

21 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

At this point I have three options:


Adding 1MB static RAM to Arduino (not easy as far as I know)
Cutting the /RE pin from AL422B chip and solder it to a cable (I'm going to burn it)
Using a Raspberry Pi instead of Arduino (I really want to use an Arduino, but...)

Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Oct 05, 2013, 01:48 am
Hello everyone. I know it has been awhile since I have responded no I did not forget about you guys. Sometimes life makes me busy but I though I would take some time to answer questions. Vichaz the archive
DOES have enough information that you need they gave you a schematic is that not enough? From there everything should be the same as in wiring the names are the same. Drkblog I am sorry that I did not
notice that /RE is not connected. I think you are just going to have to try and solder a wire to it. What I would do is prepare for the "big moment" so to say meaning watch tutorials and think about how you are
going to solder the wire before actually doing it having a plan and quickly soldering it should significantly reduce the chances of frying the chip. Just watch for bridging. I admit that I have never soldered a wire to
a surface mount chip before so I am not quite sure what it is like the previous advice is kind of generic but I hope it helps you.
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Oct 05, 2013, 02:37 am
Mr_arduino, we were missing you already. :)
I decided I'm going to buy another FIFO module before trying to solder it. Just in case, I want to have at least ONE module working ;)
My major concern is: do you agree with me in that it's a huge error in the design of the FIFO module?
Do you think we can contact one of the manufacturers and propose him exposing the /RE pin in the header connector?
In the meantime I started developing an alternative solution using a Raspberry Pi. I know I will end up making it work on the Arduino. But this project could reach it's dead line soon if I can't build one prototype at
least. I can replace the Raspberry solution for the Arduino when it's working.
I'm attaching a JPEG and a YUV of 200 lines I've got from the module. I know you will find out what am I doing wrong here. Because this portion of the frame should look better. Even when the FIFO reading
problem.

Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Oct 05, 2013, 04:05 am
Drkblog, yes I agree not having /RE is a design flaw. Having /RE is a needed function /RE does exactly what you need it to do keep the data "alive" in the fifo while saving to the sd card and then continue were
you left off without restarting. Regarding your attachment I think you may be simply missing bytes. Also relic1974 regarding your question of directly hooking up an ov7670 to an lcd screen that is very possible.
Have the arduino configure the ov7670 and send the data to the lcd screen would work just fine. The reason I never tried it is simply because I don't have a multiplexer IC and the tft screen I use needs addition
configuration written to it on startup for it to run. It also needs the "cursor" reset to zero on each frame.
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Oct 05, 2013, 02:36 pm
Quote from: Mr_arduino on Oct 05, 2013, 04:05 am
Drkblog, yes I agree not having /RE is a design flaw. Having /RE is a needed function /RE does exactly what you need it to do keep the data "alive" in the fifo while saving to the sd card and then continue were you left off without restarting. Regarding your attachment I
think you may be simply missing bytes.

Thanks. I wanted to be sure I wasn't missing something here. I just bought two more FIFO modules yesterday. I guess they will arrive within 30 days. So I can try fixing the /RE thing.
In the meantime I'm going to interface the FIFO module with the Raspberry where I have lots of RAM space for reading the frame at once. Fortunately the Raspberry is 3.3V so the electrical interface will be
easier than this:
(http://www.drk.com.ar/images/forum/old-adapter.jpg)
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Oct 06, 2013, 05:39 pm
Ok. Now I have managed to interface the OV7670 using the raspberry GPIO. And I'm stuck again with the image format. The truth is I have changed sensor configuration so many times, that I just can't
remember where did I start.
I'm trying to get an YUV frame. These are relevant registers:
Code: [Select]
//{ REG_COM7,
//
// Clock scale:
//
//

COM7_RESET },
3 = 15fps
2 = 20fps
1 = 30fps

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


{ REG_TSLB, TSLB_YVYU },
{ REG_COM7, COM7_RGB_YUV }, // YUV 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, 0x00 }, // Usar COM10_PCLK_HB para frenar el clock en el blank
......

22 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

static struct regval_list ov7670_fmt_yuv422[] = {


{ REG_COM7, COM7_RGB_YUV }, /* Selects YUV mode */
{ REG_COM17, COM17_DSP_COLORBAR },
{ REG_RGB444, 0 }, /* No RGB444 please */
{ REG_COM1, 0 },
{ REG_COM15, COM15_RANGE_TOFF }, // OJO
{ REG_COM9, 0x6A }, /* 128x gain ceiling; */
{ 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 },
};

Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Oct 06, 2013, 10:02 pm
I started over with the original register values and used BAYER mode which is one byte per pixel. Now it works.
(http://www.drk.com.ar/images/forum/cam-works.png)
Title: Re: ov7670 with both arduino uno and now mega
Post by: xKoldFuzionx on Oct 07, 2013, 04:09 am
That's a really clear looking picture. I posted earlier before I really understood a whole lot and have been working through the Arduino Cookbook since. I finally feel like Ihave a pretty good grasp of what iI need to
do to get my project up and running. I'm hoping to start working through the code soon, but I still need to get my hands on some ram. Either way, I might as well try to figure out the code and see what I can come
up with.
I hope you guys will continue to keep posting as I've learned a lot just from reading through all this.
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Oct 07, 2013, 04:16 am
Quote from: xKoldFuzionx on Oct 07, 2013, 04:09 am
That's a really clear looking picture. I posted earlier before I really understood a whole lot and have been working through the Arduino Cookbook since. I finally feel like Ihave a pretty good grasp of what iI need to do to get my project up and running. I'm hoping to start
working through the code soon, but I still need to get my hands on some ram. Either way, I might as well try to figure out the code and see what I can come up with.
I hope you guys will continue to keep posting as I've learned a lot just from reading through all this.

I'll be glad to help you and a lot of people here too. Have in mind that I'm currently working with a Raspberry Pi and the FIFO version of the module.
Title: Re: ov7670 with both arduino uno and now megayeah,
Post by: xKoldFuzionx on Oct 07, 2013, 04:34 am
Yeah, NP. I'm working with the non-FIFO module. Haven't tried the pi yet. Never even really dabbled with electronics until this past May. But I'm wanting to build a trail camera for hunting cuz I'm tired of what's
out there on the low end. Stumbled across the Arduinoat radio shack and started teaching myself . I feel like I've made huge strides in a short time, can't wait to see what I build as I continue to grow. I've always
been fascinated, but never got into it. Now I only wish Iwould hhave sooner!
Title: Re: ov7670 with both arduino uno and now mega
Post by: relic1974 on Oct 07, 2013, 08:22 am
Hey guys, here's some 3mbit x 8 FIFO memory for ya from the US for a fair price. This FIFO has been suggested on several forums. Also to make it easier to prototype here is a SOP-28 breakout board. I'm
just learning this module as well and I'm ordering these two items for the OV7670 that I have, which has no FIFO memory...
Breakout board
http://www.ebay.com/itm/221156073604
FIFO buffer / memory
http://www.ebay.com/itm/110373278217
I totally understand the hardware side, but I'm going to need some assistance with the software. It seems like there is a lot of fuses / configuration options to set and I am new to writing frame buffers to displays
;)
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Oct 07, 2013, 01:48 pm
Quote from: relic1974 on Oct 07, 2013, 08:22 am
Hey guys, here's some 3mbit x 8 FIFO memory for ya from the US for a fair price. This FIFO has been suggested on several forums.

My friend, there is a OV7670 module with that Averilogic FIFO already. In fact, that's what we mean by OV7670 + FIFO. You can buy them for 25 bucks free shipping: http://www.ebay.com/sch/i.html?_sacat=0&
_from=R40&_nkw=OV7670+FIFO&rt=nc&_pppn=r1&LH_FS=1
The module has the OV7670 images sensor connected to the write side of the FIFO. You can take one frame into the FIFO and later read the frame. There's one caveat: a design flaw makes reading the frame in
chunks, impossible. You have to read the whole frame at least at 1 byte per microsecond.
The last picture I posted was taken with such a sensor.
Title: Re: ov7670 with both arduino uno and now mega
Post by: relic1974 on Oct 07, 2013, 04:57 pm
Yes, my camera does not have FIFO. I've seen the same camera connected to an external FIFO, which is what I'm wanting to do.
Title: Re: ov7670 with both arduino uno and now mega

23 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Post by: drkblog on Oct 07, 2013, 06:07 pm


In my humble opinion, you will spend more money adding the AL422B to the non-FIFO module, than buying a OV7670+FIFO module. Because that module provides the sensor with its own 24MHz clock. Of
course, you will have access to the /RE pin (missing in the OV7670+FIFO module). But I think it would be better just to buy a FIFO module and solder the /RE pin out.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Oct 09, 2013, 07:00 pm
drkblog I am glad to see that you got it working. I should have mentioned that the fifo version has only enough room for 640x480 Bayer. I did not realize that was the problem with the image.
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Oct 09, 2013, 08:06 pm
No problem! I already knew that. But it wasn't only problem there. And I was just trying multiple configurations. Everything worked as soon as I went back to the original register set.
Is there any draw back in using bayer mode? In this project I need the maximum resolution possible from the sensor. But I don't care much about the image color quality. As long as the objects on it are well
defined (assuming the optic focus is correct).

Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Oct 11, 2013, 02:00 am
Actually there are no drawbacks that I am aware of with using the ov7670 in RAW bayer mode except maybe colors and the only reason the colors are not as good is because the ov7670 does some internal
processing with the colors that my program does not do. Looking at the source code you see that I have only coded support for bi-linear and nearest neighbor debayering https://github.com/ComputerNerd
/RawCamera-data-converter/blob/master/main.c
It looks like you may be running an old version of my converter. Bi-linear is slightly better quality than nearest neighbor. I will find hopefully find time to add support for a better algorithm. Also I remember that
there is a mode were the ov7670 does the internal processing but still outputs Bayer data I am very surprised that I did not try it out yet. So really there appears that by using bayer there are only advantages and
no disadvantages.
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Oct 11, 2013, 03:22 am
That's great! It's reasonable having lower quality colours since it's using a single byte for coding a pixel. Even if there is a processing which makes this bayer single byte coding better than plain RGB single byte.
It won't be as good as a two-byte encoding. But, as I said before, I don't care about colours that much. Of course, I will update your converter anyway. Whatever makes it better is welcome :)
I'm going to stay in Raspberry for this project because it's allows me to take a bunch of pictures for a single event. Which isn't a requirement but will add a lot of flexibility. And there is no way I can do that with
Arduino even if I get the /RE pin working. Because I will be limited by SD card speed.
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Oct 11, 2013, 02:30 pm
I'm having trouble taking images when ambient light is high. This is what happens.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Oct 12, 2013, 02:59 am
That is because you are missing a byte or two each line. Is this still the fifo version that we are talking about? if so you may just need run the ov7670 a little slower. If it is the non-fifo version work on your timing.
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Oct 12, 2013, 03:01 am
It's the FIFO version. An this only happens if there is a lot of light in the picture. Or if I point the camera to a source of light.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Oct 12, 2013, 03:57 am
Maybe the fifo is missing the byte somehow. I wonder not sure if this is correct or not but do you have this in your code?
Code: [Select]
{0x30,0},{0x31,0},//disable some delays

What it does is remove a delay in HSYNC raising and falling.


Try removing those two registers. This is in the struct format {register,value} if you are storing registers in a different order take note of the above.
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Oct 12, 2013, 03:41 pm
Nope. I mean, I have that line (I'm using the register configuration from your github repo) but nothing changes if I comment that out.
In my circuit I have another potential issue: as I'm running under Linux there is a chance that my program run out of CPU time during the FIFO reading. If that happens I'll get a broken image. I haven't thought of
a way of telling when that happens. If I get random unsynced images, it must be the CPU issue. If the unsynced images are consistent with something (like pointing to a light) then it must be something else.
I'm attaching two pictures: Both images point to the window but in ventana-oos.png the window occupies the while picture. I guess that results in lines of white, which in turn end up getting the FIFO out of sync
during write (somehow). I tried changing the clock register to something else than 0x80. But it doesn't help with this problem, and messes up the other cases where I'm getting the good ones.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Oct 15, 2013, 01:43 am
I think you are correct linux, the kernel may be to blame. With linux, the kernel there are various interupts for various things running in the background such as redrawing the screen and other stuff. What you
may need to do is write a linux kernel module so that you can disable interrupts while reading the the pixels data. I really wish I can find time to try this myself.
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Oct 15, 2013, 03:13 am
Creating a Linux kernel module is a lot of work. Specially because any error results in having to reboot. I'm going to do it eventually. Right now I'm using some tricks to induce the kernel to let my program run
during the critical stages of execution. For example I specifically give up the CPU right before reading the ov7670. That way I reduce the chances of losing it for timeout. And it works pretty well. Of course it's not
a real solution, but I can go with it by now.

24 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Oct 15, 2013, 11:40 pm
Alright that makes sense anyways I hope that this weekend I can find time to write my own kernel module yes it is lots of work. I have never wrote a module before but I think it is good experience to have. Also I
fixed Bi-linear demosaicing in my converter program the quality is slightly better.
Title: Re: ov7670 with both arduino uno and now mega
Post by: NEPRIBE on Oct 16, 2013, 10:40 pm
hi! i am a beginner in this topic so i would like receive some advice about OV7670+arduino uno.
I have a OV7670 device without FIFO. Also, I have a SD.
Nowadays I generated a 8MHz signal and i introduce its in XCLK.
I obtained the principal signal (VSYN,HREF,D0-D7). So my main problem is that i don't sure how to put the data(D0-D7) on the SD.
On the other hand, I tried to used the code that you posted :
#include <Wire.h>
#include <SdFat.h>
#include <SdFatUtil.h>
// file system
uint8_t buf2[512];
SdFat sd;
//uint8_t* buf;
// test file
SdFile file;
// SD chip select pin
const uint8_t chipSelect = 9;
uint8_t sensor_addr = 0x42;
.....
But when i compile i recieved the following error:
void readImgSerial(uint16_t, uint16_t)':
invalid conversion from 'const char*' to 'char*
However i don't sure how to correct that.
I hope some advice. Thanks!

Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Oct 17, 2013, 01:01 am
Let me save you some time: even when it's possible to take a picture using an OV7670 (without FIFO) and Arduino UNO, there is a catch. There isn't enough RAM in the Arduino for a full frame, even if you work
with a QCIF (176x120) resolution. So you have two options:
a. Saving the images in several steps of whatever you can fit in RAM. Take into account that SD card must be written using blocks of 512 bytes.
b. Using an external SPI RAM chip. But you still have a limit of 1Mbit. Which is the biggest SPI RAM you will find in market right now. So you will be able to fit a QCIF frame, but you won't be able to save a whole
VGA (640x480) frame anyway.
About the compilation error. We need to know the line where the error was found. And a link to the exact code you used will be useful. There are a lot of links in this post already.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Oct 18, 2013, 12:01 am
NEPRIBE I do not remember encountering such an error however you will notice that the function readImgSerial is unused so you can safely remove it from the program and it should fix your issue. Also was that
the whole error log if not please post the entire error log.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Tyranus on Oct 26, 2013, 05:46 pm
Hi Mr_arduino :)
I've been reading the post and sadly I've to tell you that I am really new into arduino (and electronic) world. But I have a simple question:
You thinks its possible to use the OV7670 with FIFO to capture small pictures (160*120 in grey scale) and do some simple image processing with the arduino? I just want to track a moving object to move few
servos (in sort kind of fan toy of portal torret http://gadgetsin.com/uploads/2012/11/blind_box_portal_2_turrets_1.jpg).
Do you think there is more simple camera to archive this? Despite the fact that I don't need the RGB channel (just one) and I don't need so much pixeles.
Thanks!
(sorry my english).
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Oct 26, 2013, 06:18 pm
I know I'm not Mr_arduino, but here are my two cents.
OV7670 outputs images in one or two bytes per pixel (color, not gray-scale). So in the best scenario you will get 160x120x1 = 19,200 bytes per frame. I'm not familiarized with object tracking but I reckon you will
have to store two frames in order to track a object. So you need 38400 bytes in RAM . At this point you realize you will have to use an SPI RAM like Mr_arduino used. You will have to use an Arduino Mega also.
You will run out of pins using a UNO for example.
Using this approach I think you will be able to do it. But be aware that interfacing with the OV7670 is really hard.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Tyranus on Oct 26, 2013, 06:52 pm
Hi drkblog,
You are not Mr_arduino, so I won't listen to you :P

25 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Thanks for reply :) You made a good point. I need too much memory to do that, and i will need to do some math over that matrix so I think it's not a good idea at all. I think I will go over the B plan: buy a bluetooth
module and do the math on a smartphone and just tell to arduino what to do with the servos.
Saludos compatriota!
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Oct 26, 2013, 07:07 pm
;)
Image processing with Arduino has been discussed a lot here (in this forum). I don't know what's the common opinion about it because I didn't mess with that. But even even Ardunino is very limited for that, it
doesn't mean you can't do it.
Maybe you have to start by doing the math in the processing side. How much information you need to handle (how many frames), how fast you have to process it (Arduino runs at 16MHz). Then you will know if
Arduino it up to the job. If not, meybe you want to move to something like Raspberry Pi which runs Linux and has 500MB RAM. And you can buy one in Argentina for 550 AR$ or so.

Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Oct 27, 2013, 02:11 am
Quote from: Tyranus on Oct 26, 2013, 06:52 pm
Hi drkblog,
You are not Mr_arduino, so I won't listen to you :P

Well you know drkblog is right except needing multiple frames if the object is a certain color and the same color does not appear in the background you can just follow the color. I used up all the pins on the
arduino uno with just the camera sd card and spi ram (sd card and spi ram were sharing the same spi lines by the way) Adding servos may be too much. The ov7670 needs 10 input pins for data plus 2 for i2c.
The arduino uno has 14 digtial io pins + 6 analog pins (they can be used as digital io) 2 digital io are used up by serial. So with that said just hooking up the ov7670 to the arduino uno leaves 4 free pins.
However if you are planning on getting the fifo version of the ov7670 you do not need spi ram so you could use that for the servos. Anyways image processing on the arduino is possible in fact you should see
this https://www.youtube.com/watch?v=-5QWy2uxxdM it shows color tracking on an atmega328p the same processor used on the arduino uno but they made their own board.
What you want to do is possible with the arduino uno however if you just want a simple solution could try the raspberry pi camera see http://www.raspberrypi.org/camera
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Oct 27, 2013, 02:20 am
Raspberry Cam is too expensive, in my own opinion. I successfully hooked up the OV7670+FIFO to the Raspberry Pi but that lets you with just ONE free digital pin. And the IC bus that you can share. So it
doesn't make sense. You can buy a cheap USB camera and use it with the Raspberry Pi letting the whole GPIO connector free for controlling the servos.
Of course Raspberry Cam leaves the GPIO connector free too. But you can buy USB cams for six dollars from China (free shipping).
Title: Re: ov7670 with both arduino uno and now mega
Post by: a_creed on Oct 28, 2013, 04:30 am
Hey, maybe!, Excuse my bad English, but I hope you understand me.
I have a camera I ov76 70 like this: http://bimg1.mlstatic.com/modulo-camara-omnivision-ov7670-ideal-arm-arduino_MLA-F-3233953871_102012.jpg ; I have a arduino mega also, according to what I've seen in
this post, Mr_arduino published a code on the first page where the corresponding connections was describing your code, My question is whether to have the camera with FIFO, I'll need the spi ram and sd card,
and the only thing I want is to send the image via Bluetooth for a small processing this picture, thank you very much for the help
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Oct 28, 2013, 03:57 pm
Make it simple: start by calculating the size of frame you need to send. Let's say you have a 320x240 bayer frame, which is 76,800 bytes long. And suppose you can run the OV7670 at 1 FPS. You will have to
be able to send 614,400 bits per second to the other end via BlueTooth. Because you have to work at camera speed (Pixel clock). Unless the scene you are capturing is completely steady and you can read
different parts of the frame from different frames in time. I'm not familiarized with the Bluetooth interface so I can't say whether you will be able to pass bytes from the cam to the Bluetooth device at the desired
speed.
Having a SPI RAM for storing the frame will make your life easier, as long as your frame fits in 1 Mbit. No need for an SD card if you have to send from the camera to the bluetooth adapter.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Tyranus on Oct 28, 2013, 10:32 pm
Hi again,
I just come back to say thanks to drkblog and Mr_arduino :) It's more clear now.
Title: Re: ov7670 with arduino mega
Post by: rafaelcor on Nov 07, 2013, 11:18 pm
Hello, i watched the post but i need help for do the connections to the arduino mega
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Nov 08, 2013, 02:24 am
You have to be more specific in your question. Try providing some information too, as which is you OV7670 module version.
Here is the connection information: http://forum.arduino.cc/index.php?topic=159557.msg1197477#msg1197477
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Nov 10, 2013, 05:19 pm
Actually those are the connections for the arduino uno. For the arduino mega where you connect stuff does not matter that much. The only thing I can suggest is that you make sure all the data pins D7-D0 are
on the same port so you can read pixels faster. Also make sure that you buffer XCLK to 3.3v so you don't damage the module also the pin you use for XCLK must support the fast PWM output. Also it does
matter where you put SIO_C and SIO_D make sure you use a pull-up resistor to 3.3v not 5v. SIO_C goes to pin 21. SIO_D goes to pin 20. Also make sure you set only the clock you feed the ov7670 (XCLK) as
output never set any other pins that go to the ov7670 as output and never enable the internal pull-up resistors on those input pins that connect to the ov7670.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Animat on Nov 21, 2013, 12:31 pm

26 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Hi, help me to understand c settings OV7670. I want to get a picture, and it gives you this fig1:
Settings:
WriteReg(CLKRC,
0x81);
WriteReg(DBLV ,
0x4A);
WriteReg(COM7,
0x00);
// YUV
WriteReg(COM3,
0x04);
WriteReg(COM14,
0x19);
WriteReg(SCALING_XSC,
0x3A);
WriteReg(SCALING_YSC,
0x35);
WriteReg(SCALING_DCWCTR, 0x11);
WriteReg(SCALING_PCLK_DIV, 0xF1);
WriteReg(SCALING_PCLK_DELAY, 0x02);
WriteReg(RGB444,
WriteReg(COM17,
//WriteReg(COM17,
WriteReg(COM15,

0x00);
0x08);
0x00);
0xC0);

// Disable RGB444
// color bar enable
// color bar disable
// Set normal rgb with Full range

// WINDOWING
WriteReg(HSTART,
0x16);
WriteReg(HSTOP,
0x04);
//HREF Control
//Bit[7:6]: HREF edge offset data output
//Bit[5:3]: HREF end 3 LSB(high 8 MSB at register HSTOP)
//Bit[2:0]: HREF start 3 LSB(high 8 MSB at register HSTART)
WriteReg(HREF,
0x24);
WriteReg(VSTRT,
0x02);
WriteReg(VSTOP,
0x7a);
WriteReg(VREF,
0x0a);
WriteReg(COM1,
0x00);
//21.11.2013
WriteReg(TSLB,0x0D);
WriteReg(COM13,0x88);

// 0D = UYVY 04 = YUYV
// connect to REG_TSLB

// COLOR SETTING
WriteReg(COM8,0x8F);
// AGC AWB AEC Unlimited step size
WriteReg(0xAA,0x14);
// Average-based AEC algorithm
WriteReg(BRIGHT,0x00);
// 0x00(Brightness 0) - 0x18(Brightness +1) - 0x98(Brightness -1)
WriteReg(CONTRAS,0x40); // 0x40(Contrast 0) - 0x50(Contrast +1) - 0x38(Contrast -1)
WriteReg(0xB1,4);
// really enable auto black level calibration
WriteReg(MTX1,0x80);
WriteReg(MTX2,0x80);
WriteReg(MTX3,0x00);
WriteReg(MTX4,0x22);
WriteReg(MTX5,0x5e);
WriteReg(MTX6,0x80);
WriteReg(MTXS,0x9e);
WriteReg(AWBC7,0x88);
WriteReg(AWBC8,0x88);
WriteReg(AWBC9,0x44);
WriteReg(AWBC10,0x67);
WriteReg(AWBC11,0x49);
WriteReg(AWBC12,0x0e);
WriteReg(GFIX,0x00);
WriteReg(AWBCTR3,0x0a);
WriteReg(AWBCTR2,0x55);
WriteReg(AWBCTR1,0x11);
WriteReg(AWBCTR0,0x9f);
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Nov 21, 2013, 12:41 pm
Is it a OV7670 with or without FIFO?
I think you are not that far. You are loosing some pixels though. Did you try adjusting focus? At least to know if part of your image is ok.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Animat on Nov 21, 2013, 12:44 pm
OV7670 with FIFO
Title: Re: ov7670 with both arduino uno and now mega
Post by: Animat on Nov 21, 2013, 12:46 pm
All the same, but the Color Bar
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Nov 21, 2013, 12:56 pm
Try enabling color-bar pattern:
COM17 - bit3 ON
SCALING_XSC and SCALING_YSC default values
Then capture a frame and post it here.

27 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Title: Re: ov7670 with both arduino uno and now mega
Post by: Animat on Nov 21, 2013, 01:06 pm

Captured frame
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Nov 21, 2013, 01:11 pm
Ok. There seems to be some synchronization issue. As the colorbar picture looks ordered. I guess it could be sensor configuration problem, instead of the reading of the FIFO.
There is some magic in the sensor configuration. Try ALL THESE VALUES. There are two structures here, you should set the registers in the order I pasted here, first ov7670_default_regs, then
ov7670_fmt_yuv422 and you should be able to get a 640x480 frame in bayer codification. Some register/value pairs here use defines I invented. But they are descriptive enough for finding the correct values in
the sensor documentation.
Code: [Select]
static struct regval_list ov7670_default_regs[] = {
//{ REG_COM7, COM7_RESET },
//
// Clock scale: 3 = 15fps
//
2 = 20fps
//
1 = 30fps
{ REG_CLKRC, 0x80 },
// OV: clock scale (30 fps) [26 funciona]
{ REG_TSLB, TSLB_YVYU },
// OV
{ REG_COM7, COM7_RGB_YUV },
// YUV VGA
{ REG_COM17, COM17_DSP_COLORBAR },
//
// 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, 0x00 }, // Usar COM10_PCLK_HB para frenar el clock en el blank
// Gamma curve values //
{
{
{
{
{
{
{
{

0x7a,
0x7c,
0x7e,
0x80,
0x82,
0x84,
0x86,
0x88,

0x20
0x1e
0x5a
0x76
0x88
0x96
0xaf
0xd7

},
},
},
},
},
},
},
},

{
{
{
{
{
{
{
{

0x7b,
0x7d,
0x7f,
0x81,
0x83,
0x85,
0x87,
0x89,

0x10
0x35
0x69
0x80
0x8f
0xa3
0xc4
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, 0x4A },
{ 0x74, 0x10 }, // DVL 0x4A ?? 0x04
{ 0x8d, 0x4f },
{ 0x8e, 0 },
{ 0x8f, 0 },
{ 0x90, 0 },
{ 0x91, 0 },
{ 0x96, 0 },
{ 0x9a, 0 },
{ 0xb0, 0x84 },
{ 0xb1, 0x0c },
{ 0xb2, 0x0e },
{ 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 }, // 0x40
{ REG_RED, 0x60 },
{ REG_COM8, COM8_FASTAEC|COM8_AECSTEP|COM8_BFILT|COM8_AGC|COM8_AEC|COM8_AWB },
// Matrix coefficients
{ 0x4f, 0x80 },
{ 0x51, 0 },
{ 0x53, 0x5e },
{ 0x58, 0x9e },
{
{
{
{
{
{

REG_COM16,
0x75, 0x05
0x4c, 0 },
REG_COM13,
0xc9, 0x60
0x56, 0x40

COM16_AWBGAIN },
{ REG_EDGE, 0 },
},
{ 0x76, 0xe1 },
{ 0x77, 0x01 },
0xc3 },
{ 0x4b, 0x09 },
},
/*{ REG_COM16, 0x38 },*/
},

{
{
{
{
{
{
{

0x34,
0xa4,
0x97,
0x99,
0x9b,
0x9d,
0x78,

},
},
},
},
},
},
},

0x11
0x88
0x30
0x30
0x29
0x4c
0x04

// Extra-weird stuff.
{ 0x79, 0x01 },
{ 0x79, 0x0f },
{ 0x79, 0x10 },
{ 0x79, 0x0a },
{ 0x79, 0x0b },
{ 0x79, 0x0c },

28 of 96

{ 0x50, 0x80 },
{ 0x52, 0x22 },
{ 0x54, 0x80 },

{
{
{
{
{
{

REG_COM11,
0x96, 0 },
0x98, 0x20
0x9a, 0x84
0x9c, 0x03
0x9e, 0x3f

COM11_EXP|COM11_HZAUTO|COM11_50HZ },
},
},
},
},

Some sort of multiplexor register


{ 0xc8, 0xf0 },
{ 0xc8, 0x00 },
{ 0xc8, 0x7e },
{ 0xc8, 0x80 },
{ 0xc8, 0x01 },
{ 0xc8, 0x0f },

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...


{
{
{
{
{
{

0x79,
0x79,
0x79,
0x79,
0x79,
0x79,

0x0d
0x09
0x02
0x03
0x05
0x26

},
},
},
},
},
},

{
{
{
{
{

0xc8,
0xc8,
0xc8,
0xc8,
0xc8,

0x20
0x80
0xc0
0x40
0x30

http://forum.arduino.cc/index.php?action=printpa...

},
},
},
},
},

/*
*/
{ 0xff, 0xff },
};
/*
* Here we'll try to encapsulate the changes for just the output
* video format.
*
* RGB656 and YUV422 come from OV; RGB444 is homebrewed.
*
* IMPORTANT RULE: the first entry must be for COM7, see ov7670_s_fmt for why.
*/

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_RANGE_TOFF }, // OJO
{ REG_COM9, 0x6A }, /* 128x gain ceiling; */
{ 0x4f, 0x80 },
/* "matrix coefficient
{ 0x50, 0x80 },
/* "matrix coefficient
{ 0x51, 0
},
/* vb */
{ 0x52, 0x22 },
/* "matrix coefficient
{ 0x53, 0x5e },
/* "matrix coefficient
{ 0x54, 0x80 },
/* "matrix coefficient
{ REG_COM13, /*COM13_GAMMA|*/COM13_UVSAT },
{ 0xff, 0xff },
};

1" */
2" */
4" */
5" */
6" */

Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Nov 22, 2013, 08:44 pm
Drkblog beat me to pretty much everything except one thing I was wondering about was the converter. The colors are all monochrome and washed out.could you post the raw data or try my converter?
https://github.com/ComputerNerd/RawCamera-data-converter just today I did some work on the program and added a higher quality demosaicing algorithm. I recommend you use raw Bayer data.
Title: Re: ov7670 with both arduino uno and now mega
Post by: aturcitu on Nov 25, 2013, 11:13 pm
Hello MR_Arduino, I have seen you job and it's awesome.
I amb working with OV7670 non-fifo version (I have ordered one with fifo I am still waiting for them)
I have (with long hours work...) managed to control I2C (I can read the full bank and modify any register) I also can store and entire frame (Due have enough memory). Once there I try with a VGA ouput based
on other project I found over here. And I achieve getting images directly from ov7670 to a monitor through VGA. (Poor quality)
After that I have been almost a week working trying to getting images to PC and I think I'm about to kill myself because I haven't get it.
Them, now I would be happy getting one photo to a SDcard. I have this shield. http://www.ebay.es/itm/321234880652?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649
Then I would like you to guide me on how to do it, I know that it's done in you code and library but without some help I can not understand it at all. I would be very gratefull for a little guidance on which will be the
next steps.
Here is my main code, thus you could see what I am doing.
Code: [Select]
#include <Wire.h>
#include <VGA.h>
#include <Ov7670.h>
Ov7670 ov7670;
volatile unsigned int pixelCount, lineCount;
boolean startLine,startFrame;
byte lineData[COLS*2];
void setup()
{
Serial.begin(115200);
Wire.begin();
ov7670.begin();
//ov7670.readAll();
attachInterrupt(HREF_PIN, hrefRising, RISING);
attachInterrupt(VSYNC_PIN, vsyncFalling, FALLING);
//VGA.begin(320,240,VGA_COLOUR);

// Start serial comunication


// Enable I2C
// Prepare Camera
// Read the camera's Bank Register
// Activate an interrupt when HREF goes up
// Activate an interrupt when VSYNC goes down
// Enable VGA Output

}
void loop()
{
if (startLine)
{
startLine = false;
while (pixelCount < COLS)
{
// First byte
while(!PCLK);
lineData[pixelCount*2] = DATA;
while(PCLK);
// Second byte
while(!PCLK);
lineData[pixelCount*2+1] = DATA;
while(PCLK);
pixelCount++;
}
//HERE SEND A LINE
}
}
void hrefRising()
{
noInterrupts();
startLine = true;
lineCount++;
pixelCount = 0;
interrupts();
}
void vsyncFalling()
{
noInterrupts();
//Serial.print(0x46,HEX);
startFrame=true;
lineCount = 0;
interrupts();
}

29 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

where <Ov7670.h> is my own library I have been doing


Thanks in advance,
Aitor
Title: Re: ov7670 with both arduino uno and now mega
Post by: Animat on Nov 26, 2013, 07:41 am
Hello, I tried Your settings Bayer_Raw_VGA. And here is a picture.
Settings:
const struct sensor_reg ov7670_default_regs_DRK[] PROGMEM = {
//{ REG_COM7, COM7_RESET },
//
// Clock scale: 3 = 15fps
//
2 = 20fps
//
1 = 30fps
{ REG_CLKRC, 0x80 },
// OV: clock scale (30 fps) [26 funciona]
{ REG_TSLB, 0x0D/* TSLB_YVYU */ }, // OV
{ REG_COM7, 0x01 },
// YUV VGA
{ REG_COM17, 0x08 },
//color_bar
//
// 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, 0x00 }, // Usar COM10_PCLK_HB para frenar el clock en el blank
// Gamma curve values //
{ 0x7a, 0x20 },
{ 0x7c, 0x1e },
{ 0x7e, 0x5a },
{ 0x80, 0x76 },
{ 0x82, 0x88 },
{ 0x84, 0x96 },
{ 0x86, 0xaf },
{ 0x88, 0xd7 },

{ 0x7b, 0x10 },
{ 0x7d, 0x35 },
{ 0x7f, 0x69 },
{ 0x81, 0x80 },
{ 0x83, 0x8f },
{ 0x85, 0xa3 },
{ 0x87, 0xc4 },
{ 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, 0x4A }, { 0x74, 0x10 }, // DVL 0x4A ?? 0x04
{ 0x8d, 0x4f },
{ 0x8e, 0 },
{ 0x8f, 0 },
{ 0x90, 0 },
{ 0x91, 0 },
{ 0x96, 0 },
{ 0x9a, 0 },
{ 0xb0, 0x84 },
{ 0xb1, 0x0c },
{ 0xb2, 0x0e },
{ 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"

30 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

{ 0x6a, 0x40 },
{ REG_BLUE, 0x40 }, // 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 },
{ 0xa4, 0x88 },
{ 0x97, 0x30 },
{ 0x99, 0x30 },
{ 0x9b, 0x29 },
{ 0x9d, 0x4c },
{ 0x78, 0x04 },

{ REG_COM11, COM11_EXP|COM11_HZAUTO|COM11_50HZ },
{ 0x96, 0 },
{ 0x98, 0x20 },
{ 0x9a, 0x84 },
{ 0x9c, 0x03 },
{ 0x9e, 0x3f },

// 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 },
};
Title: Re: ov7670 with both arduino uno and now mega
Post by: Animat on Nov 26, 2013, 10:39 am
Can't understand what sequence set to get a good image.
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Nov 26, 2013, 11:22 am
Can you post the RAW data so I can test that with my decoder?
Title: Re: ov7670 with both arduino uno and now mega
Post by: Animat on Nov 26, 2013, 12:17 pm
Settings:
const struct sensor_reg ov7670_default_regs_DRK[] PROGMEM = {
//{ REG_COM7, COM7_RESET },
//
// Clock scale: 3 = 15fps
//
2 = 20fps
//
1 = 30fps
{ REG_CLKRC, 0x80 },
// OV: clock scale (30 fps) [26 funciona]
{ REG_TSLB, 0x0D/* TSLB_YVYU */ }, // OV
{ REG_COM7, 0x01 },
// YUV VGA
{ REG_COM17, 0x08 },
//color_bar
//
// 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, 0x00 }, // Usar COM10_PCLK_HB para frenar el clock en el blank
// Gamma curve values //
{ 0x7a, 0x20 },
{ 0x7c, 0x1e },
{ 0x7e, 0x5a },
{ 0x80, 0x76 },
{ 0x82, 0x88 },

31 of 96

{ 0x7b, 0x10 },
{ 0x7d, 0x35 },
{ 0x7f, 0x69 },
{ 0x81, 0x80 },
{ 0x83, 0x8f },

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...


{ 0x84, 0x96 },
{ 0x86, 0xaf },
{ 0x88, 0xd7 },

http://forum.arduino.cc/index.php?action=printpa...

{ 0x85, 0xa3 },
{ 0x87, 0xc4 },
{ 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, 0x4A }, { 0x74, 0x10 }, // DVL 0x4A ?? 0x04
{ 0x8d, 0x4f },
{ 0x8e, 0 },
{ 0x8f, 0 },
{ 0x90, 0 },
{ 0x91, 0 },
{ 0x96, 0 },
{ 0x9a, 0 },
{ 0xb0, 0x84 },
{ 0xb1, 0x0c },
{ 0xb2, 0x0e },
{ 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 }, // 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 },
{ 0xa4, 0x88 },
{ 0x97, 0x30 },
{ 0x99, 0x30 },
{ 0x9b, 0x29 },
{ 0x9d, 0x4c },
{ 0x78, 0x04 },

{ REG_COM11, COM11_EXP|COM11_HZAUTO|COM11_50HZ },
{ 0x96, 0 },
{ 0x98, 0x20 },
{ 0x9a, 0x84 },
{ 0x9c, 0x03 },
{ 0x9e, 0x3f },

// 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 },
};

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

32 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Post by: Animat on Nov 26, 2013, 12:37 pm


With the other settings the picture
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Nov 26, 2013, 01:09 pm
We need some help from MR_arduino here. The RAW data has only bytes in AAh and 15h which doesn't look like a coloured image to me. But I'm not sure what could be wrong.
Title: Re: ov7670 with both arduino uno and now mega
Post by: aturcitu on Nov 26, 2013, 01:56 pm
Hi drkblog, sorry if I'm too daring But I have seen that you also have great background with this project, maybe you could help me with my post above ?
Thank you !
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Nov 26, 2013, 02:05 pm
Quote from: aturcitu on Nov 26, 2013, 01:56 pm
Hi drkblog, sorry if I'm too daring But I have seen that you also have great background with this project, maybe you could help me with my post above ?

No problem!
As far as I understand, you have successfully passed images from the sensor to RAM. You said you have enough RAM, which RAM are you talking about?
Then you tried to pass images to the PC (how?)
For storing the image to an SD card, you will have to start by having the entire frame in RAM because SD is slow (compared to the image sensor) and write speed in the card isn't constant. And you have to write
blocks of 512 bytes, even if you don't use FAT file system. So, the best approach here is you start by creating a separated project for writing to the SD card. That's very easy, you have a lot of sample code out
there. Once you have the SD module working, you can think of merging both projects: the one which passes images to RAM, and the one which writes to SD.
I've made two assumptions here so I will wait your answer before going further.
Title: Re: ov7670 with both arduino uno and now mega
Post by: aturcitu on Nov 26, 2013, 05:24 pm
Tahnks!
Arduino DUE has 96 KBytes of SRAM.
Now I am working with QQVGA (160*120) that if I am not wrong would be more or les 40 Kbytes.
I tried with Processing through Serial port. But I fail.
And what about que image processing? SD libraries incloude the functions needed to convert this amount of bytes into a png/jpeg image?
Thanks Again! :)
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Nov 26, 2013, 05:44 pm
Quote from: aturcitu on Nov 26, 2013, 05:24 pm
Tahnks!
Arduino DUE has 96 KBytes of SRAM.
Now I am working with QQVGA (160*120) that if I am not wrong would be more or les 40 Kbytes.

Yes, if you use two bytes per pixel.


Quote
I tried with Processing through Serial port. But I fail.

That can be tricky but it's possible if you are passing data from RAM to serial port. It won't work from OV7670 to serial port because it isn't fast enough.
Quote
And what about que image processing? SD libraries incloude the functions needed to convert this amount of bytes into a png/jpeg image?

I don't think SD library does JPEG encoding but you could find a proper library for that. Any way it would be better if you can delegate that task to another part of your project. Arduino processing power is limited.
Quote
Thanks Again! :)

No problem!
Title: Re: ov7670 with both arduino uno and now mega
Post by: aturcitu on Nov 26, 2013, 05:49 pm
Quote
I don't think SD library does JPEG encoding but you could find a proper library for that. Any way it would be better if you can delegate that task to another part of your project. Arduino processing power is limited.

What do you mean? saving only the bytes as text and them process it on PC side? :O
Great!
Title: Re: ov7670 with both arduino uno and now mega
Post by: xKoldFuzionx on Nov 27, 2013, 12:19 am

33 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Quote from: drkblog on Nov 26, 2013, 05:44 pm


I don't think SD library does JPEG encoding but you could find a proper library for that. Any way it would be better if you can delegate that task to another part of your project. Arduino processing power is limited.

can you elaborate? I was using the SD library for another project(VC0706), but I've been thinking of trying the SdFat library, cuz as I understand it, you can save the time/date the file was written to the file, so it
can be read by a computer. As soon as I get an RTC, I plan on trying to implement it.
By doing JPEG encoding, you mean taking it from the RAW Bayer and converting it to JPEG? Or am I missing something more on this?
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Nov 27, 2013, 01:17 am
Quote from: aturcitu on Nov 26, 2013, 05:49 pm
What do you mean? saving only the bytes as text and them process it on PC side? :O

No. Where do the text thing come from?


If you have a frame in RAM, all you have is a bunch of bytes (let say 160 x 120 x 2 bytes), a big block of 38,400 bytes. In whatever format the sensor can output (Bayer, bayer raw, RGB, etc). Then you can save
this block on a SD card, as a file. It won't be a text file because you are not saving a block of text, but a block of bytes including values outside text range. Remember that the only thing that makes a file, a text
file, is it contains ASCII printable character bytes. But this is only a conventional definition. Like the .TXT extension in Windows.
So, if you save that block to a file on the SD card, you get a binary file with the entire frame. Just like the file you posted before. You can then convert that file into JPEG or PNG or whatever format you need. But
this new file is just another binary representation of the frame. Same thing, different format. Of course, a JPEG will use less space because it is usually compressed. But then you are loosing information at some
point. And you have to spend some processing power for converting the raw binary frame from the sensor into a JPEG or PNG.
Now, having that in mind you can think if you really need to convert the frame into a JPEG file in the Arduino. Or you can do that afterwards over a PC:
Let's suppose you build an Arduino powered timelapse device which takes a picture every minute during all night (pointing to the sky). And save every picture to an SD card. There is no reason for converting the
file into JPEG using the Arduino. You can do that on your PC the next day, running a batch process over the set of raw pictures you have.
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Nov 27, 2013, 01:23 am
Quote from: xKoldFuzionx on Nov 27, 2013, 12:19 am
can you elaborate? I was using the SD library for another project(VC0706), but I've been thinking of trying the SdFat library, cuz as I understand it, you can save the time/date the file was written to the file, so it can be read by a computer. As soon as I get an RTC, I plan
on trying to implement it.

I don't know the difference between them. SDFat library writes using FAT file system, obviously. Which is the format usually used for SD cards by a computer or digital camera. I guess both libraries allow for
writing blocks on the SD card without following FAT specification. Which saves you some time, but then you have a non-standard SD format and you will have to build a special reader on the other end (where
you put the SD card once it was written by the Arduino).
Quote from: xKoldFuzionx on Nov 27, 2013, 12:19 am
By doing JPEG encoding, you mean taking it from the RAW Bayer and converting it to JPEG? Or am I missing something more on this?

Of course, JPEG encoding is exactly that.


Title: Re: ov7670 with both arduino uno and now mega
Post by: xKoldFuzionx on Nov 27, 2013, 02:40 am
Thank you, appreciate that info.
As for the two libraries, all I know is that SD was written(simplified) from SdFat. But one thing I've noticed is that it's over-simplified(great to learn with, but limits your options). I just wasn't sure if I was reading
something into that about the library itself being able to convert the image to JPEG while being saved to the SdCard.
Total newb, just been watching this for some time. I have an OV7670(non-FIFO) I haven't even touched yet. I've mainly been fooling around with the VC0706 module, getting the hang of things, especially
writing code. I purchased an OV5642 and am waiting for it to arrive. I haven't experimented much with the electronics side as of yet, so hooking everything up confuses me. But, I'm looking forward to playing
around with one of them soon.
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Nov 27, 2013, 02:52 am
A properly written SD card library should do something like encoding JPEG. Of course, it is up to the guys who write the library. But for the sake of proper order, JPEG encoding should be in a JPEG library :)
Working with these sensors is hard even for someone with knowledge about electronics. It doesn't mean you won't make it, but it isn't going to be easy.
One good recommendation is to split the problem into parts which you can build and test by its own. Once you have parts working, you try to integrate them.
Title: Re: ov7670 with both arduino uno and now mega
Post by: xKoldFuzionx on Nov 27, 2013, 11:24 am
Quote from: drkblog on Nov 27, 2013, 02:52 am
A properly written SD card library should do something like encoding JPEG. Of course, it is up to the guys who write the library. But for the sake of proper order, JPEG encoding should be in a JPEG library :)

That's good to know. So essentially, since the OV7670/OV5642 family mostly does RAW, YUV, etc, I should be able to find a library that will convert them to JPEG? Which brings me to my next question,
compression. Less compression provides better quality JPEG images? So, like on the VC0706 I can set the compression ratio from 0-255(00 - FF, in HEX), so a setting of 0 would be no compression and a
higher quality pic, where as FF would be a lower quality due to compression causing some loss in data?
Quote
Working with these sensors is hard even for someone with knowledge about electronics. It doesn't mean you won't make it, but it isn't going to be easy.

well, I've learned in 34 years of living that nothing worthwhile comes easy. I decided about 6 months ago I wanted to build my own Trail Cameras cuz I'm tired of the ones I've purchased. With the VC0706, I've
got one working(minus a few components and a desperate need for some power saving routines). It hasn't been easy, but it's been an adventure. :)
Quote

34 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

One good recommendation is to split the problem into parts which you can build and test by its own. Once you have parts working, you try to integrate them.

Exactly what I've been doing with this other module. I started with the camera, sending data, receiving, etc. Then have been integrating other components once I'm happy tweaking the existing. For example,
right now, I'm working on a menu system with a 16x2 LCD screen(small, challenging, but it's all I have at the moment). I fail, then get back on the horse and keep on trying, when that fails, I try something else.
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Nov 27, 2013, 11:43 am
Quote from: xKoldFuzionx on Nov 27, 2013, 11:24 am
Quote from: drkblog on Nov 27, 2013, 02:52 am
A properly written SD card library shouldn't do something like encoding JPEG.
That's good to know. So essentially, since the OV7670/OV5642 family mostly does RAW, YUV, etc, I should be able to find a library that will convert them to JPEG? Which brings me to my next question, compression. Less compression provides better quality JPEG
images? So, like on the VC0706 I can set the compression ratio from 0-255(00 - FF, in HEX), so a setting of 0 would be no compression and a higher quality pic, where as FF would be a lower quality due to compression causing some loss in data?

I fixed my previous answer: usually it's better to have one library for one purpose (like writing SD cards) and adding functionality outside it's main purpose is a bad idea. So I don't think SD libraries do JPEG
encoding.
Less compression leads to better quality, but I'm not sure if you can have no-compression at all when encoding JPEG. There is a difference between compression (using less space/bandwidth at the cost of
loosing some data) and data compaction (using less space/bandwidth without loosing data). If you don't want to loose any data, JPEG won't be of much help as you will end up with a bigger file than your RAW
frame file. As JPEG has to introduce a header, and then represent all your data in the file. In the other hand, your RAW frame has no header information. You can interpret the file because you know beforehand
it's a frame of a given resolution and format. If you send the file to someone else, you have to inform that too. The JPEG format (as every know image format) has a header for that.
Quote from: xKoldFuzionx on Nov 27, 2013, 11:24 am
well, I've learned in 34 years of Exactly what I've been doing with this other module. I started with the camera, sending data, receiving, etc. Then have been integrating other components once I'm happy tweaking the existing. For example, right now, I'm working on a
menu system with a 16x2 LCD screen(small, challenging, but it's all I have at the moment). I fail, then get back on the horse and keep on trying, when that fails, I try something else.

That's how electronics works, even for engineers when the project is challenging.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Animat on Nov 27, 2013, 12:39 pm
Almost did, image:
Title: Re: ov7670 with both arduino uno and now mega
Post by: xKoldFuzionx on Nov 27, 2013, 12:49 pm
Lmao, glad you fixed that. I'd have been pissed when I couldn't figure out how to compress JPEG with SdFat. Lol.
As for compression, thanks for explaining that. For now, JPEG is just easier. That's why I ordered the OV5642 cuz it can do JPEG.
And good to know that everyone struggles with tough jobs, ensures I have my work cut out for me. :)
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Nov 27, 2013, 01:12 pm
Quote from: xKoldFuzionx on Nov 27, 2013, 12:49 pm
Lmao, glad you fixed that. I'd have been pissed when I couldn't figure out how to compress JPEG with SdFat. Lol.

Big typo.
Quote from: xKoldFuzionx on Nov 27, 2013, 12:49 pm
As for compression, thanks for explaining that. For now, JPEG is just easier. That's why I ordered the OV5642 cuz it can do JPEG.

Well. Having a sensor which outputs JPEG saves you the cost of processing the encoding. But, as far as I know, you won't get a frame free of compression from such a sensor. And if you have to process the
image in the Arduino, you have to decode JPEG first. Which is why OV7670 is better in such cases.
In the end, you have to use the right sensor according to your project. If you just want to save a JPEG image to SD for using over a computer later, using a JPEG-enabled sensor makes sense. Because you
save space and time.
I didn't say this before: I don't think you will find a JPEG library for Arduino. As it isn't intended for such job. Encoding/decoding JPEG needs a lot of RAM. You have to keep in mind the Arduino isn't a computer.
Of course, we take Arduino to its limits all the time. That's the idea. But you have to keep one foot on the earth. And think about the project as a whole.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Chocobot on Nov 27, 2013, 07:42 pm
Hello, I've been trying to get this to work the past few days. I have an Arduino Uno, the camera module (I'm thinking without fifo, it has 18 pins) and a bunch of cables. At this point I just want to send a single
image from the camera over serial, nothing special with sd cards or such (I don't have the right stuff for it anyway). I've been reading trough this thread and other parts of the internet to get it to work but I haven't
made any progress so far.
Specifically I'm asking for this:
-A schematic (or description of one) of which pins I need to connect with what. I've seen the one on the first page (reply 2), but I think it's outdated, since it doesn't use the PWM as clock.
-The basic code to communicate with the camera. So if I type something in the serial box of the arduino IDE, it sends it to the camera and then sends back the camera's reply.
-Some code to properly receive the data the camera sends back with the d0-7 pins.
I've seen the huge lists of registers, I don't think they're needed in the code itself if I use serial to operate the camera?

So far I'm thinking this:


The schematic, is this ok? http://i167.photobucket.com/albums/u157/cookiebal/OV7670ArduinoUno.jpg
As for the code, I've been looking at http://pastebin.com/1nnRc5qL , I'm not very familiar with the language so I don't really understand everything. But so far I'm thinking that I'd need to add this (from page 4,
reply 57) somewhere at the start to get the clock working.
Code: [Select]
DDRB|=(1<<3);//pin 11
ASSR &= ~(_BV(EXCLK) | _BV(AS2));

35 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

TCCR2A=(1<<COM2A0)|(1<<WGM21)|(1<<WGM20);//this also results in 67 but I wanted to clean up magic numbers


TCCR2B=(1<<WGM22)|(1<<CS20);
OCR2A=0;

Then there are a whole bunch of writes to registers or something in a bunch of if statements, I suppose that's the settings?
Then the loop, it's difficult to read because of the #if stuff, but I think I should just ignore everything between #else and #endif? And then edit out all the SD related stuff and write to serial instead of the SD card?
Another problem is that I can't see where it gets the data from the D7-0 pins. I'd guess somewhere in captureImg but I don't really understand what's going on there, except a bunch of looping. Does it write
directly to the memory or something? Either way, I think I need to get the values of the pins connected to D7-0 and store it somewhere every time HREF changes? I've read it somewhere but the pin connection
in the second post in this thread doesn't mention it.
I guess it's more efficient the way this is written, but it's not helping me much :P
For the communication I'm trying to use Wire like in the wrReg function in http://pastebin.com/1nnRc5qL but I'm not getting any responses, so I guess I did it wrong.
I'm using this to read:
Code: [Select]
Wire.requestFrom(0x42, 6);
while(Wire.available()) {
char c = Wire.read();
Serial.print(c);
}

Will this work for getting the image data from d0-7?
Code: [Select]
while (digitalRead(HREF) == 1){
while(digitalRead(PCLK) == 1){}
for (int i=0; i < = 7; i++){
//get stuff from each parallel data pin
}

My apologies if I've been asking stuff that's already answered. Because of all the different things (uno/mega, fifo, and such) it's been hard to figure out what is relevant.
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Nov 27, 2013, 09:16 pm
First of all: If you want to make it work, you have to know whether you have a FIFO or non-FIFO module. Basically the FIFO module has a AL422B chip in the back of the module. In the other hand, no matter
which module you have, there is no way of passing a frame from the module to the serial port without storing the entire frame in Arduino's RAM.
As you guessed the schematic and code needed for both cases is already posted here. So I think that a good reason for not reposting. The explanation about the impossibility of passing a frame without enough
RAM is already posted too.
The schematic you posted is ok (as far as I can see) for a non-FIFO version. But the code you are referring uses a SPI RAM chip for storing 1/5 of a frame at a time while it's saved to the SD card. That means
your scene has to be steady if you want good picture.
The code which starts with "DDRB|=(1<<3)" should be in the setup() function. That will output a clock at pin 11 (according to the comment) which you are connecting to XCLK (which is ok). You have to source a
clock to this module to make it alive. Then you HAVE to pass ALL those registers if you want to get an image from the sensor.
If you can't get a response from the sensor (like reading the value of a register) don't try to go further. You have to be able to communicate with the sensor first. Most common reason for this to fail is a bad or
non-existing XCLK. If you have a oscilloscope you can check Arduino pin 11 to see that you have there. If you don't have one, you are pretty much in trouble. You have to be sure the code you are merging
doesn't conflict on that pin. I mean, if there is another configuration over pin 11 in the code, that could be a cause for the problem.
Title: Re: ov7670 with both arduino uno and now mega
Post by: aturcitu on Nov 28, 2013, 03:03 pm
Hi everybody, today I have recived my fifo version. It has supposed to be an v2 but it's not.
I have the new v3 version but I can't find relevant information about this version, Does anybody know if it has any important different I would have to take into account?
Anyway, I also would like to ask if somebody could help me undesrtanding with three lines of explanation what is the fifo funcionality like. Only explaining the differences with the non-fifo version regarding the
data capturing.
Thanks, I love your project :)
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Nov 28, 2013, 03:17 pm
Quote from: aturcitu on Nov 28, 2013, 03:03 pm
I have the new v3 version but I can't find relevant information about this version, Does anybody know if it has any important different I would have to take into account?

Ask the seller for a datasheet. Do you have a link to the product on ebay or something?
Quote from: aturcitu on Nov 28, 2013, 03:03 pm
Anyway, I also would like to ask if somebody could help me undesrtanding with three lines of explanation what is the fifo funcionality like. Only explaining the differences with the non-fifo version regarding the data capturing.

FIFO First In First Out is a special kind of RAM memory. In this case you have a chip which can store up to one frame of 640x480x1 bytes. The chip has two interfaces input and output. Input is connected to the
datalines of the OV7670 so all you have to do is to reset the FIFO write pointer and trigger write enable line when the signaling of the sensor tells you a new frame has started. And then disable FIFO's write line
when the frame has ended. You do that by reading VSYNC signal.
At this point you have a frame saved into the FIFO memory as long as you don't enable write again and you don't turn the module off. You have to read the frame using FIFO's output interface which is exposed
to you. You have to provide a reading clock of at least 1MHz and (at least for the modules I know) you have to read the entire frame at once. You can't do it at parts as I explained before in this thread.
Title: Re: ov7670 with both arduino uno and now mega
Post by: aturcitu on Nov 28, 2013, 03:21 pm
Excellent explanation, this weekend I will work it out!
The camera module is
http://www.ebay.es/itm/180946265217?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649
In the photos is the v2.. I will contact with the seller! I have feed the camera and checked vsync and href are working!

36 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Thanks
EDIT: In the clk I have to use to read the data what it is the best way to generated?
With pwm and creating some interrups? Can I create interrupts with output signals? or I would have to reconected to an input?
Or maybe : (put pin up, read, put pin down... ) I suppose the first one..haha
Title: Re: ov7670 with both arduino uno and now mega
Post by: xKoldFuzionx on Nov 28, 2013, 05:32 pm
Quote from: drkblog on Nov 27, 2013, 01:12 pm
In the end, you have to use the right sensor according to your project. If you just want to save a JPEG image to SD for using over a computer later, using a JPEG-enabled sensor makes sense. Because you save space and time.

Yeah, I just need it to be a JPEG right away. For simplicity alone, having a module that can process it as JPEG simplifies the whole thing.
Quote
I didn't say this before: I don't think you will find a JPEG library for Arduino. As it isn't intended for such job. Encoding/decoding JPEG needs a lot of RAM. You have to keep in mind the Arduino isn't a computer. Of course, we take Arduino to its limits all the time. That's the
idea. But you have to keep one foot on the earth. And think about the project as a whole.

Yeah, I looked before and couldn't find one. That makes sense. I thought about getting a Pi and trying that, but I've just invested 6 months into learning how to code with Arduino and I've almost got a finished
product. If I switch over, I have to learn a new method and go through it all over again. Lol, eventually, I'd like to learn to do both, but for now, the Arduino seems to be able to handle what I need it to do. I'm
hoping that after this is built, I can produce and sell them. But, of course, I need to get it into the field for at least 6 months to test it out and tweak it. I'm just quite honestly impressed with how quickly this has all
come together. I didn't expect that after I started diving in.
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Nov 28, 2013, 11:16 pm
Quote from: aturcitu on Nov 28, 2013, 03:21 pm
In the clk I have to use to read the data what it is the best way to generated?
With pwm and creating some interrups? Can I create interrupts with output signals? or I would have to reconected to an input?
Or maybe : (put pin up, read, put pin down... ) I suppose the first one..haha

I use pin up/ pin down approach:


Code: [Select]
digitalWrite(OE, LOW); //?
digitalWrite(RRST, LOW);
PORTE
PORTE
PORTE
PORTE

&=
|=
&=
|=

B11101111;
B00010000;
B11101111;
B00010000;

//
//
//
//

digitalWrite(RCLK,
digitalWrite(RCLK,
digitalWrite(RCLK,
digitalWrite(RCLK,

LOW);
HIGH);
LOW);
HIGH);

digitalWrite(RRST, HIGH);
digitalWrite(OE, HIGH);
digitalWrite(OE, LOW);
for(uint16_t i = 0; i <= (W * B * H); i++) {
PORTE |= B00010000; // digitalWrite(RCLK, HIGH);
unsigned char data = (uint8_t)PINA;
PORTE &= B11101111; // digitalWrite(RCLK, LOW);
// do something with data
}
digitalWrite(OE, HIGH);
}

First lines reset the read clock, then the loop reads the bytes computed by multiplying Width x Height x BytesPerPixel. Inside the loop you see the pin up / read / pin down sequence. After that you have to do
something with the value in data. You have to be quick because this loop has to run 1.000.000 times per second in order to keep the AL422B in sync. In fact you see I don't use digitalWrite() call, I'm using direct
port manipulation which is faster. But you have to change that for every Arduin Board (UNO, Mega, etc). I commented the lines with the proper code to keep it more readable. I used defines for pin numbers with
the names of the pins in my module which should be pretty much like yours.
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Nov 28, 2013, 11:21 pm
Quote from: xKoldFuzionx on Nov 28, 2013, 05:32 pm
Yeah, I looked before and couldn't find one. That makes sense. I thought about getting a Pi and trying that, but I've just invested 6 months into learning how to code with Arduino and I've almost got a finished product. If I switch over, I have to learn a new method and go
through it all over again. Lol, eventually, I'd like to learn to do both, but for now, the Arduino seems to be able to handle what I need it to do. I'm hoping that after this is built, I can produce and sell them. But, of course, I need to get it into the field for at least 6 months to
test it out and tweak it. I'm just quite honestly impressed with how quickly this has all come together. I didn't expect that after I started diving in.

Been there before. In my case I have to work with 640x480 frames without compression and save at least four or five frames per second during 6 seconds. I started using Arduino but switched to Pi because I
was about to spend more money by staying in Arduino. I'm experienced with C/C++ so switching bewteen them wasn't a problem. Pi runs a multitasking environment which in turn comes with its own issues when
you have to access hardware in real-time. But it's working now. :)
Title: Re: ov7670 with both arduino uno and now mega
Post by: xKoldFuzionx on Nov 29, 2013, 06:28 pm
Quote from: drkblog on Nov 28, 2013, 11:21 pm
Been there before. In my case I have to work with 640x480 frames without compression and save at least four or five frames per second during 6 seconds. I started using Arduino but switched to Pi because I was about to spend more money by staying in Arduino. I'm
experienced with C/C++ so switching bewteen them wasn't a problem. Pi runs a multitasking environment which in turn comes with its own issues when you have to access hardware in real-time. But it's working now. :)

Wow, a frame per second? That's crazy!


So, by a multitasking environment, you're saying that if I had a camera, clock, lcd, and temp sensor(all just for example), I could read/write to all of them at the exact same time? Sorry for the stupidity in this
question, I'm just a little slow sometimes understanding things, so I have to break it down so I can understand. Plus, I tend to misunderstand a lot, this way I ensure I'm on the same page.

37 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Nov 29, 2013, 07:11 pm
Quote from: xKoldFuzionx on Nov 29, 2013, 06:28 pm
Wow, a frame per second? That's crazy!

Up to five frames per second, actually.


Quote from: xKoldFuzionx on Nov 29, 2013, 06:28 pm
So, by a multitasking environment, you're saying that if I had a camera, clock, lcd, and temp sensor(all just for example), I could read/write to all of them at the exact same time? Sorry for the stupidity in this question, I'm just a little slow sometimes understanding things, so
I have to break it down so I can understand. Plus, I tend to misunderstand a lot, this way I ensure I'm on the same page.

Nope. Multitasking is sharing the CPU among several programs, one program at a time. When a given program is using the CPU, all the rest are paused. And from the program point of view, you don't know
when that happens. So if you are polling an input pin for a level, and waiting for a change. You could miss one or several level changes if you were paused by the kernel.
http://en.wikipedia.org/wiki/Computer_multitasking (http://en.wikipedia.org/wiki/Computer_multitasking)
Title: Re: ov7670 with both arduino uno and now mega
Post by: xKoldFuzionx on Nov 29, 2013, 07:22 pm
Quote from: drkblog on Nov 29, 2013, 07:11 pm
Up to five frames per second, actually.

Wow, that is nuts. What do you need so many FPS for? If you don't mind me asking? What's the project you're working on?
Quote
Nope. Multitasking is sharing the CPU among several programs, one program at a time. When a given program is using the CPU, all the rest are paused. And from the program point of view, you don't know when that happens. So if you are polling an input pin for a level,
and waiting for a change. You could miss one or several level changes if you were paused by the kernel.
http://en.wikipedia.org/wiki/Computer_multitasking (http://en.wikipedia.org/wiki/Computer_multitasking)

Ok, I think I understand that now. So what is an Arduino then? Single process, because it's not an actual computer?
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Nov 29, 2013, 09:09 pm
I have to capture a passing objects at different speeds (within a range).
Arduino is a computer (in the end) but working in real time. It has a single process (whatever you load into it) and no operating system. Your program is the only one using the CPU.
Title: Re: ov7670 with both arduino uno and now mega
Post by: xKoldFuzionx on Nov 29, 2013, 10:12 pm
Interesting.
Ok, that makes sense then.
Title: Re: ov7670 with both arduino uno and now mega
Post by: aturcitu on Dec 02, 2013, 03:30 pm
Hello again !
I have some doubts drkblog,
First of all, this part of the code is clear:
Code: [Select]
digitalWrite(OE, LOW);
for(uint16_t i = 0; i <= (W * B * H); i++) {
PORTE |= B00010000; // digitalWrite(RCLK, HIGH);
unsigned char data = (uint8_t)PINA;
PORTE &= B11101111; // digitalWrite(RCLK, LOW);
// do something with data
}
digitalWrite(OE, HIGH);

But not that one:


Code: [Select]
digitalWrite(OE, LOW); //?
digitalWrite(RRST, LOW);
PORTE
PORTE
PORTE
PORTE

&=
|=
&=
|=

B11101111;
B00010000;
B11101111;
B00010000;

//
//
//
//

digitalWrite(RCLK,
digitalWrite(RCLK,
digitalWrite(RCLK,
digitalWrite(RCLK,

LOW);
HIGH);
LOW);
HIGH);

digitalWrite(RRST, HIGH);
digitalWrite(OE, HIGH);

I thought you had to wait for vsync rising edge (once you have the signal inverted) for the reset. And why are pulling two bytes before start?
Thanks! you are always helpful!
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Dec 02, 2013, 04:32 pm

38 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Those signals you ask about are needed for resetting the read pointer. As you can see there is no addressing information in this memory. Once you read a byte, on the next read clock you get the next byte, and
so on. So for starting reading from the first memory byte you have to reset the read pointer.
Check last figure of page 9: http://www.frc.ri.cmu.edu/projects/buzzard/mve/HWSpecs-1/Documentation/AL422B_Data_Sheets.pdf
Title: Re: ov7670 with both arduino uno and now mega
Post by: aturcitu on Dec 02, 2013, 11:15 pm
Perfect, I have written my code, the main core look like this:
Code: [Select]
void loop()
{
//WRITING ON FIFO
OE_SET;
// Output high impedance
WEN_CLR;
onFrame=false;
while(!onFrame);
onFrame=false;
while(!onFrame);
WEN_SET;

// Enable writing

RRST_CLR;

// Reset reading pointer

RCLK_CLR;
RCLK_SET;
RCLK_CLR;
RCLK_SET;

// Waits for 2 RCLK

RRST_SET;

// Pointer is Reset

OE_CLR;

// Enables reading

// New frame starts


// An entire frame have been writing on FIFO
// Disable writing

//PULLING DATA
for(int i=0; i<COLS*ROWS*BYTES;i++)
{
RCLK_SET;
frame[i]=DATA;
RCLK_CLR;
}
//Do somithing with data
}
void vsync_rising()
{
noInterrupts();
onFrame = true;
interrupts();
}

Working in YUV and with the camera covered I should read 0x0,0x81,0x0... the entire frame?
Do you have any suggest for improve my code or maybe you can see any error?
In some days I'll be able to try the sd Card. Tomorrow I also will post some photo of my scope!
Thanks everybody
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Dec 02, 2013, 11:27 pm
Yes, for YUV no bayer (which implies two bytes per pixel) you should see 0x00 0x81 ...
But take into account that you can't place a 640x480x2 bytes frame in the FIFO.
The code looks ok but, is it working?
Title: Re: ov7670 with both arduino uno and now mega
Post by: Animat on Dec 03, 2013, 11:14 am
Hi, how to fix the image with the right edge?
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Dec 03, 2013, 01:34 pm
There is something wrong in your configuration yet. In my experience with this sensor there was times where I was about to get an image. But I was using a couple of registers out of value. In my case, I ended
up copying the registers from the Mr_arduino link and that fixed everything.
In your image there is a data loss somewhere. But I'm not sure what is the cause.
Title: Re: ov7670 with both arduino uno and now mega
Post by: aturcitu on Dec 03, 2013, 02:20 pm
It seems to be working properly, I post here all my code in case someone is also working with Arduino DUE may find it interesting.
Code: [Select]
#include <Wire.h>
//OV7670
#define ADDRESS
#define REGISTERS
//ARDUINO DUE PINTOUT
#define OE_PIN
#define VSYNC_PIN
#define WEN_PIN
#define RRST_PIN
#define RCLK_PIN
#define HREF_PIN
//CAMERA INPUTS
#define OE_SET
#define OE_CLR
#define WEN_SET
#define WEN_CLR
#define RRST_SET
#define RRST_CLR
#define RCLK_SET
#define RCLK_CLR
//CAMERA OUTPUTS
#define VSYNC

39 of 96

0x21
0x91

// Define address of OV7670


// Define # of Registesr on OV7076

44
45
46
47
48
49
PIOC->PIO_SODR=1<<19
PIOC->PIO_CODR=1<<19
PIOC->PIO_SODR=1<<17
PIOC->PIO_CODR=1<<17
PIOC->PIO_SODR=1<<16
PIOC->PIO_CODR=1<<16
PIOC->PIO_SODR=1<<15
PIOC->PIO_CODR=1<<15
REG_PIOC_PDSR>>18&0x1

// C.19

for writing

// C.17

for writing

// C.16

for writing

// C.15

for writing

// C.18

for reading

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...


#define HREF
#define DATA
//RESOLUTION
#define COLS
#define ROWS
#define BYTES

REG_PIOC_PDSR>>14&0x1
REG_PIOC_PDSR>>2&0xFF

http://forum.arduino.cc/index.php?action=printpa...

// C.14
for reading
// C.2 to C.9 for reading

160
120
2

volatile boolean onFrame;


byte frame[COLS*ROWS*BYTES];
void setup(void)
{
//INITIALIZATION
Wire.begin();
Serial.begin(115200);
cameraSetUp();
//readRegisterBank();
}

// Enable I2C
// Start serial comunication

void loop()
{
//WRITING ON FIFO
OE_SET;
// Output high impedance
WEN_CLR;
onFrame=true;
while(onFrame);
onFrame=true;
while(onFrame);
WEN_SET;

// Enable writing

RRST_CLR;

// Reset reading pointer

RCLK_CLR;
RCLK_SET;
RCLK_CLR;
RCLK_SET;
RCLK_CLR;

// Waits for 2 RCLK

RRST_SET;

// Pointer is Reset

OE_CLR;

// Enables reading

// The present frame ends


// An entire frame have been saved on the FIFO
// Disable writing

//PULLING DATA
for(int i=0; i<COLS*ROWS*BYTES;i++)
{
RCLK_SET;
frame[i]=DATA;
RCLK_CLR;
}
for(int i=0; i<COLS*ROWS*BYTES;i++)
{
Serial.print(frame[i],HEX);
Serial.println(", ");
delay(2);
}
Serial.println();
}
void vsync_falling() // A frame ends
{
noInterrupts();
onFrame = false;
interrupts();
}
void cameraSetUp()
{
//REGISTERS INICIALIZATION
write(0x12,0x80);
write(0x15,0x02);
write(0x11,0x82);

// Reset all the values


// VSYNC inverted
// Pescaler x3 (10 fps)

//QQVGA (160x120)
write(0x12,0x00);
write(0x0C,0x04);
write(0x3E,0x1A);
write(0x70,0x3A);
write(0x71,0x35);
write(0x72,0x22);
write(0x73,0xF2);
write(0xA2,0x02);
//SET FIFO'S CONTROLS AS AN OUTPUTS
pinMode(OE_PIN,
OUTPUT);
pinMode(WEN_PIN, OUTPUT);
pinMode(RRST_PIN, OUTPUT);
pinMode(RCLK_PIN, OUTPUT);
//ACTIVATE HREF, VSYNC AND PCLK INTERRUPTS
attachInterrupt(VSYNC_PIN, vsync_falling, FALLING);
}
void readRegisterBank()
{
int count=0;
byte tmp;
while(count<REGISTERS)
{
byte highByte=0;
Serial.print("\n Registro num: ");
Serial.println(count,HEX);
Wire.beginTransmission(ADDRESS);
Wire.write(count);
Wire.endTransmission();
Wire.requestFrom(ADDRESS, 1);
while(Wire.available() < 1);
highByte = Wire.read();
Serial.println(highByte,HEX);
delay(25);
count++;
}

//Start communication with cmps03


//Send the register we wish to read
//Request high byte
//While there is a byte to receive
//Read the byte as an integer

}
void write(byte address, byte val)
{
delay(5);
Wire.beginTransmission(ADDRESS);
Wire.write(address);
Wire.write(val);
Wire.endTransmission();
}

//
//
//
//

Start transmission to device


Send register address
Send value to write
End transmission

And doing this I got this through serial:


1,80,1,81,1,80,2,81,1,80,1,81,1,80,1,80,1,80,1,81,1,80,1,81,1,80,..... That it is almost the same that 0,81... I don't know why ! I'll revise the wires...
Title: Re: ov7670 with both arduino uno and now mega

40 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Post by: drkblog on Dec 03, 2013, 04:30 pm


Actually, now that you mention it, it should be 0x00 0x80 so check the LSB
Title: Re: ov7670 with both arduino uno and now mega
Post by: pgibbons66 on Dec 07, 2013, 01:07 am
Hi,
I'm trying to follow your setup step for step. I'm using a mega, an ethernet/sd shield and a non FIFO Ov7670. Im going to borrow some 23LC1024 ram from the lab.
regarding your code for clock output.:
DDRL|=8;
ASSR &= ~(_BV(EXCLK) | _BV(AS2));
//generate 8mhz clock
TCCR5A =67;
TCCR5B=17;
Where does that go in the code? does it replace
digitalWrite(10,HIGH);
DDRB|=47;//clock as output and SPI pins as output except MISO
PORTB|=6;//set both CS pins to high
DDRC&=~15;//low d0-d3 camera
DDRD&=~252;//d7-d4 and interupt pins
#ifdef useLed
DDRD|=1;//pin 0 as output
PORTD&=~1;//turn off led
//set pin 1 as input
DDRD&=~2;
PORTB|=2;//enable pullup
Finally a really amatuer question, when you pull up to A4 &A5 do you just add a 4.7k resistor between the line and the 3.3v pin on the arduino?
thanks in advance.
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Dec 07, 2013, 02:23 am
This is a question for Mr_arduino, but as he isn't posting a lot lately, I'm going to offer you my own opinion:
The code you refer to as "for clock output" is for generating an 8MHz clock with Arduino timer. In the first experiments both (Mr_ardunio and me) used the 16MHz clock from Arduino xtal instead of 8MHz
generated clock. Doing that required to change microcontroller fuses in order to output the clock on pin 8 (Arduino UNO). Then Mr_arduino tried the 8MHz approach. Which is a little under the theoretical
minimum clock for OV7670 which is 10MHz according to datasheet. But 8MHz works ok so far.
So you have to use both codes.
In my case I didn't use direct connection to the OV7670, I used this level conversion circuit (http://blog.drk.com.ar/2013/interfaz-logica-bidireccional-entre-5v-y-3-3v) (it's in spanish but you can check the figures).
But yes, you have to pull up to 3.3V those outputs and 4.7k should do. Don't forget to disable any Arduino buil-in pull up!
Title: Re: ov7670 with both arduino uno and now mega
Post by: xKoldFuzionx on Dec 07, 2013, 04:37 am
Quote from: drkblog on Dec 07, 2013, 02:23 am
Don't forget to disable any Arduino buil-in pull up!

Out of sheer curiousity, what would happen if you didn't? If the built in are higher resistance, I could see that being a problem, but if they're lower, you could just use a lower PU?
I really know nothing about the pull-ups built into Arduino. I read about them once, but don't remember anything. Lol, I just found out what a PU resistor was yesterday.
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Dec 07, 2013, 01:36 pm
Neither do I know how the internal pull-up is done. But I don't reckon it's a good idea having a node pulled up to two different power sources at the same time. If the node goes to 3.3V level, there will be a 1.7V
difference to the 5V pull-up which means a current will flow from the 5V source to somewhere (to the arduino, to the OV7670).
Title: Re: ov7670 with both arduino uno and now mega
Post by: sakeear on Dec 09, 2013, 06:42 am
Mr arduino!! i would like to know what kind of software are using to write this programmes?
Title: Re: ov7670 with both arduino uno and now mega
Post by: aturcitu on Dec 11, 2013, 10:11 pm
Hi again, drkblog .
I solved the problem with numbers, now I am getting the correct output with YUV (at least it seems), and I have set correctly up a SD Card to the arduino DUE. Then, now I can write a file with all the bytes.
But, What else? How can translate this amount of bytes to an image? Do you have any Program to do it? In case you have, Do I have to write with any header o any special order the bytes?
Thanks in advance.

Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Dec 11, 2013, 10:53 pm
Great!
Mr_arduino posted a github link to his converter in the first message in this thread (from YUV/BAYER to PNG). I use that program. Of course, you have to compile and run that over a PC with Linux or Cygwin.

41 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Title: Re: ov7670 with both arduino uno and now mega
Post by: aturcitu on Dec 12, 2013, 12:22 am
Okei, Im no used to using LInux, tomorrow I'll try!
In case It's easy for you to comprovate I have attached my first photo attempt.
Most sure it would be nothing but who knows.. haha
Its a 160x120 YUV Photo
Thanks :)
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Dec 12, 2013, 01:07 am
Here is it. For some reason I had to use 156 x 120 resolution in order to get a proper image.
Title: Re: ov7670 with both arduino uno and now mega
Post by: aturcitu on Dec 12, 2013, 12:02 pm
It was supposed to be my desktop... At least it is a coherent image.
Are there some magic registers I have to sep up in order to get a proper image?
At this moment I am only changing thist, the ones for the resolution and the ones for inverting vsync and reduce to 10 fps
Code: [Select]
//REGISTERS INICIALIZATION
write(0x12,0x80);
write(0x15,0x02);
write(0x11,0x82);

// Reset all the values


// VSYNC inverted
// Pescaler x3 (10 fps)

//QQVGA (160x120)
write(0x12,0x00);
write(0x0C,0x04);
write(0x3E,0x1A);
write(0x70,0x3A);
write(0x71,0x35);
write(0x72,0x22);
write(0x73,0xF2);
write(0xA2,0x02);

Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Dec 12, 2013, 12:09 pm
I guess what you have there is an image out of focus. And you won't be able to focus unless you can convert the image you get from the sensor. I have tested this command line with your data and it works:
ffmpeg -f rawvideo -s 156x120 -pix_fmt yuyv422 -i F0.yuv -f image2 -vcodec png output.png
Where F0.yuv is the file you posted and output.png is the converted image. The ffmpeg utility is availabe for windows here: http://ffmpeg.zeranoe.com/builds/
Title: Re: ov7670 with both arduino uno and now mega
Post by: aturcitu on Dec 12, 2013, 01:34 pm
Works properly!
I have taken a photo with QCIF resolution. First with colorbar enabled and after without.
The first weird thing is that I have to 173x144 resolution to obtain the correct colobar bar instead of 176x144
and the second one is that the normal photo doesn't really look very well... It's me, not a ghost!

Title: Re: ov7670 with both arduino uno and now mega
Post by: aturcitu on Dec 12, 2013, 05:15 pm
After a few attemps with the focus I get this!
But, as you can see I am missing the colors..
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Dec 12, 2013, 05:32 pm
This could be a wrong colour codification in the decoding side. You can ask ffmpeg to list all available pixel formats:
ffmpeg -pix_fmt list
Then you can replace yuyv422 in the conversion command with another format until you find one which works better.
Title: Re: ov7670 with both arduino uno and now mega
Post by: aturcitu on Dec 12, 2013, 09:09 pm
I have changed to rgb444 and once converted to png it have the sames colors as the YUV422 :(
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Dec 12, 2013, 09:13 pm
You will have to play with sensor configuration then. Save you current work and try using the whole set of registers from the posts in this thread until you get something different.
Title: Re: ov7670 with both arduino uno and now mega
Post by: aturcitu on Dec 12, 2013, 10:38 pm
I have noticed one thing... My the order of the colors on my colorbar are incorrent. What could be the explanation?

42 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

I have attach the color bar raw data. YUV422 QCIF (176x144)
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Dec 12, 2013, 10:49 pm
Post the command line you are using now.
Title: Re: ov7670 with both arduino uno and now mega
Post by: aturcitu on Dec 12, 2013, 11:08 pm
ffmpeg -f rawvideo -s 173x144 -pix_fmt yuyv422 -i PHOTO.RAW -f image2 -vcodec png OUTPUT.PNG
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Dec 12, 2013, 11:24 pm
Can't be 173x144 (173 is an odd number)
Title: Re: ov7670 with both arduino uno and now mega
Post by: aturcitu on Dec 13, 2013, 08:40 am
Quote from: drkblog on Dec 12, 2013, 11:24 pm
Can't be 173x144 (173 is an odd number)

Yes I know, the correct one may be 176x144 but I have to choose 173x144 in order to get a logical photo
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Dec 13, 2013, 11:11 am
Ok. My version of ffmpeg reuses to convert the file with that resolution. Anyway you already had this problem before. You are missing some pixels, somewhere.
As for the color issue, in my tests the best coding format was bayer (not yuv nor rgb)
Title: Re: ov7670 with both arduino uno and now mega
Post by: aturcitu on Dec 13, 2013, 04:25 pm
Before a long day working on my code and using the strucs with the regs....

taxan! But Your's photos have quite a lot quality that mine. I suppose that I can improve the focus and play with others registers?
Thanks ! :D :D
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Dec 13, 2013, 09:05 pm
Great!
Well, you have to take into account that my pictures were 640x480
Title: Re: ov7670 with both arduino uno and now mega
Post by: aturcitu on Dec 14, 2013, 06:00 pm
I have made a library in order to save directly in bmp the picture in the SD CARD.
bmp.h
Code: [Select]
#ifndef bmp_h
#define bmp_h
#include "Arduino.h"
class Bmp
{
public:
Bmp();
void init(unsigned int px, unsigned int py);
char bmpFileHeader[14];
char bmpInfoHeader[40];
unsigned int rowSize;
unsigned int fileSize;
int pad;
};

// How many bytes in the row (used to create padding)


// Headers (54 bytes) + pixel data
// Max paddin needed will be 3 zeros

extern Bmp bmp;


#endif

bmp.cpp
Code: [Select]
#include "bmp.h"
Bmp::Bmp() {
bmpFileHeader = {'B','M', 0,0,0,0, 0,0, 0,0, 54,0,0,0};
bmpInfoHeader = {40,0,0,0, 0,0,0,0, 0,0,0,0, 1,0, 24,0};
}
void Bmp::init(unsigned int px, unsigned int py){
rowSize = 4 * ((3*px + 3)/4);
fileSize = 54 + py*rowSize;
pad = rowSize-3*px;

//Number of zeros needed;

bmpFileHeader[ 2] = (byte)(fileSize
);
bmpFileHeader[ 3] = (byte)(fileSize >> 8);
bmpFileHeader[ 4] = (byte)(fileSize >> 16);

43 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

bmpFileHeader[ 5] = (byte)(fileSize >> 24);


bmpInfoHeader[ 4]
bmpInfoHeader[ 5]
bmpInfoHeader[ 6]
bmpInfoHeader[ 7]
bmpInfoHeader[ 8]
bmpInfoHeader[ 9]
bmpInfoHeader[10]
bmpInfoHeader[11]

=
=
=
=
=
=
=
=

(byte)(
(byte)(
(byte)(
(byte)(
(byte)(
(byte)(
(byte)(
(byte)(

px
px
px
px
py
py
py
py

);
>> 8);
>> 16);
>> 24);
);
>> 8);
>> 16);
>> 24);

}
Bmp bmp;

Then for instance, if working with rgb444 would be:


Code: [Select]
if (!sd.begin(CHIP_SELECT, SPI_HALF_SPEED)) sd.initErrorHalt();
if (!myFile.open(fileName, O_WRITE | O_CREAT ))
sd.errorHalt("opening file for write failed");
Serial.print("Writing to ");
Serial.print(fileName);
Serial.print("... ");
bmp.init(COLS,ROWS);
myFile.write(bmp.bmpFileHeader, sizeof(bmp.bmpFileHeader));
myFile.write(bmp.bmpInfoHeader, sizeof(bmp.bmpInfoHeader));
byte tmp[COLS*3];
byte padding[bmp.pad];
for( int i=0; i< bmp.pad; i++)
padding[i]=0;

// Write file header


// Write info header

//Row with RGB (3 bpp)

for (int y=0; y<ROWS; y++) {


for (int x=0; x<(COLS); x++) {
tmp[x*3+0] = (byte)((0x0F & buffer[2*y*COLS + 2*x])<<4);
// R
tmp[x*3+1] = (byte)(0xF0 & buffer[2*y*COLS + 2*x+1]);
// G
tmp[x*3+2] = (byte)((0x0F & buffer[2*y*COLS + 2*x+1]) <<4);
// B
}
myFile.write(tmp, sizeof(tmp));
// Write tmp data
myFile.write(padding, sizeof(padding));
// Padding as needed
}
Serial.println("Done");
myFile.close();

I hope it would be helpfull for someone!

Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on Dec 14, 2013, 07:16 pm
Nice!
Title: Re: ov7670 with both arduino uno and now mega
Post by: sakeear on Dec 17, 2013, 04:12 pm
Mr Arduino..can u please tell the pin configuration for the arduino mega 2560 ...
Title: Re: ov7670 with both arduino uno and now mega
Post by: lberezinski on Dec 17, 2013, 07:27 pm
Hello, all & Mr_Arduino
I'm a Arduino beginner and i need some help understanding if my connections are correct.
I attached a fritzing file that shows my pin connections (FYI my ov7670 is a non buffer unit).
I'm sure my connections are wrong please advise
Thanks in advance
Title: Re: ov7670 with both arduino uno and now mega
Post by: sakeear on Dec 22, 2013, 04:52 am
Mr Arduino,,,, can u plz tel me , how the pin connection need to use in arduino mega?? i read ur post.. but i cant find out. and im new to arduino..can plz help?
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Dec 24, 2013, 04:07 pm
Sorry everyone for my absence I have been busy lately real life can get in the way of fun things sometimes but now I am back and I hope that I will from now on keep up with this topic. What I will be doing is
going trough this topic and addressing all unaddressed issues in separate post to keep things more organized. I will go in reverse order.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Dec 24, 2013, 04:09 pm
Quote from: sakeear on Dec 22, 2013, 04:52 am
Mr Arduino,,,, can u plz tel me , how the pin connection need to use in arduino mega?? i read ur post.. but i cant find out. and im new to arduino..can plz help?

For the arduino mega you have some flexibility in the connections that you use. Just fine a port that has all pins broken out to the headers (D0-D7) this makes reading faster.
I will admit that your post is lacking in formality I would recommend you read http://www.catb.org/~esr/faqs/smart-questions.html and try again.
I would like more information before I am able to assist you.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Dec 24, 2013, 05:52 pm
Quote from: lberezinski on Dec 17, 2013, 07:27 pm
Hello, all & Mr_Arduino

44 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

I'm a Arduino beginner and i need some help understanding if my connections are correct.
I attached a fritzing file that shows my pin connections (FYI my ov7670 is a non buffer unit).
I'm sure my connections are wrong please advise
Thanks in advance

Thank you for the sketch. It made it much easier to identify what needs to be changed.
I have not of fritzing until now but I was able to correct your sketch. So with that said I have attached a corrected sketch. IMPORTANT NOTE: I could not find a part for the 74hca125 buffer that I used so I
substituted it for the '4050 in the sketch. I have not tested a '4050 but it may work.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Dec 24, 2013, 06:39 pm
Quote from: aturcitu on Dec 13, 2013, 04:25 pm
Before a long day working on my code and using the strucs with the regs....

taxan! But Your's photos have quite a lot quality that mine. I suppose that I can improve the focus and play with others registers?
Thanks ! :D :D

If you are concerned that you are getting lower quality compared to other people you really ought to post a 640x480 image. I cannot really tell with the 160x120 if that is normal or not. There is not enough
resolution to analyze it.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Dec 24, 2013, 06:44 pm
Quote from: aturcitu on Dec 12, 2013, 10:38 pm
I have noticed one thing... My the order of the colors on my colorbar are incorrent. What could be the explanation?
I have attach the color bar raw data. YUV422 QCIF (176x144)

I got the colors to appear normal I had to use "Alternative" yuv422 conversion with my program you can run it as
Code: [Select]
./convert -f Cbar.RAW -w 174 -H 144

-c yalt

And you get the right colors


The source to my program is located at https://github.com/ComputerNerd/RawCamera-data-converter
The reason you are getting the wrong colors is because the first byte is swapped because a register was not set. The yuv422 alternative mode Also from what I have noticed it seems that yuv422 is higher
quality than rgb565.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Dec 24, 2013, 07:01 pm
Quote from: drkblog on Dec 11, 2013, 10:53 pm
Great!
Mr_arduino posted a github link to his converter in the first message in this thread (from YUV/BAYER to PNG). I use that program. Of course, you have to compile and run that over a PC with Linux or Cygwin.

Yes it is here https://github.com/ComputerNerd/RawCamera-data-converter one thing I was wondering should I release windows binaries with it or not? How many people here use windows here?
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Dec 24, 2013, 07:04 pm
Quote from: pgibbons66 on Dec 07, 2013, 01:07 am
Finally a really amatuer question, when you pull up to A4 &A5 do you just add a 4.7k resistor between the line and the 3.3v pin on the arduino?
thanks in advance.

Yes you do in fact you won't be able to communicate with the ov7670 without the pull-up. Remember to disable the internal pull-up resistors if you use the arduino i2c library. I have instructions on the first page
on how to do that.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Dec 24, 2013, 07:05 pm
Quote from: xKoldFuzionx on Dec 07, 2013, 04:37 am
Quote from: drkblog on Dec 07, 2013, 02:23 am
Don't forget to disable any Arduino buil-in pull up!

Out of sheer curiousity, what would happen if you didn't? If the built in are higher resistance, I could see that being a problem, but if they're lower, you could just use a lower PU?
I really know nothing about the pull-ups built into Arduino. I read about them once, but don't remember anything. Lol, I just found out what a PU resistor was yesterday.

The internal pull-ups are to 5v the ov7670 is made to handle only 3.3v.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Dec 24, 2013, 07:46 pm
Quote from: Animat on Dec 03, 2013, 11:14 am
Hi, how to fix the image with the right edge?

You are missing data. It is important to keep your loop to read data as fast as possible.
Here is what I did https://github.com/ComputerNerd/arduino-camera-tft/blob/master/captureimage.c

45 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Look at the function capImg(void)


it is designed to capture a 320x240 image with 2 bytes per pixel so 640x240 bytes of data
I will annotate what goes on
Code: [Select]
cli();
uint8_t w,ww;
uint8_t h;
w=160;//The reason this is 160 instead of 640 is because I have unrolled loop you will see later
h=240;

Disable interrupts and set up variables notice that I use 8bit unsigned variables that is important.
Usually when coding on the PC using int is the fastest but that is not the same on the AVR it is an 8-bit processor.
Code: [Select]
tft_setXY(0,0);
CS_LOW;
RS_HIGH;
RD_HIGH;

This sets up the memory device in my case a tft screen later in the loop you will notice that when I write to the tft screen it automatically increments to the next pixel.
Here is how you initialize the 23LC1024 on the arduino uno and this code can also be used on arduino mega if and only if you edit the platform dependent functions.
Code: [Select]
spiCSt();
spiWrB(2);//sequental write mode
spiWrB(0);//24 bit address
spiWrB(0);
spiWrB(0);

You will need these platform dependent functions


Code: [Select]
static inline void spiWrB(uint8_t dat){
SPDR = dat;
while(!(SPSR & (1<<SPIF))) {}// Wait for transmission complete
}
static inline void spiCSt(void){//selects the RAM chip and resets it
//toggles spi CS used for resting sram
PORTB|=(1<<2);//cs high
PORTB&=~(1<<2);//cs low
}

Change the 2 and maybe PORTB to what pin is on that port. NOT PIN NUMBER ON ARDUINO.
You will also need to put this at the beginning of your program
Code: [Select]
spiCSt();
spiWrB(1);
spiWrB(64);//sequential mode

The next part of void capImg(void) is this


Code: [Select]
DDRA=0xFF;

This sets the tft data pins to output the only reason that is there is because other parts of my code may change it to input
This code waits for the image to actually start
Code: [Select]
#ifdef MT9D111
while (PINE&32){}//wait for low
while (!(PINE&32)){}//wait for high
#else
while (!(PINE&32)){}//wait for high
while (PINE&32){}//wait for low
#endif

You can ignore from the #ifdef MT9D111 part to the #else and ignore the #endif that is so my program can be compile for either mt9d111 or ov7670 depending on what is defined.
The code (below) is the start of my loops
Code: [Select]
while (h--){
ww=w;
while (ww--){

Notice how I am counting down instead of up it is faster to count down that it is to count up.
The next part of my code does 8 bytes per loop iteration
This:
Code: [Select]
WR_LOW;
while (PINE&16){}//wait for low
PORTA=PINC;
WR_HIGH;

Is repeated 8 times
Here is what you would do for SPI ram on the arduino mega (The above inner loop code was for the arduino mega with tft screen)
Code: [Select]
while ((PIND&4)) {}//wait for low
SPDR=(PINC&15)|(PIND&240);
while (!(PIND&4)) {}//wait for high

I close the loop with


Code: [Select]
}
}
CS_HIGH;
sei();

This sets the tft's CS pin to high and re-enables interrupts.


Also your converter ignores the color information as I have told you before here are some of your images that you posted the raw data for converted with my converter.
Title: Re: ov7670 with both arduino uno and now mega

46 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Post by: Mr_arduino on Dec 24, 2013, 08:09 pm


Quote from: Chocobot on Nov 27, 2013, 07:42 pm
So far I'm thinking this:
The schematic, is this ok? http://i167.photobucket.com/albums/u157/cookiebal/OV7670ArduinoUno.jpg

The schematic looks good to me.


Quote
As for the code, I've been looking at http://pastebin.com/1nnRc5qL , I'm not very familiar with the language so I don't really understand everything. But so far I'm thinking that I'd need to add this (from page 4, reply 57) somewhere at the start to get the clock working.

Try looking at https://github.com/ComputerNerd/ov7670-simple I will warn you that it was the first code that I have ever written for the ov7670.
Code: [Select]
DDRB|=(1<<3);//pin 11
ASSR &= ~(_BV(EXCLK) | _BV(AS2));
TCCR2A=(1<<COM2A0)|(1<<WGM21)|(1<<WGM20);//this also results in 67 but I wanted to clean up magic numbers
TCCR2B=(1<<WGM22)|(1<<CS20);
OCR2A=0;

Yes do add that at the beginning


The simple sample should make it easier for you to understand the operation of the ov7670.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Dec 24, 2013, 08:37 pm
Quote from: drkblog on Nov 27, 2013, 01:12 pm
Well. Having a sensor which outputs JPEG saves you the cost of processing the encoding. But, as far as I know, you won't get a frame free of compression from such a sensor. And if you have to process the image in the Arduino, you have to decode JPEG first. Which is
why OV7670 is better in such cases.

The OV5642 can output raw data in addition to the jpeg compressed mode.
Title: Re: ov7670 with both arduino uno and now mega
Post by: xKoldFuzionx on Dec 25, 2013, 06:47 pm
Quote from: Mr_arduino on Dec 24, 2013, 08:37 pm
Quote from: drkblog on Nov 27, 2013, 01:12 pm
Well. Having a sensor which outputs JPEG saves you the cost of processing the encoding. But, as far as I know, you won't get a frame free of compression from such a sensor. And if you have to process the image in the Arduino, you have to decode JPEG first. Which
is why OV7670 is better in such cases.
The OV5642 can output raw data in addition to the jpeg compressed mode.

I was aware of that, but the main reasons I purchased it was the 5MP and the JPEG output. Just saves me the hassle of having a separate program convert the data. I'd much rather pull the card, put it in the
PC and be able to read the data directly from the card, rather than have to start up another program and convert it all to view it. Plus, with MicroSD cards, it's easier to view the image in the field with a cellphone
by just swapping out the card.
I just wish the coding and the documentation was easier for me to figure out. I'm really quite slow with understanding all of this and don't have the experience. I had been using a VC0706 until it just crapped out
on me yesterday(I put it to sleep and now it won't respond). Now all the work I put into it is garbage and I'm stuck scrapping all the work I did and starting with something different. Wire confuses me, though I
think I have a fairly decent grasp of it. The ov5642 just has so much more going on but is a lot less inexpensive so if I scrap a few, I'm not gonna be as pissed about it as with the other. The worst part was, I
was litterally one step away from having the project completed.
I guess I'm just going to have to go back through all your code on the 7670 and see what I can figure out. I can't thank you enough for all the work you've done on these camera modules.
Title: Re: ov7670 with both arduino uno and now mega
Post by: aturcitu on Dec 26, 2013, 02:57 pm
Quote from: Mr_arduino on Dec 24, 2013, 06:44 pm
Quote from: aturcitu on Dec 12, 2013, 10:38 pm
I have noticed one thing... My the order of the colors on my colorbar are incorrent. What could be the explanation?
I have attach the color bar raw data. YUV422 QCIF (176x144)
I got the colors to appear normal I had to use "Alternative" yuv422 conversion with my program you can run it as
Code: [Select]
./convert -f Cbar.RAW -w 174 -H 144

-c yalt

And you get the right colors


The source to my program is located at https://github.com/ComputerNerd/RawCamera-data-converter
The reason you are getting the wrong colors is because the first byte is swapped because a register was not set. The yuv422 alternative mode Also from what I have noticed it seems that yuv422 is higher quality than rgb565.

Yes I have noticed this, It seems that I am missing the first byte of every row, But I don't understand why, do you know with register could it be? It happens to me either in YUV or RGB.
PD: Here you can see the project I am working with ov7670 and Arduino DUE :
http://forum.arduino.cc/index.php?topic=206660.0
Thanks in advance
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Dec 26, 2013, 03:10 pm
aturcitu I am not sure if you are actually missing bytes look at register 0x3A here is a quote from the datasheet
Quote
Bit[3]: Output sequence
(use with register

47 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

COM13
[1] (0x3D))
TSLB[3],
COM13
[1]):
00: Y U Y V
01: Y V Y U
10: U Y V Y
11: V Y U Y

Here is register another quote found at register 0x3D


Quote
Bit[0]: UV swap (use with register
TSLB
[3] (0x3A))
TSLB
[3], COM13[1]:
00: Y U Y V
01: Y V Y U
10: U Y V Y
11: V Y U Y

You see the ov7670 can output the color bytes in different orders.
Also your project is very cool I wish I could help you with PID but I have not experience with it.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Dec 26, 2013, 03:34 pm
Quote from: xKoldFuzionx on Dec 25, 2013, 06:47 pm
I just wish the coding and the documentation was easier for me to figure out. I'm really quite slow with understanding all of this and don't have the experience.

Don't feel bad it took me a long time to get the ov7670 to work most of this was my silly errors I was a beginner at one point. When I started working with the ov7670 I could not even communicate with it using i2c
it would not work. I did not relize that for i2c (sccb) communication to work you needed to feed a clock to it. I remember getting it working and the colors I got out of the ov7670 were purple and green. I found out
that there was some register that fixes this (it appears aturcitu is currently experiencing this issue) Yes it does affect rgb565 mode too. Working with these camera sensors have significantly advanced my skill
both at a hardware level and a software level. I hope you keep going with your project seeing it finally work feels great and that is part of the reason why I made this topic so that other people interested in camera
sensors can get to see their project work.
Quote
I had been using a VC0706 until it just crapped out on me yesterday(I put it to sleep and now it won't respond). Now all the work I put into it is garbage and I'm stuck scrapping all the work I did and starting with something different. Wire confuses me, though I think I have
a fairly decent grasp of it.

What do you mean "Put it to sleep"? Maybe there is a way to fix it. I can't imagine software causing damage to the sensor unless you disable the internal regulator or something which is unlikely that you did.
The ov5642 just has so much more going on but is a lot less inexpensive so if I scrap a few, I'm not gonna be as pissed about it as with the other. The worst part was, I was litterally one step away from having
the project completed.
[/quote]
Could you please tell us where you are getting ov5642 sensor modules for the cost lest than an ov7670 module the cheapest ov5642 module I could find was $25.99 on ebay. The ov7670 can be purchased for
$5.99 on ebay and includes free shipping just like the ov5642. I would like an ov5642 module myself.
Quote
I guess I'm just going to have to go back through all your code on the 7670 and see what I can figure out. I can't thank you enough for all the work you've done on these camera modules.

Well the ov5642 is quite a bit different I am not sure if much of my code will help you with that unfortunately.
Title: Re: ov7670 with both arduino uno and now mega
Post by: xKoldFuzionx on Dec 26, 2013, 07:03 pm
Well that sucks, I had written a reply and the server lost it. Electronics don't like me this week. Anything that functions on electricity of some kind is out to get me. Lol, It'll be my luck that I somehow get shocked
from my keyboard just re-writing this. But, here goes.
Quote from: Mr_arduino on Dec 26, 2013, 03:34 pm
Don't feel bad it took me a long time to get the ov7670 to work most of this was my silly errors I was a beginner at one point. When I started working with the ov7670 I could not even communicate with it using i2c it would not work. I did not relize that for i2c (sccb)
communication to work you needed to feed a clock to it. I remember getting it working and the colors I got out of the ov7670 were purple and green. I found out that there was some register that fixes this (it appears aturcitu is currently experiencing this issue) Yes it does
affect rgb565 mode too. Working with these camera sensors have significantly advanced my skill both at a hardware level and a software level. I hope you keep going with your project seeing it finally work feels great and that is part of the reason why I made this topic so
that other people interested in camera sensors can get to see their project work.

yeah, I was pretty excited to get that vc0706 working. I had created quite the camera. I literally was just 2 steps away from designing a prototype board so I could get it in the field and test it under the cold
conditions of winter. But at $33-$45, I can't justify buying a new one, since it's only 2MP. But the experience I gained from working with it was priceless.
Quote
What do you mean "Put it to sleep"? Maybe there is a way to fix it. I can't imagine software causing damage to the sensor unless you disable the internal regulator or something which is unlikely that you did.

Well, there is a "power save mode" that I attempted to put it in. The idea was that while there was no motion sensed over a 30 sec time span, the camera would go to sleep, then, when motion was detected, it
would wake the camera up, take a picture, and the whole process would start over. However, the module itself has it's own motion sensing function which I disabled because I wanted to use an infrared
sensor(my thought was, if it's in the woods and a leaf blows by, or a blade of grass moves in the wind, infrared would be less likely to trigger the camera than motion sensed by the camera, as the camera was
entirely too sensitive). So, I think my code actually told it to sleep until the camera module sensed motion. Hah, oh well. I had it crap out on me before, couldn't get it to respond to anything, either by manual
commands, or the VC0706CommTool program. I didn't touch it for a week or two, then one day was gonna show a friend that it was garbage and it magically came back to life. To my knowledge, there is no
on-board backup supply. So, I'm thinking the caps just need to leak their stored current in order for it to naturally reset.
Quote
Could you please tell us where you are getting ov5642 sensor modules for the cost lest than an ov7670 module the cheapest ov5642 module I could find was $25.99 on ebay. The ov7670 can be purchased for $5.99 on ebay and includes free shipping just like the ov5642.
I would like an ov5642 module myself.

Well, I think I paid somewhere around $20-$25 for my 5642, my 7670(bought this first, but realized I was in over my head and switched to vc0706) I think I paid $3.88 with shipping. I've noticed on eBay that your
searches depend entirely on how you word them. When I found the 7670, I had just searced for "camera module" and came up with different results than when I searched for ov7670 or any other camera
module. Even including "arduino" in the search changed everything. But since then, I haven't been able to find an ov7670 for under $8. People keep bidding them up and I don't feel like paying over $8 for a
2MP camera module anymore.

48 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Quote
Well the ov5642 is quite a bit different I am not sure if much of my code will help you with that unfortunately.

From what I've understood, the 56 and 76 are very similar. Even if there are some major differences, understanding what you did with the 76(especially) the protocols(sending/receiving commands) would help
me understand how to work the 56. I read through that documentation for either of these, and I feel like I'm looking at a bunch of strange archaic symbols that mean nothing to me. Haha. I was starting to
understand the 76 when I first started looking into it, but then I couldn't figure out how in the world I was supposed to send those commands. Reading your code is about the same to me. I get it a little bit more
now, but this is going to be a lengthy project and I'm expecting it will take me the better part of a year to get it all figured out. The VC0706 came with an example sketch that I was able to piece together with the
help of a few guys on this board how to make it all work. This one, I want to understand more before I start getting into it. I learn little by little every day, but having multiple examples to see different variations is
a huge help. Right now, you're about the only one who has shared anything (atleast that I've been able to find) about how you got this going. Everyone else just wants you to buy the Arducam and cheat. I don't
even like using libraries, cuz I like to understand for myself how it works, first, then, either write my own, or use theirs. It just makes more sense to me if I can see it, then do it, rather than just steal someone
else's work.

Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Dec 27, 2013, 08:03 pm
Ok that makes more sense now I though that when you were talking about the vc7670 I though you were talking about the ov7670 but now I realize that they are two different things however I assume you are
talking about this https://www.adafruit.com/products/397 if so you relize it is only 0.3 MP not 2.0 MP. I agree that it is too expensive.
Title: Re: ov7670 with both arduino uno and now mega
Post by: nerdroide on Dec 27, 2013, 11:16 pm
Hello guys. I'm brazillian and all of you are very amazing. Really. Well, I don't speak english very well, so you will forgive me about my mistakes. Mr_Arduino I would like to know if you could take a look in my
code and tell me what could be are wrong.
https://github.com/nerdroid/OV7670-Project
It's my git. I really appreciate.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Dec 28, 2013, 05:26 am
I submitted a pull request that may solve some issues but I doubt it will work. There are two problems first of all the Ethernet shield that you are using uses pins 2,4,10,11,12,13 you appear to have pins 2 and 4
hooked up to the ov7670 also I think that the function you are using to send data to the wiznet 5100 is too slow try directly sending the data without using those silly arduino library functions.
Title: Re: ov7670 with both arduino uno and now mega
Post by: xKoldFuzionx on Dec 28, 2013, 05:38 am
Quote from: Mr_arduino on Dec 27, 2013, 08:03 pm
Ok that makes more sense now I though that when you were talking about the vc7670 I though you were talking about the ov7670 but now I realize that they are two different things however I assume you are talking about this https://www.adafruit.com/products/397 if so
you relize it is only 0.3 MP not 2.0 MP. I agree that it is too expensive.

I was actually talking about [link]http://www.ebay.com/itm/VC0706-3-3V-Camera-Module-TTL-UART-Jpeg-CVBS-For-AVR-STM32-Arduino-Compatible-/171000874348?pt=LH_DefaultDomain_0&


hash=item27d072456c]this one[/link], but looks like they're the same thing. I originally bought the one at Radio Shack for about $45. That said it was a 2.0MP camera board. How can you tell it was only .3MP?
I didn't see that anywhere on my info.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Dec 28, 2013, 06:57 am
Is the maximum output resolution 640x480 (vga) if so
640x480/1000000=0.3072
Title: Re: ov7670 with both arduino uno and now mega
Post by: sakeear on Dec 28, 2013, 03:02 pm
hey Mr Arduino, im very sorry about language. Im not good at English. I baught Arduino mega 2560 board and ov7660 CMOS camera (With out FIFO). i want to take and image stream and save it in a SD card. I
have sucessfully operated the SD card and its ,working perfectly. I like to know .How shold i connect camera sensor to the board and get it work out. actually i like to know about how the pins need to connect or
give me a clue. if u can plz help me. thanks alot!!
Title: Re: ov7670 with both arduino uno and now mega
Post by: nerdroide on Dec 28, 2013, 04:16 pm
Quote from: Mr_arduino on Dec 28, 2013, 05:26 am
I submitted a pull request that may solve some issues but I doubt it will work. There are two problems first of all the Ethernet shield that you are using uses pins 2,4,10,11,12,13 you appear to have pins 2 and 4 hooked up to the ov7670 also I think that the function you are
using to send data to the wiznet 5100 is too slow try directly sending the data without using those silly arduino library functions.

Hum... so, my function that sends the pixels to the server is slow? Well, I will change this, I just need to finish the article about the project... hehe
And the shield ethernet is using the pins 10,11,12 and 13. I think that just this. The pin 4 is used for the sdCard, so I disabled it. The registers are right?
Title: Re: ov7670 with both arduino uno and now mega
Post by: xKoldFuzionx on Dec 29, 2013, 10:17 am
Quote from: Mr_arduino on Dec 28, 2013, 06:57 am
Is the maximum output resolution 640x480 (vga) if so
640x480/1000000=0.3072

That would mean that even the OV7670 is only a .3 MP camera and the reason I originally bought that was cuz it boasted 2MP. Well, this is great information to know, thanks!

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

49 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Post by: xKoldFuzionx on Dec 29, 2013, 07:06 pm


Mr_Arduino, can you explain something to me about your code? I was looking it over, and I'm unclear as to why wrReg() is a "byte" rather than a "void". I don't understand why that is.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Dec 29, 2013, 09:02 pm
So you could check for errors if you wanted to.
Title: Re: ov7670 with both arduino uno and now mega
Post by: xKoldFuzionx on Dec 29, 2013, 09:07 pm
ok, Gotcha, so essentially, saving as a byte will allow you to say :
Code: [Select]
Serial.println(wrReg(regID, regDat));

this would print out what you sent?


Sorry, most everything I've seen just uses a Serial.print() function to debug, this whole byte thing is a bit new to me.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Dec 30, 2013, 12:42 am
Yes you can do that but it returns 0 or 1 it does not return what was sent in this case. What you are seeing is a function returning a value. Returning an error/success value is just one application for functions
returning a value you should read https://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8l.doc%2Flanguage%2Fref%2Fcplr240.htm
Title: Re: ov7670 with both arduino uno and now mega
Post by: xKoldFuzionx on Dec 30, 2013, 12:59 am
Ok, gotcha, so, like the old school days of computing when that's all it would return is a 1 or 0. I'm learning. I saved that page, I'll probably end up reading it tomorrow and if I have more questions, I'll be sure to
send them your way.
On a side note, after looking over your code, I think I see (for the most part) what you did to get results from the camera. I think I see now how to program the 0V5642. I'm just gonna have to figure out the wiring
for it. The datasheet I was looking at only has (from what I can see, so far) the wiring for hooking up the actual sensor instead of the module. I didn't see anything yet about pullups, but I'm not done looking
through it, and I also have another datasheet for it, so I need to look that one over still. Seems like this camera won't be too difficult. Also, according to that calculation you gave me, the 7670 is only .3MP? I
could have sworn when I bought it, it was a 2MP. SMH, oh well, eventually I'll get to that one and get it running.
Title: Re: ov7670 with both arduino uno and now mega
Post by: nerdroide on Dec 30, 2013, 03:13 am
Mr_Arduino, I would like to know the best way to do my code to work in your opinion. I would to use the SD card or I must to leave in that way?
Thanks for your help man. You're very good. I really appreciate your help. XD
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Dec 30, 2013, 03:19 am
You can still use the Ethernet and/or SD card. What I was trying to tell you is that you cannot plug the ov7670 to any pins used by the Ethernet shield.
Title: Re: ov7670 with both arduino uno and now mega
Post by: nerdroide on Jan 03, 2014, 04:13 am
Mr_Arduino, I haven't a no FIFO camera and I don't have sram chips. So my project is very slowly. I couldn't to configure the registers. I disconnected the ethernet shield, I'm just using the sd card. How can I to
fix this?
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jan 07, 2014, 01:59 am
Actually in my option the Ethernet shield was the only device you had that could receive the data at a reasonable speed. I was just saying the way you were sending data to the wiznet 5100 was too slow you
need to directly write to the spi port to send data. I have examples on how to do this. You can easily adapt them to fit your own needs. The same goes for registers I have already provided examples on camera
registers. I am currently working on improving my Raw data converter I have been reading some research papers about demosaicing and have found ways to make the image quality outputted from my converter
better after I finish this I will look at your code again.
Title: Re: ov7670 with both arduino uno and now mega
Post by: zoomx on Jan 07, 2014, 10:36 am
Maybe dcraw code can be useful
http://en.wikipedia.org/wiki/Dcraw
http://www.cybercom.net/~dcoffin/dcraw/
Title: Re: ov7670 with both arduino uno and now mega
Post by: angeleye9 on Jan 07, 2014, 01:30 pm
Mr arduino I am starting a project about OV7670 + fifo camera module control with arduino mega.
Is your code at github camera control without fifo or with fifo?
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jan 07, 2014, 05:10 pm
It is for the one without fifo. Lots of code is still relevant though. Just disable the PWM clock generation and modify the code to read pixels and you should be good to go.
Title: Re: ov7670 with both arduino uno and now mega

50 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Post by: angeleye9 on Jan 08, 2014, 06:02 am


will I apply I2c protocol to camera or will I just communicate with fifo?
It has pin diagram like below;
// 1 3.3V
// 2 GND
// 3 SCCB_C
// 4 SCCB_D
// 5 VSYNC
// 6 WRST
// 7 WEN
// 8 NC
// 9 RRST
// 10 OE

// 11 RCLK
// 12 GND
// 13 D0
// 14 D1
// 15 D2
// 16 D3
// 17 D4
// 18 D5
// 19 D6
// 20 D7

The pins D0 to D7 is output that I read pixels.


what will I do with SCCB_C and SCCB_D pins? Could you please explain the procedure little bit? (How to save image into fifo and read from there)

Title: Re: ov7670 with both arduino uno and now mega
Post by: nomiz on Jan 08, 2014, 10:48 am
Hi!
From what I've understood :
SCCB_C and SCCB_D pins are for the I2C communication, so you have to pull-up them to 3.3V!
For that you have to unable two lines by comment or suppress in the twi.c library (in INSTALL_FOLDER\Arduino\libraries\Wire\utility\twi.c)
Code: [Select]
// activate internal pullups for twi.
digitalWrite(SDA, 1); //to suppress
digitalWrite(SCL, 1); //to suppress

And put 2 resistors to 3.3V


To take the picture, you have a procedure with the WEN_PIN and synchronization with the VSYNC.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jan 08, 2014, 09:40 pm
Yes nomiz you are correct about the i2c part you must somehow suppress the two lines. As for the WEN_PIN I am not sure what you are talking about.
Also yes angeleye9 you will be using i2c to configure the camera otherwise you will get a low quality image out of the camera module.
Title: Re: ov7670 with both arduino uno and now mega
Post by: nomiz on Jan 08, 2014, 09:56 pm
Hi Mr_arduino,
I was talking about the procedure to take a picture. But I'm probably missing something because I didn't success to take a good picture. :smiley-roll-sweat:
Actually, to take a picture I'm using this function :
Code: [Select]
void take_picture()
{
digitalWrite(OE_PIN, HIGH);
// Output high impedance
while(digitalRead(VSYNC_PIN)!=HIGH);
while(digitalRead(VSYNC_PIN)!=LOW);
// The present frame ends
digitalWrite(RRST_PIN,
digitalWrite(RCLK_PIN,
digitalWrite(RCLK_PIN,
digitalWrite(RCLK_PIN,
digitalWrite(RCLK_PIN,
digitalWrite(RCLK_PIN,
digitalWrite(RRST_PIN,

LOW);
LOW);
HIGH);
LOW);
HIGH);
LOW);
HIGH);

// Reset writing pointer (RRST & WRST)

// Pointer is Reset

digitalWrite(WEN_PIN, HIGH);
// Enable writing
Serial.println("ENABLE WRITING");
while(digitalRead(VSYNC_PIN)!=HIGH);
delay(1);
digitalWrite(WEN_PIN,LOW );
// Disable writing
Serial.println("A COMPLETE IMAGE IS CAPTURED");
digitalWrite(RRST_PIN,
digitalWrite(RCLK_PIN,
digitalWrite(RCLK_PIN,
digitalWrite(RCLK_PIN,
digitalWrite(RCLK_PIN,
digitalWrite(RCLK_PIN,
digitalWrite(RRST_PIN,

LOW);
LOW);
HIGH);
LOW);
HIGH);
LOW);
HIGH);

digitalWrite(OE_PIN, LOW);
delay(1);

// Reset reading pointer (RRST & WRST)

// Pointer is Reset
// Enables reading

PS : to reset the writing pointer WRST, I've connected this pin to the RRST pin, so I'm resetting each time both...
and to copy the picture to the BMP file on my SD card I'm copying each pixel 1 by one, I tried to use the RGB classic format, meaning 3 times 8 bits for each pixel.
so I've programmed the registers with this code :
Code: [Select]
//REGISTERS INITIALIZATION
write(0x11,0x82);

51 of 96

// Pescaler x3 (m)

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...


write(0x12,0x00);
write(0x12,0x01);

http://forum.arduino.cc/index.php?action=printpa...

// Reset all the values

write(0x0C,0x00);
write(0x3E,0x00);
write(0x70,0x3A);
write(0x71,0x35);
write(0x72,0x11);
write(0x73,0xF0);
write(0xA2,0x02);

I want to take a picture in VGA resolution. But my result is very strange (cf attached image) =(
Do you have any ideas of what I'm missing ?
Title: Re: ov7670 with both arduino uno and now mega
Post by: angeleye9 on Jan 09, 2014, 05:06 am
nomiz could you send me your full code? I will start to work with camera and it will be helpful....
and Do we have to use a SD card? couldn't we just send the image to the pc with serial communication or a tft screen?
Title: Re: ov7670 with both arduino uno and now mega
Post by: pito on Jan 12, 2014, 01:50 pm
Quote
Having /RE is a needed function /RE does exactly what you need it to do keep the data "alive" in the fifo while saving to the sd card and then continue were you left off without restarting.

Hi, great post! Interested in the module with FIFO I have a question regarding the "/RE" pin issue.
Why it is an issue? Based on the fifo's datasheet and OV7670 v1/v2 schematics, the fifo's data are kept alive by OV7670's PCLK signal (24MHz) wired directly to fifo's WCK, and PCLK is free running. Does
PCLK stop after writing the frame into fifo? When it does not, you can read the data out of fifo at any speed (the fifo's data are kept alive by clocking WCK or RCK with min 1MHz). Of course, the read speed must
fit the number of fps you want to achieve..
Is the /RE fix needed?
Thanks.
PS:
com10 bit[5] "0" - PCLK free running
Title: Re: ov7670 with both arduino uno and now mega
Post by: sakeear on Jan 15, 2014, 02:59 am
Mr arduino... i have a simulation problem in my software wen i'm uploading program..
"Binary sketch size: 24,512 bytes (of a 32,256 byte maximum)
avrdude: stk500_getsync(): not in sync: resp=0x00"
Do u have any Idea?
Title: Re: ov7670 with both arduino uno and now mega
Post by: nomiz on Jan 15, 2014, 06:32 am
Hi!
Your problem is probably that you have something connected to the pins Rx and Tx (pins 0 and 1 on the UNO), and because it is the serial communication...
Try to unconnect, upload, ans then reconnect those pins :)
Title: Re: ov7670 with both arduino uno and now mega
Post by: Benji1992 on Jan 19, 2014, 01:44 pm
Hy!
I builded the circuit and upload this code to my arduino uno with ethernet shield but dont make anything!
What is the problem? How can I change the fuse bits? The program in serial monitor dont send anything.
Thanks!
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jan 19, 2014, 03:06 pm
You DON'T need to change the fuse bits it is a waste of time. Just use the fast PWM mode it will output an 8mhz clock.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Benji1992 on Jan 19, 2014, 03:34 pm
I tryed this program http://pastebin.com/1nnRc5qL (http://pastebin.com/1nnRc5qL) but dont send anything in serial monitor.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jan 19, 2014, 06:04 pm
Ok you tried the program but it seems as though you tried nothing to fix it. Please add fast PWM code to the program read the atmega328p datasheet if you are unsure of how to do so. Also I don't like that
program anymore (the ones on pastebin). You should checkout https://github.com/ComputerNerd/arduino-camera-tft I am working on the ov7670 with the stm32f4 discovery but have been extremely busy with
non-electronics stuff. I would rather do this but can't sorry.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Benji1992 on Jan 19, 2014, 06:30 pm
I tryed with this in void setup():
Code: [Select]
TCCR0B = TCCR0B & 0b11111000 | 0x01;

But dont work.


Title: Re: ov7670 with both arduino uno and now mega
Post by: Fadik on Jan 20, 2014, 07:51 pm

52 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Hi All
I fear that I share the frustration most of you had here, and unfortunately I am stuck.
Can someone help point me in the right direction?
(I literally went through the whole thread and because of the non-fifo, fifo v1, fifo v2 variances and different
arduino products it is getting much confusing!!)
What would your guess if the following is the output of a QQVGA, YUV...etc (basically the array of settings provided here
in the forum).
I am running only
uint8_t init_yuv_qqvga();
void init_camera_reset();
uint8_t init_default_values();
and commented out
void init_negative_vsync();
as I have Version 1.
I added the Color bars of course, and reading two bytes, discarding the first one and sending the 2nd one (Y-values = grayscale)
Feedback is much appreciated, and sorry for not putting out any bits and pieces of code, i will do so as you ask as it iwll be difficult to put everything at once.
Title: Re: ov7670 with both arduino uno and now mega
Post by: sakeear on Jan 21, 2014, 03:50 pm
hello mr Arduino. I bought arducam shiel and i used it with aduino uno. and its work perfectly. but i want to change it to take several pictures at a single push in a button. like a picture serious.
this is the program
// ArduCAM demo (C)2013 Lee
// web: http://www.ArduCAM.com
// This program is a demo of how to use most of the functions
// of the library with a supported camera modules.
//
// This demo was made for Omnivision OV2640 sensor.
// 1. Set the sensor to JPEG output mode.
// 2. Capture and buffer the image to FIFO.
// 3. Store the image to Micro SD/TF card with JPEG format.
// 4. Resolution can be changed by myCAM.OV2640_set_JPEG_size() function.
// This program requires the ArduCAM V3.0.0 (or above) library and Rev.C ArduCAM shield
// and use Arduino IDE 1.5.2 compiler
#include <UTFT_SPI.h>
#include <SD.h>
#include <Wire.h>
#include <ArduCAM.h>
#include <SPI.h>
#if defined(__arm__)
#include <itoa.h>
#endif
#define SD_CS 9
// set pin 10 as the slave select for SPI:
const int slaveSelectPin = 10;
ArduCAM myCAM(OV2640,10);
//UTFT myGLCD(slaveSelectPin);
void setup()
{
#if defined (__AVR__)
Wire.begin();
#endif
#if defined(__arm__)
Wire1.begin();
#endif
Serial.begin(115200);
Serial.println("hello");
// set the slaveSelectPin as an output:
pinMode(slaveSelectPin, OUTPUT);
// initialize SPI:
SPI.begin();
myCAM.write_reg(ARDUCHIP_MODE, 0x00);
//myGLCD.InitLCD();
myCAM.set_format(JPEG);
myCAM.InitCAM();
//myCAM.OV2640_set_JPEG_size(OV2640_320x240);
myCAM.OV2640_set_JPEG_size(OV2640_1600x1200);
//Initialize SD Card
if (!SD.begin(SD_CS))
{
//while (1);
//If failed, stop here
}
Serial.println("init done");
}
void loop()
{
char str[8];

53 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

File outFile;
static int k = 0;
static int n = 0;
uint8_t temp,temp_last;
uint8_t start_capture = 0;
//Wait trigger from shutter buttom
if(myCAM.read_reg(ARDUCHIP_TRIG) & SHUTTER_MASK)
{
//Wait until buttom released
while(myCAM.read_reg(ARDUCHIP_TRIG) & SHUTTER_MASK);
start_capture = 1;
}
//Start capture when detect a valid shutter press
if(start_capture)
{
//Flush the FIFO
myCAM.flush_fifo();
//Clear the capture done flag
myCAM.clear_fifo_flag();
//Start capture
myCAM.start_capture();
}
if(myCAM.read_reg(ARDUCHIP_TRIG) & CAP_DONE_MASK)
{
//Construct a file name
k = k + 1;
itoa(k, str, 10);
strcat(str,".jpg");
//Open the new file
outFile = SD.open(str,FILE_WRITE);
if (! outFile)
{
Serial.println("open file failed");
return;
}
temp = myCAM.read_fifo();
outFile.write(temp);
//Read JPEG data from FIFO
while( (temp != 0xD9) | (temp_last != 0xFF) )
{
temp_last = temp;
temp = myCAM.read_fifo();
//Write image data to file
outFile.write(temp);
}
//Close the file
outFile.close();
//Clear the capture done flag
myCAM.clear_fifo_flag();
//Clear the start capture flag
start_capture = 0;
}
}
where do i need to change ??

Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jan 22, 2014, 02:37 am
@Fadik you are missing bytes or have configured the camera wrong. Please post the code you use to get bytes from the camera.
@sakeear After the button is pressed you just need to put the code that saves the image in a loop and in that loop make sure to "increment" the file-name so you don't overwrite the same image.
Title: Re: ov7670 with both arduino uno and now mega
Post by: JPedroBelo on Jan 22, 2014, 11:50 pm
Good night Mr_arduino! I'm from Brazil and do not understand English, but I I'm using Chrome tool that makes the automatic translation into Portuguese, translation is not very good, so some things are
confusing this topic for me. I have the module ov7670 without the FIFO, an Arduino MEGA and SD card module, how do I take a picture with the camera and store it on the SD card? What other components are
needed so that I can do this? And where each pin is docked? Thanks for attention and sorry for the inconvenience.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Fadik on Jan 24, 2014, 04:22 am
Mr_Arduino,
this is a snippet of the code that reads back from the camera:
it loops for the height of the image, reading back each row by looping through the row's bytes.
I am working with QQVGA and YUV422.
Code: [Select]
int CameraAL422B::readFrame(/*OutputStream *out*/) {
int i, n = 0;
resetReadPointer();
for (i = 0; i < height; i++) {
n += readRow(/*out*/);
}

54 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

//OE always LOW as it is GROUNEDED


//handle readClockPin
digitalWriteFast(readClockPin,HIGH);
digitalWriteFast(readClockPin,LOW);
digitalWriteFast(readClockPin,HIGH);
return n;
}
int CameraAL422B::readRow(/*OutputStream *out*/) {
int i;
uint8_t b,b1,b2;
uint8_t b3,b4,b5,b6,b7,b8;
for (i = 0; i < width; i++) {
digitalWriteFast(readClockPin,HIGH);
//out->write(read());
//read();f
//I want to waste the U/V component and take only the Y for gray scale.
//Fake a read for the first byte, take the second byte down below
digitalWriteFast(readClockPin,LOW);
//delayMicroseconds(1);
digitalWriteFast(readClockPin,HIGH);
//Low Byte in PINB
//High Byte in PIND
b1 = (PINB & (0b00001111));
b2 = (PIND & (0b11110000));
digitalWriteFast(readClockPin,LOW);
//combine and send to PC
b = b1 | b2;
Serial.write(b);
}
return i;
}

I have also attached the code I am using. it has been modified a lot from the original source I found on the net by combining another fellow contributor's work to do the list of reg. configurations.
missing some parent camera.cpp/.h files and digitalfastwrite.h library. but other than that i think you have all the necessary code.
I appreciate your time , this module has been driving me crazy!!!
Title: Re: ov7670 with both arduino uno and now mega
Post by: Fadik on Jan 24, 2014, 04:27 am
oh and this is the latest image.
Title: Re: ov7670 with both arduino uno and now mega
Post by: WendelOS on Jan 25, 2014, 11:55 am
Hello, I'm new here. I'm working with the camera OV7670 without fifo and am using a Arduino UNO to capture video from the camera and show this video to PC via USB. I will work with an 8MHz clock. Besides
the Arduino UNO and OV7670 camera, I wonder which integrated circuits (ICs) will need to capture the video? And what is the lowest resolution camera possible?
Thank you!
Title: Re: ov7670 with both arduino uno and now mega
Post by: xKoldFuzionx on Jan 26, 2014, 05:16 pm
OK, so, I'm still as lost as can be and just don't understand some things. First off, how did you know what registers to write to and in what order? The more I look at datasheets for almost anything, the more
frustrated I feel. It honestly is like I'm trying to decipher some ancient language that I just can't seem to grasp.
I get the registers and how to write to them. I get the code(for the most part), but I don't want to just copy yours. I really want to just write it for myself. That's why I ask how you knew which registers to write to.
Clearly you don't use them all. I'm assuming you left more than a few to default. I ask, cuz working with the 0V5642, I found some documentation for writing to the registers, but after going over it multiple times,
it seems to be application specific, and also not for the camera module/included hardware that I am using.
I know the 5642 is different, but it follows the same concept. You write to certain registers to adjust specific settings, then the camera responds when certain calls are made. (I know that's a crude explanation,
but you understand). I know if I can get the proper order and how you derived that from the datasheet, I can figure out the rest. I'm just not seeing anything about the order. Did I miss something?
Title: Re: ov7670 with both arduino uno and now mega
Post by: Jivex on Jan 26, 2014, 06:24 pm
Hello. I have following questions:
1. What additional hardware is necessary to connect OV7670 with fifo to Uno or Mega?
2. Is it possible to connect 2 cameras (OV7670 with fifo) to Uno or Mega (or any other Arduino board) and what additional hardware is necessary?
3. Is it possible to process pixel level information from the camera (e.g. if the specific pixel color of the specific image equals to red, light up an LED or do something else)?
4. Is any Arduino board capable to connect and manipulate 2 cameras, 2 audio input devices (e.g. microphone), a speaker, a gyro sensor and 4 or 5 motors? If yes, what additional hardware is necessary?
Many questions, but this is the right place to ask. Thank you in advance.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Benji1992 on Jan 28, 2014, 03:03 pm
I tryed to use this code but it dosn't work. First I need read the pixels in Raw RGB mode and send to serial.
This is my code:
Code: [Select]
#include <Wire.h>
#include <SdFat.h>
#include <SdFatUtil.h>
const int sd_select = 4;
uint8_t sensor_addr = 0x42;
SdFat sd;
SdFile file;

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

DDRB|=47;//clock as output and SPI pins as output except MISO


PORTB|=6;//set both CS pins to high

55 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

DDRC&=~15;//low d0-d3 camera


DDRD&=~252;//d7-d4 and interupt pins
//set up twi for 100khz
TWSR&=~3;//disable prescaler for TWI
TWBR=72;//set to 100khz
PgmPrintln("Camera init!");
// wrReg(0x15,32);//pclk does not toggle on HBLANK COM10 vsync falling
wrReg(0x12,0x80);
wrReg(0x11,0x01 );
wrReg(0x3a,0x04 );
wrReg(0x12,0x01 );
wrReg(0x17,0x12 );
wrReg(0x18,0x00 );
wrReg(0x32,0xb6 );
wrReg(0x19,0x02 );
wrReg(0x1a,0x7a );
wrReg(0x03,0x00 );
wrReg(0x0c,0x00 );
wrReg(0x3e,0x00 );
wrReg(0x70,0x3a );
wrReg(0x71,0x35 );
wrReg(0x72,0x11 );
wrReg(0x73,0xf0 );
wrReg(0xa2,0x02 );
wrReg(0x13,0xe0 );
wrReg(0x00,0x00 );
wrReg(0x10,0x00 );
wrReg(0x0d,0x40 );
wrReg(0x14,0x38 );
wrReg(0xa5,0x07 );
wrReg(0xab,0x08 );
wrReg(0x24,0x95 );
wrReg(0x25,0x33 );
wrReg(0x26,0xe3 );
wrReg(0x9f,0x78 );
wrReg(0xa0,0x68 );
wrReg(0xa1,0x0b );
wrReg(0xa6,0xd8 );
wrReg(0xa7,0xd8 );
wrReg(0xa8,0xf0 );
wrReg(0xa9,0x90 );
wrReg(0xaa,0x94 );
wrReg(0x13,0xe5 );
wrReg(0x0e,0x61 );
wrReg(0x0f,0x4b );
wrReg(0x16,0x02 );
wrReg(0x21,0x02 );
wrReg(0x22,0x91 );
wrReg(0x29,0x07 );
wrReg(0x33,0x03 );
wrReg(0x35,0x0b );
wrReg(0x37,0x1c );
wrReg(0x38,0x71 );
wrReg(0x3c,0x78 );
wrReg(0x3d,0x08 );
wrReg(0x41,0x3a );
wrReg(0x4d,0x40 );
wrReg(0x4e,0x20 );
wrReg(0x69,0x55 );
wrReg(0x6b,0x4a );
wrReg(0x74,0x19 );
wrReg(0x76,0x61 );
wrReg(0x8d,0x4f );
wrReg(0x8e,0x00 );
wrReg(0x8f,0x00 );
wrReg(0x90,0x00 );
wrReg(0x91,0x00 );
wrReg(0x96,0x00 );
wrReg(0x9a,0x80 );
wrReg(0xb0,0x8c );
wrReg(0xb1,0x0c );
wrReg(0xb2,0x0e );
wrReg(0xb3,0x82 );
wrReg(0xb8,0x0a );
wrReg(0x43,0x14 );
wrReg(0x44,0xf0 );
wrReg(0x45,0x34 );
wrReg(0x46,0x58 );
wrReg(0x47,0x28 );
wrReg(0x48,0x3a );
wrReg(0x59,0x88 );
wrReg(0x5a,0x88 );
wrReg(0x5b,0x44 );
wrReg(0x5c,0x67 );
wrReg(0x5d,0x49 );
wrReg(0x5e,0x0e );
wrReg(0x6c,0x0a );
wrReg(0x6d,0x55 );
wrReg(0x6e,0x11 );
wrReg(0x6f,0x9f );
wrReg(0x6a,0x40 );
wrReg(0x01,0x40 );
wrReg(0x02,0x40 );
wrReg(0x13,0xe7 );
wrReg(0x34,0x11 );
wrReg(0x92,0x66 );
wrReg(0x3b,0x0a );
wrReg(0xa4,0x88 );
wrReg(0x96,0x00 );
wrReg(0x97,0x30 );
wrReg(0x98,0x20 );
wrReg(0x99,0x20 );
wrReg(0x9a,0x84 );
wrReg(0x9b,0x29 );
wrReg(0x9c,0x03 );
wrReg(0x9d,0x4c );
wrReg(0x9e,0x3f );
wrReg(0x78,0x04 );
wrReg(0x79,0x01 );
wrReg(0xc8,0xf0 );
wrReg(0x79,0x0f );
wrReg(0xc8,0x20 );
wrReg(0x79,0x10 );
wrReg(0xc8,0x7e );
wrReg(0x79,0x0b );
wrReg(0xc8,0x01 );
wrReg(0x79,0x0c );
wrReg(0xc8,0x07 );
wrReg(0x79,0x0d );
wrReg(0xc8,0x20 );
wrReg(0x79,0x09 );
wrReg(0xc8,0x80 );
wrReg(0x79,0x02 );
wrReg(0xc8,0xc0 );
wrReg(0x79,0x03 );
wrReg(0xc8,0x40 );
wrReg(0x79,0x05 );
wrReg(0xc8,0x30 );
wrReg(0x79,0x26 );
if (!sd.begin(sd_select, SPI_FULL_SPEED)) sd.initErrorHalt();
PgmPrintln("RDY2B!");

56 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

;
pinMode(8,INPUT);
}
void loop(){
//PgmPrintln("Send One key to start image save");
int buttonState=1;
buttonState = digitalRead(8);

if(buttonState==0){
PgmPrintln("Img Capture Ok");
captureImg(0,0,1920,5);//each pixel is 2 bytes so 1280 instead of 640 for width
/*captureImg(1920,96,1920,96);
captureImg(1920,192,1920,96);
captureImg(1920,288,1920,96);
captureImg(1920,384,1920,96);*/
}

}
byte wrReg(int regID, int regDat)
{
//
Serial.println("Started");
Wire.beginTransmission(sensor_addr >> 1);
//
Serial.println("Began");
Wire.write(regID & 0x00FF);
Wire.write(regDat & 0x00FF);
if(Wire.endTransmission())
{
return 0;
PORTB|=32;
while (1) {}
}
//
Serial.println("Done!");
delay(1);
return(1);
}
void captureImg(uint16_t ws,uint16_t hs,uint16_t wg,uint8_t hg)
{//TODO: speed up this loop it misses one byte partway through the first line
//right now I am correcting this in the image converter software it is just one byte and not very
//noticable but it would still be nice to fix in my opion I do not have this issue when this loop is compiled with avr-gcc with a setting of -O2
Serial.end();
delay(200);
Serial.begin(115200);
Serial.println("OK");
uint16_t ls2,lg2;
//skip 1 multiplies skip 2 same with get1 and get2
//first wait for vsync it is on pin 3 (counting from 0) portD
//start spi ram
// cli();//make sure interupts are off
char* str;
char tmp;
str=(char*)malloc(12*sizeof(char));
while (!(PIND&8)) {}//wait for high
while ((PIND&8)) {}//wait for low
str[3]=';';
str[7]=';';
str[3]=';';
//for (lg1=0;lg1<hg;lg1++)
while ((uint8_t)hg--)
{
//for (lg2=0;lg2<wg;lg2++)
lg2=wg;
while (lg2--)
{
while (!(PIND&4)) {}//wait for high
// SPDR=(uint8_t)(PINC&15)|(PIND&240);
tmp=(PINC&15)|(PIND&240);
while ((PIND&4)) {}//wait for low
str[0]=tmp/100;
str[1]=(tmp%100)/10;
str[2]=tmp%10;
/*while (!(PIND&4)) {}//wait for high
// SPDR=(uint8_t)(PINC&15)|(PIND&240);
tmp=(PINC&15)|(PIND&240);
while ((PIND&4)) {}//wait for low
str[4]=tmp/100;
str[5]=(tmp%100)/10;
str[6]=tmp%10;
while (!(PIND&4)) {}//wait for high
// SPDR=(uint8_t)(PINC&15)|(PIND&240);
tmp=(PINC&15)|(PIND&240);
while ((PIND&4)) {}//wait for low
str[8]=tmp/100;
str[9]=(tmp%100)/10;
str[10]=tmp%10;*/
str[3]='\0';
//str[4]='\0';
for(int i=0;i<3;i++) str[i]+=48;
for(int i=4;i<7;i++) str[i]+=48;
for(int i=8;i<11;i++) str[i]+=48;
// str[4]='\0';
//PgmPrintln(str);
Serial.println(str);
}
/*
str[1]='\0';
str[0]='\r';
StringPgm(str);
str[0]='\n';
StringPgm(str);*/
}
}
uint8_t RdSerial(void)
{
/* Wait for data to be received */
while ( !(UCSR0A & (1<<RXC0)) );
/* Get and return received data from buffer */
return UDR0;
}
void spiCSt(void)

57 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

{
//toggles spi CS used for reseting sram
PORTB|=6;//cs high
//_delay_ms(1);
PORTB&=~4;//cs low
}
void spiWrB(uint8_t dat)
{
SPDR = dat;
// Wait for transmission complete
while(!(SPSR & (1<<SPIF))) {}
}
void StringPgm(char * str)
{
do {
serialWrB(pgm_read_byte_near(str));
} while(pgm_read_byte_near(++str));
}
void serialWrB(uint8_t dat)
{
while ( !( UCSR0A & (1<<UDRE0)) ) {}
UDR0=dat;
while ( !( UCSR0A & (1<<UDRE0)) ) {} //wait for byte to transmit
}

I generate XCLOCK an external source and its 13MHz.


This is what send on serial:
Code: [Select]
Camera init!
RDY2B!
Img Capture Ok
OK
016
016
016
016
016
016
016
016
016
016
016
016
016
016
016
016
016
016
016
016
016
016
016
016
016
016
016
016
016
016
016
016
016
016
016
016
016
016
016
016
016
016
017
028
016
017
022
023
016
016
023
..... etc.

I converted the RGB code to bmp image but the pixels don't show what camera see.
Can anybody help me whats the problem?
Thanks!
Title: OV7670 Query Alert
Post by: TekuConcept on Feb 04, 2014, 08:46 pm
As many others out there, I've been at this camera setup for quite a while... I have read and re-read the various forums and documentation out there. The pinouts are pretty self explanatory but I do believe there
are still unanswered questions on behalf of this camera:
[OV7670 w/o FIFO]
Are frames captured automatically when the camera is powered on? (In other words, when I tie 3v3, Gnd, XCLK, PCLK, VSYNC/HREF, and [D7:D0] respectively, will I be able to observe rising and falling
edges on a digital oscilloscope?) If not, which register do I need to write to to capture a frame? Answer: YES

Is this correct formatting? a) SCCB runs at at-most 100KHz; b) To start and end a transmission with SCCB, one must toggle { SIO_D->high, SIO_C->high, SIO_D->low, SIO_C->low } in that order. (Or in
other words toggle data line while clock is high.) In between the start and stop signals, an 8-bit word is clocked { SIO_D->X, SIO_C->high, SIO_C->low }[7:0]. Following the word, a parity bit is received {
SIO_D<-low, SIO_C->high, SIO_D<-X, SIO_C->low }. c) To write to an address, one must write 0x42, register, and data, in that order. d) To read from an address, one must write 0x42, register, end, start,
0x43, and then read data.

The OV chip is of type CMOS which are fragile to the electromagnetic environment. Do these cameras have built in protection or will I need to take the same precautions as with any other CMOS device?
ie: anti-static wrist strap, and capacitive/inductive/zener voltage protection from sudden power on/off (un/plugging arduino). Answer: In a way they do in that they can be handled physically and come
shipped w/o anti-static protection; This also seems to be the same with power - though I wouldn't risk pulling it's 3v3 line while hot.

At the very least, I needed to know the answer to the first.


Background: no queue (fifo), 20MHz XCLK (no PCKL signal at the moment - due to open circuit), 2v9 for logic high and power (330ohm/R:470ohm/R for voltage divider), using Arduino Uno R3 for prototyping

58 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

and debugging
Source references:
SCCB Code: https://github.com/una1veritas/ARMWork/blob/master/stm32f3x_OV7670/sccb.cpp
SCCB Specification: http://www.ovt.com/download_document.php?type=document&DID=63
Title: Re: ov7670 with both arduino uno and now mega
Post by: rock5566r on Mar 08, 2014, 06:37 pm
Hi! I'm a beginner of electronics. I'm wondering that can I use uno3 to control OV7670 with FIFO to take a picture and save it as a file. Then send it to my PC by using Ethernet shell. Is it possible to do that?
Thanks in advance.
rock5566r
Title: Re: ov7670 with both arduino uno and now mega
Post by: Koepi on Mar 09, 2014, 03:07 pm
I'm also absolutely new to Arduino, will shortly have 5 different Arduino Nano versions.
But I also ordered the cheap non-FIFO OV7670 (http://www.ebay.ca/itm/CMOS-Camera-Module-OV7670-Display-Active-Size-640X480-SCCB-Compatible-I2C-3-6-m-/400578369245) (and also the FIFO version
which seems only to be usable with different platform like RasPi). After reading through this thread I realized that the 2k SRAM definitly is insufficient. Thus I also ordered 5 pieces of 16MBit SPI eeproms
(http://www.ebay.com/itm/5PCS-W25Q16BVSSIG-16M-BIT-SERIAL-FLASH-MEMORY-WITH-DUAL-AND-QUAD-SPI-SOP8-/321165418730), and SOIC8-to-DIP sockets (http://www.ebay.com/itm/New5pcs-SOP8-SO8-SOIC8-TO-DIP8-adapter-pcb-conveter-board-/180952961067) to carry them. Quite cheap, actually altogether about 7 Euros. If I understand SPI/I2C correctly, I share the MISO/MOSI/SCK line
and only need one pin for addressing each of the different devices like EEPROM and SDCARD. My idea is to fetch the image without the FIFO byte-by-byte and directly write through to the EEPROM (it supports
writing even single bytes according to the data sheet (http://www.winbond.com/NR/rdonlyres/7EB3B29C-1B35-421C-AA24-F430B51C776A/0/W25Q16BV.pdf)) which could even hold 2 images in 640x480x3
RAW format (921KByte x 2). As soon as it is stored in EEPROM, I have all the time in the world to copy that over to SDcard.
My project is a long-time observation with 1 image per day, for example each evening at 18h one image (RTC (http://www.ebay.com/itm/New-Arduino-RTC-DS1302-Real-Time-Clock-Module-For-AVR-ARM-PICSMD-/200931981696) is also on the way). I would put the Arduino-timelapse-cam somewhere where it is dry but the nature is well visible. From theory, the Arduino needs so little power, for one image per day,
that with a single LiIon 18650 battery charge it should give me 365 images without needing any service. ;)
Do you have any suggestions if I'm on the right track?
Is there maybe some 8 MBit RAM module out there which could be used via SPI?
Is this camera a total loss and I should spend the money on a JPEG camera, about triple to quadruple the price?
I hope I won't need to stress your help too much and too often as soon as the items arrive :D
Another thought about the FIFO version. A friend suggested - if I need to pause read-out for writing the data, instead of using the /RE pin which isn't available in pinout, set the RCLK (read clock) to 0. Sounds
plausible as solution.
Thanks a million,
Best regards,
Koepi

Edit4: Some major cleanup with properly using links, additional info about FIFO camera module...
Title: Re: ov7670 with both arduino uno and now mega
Post by: angeleye9 on Mar 12, 2014, 04:03 am
Hi Mr arduino;
I am getting an completeley white image from OV7670+fifo driven by Arduino mega. Do you have any idea why this is happen?
Title: Re: ov7670 with both arduino uno and now mega
Post by: marcioferrari on Mar 13, 2014, 12:12 am
Quote from: nerdroide on Dec 28, 2013, 04:16 pm
Quote from: Mr_arduino on Dec 28, 2013, 05:26 am
I submitted a pull request that may solve some issues but I doubt it will work. There are two problems first of all the Ethernet shield that you are using uses pins 2,4,10,11,12,13 you appear to have pins 2 and 4 hooked up to the ov7670 also I think that the function you
are using to send data to the wiznet 5100 is too slow try directly sending the data without using those silly arduino library functions.

Hum... so, my function that sends the pixels to the server is slow? Well, I will change this, I just need to finish the article about the project... hehe
And the shield ethernet is using the pins 10,11,12 and 13. I think that just this. The pin 4 is used for the sdCard, so I disabled it. The registers are right?

Title: Re: ov7670 with both arduino uno and now mega
Post by: dtsonchev on Apr 02, 2014, 10:50 am
Hello
My name is Desislav, am Bulgarian.
Advance I want to apologize for my bad English.
I have the ARDUINO MEGA, LCD and camera MT9D111
I downloaded the code and https://github.com/ComputerNerd/arduino-camera-tft,
and I have two problems:
1. Can you give me a wiring diagram of the three modules?
2. When I try to compile my project out error:
Error 15 exiticon.h: No such file or directory, this file miss.
Thank PRELIMINARY.
Title: Re: ov7670 with both arduino uno and now mega
Post by: jonpwn on Apr 19, 2014, 05:07 pm
sorry for the grave digging.. i am absolutely stumped and not sure about a few things. I am using the OV7670 with FIFO buffer, the 22 pin header version.
Do i need to do ANYTHING to the control registers upon boot up? I want to use all default settings, YUV, no gain or any DSP of any kind. My intention is to read every other byte and grab the Y byte for each
pixel. I am under the impression that if i want to use the default registers, I do not need to use sccb interface to do anything. Is this wrong?
also is anyone familiar with the FIFO version? If so, is my initalization sequence and data read correct per the data sheet for al422b? (i am implementing a bit banging process because I am using raspberry pi)

59 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

apply power to module:


write_reset = low; //resetting read and write addresses to 0 (beginning)
read_reset = low;
write_reset = high;
read_reset = high;
write_enable = high;

//allow ov7670 to write to FIFO

to read data from FIFO:


write_enable = low;
output_enable = low; //active low
read_reset = low;
read_clock = low; //allow one RCK cycle for reset cycle
read_clock = high;
read_clock = low; //one more cycle
read_clock = high; //finish reset cycle
read_reset = high;
read_clock = low;
grab first byte
read_clock = high;
and so on for 300K pixels
output_enable = high;
write_enable = high
thank you very much for all your help
Title: Re: ov7670 with both arduino uno and now mega
Post by: vvavepacket on Apr 22, 2014, 03:17 am
anybody tried to use the 'Wire.h' to write registers in OV7670?
Thanks
Title: Re: ov7670 with both arduino uno and now mega
Post by: AlienXdani on Apr 25, 2014, 09:27 pm
:D opinion? https://www.kickstarter.com/projects/254449872/pixy-cmucam5-a-fast-easy-to-use-vision-sensor
Title: Re: ov7670 with both arduino uno and now mega
Post by: vvavepacket on Apr 28, 2014, 12:45 pm
Does anybody here have success in writing registers like 0x01 and 0x02, 0x03?
I can write to registers like 0x80, etc.. but I can't write those first range registers..
Thanks
Title: Re: ov7670 with both arduino uno and now mega
Post by: Koepi on Apr 30, 2014, 04:41 pm
Just to give some info about my progress: I currently am fiddling with the non-FIFO version on a STM32F103 - it can cope with the data and speed way better than a poor 8-bit ATmega. It also has way more
GPIO pins. I didn't take a too close look at the FIFO version, but it should be much easier to fetch the data as you don't react on PCLK as signal for reading the input byte, but instead toggle/clock RCLK. (And as
the question came up and I had it myself: No, you don't need any I2C initialisation of the cam. It spits out YUV, 640x480 at the provided XCLK frame rate. And having the possibility to talk to the camera with I2C
is sure nice. I need that for setting a prescaler on XCLK to get the data rate down.)
I now found some very cheap offers for JPEG cameras with higher resolution - namely the MD9T111 (1600x1200, 2 Mpix, ordered here (http://www.ebay.com/itm/2-Mega-pixel-Camera-Module-MT9D111JPEG-Out-/280572965951)) Mr.arduino is using now, and a OV5642 (2592x1944, 5MPix, for example here (http://www.ebay.com/itm/5-Mega-pixel-Camera-Module-OV5642-1080P-JPEG-Output/271130719953)). The first one is less than 15 Euros shipped, the last one did cost me 19,50 Euros this morning. Just use Google for the chip, it'll guide you to the cheaper eBay offers, while eBay doesn't even
show those when using the eBay search(!).
Both cameras offer the advantage of higher resolution, better image quality and already usable JPEG image output; their JPEG encoder also offers a (very small but) slightly intelligent FIFO buffer with a
tripple-stage data rate reduction scheme (clock slowdown) until buffer overrun ;) Ideal solution for my timelapse-camera idea.
Anyhow, I will still be fiddling around with the just little cheaper OV7670 based cams as I already have those and it's a good training.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on May 06, 2014, 03:17 am
Though I regret taking a break from responding to everyone that is what happend so I will now go in reverse order and answer peoples questions.
Koepi Good to hear that you are making good progress Koepi. I admit to not having done much with camera modules in a while. I plan to this weekend or whenever I can find some time. The reason I played for
the ov7670 in the first place was time lapse reasons. I find the flexibility of controlling the camera in a way desired by the programmer to be beneficial for higher quality time lapses.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on May 06, 2014, 03:18 am
Quote from: vvavepacket on Apr 28, 2014, 12:45 pm
Does anybody here have success in writing registers like 0x01 and 0x02, 0x03?
I can write to registers like 0x80, etc.. but I can't write those first range registers..
Thanks

Yes vvavepacket I have had success writting to registers. Have you considered just copying and pasting the code I have written that writes to registers and using that. You may need to make some modifications
but it should work for your needs.

60 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on May 06, 2014, 03:21 am
Quote from: AlienXdani on Apr 25, 2014, 09:27 pm
:D opinion? https://www.kickstarter.com/projects/254449872/pixy-cmucam5-a-fast-easy-to-use-vision-sensor

I have not done much research on the project but it is kind of an inspiration as in I want to make a product myself one day based on a more powerful cmos sensor that has ready to use code and such and I am
glad to know that there is a good market for that.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on May 06, 2014, 03:30 am
Quote from: vvavepacket on Apr 22, 2014, 03:17 am
anybody tried to use the 'Wire.h' to write registers in OV7670?
Thanks

Yes I have done such in fact I have really old code that does just that see http://pastebin.com/1nnRc5qL the function of interest is called wrReg. I have cleaned up the code and posted it below
Code: [Select]
byte wrReg(unsigned char regID, unsigned char regDat){
Wire.beginTransmission(sensor_addr >> 1);
Wire.write(regID);
Wire.write(regDat);
if(Wire.endTransmission()){
return 0;
while(1);
}
delay(1);
return 1;
}

Before using the function please add this to setup()


Code: [Select]
Wire.begin();

Also you will need to add


Code: [Select]
#define sensor_addr 0x42

To your code
I will try and get to more questions tomorrow.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on May 06, 2014, 10:53 pm
Quote from: jonpwn on Apr 19, 2014, 05:07 pm
Do i need to do ANYTHING to the control registers upon boot up?

Yes but I have found that by modifying registers you can get better picture quality. I remember the first pictures I took with the ov7670 they looked like the hue was shifted. By better configuring the registers I
fixed the wrong colors.
Quote
also is anyone familiar with the FIFO version?

I keep forgetting to buy one I plan to at some point in time.


Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on May 06, 2014, 10:56 pm
Quote from: dtsonchev on Apr 02, 2014, 10:50 am
Hello
My name is Desislav, am Bulgarian.
Advance I want to apologize for my bad English.
I have the ARDUINO MEGA, LCD and camera MT9D111
I downloaded the code and https://github.com/ComputerNerd/arduino-camera-tft,
and I have two problems:
1. Can you give me a wiring diagram of the three modules?

The code only supports one camera module at a time. It does have an sd card and tft screen attached to it also is that what you mean?
Quote
2. When I try to compile my project out error:
Error 15 exiticon.h: No such file or directory, this file miss.
Thank PRELIMINARY.

Sorry I forgot to include that file in my repository I have added it.


Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on May 06, 2014, 11:02 pm
Quote from: Koepi on Mar 09, 2014, 03:07 pm
Thus I also ordered 5 pieces of 16MBit SPI eeproms (http://www.ebay.com/itm/5PCS-W25Q16BVSSIG-16M-BIT-SERIAL-FLASH-MEMORY-WITH-DUAL-AND-QUAD-SPI-SOP8-/321165418730), and SOIC8-to-DIP sockets (http://www.ebay.com/itm/New-5pcs-SOP8SO8-SOIC8-TO-DIP8-adapter-pcb-conveter-board-/180952961067) to carry them. Quite cheap, actually altogether about 7 Euros. If I understand SPI/I2C correctly, I share the MISO/MOSI/SCK line and only need one pin for addressing each of the different devices like
EEPROM and SDCARD. My idea is to fetch the image without the FIFO byte-by-byte and directly write through to the EEPROM (it supports writing even single bytes according to the data sheet (http://www.winbond.com/NR/rdonlyres/7EB3B29C-1B35-421CAA24-F430B51C776A/0/W25Q16BV.pdf)) which could even hold 2 images in 640x480x3 RAW format (921KByte x 2). As soon as it is stored in EEPROM, I have all the time in the world to copy that over to SDcard.
My project is a long-time observation with 1 image per day, for example each evening at 18h one image (RTC (http://www.ebay.com/itm/New-Arduino-RTC-DS1302-Real-Time-Clock-Module-For-AVR-ARM-PIC-SMD-/200931981696) is also on the way). I would put the
Arduino-timelapse-cam somewhere where it is dry but the nature is well visible. From theory, the Arduino needs so little power, for one image per day, that with a single LiIon 18650 battery charge it should give me 365 images without needing any service. ;)

Wow that sounds like an exciting project. I will say that eeprom can wear out however I doubt that you will be taking 100000 images. I use sram.

61 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Quote
Do you have any suggestions if I'm on the right track?
Is there maybe some 8 MBit RAM module out there which could be used via SPI?
Is this camera a total loss and I should spend the money on a JPEG camera, about triple to quadruple the price?

It really depends on what you want to do. I will note that the MT9D111 has a much better quality image and the jpeg output is nice to have it saves on memory.
Quote
I hope I won't need to stress your help too much and too often as soon as the items arrive :D

I am sure you won't feel free to ask whatever you need to.
Quote
Another thought about the FIFO version. A friend suggested - if I need to pause read-out for writing the data, instead of using the /RE pin which isn't available in pinout, set the RCLK (read clock) to 0. Sounds plausible as solution.
Thanks a million,
Best regards,
Koepi

Edit4: Some major cleanup with properly using links, additional info about FIFO camera module...
Here is what the datasheet has to say about that
Quote
It is recommended that the WCK and RCK are kept running at least 1MHz at all times. The faster one
of WCK and RCK is used as the DRAM refresh timing clock and has to be kept free running. When
irregular FIFO I/O control is needed, keep the clock free running and use /WE or /RE to control the
I/O as follows:

Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on May 06, 2014, 11:03 pm
Quote from: rock5566r on Mar 08, 2014, 06:37 pm
Hi! I'm a beginner of electronics. I'm wondering that can I use uno3 to control OV7670 with FIFO to take a picture and save it as a file. Then send it to my PC by using Ethernet shell. Is it possible to do that?
Thanks in advance.
rock5566r

Yes it is very possible.


Title: Re: OV7670 Query Alert
Post by: Mr_arduino on May 07, 2014, 02:33 am
Quote from: TekuConcept on Feb 04, 2014, 08:46 pm

Is this correct formatting? a) SCCB runs at at-most 100KHz; b) To start and end a transmission with SCCB, one must toggle { SIO_D->high, SIO_C->high, SIO_D->low, SIO_C->low } in that order. (Or in other words toggle data line while clock is high.)

Yes for the start transmission before that SIO_C must be held high infact accourding to the SCCB specification that you linked to says that
Quote
The
master must drive SIO_C at logical 1 when the
bus is idle. A data transmission starts when SIO_C is driven at logical 0 after the start of
transmission. A logical 1 of SIO_C during a data
transmission indicates a
single transmitted bit.
Thus, SIO_D can occur only when SIO_C is driven
at 0.
Quote
In between the start and stop signals, an 8-bit word is clocked { SIO_D->X, SIO_C->high, SIO_C->low }[7:0]. Following the word, a parity bit is received { SIO_D<-low, SIO_C->high, SIO_D<-X, SIO_C->low }. c) To write to an address, one must write 0x42, register, and
data, in that order. d) To read from an address, one must write 0x42, register, end, start, 0x43, and then read data.[/li][/list]

Well you are correct first you send the device ID except the 9th bit send is not a parity bit it is a don't care bit.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on May 07, 2014, 02:38 am
Quote from: Benji1992 on Jan 28, 2014, 03:03 pm
I tryed to use this code but it dosn't work. First I need read the pixels in Raw RGB mode and send to serial.

Your problem is that you are reading pixels too slowly you cannot do a string conversion and send it over serial after reading a byte. What you could do is send it to external SRAM and then send it over serial.
Also never convert to plain text when sending binary data there are NO ADVANTAGES to doing such. It will make the image take much longer to transfer over 3 times the amount of time. Also how did you
convert it from raw rgb to regular rgb. Remember the ov7670 uses a bayer filter (see https://en.wikipedia.org/wiki/Bayer_filter ) you must use a demosaicing algorithm. I have written a program to do such see:
https://github.com/ComputerNerd/RawCamera-data-converter
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on May 07, 2014, 02:43 am
Quote from: Jivex on Jan 26, 2014, 06:24 pm
Hello. I have following questions:
1. What additional hardware is necessary to connect OV7670 with fifo to Uno or Mega?

Two resistors and a method to get a 5v signal down to 3.3v (only needed for one output). I use a buffer.
Quote

62 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

2. Is it possible to connect 2 cameras (OV7670 with fifo) to Uno or Mega (or any other Arduino board) and what additional hardware is necessary?

The arduino uno does not have enough pins. The arduino mega could handle it.
Quote
3. Is it possible to process pixel level information from the camera (e.g. if the specific pixel color of the specific image equals to red, light up an LED or do something else)?

Well technically yes but you may want a faster processor for this
Quote
4. Is any Arduino board capable to connect and manipulate 2 cameras, 2 audio input devices (e.g. microphone), a speaker, a gyro sensor and 4 or 5 motors? If yes, what additional hardware is necessary?
Many questions, but this is the right place to ask. Thank you in advance.

Do you want to run these all at the same time? If so you may want to use a better processor.
Title: Re: ov7670 with both arduino uno and now mega
Post by: maminej on May 07, 2014, 09:24 pm
Hello Guys,
I started working on interfacing the OV7670 sensor with Arduino Mega with an SRAM and an SD card.
I used Mr_Arduino code to generate an 8Mhz clock signal, buffered to 3.3V then connected it to the system clock input XCLK pin of the OV7670.
Here is the traces I recoded with an oscilloscope.
I recoded these at the output of the Arduino before connecting ( Trace 1) , after connecting to the XCLK then at the Pixel clock output PCLK.
Here is the results:
At the output of the Buffer:
(http://i59.tinypic.com/2vb4x1u.png)
After connecting the XCLK
(http://i58.tinypic.com/2u89uky.png)
At the output PCLK output.
(http://i62.tinypic.com/99gpac.png)
Mr_Arduino,
Did you have a similar wave at the PCLK output pin ? Do you think I can use such a signal to trigger the capture image function ?
Why is the clock signal coming out so distorted ?
Thanks in advance for your help..
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on May 07, 2014, 11:27 pm
It seems like an issue of noise I have looked at the PCLK from the ov7670 and it is way cleaner that what you posted. Here is a picture of XCLK
(http://img689.imageshack.us/img689/4474/x4yt.jpg)
What buffer are you using?
Title: Re: ov7670 with both arduino uno and now mega
Post by: maminej on May 07, 2014, 11:39 pm
I am using a 74HC245 with a Vcc of 3.3V.
I added a 200R load at the output of the PWM pin, otherwise the output shape is even worse.
I don't see a waveform degradation at the output of the buffer, The waveform right after the PWM is pretty close the buffer output.
I am using a 200Mhz Tektronix probe.
Can you please post a picture of your PCLK output.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on May 09, 2014, 10:08 pm
This is just a guess but I believe that the buffer that you are using is too slow.
For my buffer of choice I used a 74ahc125.
Here is the datasheet for that buffer: http://www.ti.com/lit/ds/symlink/sn74ahc125.pdf
Look at SWITCHING CHARACTERISTICS over recommended operating free-airtemperature range VCC=3.3V0.3V note that the switching time is faster that the 74hc245 http://www.ti.com/lit/ds/symlink
/sn54hc245-sp.pdf you can also read about it's switching characteristics but their is no 3.3v measurements done.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on May 09, 2014, 11:04 pm
Quote from: xKoldFuzionx on Jan 26, 2014, 05:16 pm
OK, so, I'm still as lost as can be and just don't understand some things. First off, how did you know what registers to write to and in what order? The more I look at datasheets for almost anything, the more frustrated I feel. It honestly is like I'm trying to decipher some
ancient language that I just can't seem to grasp.

Yes it may seem complicated at first, but with practice you will get better and no more will it feel challenging. Order does not always matter. If it does it may should be stated in the datasheet however omnivision
has a track record of releasing crappy datasheets that leave out important details. Actually I think they have a datasheet with the information but they keep it secret. That could be at-least part of your frustration.
However in the case of the OV5642 I think the Preliminary specifications seem more complete. It should allow you to get an image out of it.
Quote
I get the registers and how to write to them. I get the code(for the most part), but I don't want to just copy yours. I really want to just write it for myself. That's why I ask how you knew which registers to write to. Clearly you don't use them all. I'm assuming you left more
than a few to default. I ask, cuz working with the 0V5642, I found some documentation for writing to the registers, but after going over it multiple times, it seems to be application specific, and also not for the camera module/included hardware that I am using.

Yes that is correct you don't need to write to all the registers just what needs to be changed.
Quote
I know the 5642 is different, but it follows the same concept. You write to certain registers to adjust specific settings, then the camera responds when certain calls are made. (I know that's a crude explanation, but you understand). I know if I can get the proper order and
how you derived that from the datasheet, I can figure out the rest. I'm just not seeing anything about the order. Did I miss something?

Yes that is correct. Just write to registers and the camera will respond with the changes they key is making the right changes and knowing what those changes imply for example the ov7670 has undocumented
values you can write to those registers but I don't know what they actually do.

63 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on May 09, 2014, 11:12 pm
Quote from: WendelOS on Jan 25, 2014, 11:55 am
Hello, I'm new here. I'm working with the camera OV7670 without fifo and am using a Arduino UNO to capture video from the camera and show this video to PC via USB. I will work with an 8MHz clock. Besides the Arduino UNO and OV7670 camera, I wonder which
integrated circuits (ICs) will need to capture the video? And what is the lowest resolution camera possible?
Thank you!

You will need a buffer to get the 5v clock signal to 3.3v. Also you will need two resistors. 4.7k or 10k work well. The lowest resolution is 40x30.
Title: Re: ov7670 with both arduino uno and now mega
Post by: vvavepacket on May 10, 2014, 01:11 am
@Mr_Arduino
Ive been getting YUV output from the camera.. Y - grayscale looks ok, but when I try to convert YUV422 to RGB,, it doesnt display correct colors/messes up.. Heres a sample output.
(http://puu.sh/8G00J.jpg)
and here is the correct / actual shot from ipad
(http://puu.sh/8G0np.jpg)
PS: I use this formula
(http://upload.wikimedia.org/wikipedia/en/math/4/e/b/4ebf7992636ec7100e2f0f68a4f2c2ca.png)
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on May 10, 2014, 02:13 am
Could you please attach the raw data that gave you purple image. I will analyze it. I think it has to do with byte order.
Title: Re: ov7670 with both arduino uno and now mega
Post by: vvavepacket on May 10, 2014, 02:24 am
Attached the raw file.

@Mr_Arduino.. I did the color bar test,, and captured it in MATLAB, then applied RGB conversions,, heres what I got.
(http://puu.sh/8G4rU.png)
The colorbar test I captured looks good. I think it has something to do with correct registers. Do you have the optimum registers for YUV? i think hues are shifted. Thanks
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on May 10, 2014, 02:48 am
That file that you posted appears to be specific to matlab. I do not have matlab. Could you just post headerless data. For example what I do is just have a file that stores all pixels captured in order for example
byte 0 is pixel (0,0). byte 1 would be pixel (1,0) and so on. Anyways if I have to guess on what register could solve you problem in the past I too have had a problem with getting purple pictures. I found that an
undocumented register solved my issue try writing to the address 0xb0 sending a value of 0x84
This may solve your issue. If not try adding this in addition to writing 0x84 to the address 0xB0
Code: [Select]

{
{
{
{
{
{
{
{
{
{
{

{ REG_COM7, 0x0 }, /* Selects YUV mode */


REG_RGB444, 0 },
/* No RGB444 please */
REG_COM1, 0 },
REG_COM15, COM15_R00FF },
REG_COM9, 0x6A }, /* 128x 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 },

The order is address,register value


There are some definitions that you need get them from here https://github.com/ComputerNerd/arduino-camera-tft/blob/master/camregdef.h
Title: Re: ov7670 with both arduino uno and now mega
Post by: vvavepacket on May 10, 2014, 02:57 am
Here is the headerless binary file, straight from the memory (attached)
Cheers

PS: the 01,03,05,07,09,b,d,f, are all '0'/zeros, nevermind those. (something to do with memory/byte addressing)

(http://puu.sh/8G6f2.png)
Title: Re: ov7670 with both arduino uno and now mega
Post by: vvavepacket on May 10, 2014, 03:34 am
result:
(http://puu.sh/8G8sV.jpg)
actual:
(http://puu.sh/8G0np.jpg)

64 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on May 10, 2014, 03:44 am
Alright it looks like you are making progress. I think it may be registers that are causing the coloration not byte order. I have tried a few different orders and so far I get the same results the purple image. Also I
think you may need to write more registers. Auto white balance would be of benefit. Try adding these registers
Code: [Select]
wrReg(AWBC7,0x88);
wrReg(AWBC8,0x88);
wrReg(AWBC9,0x44);
wrReg(AWBC10,0x67);
wrReg(AWBC11,0x49);
wrReg(AWBC12,0x0e);
wrReg(AWBCTR3,0x0a);
wrReg(AWBCTR2,0x55);
wrReg(AWBCTR1,0x11);
wrReg(AWBCTR0,0x9f);

Tell me if it works for you. However better yet you could use these registers instead
Code: [Select]
const struct regval_list ov7670_default_regs[] PROGMEM = {//from the linux driver
{ REG_COM7, COM7_RESET },
{ 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 changed to 1*/1},{ REG_COM10, 0x0 },
/* 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 },
{ 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_AGC|COM8_AEC },
{0x30,0},{0x31,0},//disable some delays
/* 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 },
/*{ 0x6b, 0x4a },*/
{ 0x74,0x10},
{ 0x8d, 0x4f }, { 0x8e, 0 },
{ 0x8f, 0 },
{ 0x90, 0 },
{ 0x91, 0 },
{ 0x96, 0 },
{ 0x9a, 0 },
{ 0xb0, 0x84 },
{ 0xb1, 0x0c }, { 0xb2, 0x0e },
{ 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, 0x9e }, /* it was 0x9F "9e for advance AWB" */
{ 0x6a, 0x40 }, { REG_BLUE, 0x40 },
{ REG_RED, 0x60 },
{ REG_COM8, COM8_FASTAEC|COM8_AECSTEP|COM8_AGC|COM8_AEC|COM8_AWB },
/* Matrix coefficients */
{ 0x4f, 0x80 }, { 0x50, 0x80 },
{ 0x51, 0 },
{ 0x52, 0x22 },
{ 0x53, 0x5e }, { 0x54, 0x80 },
{ 0x58, 0x9e },
{
{
{
{
{
{

REG_COM16,
0x75, 0x05
0x4c, 0 },
REG_COM13,
0xc9, 0x60
0x56, 0x40

{
{
{
{
{
{
{

0x34,
0xa4,
0x97,
0x99,
0x9b,
0x9d,
0x78,

COM16_AWBGAIN },
{ REG_EDGE, 0 },
}, { REG_REG76, 0xe1 },
{ 0x77, 0x01 },
/*0xc3*/0x48 },
{ 0x4b, 0x09 },
}, /*{ REG_COM16, 0x38 },*/
},

0x11 }, {
0x82/*Wax
0x30 }, {
0x30 }, {
0x29 }, {
0x4c }, {
0x04 },

REG_COM11,
0x88*/ },
0x98, 0x20
0x9a, 0x84
0x9c, 0x03
0x9e, 0x3f

COM11_EXP|COM11_HZAUTO },
{ 0x96, 0 },
},
},
},
},

/* 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 }, /* END MARKER */
};

65 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

These are from my code located here https://github.com/ComputerNerd/arduino-camera-tft/blob/master/ov7670_regs.h


Just don't write the last register group 0xFF to the ov7670 that is just an end marker. Anyways tomorrow I plan to write a program that tries every single byte order and see if any are the right color. I am
interested in the real cause of the purple images.
Title: Re: ov7670 with both arduino uno and now mega
Post by: vvavepacket on May 10, 2014, 04:01 am
result

the purple thingy hue effect doesnt go away.. makes us curious. hmmm

@Mr_Arduino
why is that the U and V components are so grainy?? how do we remove, smooth or lessen the grainiess of that in the image? (basically i have an algorithm that works in the Y-U-V colorspace,, and the
grainyness kills it)
btw, why is that my image has those horizontal like streaks distributed everywhere..
here are the rgb and grayscale
(http://puu.sh/8Geaw.jpg)
here are the U and V
(http://puu.sh/8GdYN.jpg)
basically, how can we remove or lessen the grainess in the U-V?
Cheers
Title: Re: ov7670 with both arduino uno and now mega
Post by: erdikuzu on May 10, 2014, 01:02 pm
Hey all,
I've been working on a school project that captures an image and sends it to android system via bluetooth.
I've looked this topic and i'm bit confused.
My system has an Arduino uno, Arduino BT (Bluetooth) and OV7725 (with FIFO) .
I understood i2c, FIFO communication, how image captured, but i can't understand registry codes. Would you help me?
Note: When i was searching, i found a project same as my project. Here it's source code (in attach) and shema. Is it posible?
http://nicolasfley.fast-page.org/wp-content/uploads/2013/09/schema_arduino_FIFO_OV7670.png
Title: Re: ov7670 with both arduino uno and now mega
Post by: vvavepacket on May 10, 2014, 01:05 pm
@Mr_Arduino
ive wake up and notice a different / messed up colors.
(http://puu.sh/8GxEq.jpg)
I dont know how can I get the same correct colors as before (registers settings) like this
(http://puu.sh/8GxNa.jpg) :(
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on May 10, 2014, 02:11 pm
Here is how I initialize the ov7670 I first reset it using
Code: [Select]
wrReg(0x12, 0x80);
_delay_ms(100);

The delay makes sure that everything is ready before doing any further writes.
I then write that long list of initialization registers. After that I set color space settings and then finally after that I write resolution settings. Note that before I set vga mode I write
Code: [Select]
wrReg(REG_COM3,0);

// REG_COM3

Since the ov7670 defaults to vga you may not need to worry about setting the resolution. However if you want to change to something other than vga I write this before sending the registers to set the resolution.
Code: [Select]
wrReg(REG_COM3,4);

// REG_COM3 enable scaling

Again you can get the register lists from here https://github.com/ComputerNerd/arduino-camera-tft/blob/master/ov7670_regs.h
There are a few ways to reduce noise. The first way is to enable the built in noise filter. This is done in the ov7670's software.Remember the ov7670 is actually an SoC. It has an internal dsp. You can enable bit
4 in register 0x41 (COM16).
The second way is to enable night mode. This will increase the exposure time and you will have less noise. To enable night mode write 0xE0 to register 0x3B (COM11). The ov7670 will use a lower gain if
possible however if things get really dark it will still use the maximum programmed gain. To adjust maximum gain see register 0x14 (COM9). I find it better to have a noisy bright image than a dark image. Also it
is better to have the ov7670 give you a bright image with it's analog gain feature than it is to brighten the image in software by multiplying the pixel values.
The third way is to get a better lens with a lower aperture number. This will allow more light into the sensor. You will first need a lens mount that allows you to screw a better lens on the board. I got mine off of
ebay just type in CCTV board mount in the search bar and look for something mentioning c mount or cs mount.
You just replace the m12 mount with this. That is what I did for my ov7670. Then you need a c mount or cs mount lens they can be found for cheap on ebay. Just type in f1.2 cctv or something like that. Sort by
price lowest to highest. Or type in c mount lens or cs mount lens. I spend less than $10 total including shipping when I bought my lens and mount.
Title: Re: ov7670 with both arduino uno and now mega

66 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Post by: Mr_arduino on May 10, 2014, 02:42 pm


Quote from: erdikuzu on May 10, 2014, 01:02 pm
Hey all,
I've been working on a school project that captures an image and sends it to android system via bluetooth.
I've looked this topic and i'm bit confused.
My system has an Arduino uno, Arduino BT (Bluetooth) and OV7725 (with FIFO) .
I understood i2c, FIFO communication, how image captured, but i can't understand registry codes. Would you help me?
Note: When i was searching, i found a project same as my project. Here it's source code (in attach) and shema. Is it posible?
http://nicolasfley.fast-page.org/wp-content/uploads/2013/09/schema_arduino_FIFO_OV7670.png

The ov7725 is different than the ov7670. I do not have one and I lack experience with the ov7725. I was thinking about buying one but the cheapest I could find was $30.00 plus shipping. I would need a good
reason justify purchasing one. I even see them selling for $50.00 Where did you purchase the ov7725 + fifo?
Title: Re: ov7670 with both arduino uno and now mega
Post by: erdikuzu on May 10, 2014, 06:35 pm
Quote from: Mr_arduino on May 10, 2014, 02:42 pm
The ov7725 is different than the ov7670. I do not have one and I lack experience with the ov7725. I was thinking about buying one but the cheapest I could find was $30.00 plus shipping. I would need a good reason justify purchasing one. I even see them selling for
$50.00 Where did you purchase the ov7725 + fifo?

From a local store.


Actually first i bought OV7670 and then i realised OV7670 that i bought don't have FIFO. Then i changed it with OV7725.
Difference between these two, have any effect on code?
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on May 10, 2014, 07:42 pm
Wow I would never have guessed that a local store would sell such kind of things. Anyways yes there are differnces. Reading pixels will be the same as an ov7670 with fifo but you will need to send different
registers to the camera. You cannot use the same ones as the ov7670.
Title: Re: ov7670 with both arduino uno and now mega
Post by: erdikuzu on May 16, 2014, 01:53 pm
Hey again,
I've working on my project and i wrote a code based on a OV7670 test code.
I can get Data outputs from the FIFO but i can't understand what they means(How they combined to image).
I must send this datas with a Bluetooth.
Can you suggest a way?

Code: [Select]
#define SIO_C 5
#define SIO_D 4
#define SIO_CLOCK_DELAY 100

void setup()
{
pinMode(3,OUTPUT);
pinMode(2,INPUT);
pinMode(13,INPUT);
pinMode(12,INPUT);
pinMode(11,INPUT);
pinMode(10,INPUT);
pinMode(9,INPUT);
pinMode(8,INPUT);
pinMode(7,INPUT);
pinMode(6,INPUT);
digitalWrite(2,LOW);
;
//
//
//
//
//
//
//

while(1)
{
digitalWrite(8,HIGH);
delayMicroseconds(SIO_CLOCK_DELAY);
digitalWrite(8,LOW);
delayMicroseconds(SIO_CLOCK_DELAY);
}
Serial.begin(9600);
Serial.println("Start InitOV7670 test program");
digitalWrite(3,HIGH);delayMicroseconds(SIO_CLOCK_DELAY);
digitalWrite(3,LOW);delayMicroseconds(SIO_CLOCK_DELAY);
digitalWrite(3,HIGH);delayMicroseconds(SIO_CLOCK_DELAY);
if(InitOV7670())
Serial.println("InitOV7670 OK");
else
Serial.println("InitOV7670 NG");

}
void loop()
{
int VSYN = digitalRead(2);
StartSCCB();
if (VSYN == 0){
Serial.println("VSYN is LOW!");
int D0 = digitalRead(6);
int D2 = digitalRead(7);
int D4 = digitalRead(8);
int D6 = digitalRead(9);
int D1 = digitalRead(10);
int D3 = digitalRead(11);
int D5 = digitalRead(12);
int D7 = digitalRead(13);
Serial.println(D0);
Serial.print("\t");

67 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Serial.print(D1);
Serial.print("\t");
Serial.print(D2);
Serial.print("\t");
Serial.print(D3);
Serial.print("\t");
Serial.print(D4);
Serial.print("\t");
Serial.print(D5);
Serial.print("\t");
Serial.print(D6);
Serial.print("\t");
Serial.print(D7);
Serial.println("\t");
}
StopSCCB();
}

void InitSCCB(void) //SCCB???


{
pinMode(SIO_C,OUTPUT);
pinMode(SIO_D,OUTPUT);
digitalWrite(SIO_C,HIGH);
digitalWrite(SIO_D,HIGH);
Serial.println("InitSCCB - PortDirectionSet & Set High OK");
}
void StartSCCB(void) //SCCB????
{
Serial.println("StartSCCB");
digitalWrite(SIO_D,HIGH);
delayMicroseconds(SIO_CLOCK_DELAY);
digitalWrite(SIO_C,HIGH);
delayMicroseconds(SIO_CLOCK_DELAY);
digitalWrite(SIO_D,LOW);
delayMicroseconds(SIO_CLOCK_DELAY);
digitalWrite(SIO_C,LOW);
delayMicroseconds(SIO_CLOCK_DELAY);
}
void StopSCCB(void) //SCCB????
{
//Serial.println("StopSCCB");
digitalWrite(SIO_D,LOW);
delayMicroseconds(SIO_CLOCK_DELAY);
digitalWrite(SIO_C,HIGH);
delayMicroseconds(SIO_CLOCK_DELAY);
digitalWrite(SIO_D,HIGH);
delayMicroseconds(SIO_CLOCK_DELAY);
}
char SCCBWrite(byte m_data)
{
unsigned char j,tem;
//Serial.print("SCCBWrite 0x");
//Serial.println(m_data,HEX);
//Serial.print("SCCBWrite");
for(j=0;j<8;j++) //??8?????
{
if((m_data<<j)&0x80)
{
digitalWrite(SIO_D,HIGH);
}
else
{
digitalWrite(SIO_D,LOW);
}
delayMicroseconds(SIO_CLOCK_DELAY);
digitalWrite(SIO_C,HIGH);
delayMicroseconds(SIO_CLOCK_DELAY);
digitalWrite(SIO_C,LOW);
delayMicroseconds(SIO_CLOCK_DELAY);
}
//Serial.println("");
//delayMicroseconds(SIO_CLOCK_DELAY);
digitalWrite(3,LOW); //debug
pinMode(SIO_D,INPUT); //SIO_D????????(OV7670)???
digitalWrite(SIO_D,LOW); //???????
delayMicroseconds(SIO_CLOCK_DELAY);
digitalWrite(3,HIGH); //debug
digitalWrite(SIO_C,HIGH);
delayMicroseconds(SIO_CLOCK_DELAY);
//Serial.println(" Write done");
digitalWrite(3,LOW); //debug
if(digitalRead(SIO_D)==HIGH)
{
//SIO_D=H????
tem=0;
Serial.println("SCCBWrite NG");
}
else
{
//SIO_D=L????
tem=1;
//Serial.println("SCCBWrite OK");
}
digitalWrite(SIO_C,LOW);
delayMicroseconds(SIO_CLOCK_DELAY);
pinMode(SIO_D,OUTPUT); //SIO_D????????(Arduino)???
//delayMicroseconds(SIO_CLOCK_DELAY);
//digitalWrite(SIO_D,LOW);
//delayMicroseconds(SIO_CLOCK_DELAY);
//pinMode(SIO_C,OUTPUT); //SIO_C????????(Arduino)???
return tem;
}
int InitOV7670(void)
{
char temp;
int i=0;
InitSCCB();
temp=0x80;
if(WriteOV7670(0x12, temp)==0) //Reset SCCB
{
Serial.println("Resetting SCCB NG");
return 0 ;
}
//Serial.println("Resetting SCCB OK");
//delayMicroseconds(10);
//
//

68 of 96

for(i=0;i<CHANGE_REG_NUM;i++)
{

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...


//
//
//
//
//

http://forum.arduino.cc/index.php?action=printpa...

if( 0==wrOV7670Reg(pgm_read_byte( &change_reg[i][0]),pgm_read_byte( &change_reg[i][1]) ))


{
return 0;
}
}
return 0x01; //ok

}
////////////////////////////
//???OV7660?????????
//?????=1 ??=0
int WriteOV7670(char regID, char regDat)
{
StartSCCB();
if(SCCBWrite(0x42)==0)
{
Serial.println(" Write Error 0x42");
StopSCCB();
return(0);
}
delayMicroseconds(SIO_CLOCK_DELAY);
if(SCCBWrite(regID)==0)
{
StopSCCB();
return(0);
}
delayMicroseconds(SIO_CLOCK_DELAY);
if(SCCBWrite(regDat)==0)
{
StopSCCB();
return(0);
}
StopSCCB();
return(1);
}

Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on May 16, 2014, 11:14 pm
Yes, use my converter to convert image. Data hint DO NOT DO THE CONVERSION ON THE ARDUINO. Instead once you get the data on the more powerful device do the conversion to rgb. https://github.com
/ComputerNerd/RawCamera-data-converter I know for a fact that the ov7670 can output rgb565 data and maybe the ov7725 can also.
Title: Re: ov7670 with both arduino uno and now mega
Post by: erdikuzu on May 17, 2014, 02:45 pm
OV7725 can convert rgb565. COM7 register adress 0x12, i think i can turn rgb565 with 0x43.
Here its datasheet. (Page 13)
http://www.haoyuelectronics.com/Attachment/OV7725%20+%20AL422B(FIFO)%20Camera%20Module(V1.0)/OV7725%20datasheet(V1.2).pdf
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on May 17, 2014, 04:11 pm
No don't write 0x43 to 0x12 instead use 0x06 or if you want qvga instead of vga use 0x46
Title: Re: ov7670 with both arduino uno and now mega
Post by: erdikuzu on May 17, 2014, 07:34 pm
I use QVGA for fast transportation, but why 46? Why we select processed bayer RAW?
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on May 18, 2014, 01:26 am
If you want to get rgb565 data you want to use RGB instead of processed bayer. Processed bayer means that you get bayer data that has been processed by the dsp but is not demosaiced. This means there is
will not be full color at each pixel. So it is for this reason that I recommend the use of 0x46 instead of 0x43.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Muon-Neutrino on May 24, 2014, 05:50 am
Hi guys,
I'm new at this, so sorry if i ask stupid questions.
I have OV7670 without FIFO and I want the camera to capture/show images through USB to my laptop.
Here's some questions :
1. Where do i connect HREF, XCLK, PWDN, and RESET?
2. How do i view the visual input from the cam? Is it through serial monitor? or do i need another software?
If anyone able to give me step to steps to do it, i would really appreciate it.
Thank you very much!
Title: Re: ov7670 with both arduino uno and now mega
Post by: cloudstrife on May 30, 2014, 09:19 pm
sorry my English, but I have an inquiry for Mr_arduino I tried to get the microchip 23lc1024 I got it but I could say that other elements could change. and I got a OV7670 without fifo and I could not make it work.
thanks in advance.
Title: Re: ov7670 with both arduino uno and now mega
Post by: rogerClark on May 31, 2014, 12:15 am
At the risk of damaging the module
Has anyone tried using very slow clock rates.
I know the spec if for 10Mhz and most people seem to use 8Mhz (16/2), but has anyone tried using 1Mhz or lower and looked at the results?
I'm not sure if this would damage the module. Normally, overclocking causes either overheating damage, or for data not be be available in time, or for the various internal clocks to not be aligned, and data gets

69 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

corrupted.
However, under-clocking doesn't normally suffer from these issues.
The only think I can think of is that either there is something about the CCD that could be damaged by under clocking, or that the image frame time is so slow that you get blurred images if things move.
People seem to have posted that the I2C doesn't work if there is no clock, so they must have powered the module with no clock, and I have not seen any postings of dire warnings if you run the module without a
clock.
So I'm thinking about giving it a try ;-)

Title: Re: ov7670 with both arduino uno and now mega
Post by: msliva on Jun 01, 2014, 09:50 am
CF7670C-V3 OV7670 Camera Module with FIFO AL422B directly drives MCU
Has anybody experiences with "V3" connection to the Arduino UNO/Nano?
http://www.ebay.com/itm/CF7670C-V3-OV7670-Camera-Module-with-FIFO-AL422B-directly-drives-MCU-/290948279117?pt=LH_DefaultDomain_0&hash=item43bdde6b4d
http://www.wayengineer.com/wang-cf7670cv3-with-fifo-ov7670-camera-single-chip-mcu-p-6688.html#.U4rn2p1ItYo
Title: Re: ov7670 with both arduino uno and now mega
Post by: rogerClark on Jun 01, 2014, 09:59 am
If you are considering spending $28 you may like to look at
http://www.aliexpress.com/item/UART-RS232-JPEG-serial-port-camera-module-OV528-communication-protocol-SPI-camera/1716307824.html

I've not got one of these RS232 JPEG cameras, but I think that for some applications they are probably going to be better than the 7670
I have a 7670 without fifo and its not very usable, and I'm not sure even the V2 fifo version (which I have on order) is much better.
Are there any details of whats different on the V 3, is it the ability to reset the read pointer ?
Title: Re: ov7670 with both arduino uno and now mega
Post by: msliva on Jun 01, 2014, 12:57 pm
Hi rogerClark,
here is for $22: http://www.aliexpress.com/item/-/1275340212.html
here is for $23: http://www.wayengineer.com/wang-ov7670-camera-modulev3-p-4845.html#.U4sR4Z1ItYo
here is for $20: http://www.wayengineer.com/wang-cf7670cv3-with-fifo-ov7670-camera-single-chip-mcu-p-6688.html#.U4sSHJ1ItYp
and there are a some info (last link):
"V3 Version : CF7670C-V3 module without WRST ( without user software control AL422 write address reset )
There HREF feet ( software, the user can control the precise data collection in a row )
Users can choose a model with RE # pin ( tell the shopkeeper when purchased directly linked to the MCU external system bus acquisition image)" ...
Title: Re: ov7670 with both arduino uno and now mega
Post by: rogerClark on Jun 05, 2014, 09:41 am
Does anyone have a schematic for the OV7670 + Fifo module where the Data is not on Pin13 to Pin 20?
The module I bought on ebay seems to have 2 more pins than any schematic I can find on the web, i.e its got 22pins where as the other fifo modules seem to have 20.
Although this is probably good news, as I suspect it must give more control, I'm not sure what some of these pins do.
e.g. the WR pin, as there isnt a pin on either the OV7670 or the Fifo called WR
The pinout on this module is..
1. RRST
2. WRST
3. OE
4. WR
5. RCK
6. STR
7. PWDN
8. RST
9.D0
10.D1
11.D2
12.D3
13.D4
14.D5
15.D6
16.D7
17.HREF
18VSYNC
19.SDOD
20.SIOC
21.GND
22.3V3
I'm going to power it up with 3.3V and see if any the data pins appear to be doing anything, but I suspect I'll need to get the Arduino to control the frame grab and subsequent frame retrieval (somehow)
i.e I'm not sure if any of the existing code e.g from Mr Arduino will work with this variant (apart from the I2C control stuff)
Title: Re: ov7670 with both arduino uno and now mega

70 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Post by: msliva on Jun 05, 2014, 12:48 pm


Schematic for the OV7670 + Fifo "V3" in attachment
Title: Re: ov7670 with both arduino uno and now mega
Post by: rogerClark on Jun 05, 2014, 10:01 pm
Msilva
Thanks for the v3 schematic, but my module is different it has 22 pins not 20.
Ie it appears to be a new variant, but I've no idea who is making these, nor does my supplier on ebay,
I tried yo buzz the WR pin, which seems to be a new one, and it doesn't seem to go to the FIFO.
I didn't get around to powering it up yet, as I had issues with a 3.3v power supply I normally use.
Title: Arduino interfacing with 0v7670..
Post by: muhammadshaik4 on Jun 07, 2014, 07:06 am
How to interface ov7670 with Arduino Mega 2560?
Title: Re: ov7670 with both arduino uno and now mega
Post by: rogerClark on Jun 07, 2014, 07:12 am
@muhammadshaik4
It depends on which version you have, Do you have a version with or without a fifo.
Its best to read the start of this thread where Mr Arduino has posted full details
Title: Re: ov7670 with both arduino uno and now mega
Post by: gaurav_sharma132 on Jun 07, 2014, 05:24 pm
I was just looking for high resolution camera to be interfaced with arduino.
So, I wondering that can we interface OV2640 with FIFO and then to arduino in similar fashion we do with OV7670.
The pixel read by arduino can be stored on SD card.
Please find schematic for ref:
http://www.beyondlogic.org/pdf/OV7670_FIFO_SCH_V2.pdf (http://www.beyondlogic.org/pdf/OV7670_FIFO_SCH_V2.pdf)
Title: Re: ov7670 with both arduino uno and now mega
Post by: ABBA2014 on Jun 15, 2014, 05:51 pm
Mr_Arduino and the broader community,
Thank you for posting all of the information and code to enable this project. Your help is much appreciated. I am having a tough time understanding the connections. Is there any chance you can post a detailed
photo or a diagram of the wiring between the OV7670 with FIFO and the Arduino Mega?
I am having a tough time visualizing how to incorporate the 74HC25 chip.
Thanks in advance.
Title: Re: ov7670 with both arduino uno and now mega
Post by: ABBA2014 on Jun 15, 2014, 05:54 pm
Mr_Arduino and the broader community,
Thank you for posting all of the information and code to enable this project. Your help is much appreciated. I am having a tough time understanding the connections. Is there any chance you can post a detailed
photo or a diagram of the wiring between the OV7670 with FIFO and the Arduino Mega?
I am having a tough time visualizing how to incorporate the 74HC25 chip.
Thanks in advance.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jun 26, 2014, 04:51 am
The 74hc125 allows for you to easily to convert the 5v clock signal generated by the AVR processor into a 3.3v signal. What you do is simply power the 74hc125 with 3.3v and plug in the 5v signal into the input
and out will come a 3.3v signal. Note that the 74hc125 has a output enable pins. Pull the ones you are using to ground to enable output. As for a schematic I do need to get going on that.
Title: Re: ov7670 with both arduino uno and now mega
Post by: vvavepacket on Jun 29, 2014, 01:47 pm
@Mr_Arduino
Would you mind use your OV7670 and capture your skin / hand in the YUV/YCbCr format?
Are you getting results similar to these?
(http://www.cs.cmu.edu/afs/cs/academic/class/15494-s14/final-projects/2009/facetracker/face_detection/face3.png)
Thanks
Title: Re: ov7670 with both arduino uno and now mega

71 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Post by: Mr_arduino on Jun 29, 2014, 03:18 pm


No the colors I get from the camera look quite nice especially indoors. Try changing your registers. I have disucessed the registers that I have on github multiple times in this thread. Please refer back to them.
Check out these page https://github.com/ComputerNerd/arduino-camera-tft/blob/master/ov7670_regs.h https://github.com/ComputerNerd/arduino-camera-tft/blob/master/twicam.h https://github.com
/ComputerNerd/arduino-camera-tft/blob/master/twicam.c
Title: Re: ov7670 with both arduino uno and now mega
Post by: TeamAlpha on Jul 02, 2014, 08:02 pm
Dear Mr_arduino,
I am currently working with a group of students trying to get the OV7670 working as a sensor with an Arduino Due or Uno. How exactly do we drive the XCLK and connect HREF? And is which code best suits
our interests? We are very confused. Thanks!
Edit: We are trying to configure this using i2C configuration
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jul 02, 2014, 09:52 pm
HREF just goes to an arduino PIN if you want to do that. Just don't plug it in if you don't need to use it. I use VREF. As for XCLK generate it with fast PWM and use a buffer to get it from 5v to 3.3v
Title: Re: ov7670 with both arduino uno and now mega
Post by: vvavepacket on Jul 03, 2014, 02:25 pm
Hello,
anyone have success in making the ov7670 output QQVGA (160 by 120) ?
Thanks. What are the proper register settings?
Ive done my research and I tried putting these
(http://puu.sh/9V2OI/cf761b2960.png)
yet the signals(href) is not stopping at the 320th data.

Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jul 03, 2014, 03:28 pm
I have used qqvga before check out the registers that I used on my github pages.
Title: Re: ov7670 with both arduino uno and now mega
Post by: TeamAlpha on Jul 03, 2014, 09:41 pm
Quote from: Mr_arduino on Jul 02, 2014, 09:52 pm
HREF just goes to an arduino PIN if you want to do that. Just don't plug it in if you don't need to use it. I use VREF. As for XCLK generate it with fast PWM and use a buffer to get it from 5v to 3.3v

Just a few basic follow up questions.


How do you buffer the the XCLK? Is it just simple voltage division with a pull-up resistor?
How do you drive the XCLK using PWM? What is the connection/code?
Sorry for the redundant questions, thanks!
Title: Re: ov7670 with both arduino uno and now mega
Post by: vvavepacket on Jul 04, 2014, 04:18 am
@Mr_Arduino
Hello, how do I remove the white glare in my face?
(http://puu.sh/9W9Xu/d971368f54.jpg)
Heres my register setting

Write(0xb0,0x84); //adding this improve the color a little bit


Write(AWBC7,0x88);
Write(AWBC7,0x88);
Write(AWBC8,0x88);
Write(AWBC9,0x44);
Write(AWBC10,0x67);
Write(AWBC11,0x49);
Write(AWBC12,0x0e);
Write(AWBCTR3,0x0a);
Write(AWBCTR2,0x55);
Write(AWBCTR1,0x11);
Write(AWBCTR0,0x9f);
Write(0x14,0x6a);
Write(0x4f,0x80);
Write(0x50,0x80);
Write(0x51,0x0);
Write(0x52,0x22);
Write(0x53,0x5e);
Write(0x54,0x80);

72 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Heres the second image


(http://puu.sh/9WcxI/a9c8d7876c.jpg)
The background looks ok but my body and my shirt is full of brightness, we cant see details (unlike in the back). Any suggestions thanks?
Title: Re: ov7670 with both arduino uno and now mega
Post by: vvavepacket on Jul 04, 2014, 12:48 pm
Is this item good? I think there are variations of OV7670 with FIFO buffer
http://www.ebay.com/itm/OV7670-FIFO-AL422B-VGA-CIF-Camera-SCCB-I2C-for-AVR-STM32-Arduino-Compatible-/230980005304?pt=LH_DefaultDomain_0&hash=item35c77b2db8

What do you suggest when someone is looking for OV7670 with FIFO?
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jul 04, 2014, 05:13 pm
Alright I will answer both vvavepacket's two questions and TeamAlpha's question. I will be going in reverse order by post.
@vvavepacket
First of all you can get the same thing for cheaper http://www.ebay.com/itm/640-x-480-VGA-CMOS-AL422-3M-Bits-OV7670-FIFO-Camera-STM32-Driver-Module-I2C-/161333211986?pt=LH_DefaultDomain_0&
hash=item2590357352
they both appear to be at-least similar.
To fix the glare you are going to have to first of all make sure that bits 7 and 6 in register 0x40 are set to one by default (according to the datasheet) they are set.
Also make sure register 0x55 is set to 0 (brightness should never be changed using this register)
and that register 0x56 is set to 0x40. (Contrast should not be changed like this).
if you want a different brightness you should instead vary the exposure and/or gain settings. It may be that the ov7670 is picking the wrong exposure and gain settings if that is the case the https://github.com
/dalmirdasilva/ArduinoCamera/blob/master/CameraAL422B/datasheet/OV7670%20Implementation%20Guide%20%28V1.0%29.pdf explains auto exposure and auto gain best.
There are some undocumented registers that I have pulled from various places. I just write all those and end up with a nice looking image. I wish I could find out what all the registers do. Is that all the registers
that you are writing to the ov7670?
I have attached some pictures I have taken with the ov7670 to show you the quality that can be achieved with better register settings.
@TeamAlpha I have not tried a resistor voltage divider. I have heard that resistor voltage dividers may be noisy so look at the output using an oscilloscope. I just use a buffer IC chip. Also to generate the XCLK
clock you need to use PWM. The way you set this up is slightly different depending on which microcontroller you are using. If you could tell me what you have I can further help you with this.
Title: Re: ov7670 with both arduino uno and now mega
Post by: vvavepacket on Jul 04, 2014, 11:35 pm
Which should we get, version 1 or version 2 of fifo version?
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jul 05, 2014, 01:24 am
The difference is minor and is more of a preference issue you can read about the difference here http://wiki.beyondlogic.org/index.php/OV7670_Camera_Module_with_AL422_FIFO_Theory_of_Operation
Also any luck improving the image quality?
Title: Re: ov7670 with both arduino uno and now mega
Post by: vvavepacket on Jul 05, 2014, 03:32 am
Going to try when i get home. I feel sad since i cant get a good capture as you do. Bpught 2 sensors of non fifo version woth same rrsults
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jul 05, 2014, 04:44 am
Fifo vs non fifo does not affect image quality. Also there is no need to feel sad. You will eventually end up with a high quality image. When I first started with the ov7670 all I got was purple images.
Title: Re: ov7670 with both arduino uno and now mega
Post by: vvavepacket on Jul 05, 2014, 10:30 am
(http://puu.sh/9XCEl/bc9874bc57.jpg)
colors seems ok now as you can see pencil is now yellow, and color of skin looks ok but problem is the glare,, so much glare in ma face i cant do face detection :( also, i checked com40 register and both bit 6
and 7 are one / '1'. also i dont control anymore the brightness and contrast registers.. im only using the AWB registers you provided..

=( =( =( =(
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jul 05, 2014, 05:54 pm
The picture does look a little bit better. Also if you cannot resolve the issue could you please post a list of all the registers you used. I think the issue is you are not writing to some undocumented registers that
make the quality better. There are some undocumented parts of the ov7670 that I do not know about but after using a long list of registers that may have come from omnivision the quality improves. Also is auto
gain and auto exposure enabled? If not enabling it could help with your problem. Maybe just try copying and pasting all registers that I used from one of my code examples. Also to anyone who is reading this
thread if you have ANYTHING from omnivsion that is not posted on the internet I will take a look at it. If you don't want me to post it online I will respect that wish. I tried getting a full datasheet from omnivsion
once but they said it is obsolete and as such I got nothing for the ov7670. I do have a datasheet for the ov7675 but nothing is learned from it and I cannot post it anyways however you can find the same exact
datasheet that is not bound by an NDA here http://media.digikey.com/pdf/Data%20Sheets/OmniVision%20PDFs/OV7675,OV7175_Web.pdf The ov7670 did appear in an EOL notice a while ago but they must be
still selling them how else will you explain the thousands of modules that get sold on ebay and other places every month.
Title: Re: ov7670 with both arduino uno and now mega
Post by: michinyon on Jul 06, 2014, 12:06 am
Quote
The ov7670 did appear in an EOL notice a while ago but they must be still selling them how else will you explain the thousands of modules that get sold on ebay and other places every month.

73 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

There are many kinds of obsolete chips which the makers no longer make,
superseded parts in their production pipeline.

but which are still sold on ebay,

http://forum.arduino.cc/index.php?action=printpa...

and that is because various wholesalers and subassembly makers are stuck with lots of obsolete or

In fact that is one of the main reasons why there are so many cheap and useful devices on ebay, it is because they are superseded.
Title: Re: ov7670 with both arduino uno and now mega
Post by: vvavepacket on Jul 06, 2014, 01:08 am
@Mr_Arduino
attached is the comparative analysis and side by side preview of register settings.
so far I found that these registers make it appear the best as of now, (but the glare issue,, so much whiteness in ma face cant do face detection)
Code: [Select]
Write(0x12,0xff); // perform reset first. reset first everything
Write(0xb0,0x84); //adding this improve the color a little bit
Write(AWBC7,0x88);
Write(AWBC7,0x88);
Write(AWBC8,0x88);
Write(AWBC9,0x44);
Write(AWBC10,0x67);
Write(AWBC11,0x49);
Write(AWBC12,0x0e);
Write(AWBCTR3,0x0a);
Write(AWBCTR2,0x55);
Write(AWBCTR1,0x11);
Write(AWBCTR0,0x9f);

also when I do write the registers about the gain ceiling,, pictures turn very grainy and colors are like smashed just like in the word document I attached below. Thanks
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jul 06, 2014, 01:30 am
I have noticed that multiple users have been sending me word documents lately. I have not had anyone send me a word document ever but now multiple users have tried to send me a word document this week.
What you put in there could have easily been added to your post. I admit I was actually a bit paranoid when opening the file thinking the document contains a zero day or something. I doubt that is the case but it
was a strange choice to use that format. Next time please just put what you need to put in your forum post. I do not like downloading word documents. If that is really all the registers that you used, you are not
using enough. Just copy my long list of registers and use that. It will fix your problems.
Also michinyon yes that does make sense. I would not be surprised if someone has lots of ov7670 sensors that they purchased a while ago before it was declared EOL.
Title: Re: ov7670 with both arduino uno and now mega
Post by: s89146892002 on Jul 06, 2014, 03:14 am
hi everyone I from Taiwan my English is not good
i have some programs
i want use Uno drive OV 7670 fifo
but i dont no any circuit connection and icant understand why use 74HC245
please help me
thx~~
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jul 06, 2014, 03:19 am
For the fifo version it appears as though you don't need to buffer any pins. The only reason you would need to use the 74HC245 or similar is if you are directly driving a pin that goes to the ov7670 with arduino
pins. The al422 can handle 5v and for sccb (i2c) communication you just pull up to 3.3v instead of 5v.
Title: Re: ov7670 with both arduino uno and now mega
Post by: vvavepacket on Jul 06, 2014, 03:20 am
@Mr_arduino
Sorry, my apologies
------------------------------------------------------AWB AND GAIN CEILING ON
Write(0xb0,0x84); //adding this improve the color a little bit
Write(AWBC7,0x88);
Write(AWBC7,0x88);
Write(AWBC8,0x88);
Write(AWBC9,0x44);
Write(AWBC10,0x67);
Write(AWBC11,0x49);
Write(AWBC12,0x0e);
Write(AWBCTR3,0x0a);
Write(AWBCTR2,0x55);
Write(AWBCTR1,0x11);
Write(AWBCTR0,0x9f);
Write(0x14,0x6a);
Write(0x4f,0x80);
Write(0x50,0x80);
Write(0x51,0x0);
Write(0x52,0x22);
Write(0x53,0x5e);
Write(0x54,0x80);
image -> (http://puu.sh/9YBj1/59ab132f2e.jpg)

AWB ON AND GAIN CEILING OFF

74 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Write(0xb0,0x84); //adding this improve the color a little bit


Write(AWBC7,0x88);
Write(AWBC7,0x88);
Write(AWBC8,0x88);
Write(AWBC9,0x44);
Write(AWBC10,0x67);
Write(AWBC11,0x49);
Write(AWBC12,0x0e);
Write(AWBCTR3,0x0a);
Write(AWBCTR2,0x55);
Write(AWBCTR1,0x11);
Write(AWBCTR0,0x9f);
image ->
(http://puu.sh/9YBle/5d8da72b1c.jpg)
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jul 06, 2014, 04:17 am
Don't worry it is not a big deal. Anyways I was able to open it before you posted the contents of it here. My opposition to Microsoft word is more of a political issue. I disagree with their practices of making their
formats secret. I use libreoffice. However I have already answered your question in my previous post to you and again before that in regards to improving quality. Your problem is that you are not writing enough
registers to the module. There are bunch of undocumented registers that when I write the long to the ov7670 list it improves quality. I would like to know what all the registers do but until I can find more
documentation this is the best I got. My project https://github.com/ComputerNerd/ov7670-simple contains less "magic" registers if you are interested or you can try one of my pastebin links.
Title: Re: ov7670 with both arduino uno and now mega
Post by: TeamAlpha on Jul 08, 2014, 10:53 pm
Quote from: Mr_arduino on Jul 04, 2014, 05:13 pm
@TeamAlpha I have not tried a resistor voltage divider. I have heard that resistor voltage dividers may be noisy so look at the output using an oscilloscope. I just use a buffer IC chip. Also to generate the XCLK clock you need to use PWM. The way you set this up is
slightly different depending on which microcontroller you are using. If you could tell me what you have I can further help you with this.

I see. We will be using a 10k resistor instead because we don't have access to a buffer IC chip. Right now, we are testing our XCLK code to see if the Due is properly generating a clock. For our
microcontroller, we are using a AT91SAM3X8E (Due R3). Our superior is expecting us to connect the OV7670 with the due with 2 wires in a I2C connection (4 wires if you count SDA, SCL, Ground, and
Power). Is this enough for the camera to properly function? Or is there an easier solution? And will XCLK output a 5V pulse instead of a 3.3V? That's why we buffer?
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jul 08, 2014, 11:17 pm
The arduino due is 3.3v you do not need a buffer. Sorry for the confusion. Also you did not appear to read my FAQ.
Quote
Q: Will the ov7670 accept twi/sccb/i2c (same thing different names) commands without XCLK?
A: No

If you noticed after posting this I fixed a typo in the FAQ on the first post.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jul 11, 2014, 06:18 am
Very sorry to double post but this is important.
Previously I have told you all that you would need either external spi ram or the fifo version to get data. For the most part that is true.
Today I decided to get out the 0v7670 module (I admit I haven't done anything with it for a while) and write some code that only uses only the ov7670 and the buffer for 5v to 3.3v conversion.
What the code does is it will send the data from the ov7670 to uart and you can receive it using your pc.
https://github.com/ComputerNerd/ov7670-no-ram-arduino-uno
It also generates a 8mhz clock on pin 11 that you get from 5v to 3.3v and plug into the ov7670.
I called it no-ram but I just mean external ram.
This should be a simpler example of the ov7670 using newer register functions.
Tell me what you think. One thing I think people seem to be forgetting is that I am always open to pull requests.
Title: Re: ov7670 with both arduino uno and now mega
Post by: rogerClark on Jul 11, 2014, 06:22 am
Thanks.
I bought the non-fifo version but couldnt get it to work, so I bought the FIFO one, but again couldnt get it to work as I was supplied a new version that has 2 more pins (without any documentation !!!)
So if I can use the non fifo one, that would be interesting ;-)
Title: Re: ov7670 with both arduino uno and now mega
Post by: rogerClark on Jul 11, 2014, 06:58 am
Where is the code for the PC?
The code on GitHub just looks like the Arduino code for use with AVRStudio
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jul 11, 2014, 02:59 pm
It's on my hardrive. The code is very messy. I actually posted an earlier version in 2013 you can find it on the first page. I was planning on making a new one but have not got to it yet.
Title: Re: ov7670 with both arduino uno and now mega
Post by: rogerClark on Jul 11, 2014, 11:28 pm
messy code would be better than none, but I understand why you've not released it.
It takes me ages to tidy up code that I want to make public ;-)

75 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jul 12, 2014, 03:24 am
I already posted a similar version on page one but here is my up to date code.
http://pastebin.com/f2pShvZB
The issue is that I wrote a bulk of the code almost two years ago. Back then I was not as good of a programmer. I just hacked on some recent changes as I anticipated this to be a quick way to test stuff for
personal use only. The program is now posix only (such as linux and bsd).
I am planning to write a new application that grabs frames but is cleaner both code wise and user interface wise. It will also let you edit registers from pc.
Title: Re: ov7670 with both arduino uno and now mega
Post by: montagNZ on Jul 12, 2014, 09:48 pm
Quote from: Mr_arduino on Jul 11, 2014, 06:18 am
Very sorry to double post but this is important.
Previously I have told you all that you would need either external spi ram or the fifo version to get data. For the most part that is true.
Today I decided to get out the 0v7670 module (I admit I haven't done anything with it for a while) and write some code that only uses only the ov7670 and the buffer for 5v to 3.3v conversion.
What the code does is it will send the data from the ov7670 to uart and you can receive it using your pc.
https://github.com/ComputerNerd/ov7670-no-ram-arduino-uno
It also generates a 8mhz clock on pin 11 that you get from 5v to 3.3v and plug into the ov7670.
I called it no-ram but I just mean external ram.
This should be a simpler example of the ov7670 using newer register functions.
Tell me what you think. One thing I think people seem to be forgetting is that I am always open to pull requests.

This looks like a great place to start for me i have both the fifo and non fifo. I am using a resistor voltage divider for pin 11
5v<-----------Arduino
220r
3.3v---------->Pin 11
220r
220r
GND<---------Arduino
will let you know how i go, I dont have much coding experience but can muddle my way though
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jul 13, 2014, 04:13 am
Alright good to hear that my new program seems more viable for people.
Title: Re: ov7670 with both arduino uno and now mega
Post by: montagNZ on Jul 13, 2014, 05:43 am
Did you use OV7670 grabber usb v1.5?
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jul 13, 2014, 06:12 am
No. I just looked it up and I have not used it. The arduino is not true usb, it just uses microcontroller programmed to do serial<->usb.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Near32 on Jul 24, 2014, 02:39 pm
Hello everyone,
Firstly I'd like to thank you all since, having read the whole 26 pages, I have learnt quite a lot.
Nevertheless, I still appear to be having a tough time at getting my OV7670 without FIFO running on my Arduino Mega2560.
Here ares my issues that hope someone will be able to guide me through :
1) I have read that a buffer is needed in order to lower the voltage of the pin that is to be wired to XCLK. Can't we use a resistor ?
(I might have not understood what is the whole problem here therefore I would very much appreciate to have someone pointing me the direction a good explanation of the whole problem with regards to resistors
use/pull up use/buffer telnet and use.)
2) I have spent a lot of time trying to communicate with registers without the XCLK wired or any resistors wired to the SCCB related pins. It was way before I encountered this topic... Is it probable for my module
to be damaged ? if yes, how can I assess it ?
3) During my journey to communication with registers, the only thing that would appears weird was that during the 2-phase read transmission cycle, more especially the first phase of it : the writing of 0x43, I read
the last bit as a logical 0 and thus encountered any expected error : here's "my"(I've mostly concatenate some code that I've encountered, mostly here : https://gist.github.com/freespace/2585921 ) code :
https://gist.github.com/Near32/225cdca19ad55c6d8306
See Line 318.
(I've done the same with Wire (with and without the internal pull-up resistors of the arduino....) and I could read things that was pretty weird.....)
I hope that someone will be able to help me. I can already thank you for having made it through this post ^^" !
Best Regards,
Near32
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jul 24, 2014, 07:45 pm
To answer your questions.
1. You could try a voltage resistor divider. I have not tested it myself but it won't hurt to try. Also you need pulls ups for i2c. The resistor value does matter. I have found 10k to work just fine, I also remember
testing 4.7k and that worked fine too. However using a resistor that has too much or too little does not work for example when I tried a 1k it would not work. The two resistors will be a pull up resistor to 3.3v. The
way this works is you plug in the i2c pins to 3.3v using the resistor and then plug that into the ov7670 all wired up together. Another thing is to disable the internal pull up resistors, they are off by default however
the arduino wiring library enables them please follow my instructions on how to disable the internal pull up resistors if using the wiring library.
2. When I first got the ov7670 I also made that mistake and it works just fine. I do not think this will cause any damage I am more concerned about the internal pullup resistors causing damage however when I
first got the module (if I remember right) I did not disable the internal pull resistors and the ov7670 still works but when enabled I do not remember having any luck with writing and reading resistors. However just
because I got lucky does not mean you will.
3. Why are you bitbanging? Use the hardware i2c peripheral. Try my code, it uses hardware i2c and it works fine for me. Also the ov7670's i2c address is 0x42 the LSB (bit 0) is set to 0 when writing and 1 when
reading so yes you do use 0x43 to read. Also when using the wiring library you must specify the 7bit address so use 0x21.

76 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Title: Re: ov7670 with both arduino uno and now mega
Post by: Near32 on Jul 27, 2014, 08:57 am
Firstly, thank you for your answer :).
Quote from: Mr_arduino on Jul 24, 2014, 07:45 pm
To answer your questions.
1. You could try a voltage resistor divider. I have not tested it myself but it won't hurt to try. Also you need pulls ups for i2c. The resistor value does matter. I have found 10k to work just fine, I also remember testing 4.7k and that worked fine too. However using a resistor
that has too much or too little does not work for example when I tried a 1k it would not work. The two resistors will be a pull up resistor to 3.3v. The way this works is you plug in the i2c pins to 3.3v using the resistor and then plug that into the ov7670 all wired up together.
Another thing is to disable the internal pull up resistors, they are off by default however the arduino wiring library enables them please follow my instructions on how to disable the internal pull up resistors if using the wiring library.

Sure, I'll try using a voltage resistor divider if I manage to find the materials I need. I'll give feedback about that maybe at the end of this week...
Quote from: Mr_arduino on Jul 24, 2014, 07:45 pm
2. When I first got the ov7670 I also made that mistake and it works just fine. I do not think this will cause any damage I am more concerned about the internal pullup resistors causing damage however when I first got the module (if I remember right) I did not disable the
internal pull resistors and the ov7670 still works but when enabled I do not remember having any luck with writing and reading resistors. However just because I got lucky does not mean you will.

Thank you, I hope I will be lucky too then...

Quote from: Mr_arduino on Jul 24, 2014, 07:45 pm


3. Why are you bitbanging? Use the hardware i2c peripheral. Try my code, it uses hardware i2c and it works fine for me. Also the ov7670's i2c address is 0x42 the LSB (bit 0) is set to 0 when writing and 1 when reading so yes you do use 0x43 to read. Also when using the
wiring library you must specify the 7bit address so use 0x21.

The bitbanged implementation was the one that I understood at first and thus I thought I could give it a try.
I do want to try your code and using the hardware i2c peripheral but the fact is that I appear to be unsuccessfull in my quest to use the correct registers on the arduino MEGA2560 that I am using, or, I should put
it that way : I am currently browsing the datasheet but the use of the hardware i2c peripheral and the associated registers is not as plain as a pikestaff...
I am currently waiting for resistors and other materials to arrive...
Thank you for your help, I'll give feedback if there is any progress.
Title: Re: ov7670 with both arduino uno and now mega
Post by: i4xcc on Jul 27, 2014, 03:55 pm
To all good afternoon and thanks for this nice thread.
I'm a newbie and I've buyed an OV7670 (buffered or not? don't know) and would like to use it with an arduino MEGA 2560.
Firstly I need only to save some image into a microSD regardless tips to speedup the fps.
I've quickly browsed the pages of this thread and maybe I've lost some useful link, so I need a simple schematic (I would like to try with resistors to pull-up the pins and to match the 3,3 V level inputs of
OV7670) to connect the camera to arduino.
The code I've seen on github is C or C++ (objective C) : can I copy that code and paste into the editor of arduino IDE?
Thanks for replies.
Claudio.

Title: Re: ov7670 with both arduino uno and now mega
Post by: Near32 on Jul 29, 2014, 07:09 pm
@Claudio :
Quote from: i4xcc on Jul 27, 2014, 03:55 pm
I've quickly browsed the pages of this thread and maybe I've lost some useful link, so I need a simple schematic (I would like to try with resistors to pull-up the pins and to match the 3,3 V level inputs of OV7670) to connect the camera to arduino.

Firstly, you have to figuring out if your version is the fifo or the non-fifo one, otherwise the schematic might change.
The non-fifo version have 18 pins :
D0..D7 - for data (pixel) connected to arduino digital pins as INPUT on arduino board
XCLK - for camera clock connected to arduino digital pin as OUTPUT from arduino board : you have to generate a clock
(I am lost on this part : the documentation that I have found on oscillators/PWN/timers/interruptions is non-specific to the arduino MEGA2560 and haven't been able to replicate it....)
PCLK - for pixel clock connected to arduino digital pin as INPUT on arduino board
HREF - to define when a line starts / ends connected to arduino digital pin as INPUT on arduino board
VSYCH - to define when a frame starts / ends connected to arduino digital pin as INPUT on arduino board
GRD - groud connected to arduino GRD
3V3 - 3,3 INPUT connected to arduino 3,3v
RESET - connected to arduino RESET
PWDN - connected to arduino GRD
SIOC - to communicate on the SCCB/i2c : the user, through the arduino, as to drive it in order to assert the data that are being written/read through SIOD : you have to connect it to a digital pin if you use a
bitbanged implementation of SCCB/i2c or to the SCL pin of the MEGA2560 if you use the hardware i2c ; unless I am mistaken... Anyway, it's an OUTPUT.
SIOD - to communicate on the SCCB/i2c : alternativaly, the user may drive in order to write (OUTPUT), or it's the OV7670 which drives it whenever there is a data that is being read.
If you happen to have the fifo version, you'll find a schematic here :
http://nicolasfley.fast-page.org/?page_id=35

Quote from: i4xcc on Jul 27, 2014, 03:55 pm


The code I've seen on github is C or C++ (objective C) : can I copy that code and paste into the editor of arduino IDE?

The code you have seen is written in C, mostly, and you cannot copy/paste it directly into the arduino IDE editor.
You may want to consider this :

77 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

http://www.vascop.com/compiling-and-uploading-arduino-programs-without-the-ide.html
Nevertheless, you may copy/paste some parts directly into the arduino IDE editor but be careful since the code you may have seen deals with registers directly and it can be very tricky sometimes if you do not
know what you're doing...
Good luck ;)!
Title: Re: ov7670 with both arduino uno and now mega
Post by: raduen on Aug 07, 2014, 11:45 pm
Hallo,
I'm a nooby and need some help.
How must i wire the ov7670 to an UNO or MEGA?
And where can i find a code to test if the camera is wired properly (working).

Raduen
Title: Re: ov7670 with both arduino uno and now mega
Post by: WASJA1991 on Aug 10, 2014, 10:53 am
Hello for all. I have camera CF7670 v3 (with FIFO). And I tried to connect it to my arduino uno board. But it seems that something is wrong.
Can you help me with this moment? I used next pins connection:
1.
3.3v - 1. VCC
2.
GND - 2. GND
3.
A5 - 3. SCL (SIO_C)
4.
A4 - 4. SDA (SIO_D)
5.
D7 - 20. D7
6.
D6 - 19. D6
7.
D5 - 18. D5
8.
D4 - 17. D4
9.
A3 - 16. D3
10.
A2 - 15. D2
11.
A1 - 14. D1
12.
A0 - 13. D0
13.
D3 - 5. VSYNC
14.
GND - 12. GND
15.
D2 - 6. HREF
16.
D8 - 7. WEN
17.
D9 - 8. NC/XCLK
18.
D10 - 9. RRST
19.
D11 - 10. OE/CS
20.
D12 - 11. RCLK/WR
__________________________
for connecting SIO_C and SIO_D I used 10k resistor for each one.
Please tell me. Is it correct connection and do I use 10k resistors right ?

Title: Re: ov7670 with both arduino uno and now mega
Post by: diesel on Aug 15, 2014, 06:15 am
Hello,
I am trying to get Arduino Uno with the OV7670 w/o FIFO to run https://github.com/ComputerNerd/ov7670-no-ram-arduino-uno. I am sending data at 1mbs to the serial port, for vga I get 30720 bytes(taking out
the "RDY") statement. I have also tried the other resolutions and get a consistent amount of bytes. Clock is on pin 11, running at 8 mhz, output voltage 3V (going thru a 74HC244..also tried 74LVC245). A4 (SDA)
and A5 (SCL) have a 4.7kohm pullup resistor to 3.3V. I also removed the pullups in the twi library. I verified that PLCK has an output signal. All the rest of the connections look good. I am using Realterm to
capture the serial data. It writes this data directly to a file. I have tried converting over a "useQvga" image like so:
ffmpeg -f rawvideo -s 320*240 -pix_fmt yuvj422p -i frame0.yuv -f image2 -vcodec png img.png
I get a green screen, nothing that looks like a picture image. I have also used a couple other utilities that I found, but they do not produce an image either. One of which converted the image into grayscale, looks
similar to static on tv . So, I am not sure what I am doing wrong here. If anybody can provide some insight I would be interested. By the way, I also tried another camera, similar results.
Also, Mr Arduino, you posted below about your data-converter, I would like the windows binary if you could post it? I am having trouble getting the data-converter to compile on my win 7 machine. I think it is
related to a problem with the libpng library. Perhaps your converter would help me produce a good image.
"Yes it is here https://github.com/ComputerNerd/RawCamera-data-converter one thing I was wondering should I release windows binaries with it or not? How many people here use windows here?
Thanks,
-diesel
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Aug 21, 2014, 01:54 am
Yes it could, I added a windows binary https://github.com/ComputerNerd/RawCamera-data-converter/blob/master/convert.exe.7z
What I did instead of bothering to compile libpng and zlib I just used a different library called miniz. It has support for saving a png file so I used it. The reason for doing this is to keep executable size down and
also I found that it saved the png file faster and had a similar filesize.
Title: Re: ov7670 with both arduino uno and now mega
Post by: diesel on Aug 21, 2014, 05:27 am
Mr Arduino,
Thanks, I finally was a able to get a good image! I think part of my problem was the synchronization of the serial port. It takes a few pics for it to lock in, at least when using Realterm. Thanks again for all the
information you provided, it was very helpful in getting this camera to work.
-diesel

78 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Aug 21, 2014, 03:48 pm
Glad I could help. Actually when using the stm32 I made a slightly different protocol. After sending RDY I sent the line number that was about to be sent. This allowed for quicker synchronization. Yes I also get
the same issue.
Title: Re: ov7670 with both arduino uno and now mega
Post by: LucasRoth on Aug 25, 2014, 11:13 pm
Hi Mr Arduino,
First of all, really thanks for your posts! you rock?? ;)
I got an OV 2640 and trying to make it run without Fifo, as you have shown is possible using the OV 7670.
The idea is to get a cheap DIY solution that takes photos with movement detection (PIR sensor) trigger -> stored to SD card.
After reading your posts and documentation available, I feel like the dumbest newbie :/ do you think is possible? theres very little info about using this module. http://forum.arduino.cc/index.php
/topic,200366.0.html
I have ordered a OV 7670 to wireup the examples you upload, as far as I look to the files in github could,t find a *.ino file to test in Arduino. Do you have a "hello world" like project, just get to get a photo and
store it in memory (ideally using the SD module)?
Most of us, newbies with cameras (and moreless with open harware) will be so glad for that!!
Thanks in advance, best regards.
Lucas.
Title: Re: ov7670 with both arduino uno and now mega
Post by: josephchrzempiec on Sep 04, 2014, 08:31 am
Hello i know this is a told topic but can someone help me out i bought this camera from ebay with 18 pins on it got all kinda of pinout on it i don't understand trying to get this to work on my arduino mega not sure
how to wire it up to video from my pc or what sketch and library to use can someone help me out not very good at coding or wiring but trying.

Joseph
Title: Re: ov7670 with both arduino uno and now mega
Post by: diesel on Sep 05, 2014, 06:52 am
Mr Arduino,
I able to get a good "useVga" vga bayerRGB image using your ov7670-no-ram-arduino-uno-master files and your converter. The colors of the image look good. However, I am having some trouble with the qvga
and qqva yuv422 images. I am getting the correct # of bytes, 153603 with the qvga(including the RDY..which I remove). I get an sharp image, but the color is off, mostly green. This is using your converter. I have
tried the variations of yuv, but still green. After the serial settles in, the green is less, but still contributes significantly to the image(70%). I have a 4.7kohm resistor terminated to 5V on the i2c lines. I am now
using a 74AHCT125 for the 8 mhz from pin 11. Using a uno and ov7670 w/o fifo. I have tried setting the registers differently, no change. Tried re-setting the wiring, no change. Changed serial speeds, no
change. Have you encountered this? Have any pointers? I noticed you had a capacitor in your picture on the 1st page, perhaps I need to add that? Just trying to figure out what is causing the issue, so I can
address it.
Thanks,
-diesel
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Sep 06, 2014, 01:35 am
I will be answering these questions in reverse order (most recent first).
diesel try using -o 1 as a parameter. Try incrementing the one and seeing if that solves anything. This will skip n bytes. The capacitor in that picture is not connected to anything. It was just a leftover from a
different project.
josephchrzempiec
I have wrote about wiring in the past. Did it help you?
LucasRoth the ov2640 is not the same as the ov7670. I do not own an ov2640 camera module and as such I don't have much to say about it. I disagree with the person on the topic you linked to where he almost
in effect said it won't work at all. I would say try and prove him wrong.
As for arduino *ino I do have those, they are very old and I can now code better as you can see on github. Yes there is an SD card example that is a *.ino.
Title: Re: ov7670 with both arduino uno and now mega
Post by: diesel on Sep 08, 2014, 05:41 am
Mr Arduino,
Thanks for the tip. I used a 1 byte offset for the qvga(w/yuv422) image with the converter. Yes, the colors came out much better. Still have a little bit of green hue and dark green around certain edges though. I
might give this a try another day, thanks again.
-diesel
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Sep 09, 2014, 09:55 pm
Yes I admit that this is more of a hack than a solution. This would mean that n amount of bytes were missed.
Title: Re: ov7670 with both arduino uno and now mega
Post by: flz47655 on Sep 10, 2014, 12:07 am
Hello,
I get this color bar:
(http://i58.tinypic.com/30cnhpw.png)
Also images are very greenish
What can be wrong?

79 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Sep 10, 2014, 12:45 am
Did you read what I recently wrote? I am getting tired of answering duplicate questions.
Title: Re: ov7670 with both arduino uno and now mega
Post by: flz47655 on Sep 10, 2014, 02:39 am
Yes, I read all thread. I set camera for 320x240 RGB565.
White look like green..
(http://i59.tinypic.com/30sumb6.png)
These are registers:
Code: [Select]
{0x0,0xF},
{0x1,0x60},
{0x2,0x5A},
{0x3,0x5},
{0x4,0x1},
{0x5,0x0},
{0x6,0x24},
{0x7,0x40},
{0x8,0x37},
{0x9,0x1},
{0xA,0x76},
{0xB,0x73},
{0xC,0x0},
{0xD,0x0},
{0xE,0x61},
{0xF,0x4B},
{0x10,0x7F},
{0x11,0x0},
{0x12,0x14},
{0x13,0xE7},
{0x14,0x0},
{0x15,0x2},
{0x16,0x2},
{0x17,0x16},
{0x18,0x4},
{0x19,0x2},
{0x1A,0x7A},
{0x1B,0x0},
{0x1C,0x7F},
{0x1D,0xA2},
{0x1E,0x27},
{0x1F,0x0},
{0x20,0x4},
{0x21,0x2},
{0x22,0x91},
{0x23,0x0},
{0x24,0x8A},
{0x25,0x73},
{0x26,0xA5},
{0x27,0x80},
{0x28,0x80},
{0x29,0x7},
{0x2A,0x0},
{0x2B,0x0},
{0x2C,0x80},
{0x2D,0x0},
{0x2E,0x0},
{0x2F,0x24},
{0x30,0x8},
{0x31,0x30},
{0x32,0x80},
{0x33,0xB},
{0x34,0x11},
{0x35,0xB},
{0x36,0x0},
{0x37,0x1D},
{0x38,0x71},
{0x39,0x2A},
{0x3A,0x4},
{0x3B,0x0},
{0x3C,0x78},
{0x3D,0x88},
{0x3E,0x0},
{0x3F,0x0},
{0x40,0xD0},
{0x41,0x8},
{0x42,0x0},
{0x43,0x14},
{0x44,0xF0},
{0x45,0x34},
{0x46,0x58},
{0x47,0x28},
{0x48,0x3A},
{0x49,0x0},
{0x4A,0x0},
{0x4B,0x0},
{0x4C,0x0},
{0x4D,0x40},
{0x4E,0x20},
{0x4F,0x80},
{0x50,0x80},
{0x51,0x0},
{0x52,0x22},
{0x53,0x5E},
{0x54,0x80},
{0x55,0x0},
{0x56,0x50},
{0x57,0x80},
{0x58,0x9E},
{0x59,0x88},
{0x5A,0x88},
{0x5B,0x44},
{0x5C,0x67},
{0x5D,0x49},
{0x5E,0xE},
{0x5F,0xF0},
{0x60,0xF0},
{0x61,0xF0},
{0x62,0x0},
{0x63,0x0},
{0x64,0x4},
{0x65,0x20},
{0x66,0x5},
{0x67,0xC0},
{0x68,0x80},
{0x69,0x0},
{0x6A,0x40},
{0x6B,0xA},
{0x6C,0xA},
{0x6D,0x55},

80 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

{0x6E,0x11},
{0x6F,0x9F},
{0x70,0x0},
{0x71,0x1},
{0x72,0x11},
{0x73,0x0},
{0x74,0x19},
{0x75,0xF},
{0x76,0xE1},
{0x77,0x10},
{0x78,0x0},
{0x79,0x0},
{0x7A,0x2C},
{0x7B,0x11},
{0x7C,0x1A},
{0x7D,0x2A},
{0x7E,0x42},
{0x7F,0x4C},
{0x80,0x56},
{0x81,0x5F},
{0x82,0x67},
{0x83,0x70},
{0x84,0x78},
{0x85,0x87},
{0x86,0x95},
{0x87,0xAF},
{0x88,0xC8},
{0x89,0xDF},
{0x8A,0x0},
{0x8B,0x0},
{0x8C,0x0},
{0x8D,0x4F},
{0x8E,0x0},
{0x8F,0x0},
{0x90,0x0},
{0x91,0x0},
{0x92,0x0},
{0x93,0x0},
{0x94,0x4},
{0x95,0x8},
{0x96,0x0},
{0x97,0x1},
{0x98,0x10},
{0x99,0x40},
{0x9A,0x80},
{0x9B,0x20},
{0x9C,0x0},
{0x9D,0x99},
{0x9E,0x7F},
{0x9F,0x78},
{0xA0,0x68},
{0xA1,0x3},
{0xA2,0x2},
{0xA3,0x1},
{0xA4,0x0},
{0xA5,0x5},
{0xA6,0xDF},
{0xA7,0xDF},
{0xA8,0xF0},
{0xA9,0x90},
{0xAA,0x94},
{0xAB,0x7},
{0xAC,0x0},
{0xAD,0x80},
{0xAE,0x80},
{0xAF,0x80},
{0xB0,0x84},
{0xB1,0xC},
{0xB2,0xE},
{0xB3,0x82},
{0xB4,0x0},
{0xB5,0x4},
{0xB6,0x0},
{0xB7,0x66},
{0xB8,0xA},
{0xB9,0x6},
{0xBA,0x0},
{0xBB,0x0},
{0xBC,0x0},
{0xBD,0x0},
{0xBE,0x41},
{0xBF,0x41},
{0xC0,0x41},
{0xC1,0x41},
{0xC2,0x0},
{0xC3,0x0},
{0xC4,0x0},
{0xC5,0x0},
{0xC6,0x0},
{0xC7,0x0},
{0xC8,0x6}

I have also tried YUV but result look bad too...


(http://i57.tinypic.com/15i44qx.png)
Code: [Select]
{0x0,0x1},
{0x1,0x62},
{0x2,0x5E},
{0x3,0x5},
{0x4,0x1},
{0x5,0x50},
{0x6,0x26},
{0x7,0x40},
{0x8,0x81},
{0x9,0x1},
{0xA,0x76},
{0xB,0x73},
{0xC,0x0},
{0xD,0x0},
{0xE,0x61},
{0xF,0x4B},
{0x10,0x7F},
{0x11,0x0},
{0x12,0x10},
{0x13,0xE7},
{0x14,0x0},
{0x15,0x2},
{0x16,0x2},
{0x17,0x16},
{0x18,0x4},
{0x19,0x2},
{0x1A,0x7A},
{0x1B,0x0},
{0x1C,0x7F},
{0x1D,0xA2},
{0x1E,0x27},
{0x1F,0x0},
{0x20,0x4},
{0x21,0x2},
{0x22,0x91},

81 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

{0x23,0x0},
{0x24,0x8A},
{0x25,0x73},
{0x26,0xA5},
{0x27,0x80},
{0x28,0x80},
{0x29,0x7},
{0x2A,0x0},
{0x2B,0x0},
{0x2C,0x80},
{0x2D,0x0},
{0x2E,0x0},
{0x2F,0x26},
{0x30,0x8},
{0x31,0x30},
{0x32,0x80},
{0x33,0xB},
{0x34,0x11},
{0x35,0xB},
{0x36,0x0},
{0x37,0x1D},
{0x38,0x71},
{0x39,0x2A},
{0x3A,0xC},
{0x3B,0x0},
{0x3C,0x78},
{0x3D,0x98},
{0x3E,0x0},
{0x3F,0x0},
{0x40,0xC0},
{0x41,0x8},
{0x42,0x0},
{0x43,0x14},
{0x44,0xF0},
{0x45,0x34},
{0x46,0x58},
{0x47,0x28},
{0x48,0x3A},
{0x49,0x0},
{0x4A,0x0},
{0x4B,0x0},
{0x4C,0x0},
{0x4D,0x40},
{0x4E,0x20},
{0x4F,0x80},
{0x50,0x80},
{0x51,0x0},
{0x52,0x22},
{0x53,0x5E},
{0x54,0x80},
{0x55,0x0},
{0x56,0x50},
{0x57,0x80},
{0x58,0x9E},
{0x59,0x88},
{0x5A,0x88},
{0x5B,0x44},
{0x5C,0x67},
{0x5D,0x49},
{0x5E,0xE},
{0x5F,0xF0},
{0x60,0xF0},
{0x61,0xF0},
{0x62,0x0},
{0x63,0x0},
{0x64,0x4},
{0x65,0x20},
{0x66,0x5},
{0x67,0xC0},
{0x68,0x80},
{0x69,0x0},
{0x6A,0x40},
{0x6B,0xA},
{0x6C,0xA},
{0x6D,0x55},
{0x6E,0x11},
{0x6F,0x9F},
{0x70,0x0},
{0x71,0x81},
{0x72,0x11},
{0x73,0x0},
{0x74,0x19},
{0x75,0xF},
{0x76,0xE1},
{0x77,0x10},
{0x78,0x0},
{0x79,0x0},
{0x7A,0x2C},
{0x7B,0x11},
{0x7C,0x1A},
{0x7D,0x2A},
{0x7E,0x42},
{0x7F,0x4C},
{0x80,0x56},
{0x81,0x5F},
{0x82,0x67},
{0x83,0x70},
{0x84,0x78},
{0x85,0x87},
{0x86,0x95},
{0x87,0xAF},
{0x88,0xC8},
{0x89,0xDF},
{0x8A,0x0},
{0x8B,0x0},
{0x8C,0x0},
{0x8D,0x4F},
{0x8E,0x0},
{0x8F,0x0},
{0x90,0x0},
{0x91,0x0},
{0x92,0x0},
{0x93,0x0},
{0x94,0x4},
{0x95,0x8},
{0x96,0x0},
{0x97,0x1},
{0x98,0x10},
{0x99,0x40},
{0x9A,0x80},
{0x9B,0x20},
{0x9C,0x0},
{0x9D,0x99},
{0x9E,0x7F},
{0x9F,0x78},
{0xA0,0x68},
{0xA1,0x3},
{0xA2,0x2},
{0xA3,0x2},
{0xA4,0x0},
{0xA5,0x5},
{0xA6,0xDF},
{0xA7,0xDF},
{0xA8,0xF0},
{0xA9,0x90},
{0xAA,0x94},

82 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

{0xAB,0x7},
{0xAC,0x0},
{0xAD,0x80},
{0xAE,0x80},
{0xAF,0x80},
{0xB0,0x84},
{0xB1,0xC},
{0xB2,0xE},
{0xB3,0x82},
{0xB4,0x0},
{0xB5,0x4},
{0xB6,0x0},
{0xB7,0x66},
{0xB8,0xA},
{0xB9,0x6},
{0xBA,0x0},
{0xBB,0x0},
{0xBC,0x0},
{0xBD,0x0},
{0xBE,0x41},
{0xBF,0x42},
{0xC0,0x41},
{0xC1,0x42},
{0xC2,0x0},
{0xC3,0x0},
{0xC4,0x0},
{0xC5,0x0},
{0xC6,0x0},
{0xC7,0x0},
{0xC8,0x6}

I have tried a lot of combinations for registers (also from your github) but colors remains bad.. =(
Thank you
Title: Re: ov7670 with both arduino uno and now mega
Post by: flz47655 on Sep 10, 2014, 12:50 pm
Using registers from https://github.com/ComputerNerd/ov7670-simple where I have changed only REG_COM10 (I use module v2 with patch to connect RE pin).
Code: [Select]
//set up camera
wrReg(REG_COM10, 0x02);//pclk does not toggle on HBLANK COM10 //32
//wrReg(0x11,32);//Register 0x11 is for pixel clock divider
wrReg(REG_RGB444, 0x00);// Disable RGB444
wrReg(REG_COM11,226);//enable night mode 1/8 frame rate COM11*/
//wrReg(0x2E,63);//Longer delay
wrReg(REG_TSLB,0x04);
// 0D = UYVY 04 = YUYV
wrReg(REG_COM13,0x88);
// connect to REG_TSLB
//wrReg(REG_COM13,0x8);
// connect to REG_TSLB disable gamma
wrReg(REG_COM7, 0x00);
// YUV
//wrReg(REG_COM17, 0x00);
// color bar disable
wrReg(REG_COM15, 0xC0);
//Full range
//wrReg(REG_COM3, 0x04);
wrReg(REG_COM3,4);
// REG_COM3
//wrReg(0x3e,0x00);
// REG_COM14
//wrReg(0x72,0x11);
//
//wrReg(0x73,0xf0);
//
//wrReg(REG_COM8,0x8F);
// AGC AWB AEC Unlimited step size
/*wrReg(REG_COM8,0x88);//disable AGC disable AEC
wrReg(REG_COM1, 3);//manual exposure
wrReg(0x07, 0xFF);//manual exposure
wrReg(0x10, 0xFF);//manual exposure*/
wrReg(REG_COM14, 0x19);
wrReg(0x72, 0x11);
wrReg(0x73, 0xf1);
wrReg(REG_HSTART,0x16);
wrReg(REG_HSTOP,0x04);
wrReg(REG_HREF,0x24);
wrReg(REG_VSTART,0x02);
wrReg(REG_VSTOP,0x7a);
wrReg(REG_VREF,0x0a);
//wrReg(0x70, 0x3a);
// Scaling Xsc
//wrReg(0x71, 0x35);
// Scaling Ysc
//wrReg(0xA2, 0x02);
// pixel clock delay
//Color Settings
//wrReg(0,0xFF);//set gain to maximum possible
//wrReg(0xAA,0x14);
// Average-based AEC algorithm
wrReg(REG_BRIGHT,0x00);
// 0x00(Brightness 0) - 0x18(Brightness +1) - 0x98(Brightness -1)
wrReg(REG_CONTRAS,0x40);
// 0x40(Contrast 0) - 0x50(Contrast +1) - 0x38(Contrast -1)
//wrReg(0xB1,0xB1);
// Automatic Black level Calibration
wrReg(0xb1,4);//really enable ABLC
wrReg(MTX1,0x80);
wrReg(MTX2,0x80);
wrReg(MTX3,0x00);
wrReg(MTX4,0x22);
wrReg(MTX5,0x5e);
wrReg(MTX6,0x80);
wrReg(MTXS,0x9e);
wrReg(AWBC7,0x88);
wrReg(AWBC8,0x88);
wrReg(AWBC9,0x44);
wrReg(AWBC10,0x67);
wrReg(AWBC11,0x49);
wrReg(AWBC12,0x0e);
wrReg(REG_GFIX,0x00);
//wrReg(GGAIN,0);
wrReg(AWBCTR3,0x0a);
wrReg(AWBCTR2,0x55);
wrReg(AWBCTR1,0x11);
wrReg(AWBCTR0,0x9f);
//wrReg(0xb0,0x84);//not sure what this does
wrReg(REG_COM16,COM16_AWBGAIN);//disable auto denoise and edge enhancement
//wrReg(REG_COM16,0);
wrReg(0x4C,0);//disable denoise
wrReg(0x76,0);//disable denoise
wrReg(0x77,0);//disable denoise
wrReg(0x7B,4);//brighten up shadows a bit end point 4
wrReg(0x7C,8);//brighten up shadows a bit end point 8
//wrReg(0x88,238);//darken highlights end point 176
//wrReg(0x89,211);//try to get more highlight detail
//wrReg(0x7A,60);//slope
//wrReg(0x26,0xB4);//lower maximum stable operating range for AEC
//hueSatMatrix(0,100);
//ov7670_store_cmatrix();
//wrReg(0x20,12);//set ADC range to 1.5x
wrReg(REG_COM9,0x6A);//max gain to 128x
wrReg(0x74,16);//disable digital gain
//wrReg(0x93,15);//dummy line MSB
wrReg(0x11,4);
//wrReg(0x2a,5);//href delay

I get thi YUV image


(http://i62.tinypic.com/e0fy1c.png)

83 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

With 4mm lens is also worse.. maybe can be low-quality lens?


UPDATE: I also tried
Code: [Select]
wrReg(REG_COM10, 0x02);//pclk does not toggle on HBLANK COM10 0x15
ov7670_default_regs();
qvga_ov7670();
rgb565_ov7670();

where functions simply set register like defined in https://github.com/ComputerNerd/arduino-camera-tft/blob/master/ov7670_regs.h (https://github.com/ComputerNerd/arduino-camera-tft/blob/master


/ov7670_regs.h) but nothing... green stay.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Sep 10, 2014, 07:19 pm
The issue appears to be the fact that you are enabling rgb565 mode but trying to treat it as yuv422. After making sure that you have yuv422 enabled if that is what you want you will then need to see if any bytes
need to be skipped if you still get a green image. Also I just realized instead of skipping bytes you will be better off changing the order by changing registers 0x3D and 0x3A.
Title: Re: ov7670 with both arduino uno and now mega
Post by: flz47655 on Sep 10, 2014, 08:51 pm
I've tried both RGB565 and YUV422 with right decoding on pc side but green stay :( I've tried changing order and skipping bytes, hours and hours of trying. RGB565 seem better but far from your images.
Could be sensor broken? ov7725 is better? If I have to buy the sensor I want better.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Sep 10, 2014, 09:37 pm
Is d7-d0 connected correctly? Also yes the ov7725 is better relative to the ov7670 but there are even better than the ov7670 depending on what you want. Also what converter are you using. Did you try mine?
Title: Re: ov7670 with both arduino uno and now mega
Post by: flz47655 on Sep 10, 2014, 11:49 pm
Yes, data lines are ok.
It seems like white saturate to green
(http://i58.tinypic.com/sgo29i.png)
This is 320x240 image stretched to 640x480 . I'm using a software that I wrote in C#.
I confirm my results with ffmpeg, converting raw rgb565 bytes received from camera (attached) into png image with
ffmpeg -f rawvideo -s 320x240 -pix_fmt rgb565be -i 0.raw -f image2 -vcodec png img.png
Give same image
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Sep 11, 2014, 01:04 am
I get a similar image. I do not understand why the image looks like that. Are you using the fifo version? If so you should use a faster XCLK. If so remove the code that changes the divider settings. The fifo uses
DRAM and maybe it is not being refreshed fast enough.
Title: Re: ov7670 with both arduino uno and now mega
Post by: flz47655 on Sep 11, 2014, 01:18 am
I was analyzing in frequency images generated.. bit 7 is always zero. Electrical connection between pcb and camera module is ok, also between pin header and FIFO.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Sep 11, 2014, 01:48 am
Yes that would cause the images to look weird. From your post it sounds like you did not check from pin header to microcontroller please do that. Also make sure that all pins d0 to d7 are an input. Also make
sure internal pull up resistors are disabled. Also you are using the fifo version so remove the writes to register 0x11.
Title: Re: ov7670 with both arduino uno and now mega
Post by: flz47655 on Sep 11, 2014, 01:56 am
From pin header to microcontroller is ok, maybe problem is into ov7670 sensor pin.. but.. I changed to RGB555 so I don't need D7
Here is Color Bar
(http://i58.tinypic.com/14dldms.png)
And a Mario image
(http://i57.tinypic.com/289cuu8.png)
Much better :)
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Sep 11, 2014, 02:22 am
Better is relative. See some pictures I took with the ov7670. Anyways I am not quite sure with the issue is but your solution does not actually solve the problem, it is just a hack and the colors are still wrong. I
guess it is up to you if you want to settle for this. Have you tried my advice to not write to register 0x11? If so tell me what the results were and from there we can continue to try the issue.

84 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Title: Re: ov7670 with both arduino uno and now mega
Post by: flz47655 on Sep 11, 2014, 02:37 am
I had
Code: [Select]
{0x11, 0x00}

And removed it but nothing changed.


Yes better is relative, tomorrow I tweak registers to see if I manage to improve the quality of image.
Title: Re: ov7670 with both arduino uno and now mega
Post by: ahmad_odeh on Sep 13, 2014, 02:22 am
hey
now i have camera modul ov7670 but i don't know how connect to arduino mega i need just RX & TX and in camera very pin's i don't know any one rx or tx plz help me .
i need just photo from camera and send it dirct to computer via usb cable.
i need any thing + rx & tx ??
plz plz help me very important
thnx alot
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Sep 13, 2014, 02:43 am
A better understanding of the ov7670 and a better written post would help both yourself and I. The ov7670 does not have RX and TX pins. The arduino has those.
Title: Re: ov7670 with both arduino uno and now mega
Post by: ahmad_odeh on Sep 13, 2014, 10:13 am
sorry for miss understanding but i was searching whole the internet for which camera i could purchase after i hava seen this thread i purchased Ov7670 and now i'm sticking :smiley-roll-sweat: .
sorry but i only want a simple configuration cause i'm not advance
Title: Re: ov7670 with both arduino uno and now mega
Post by: jaolho on Sep 15, 2014, 08:34 am
Hi!
Im trying to read values from the ov7670 registers (second week of trying) with Arduino Uno R3. Could somebody confirm that the following is possible (or any of the things on the list):
1) Using the Arduino Wire Library http://arduino.cc/en/reference/wire (http://arduino.cc/en/reference/wire) (I2C protocol) without modifications to communicate with the ov7670.
2) Using the addresses 0x42 (0b1000010) and 0x43 (0b1000011) for reading and writing with the WIRE library. The Omnivision datasheets are horrible (the addresses given in the datasheet are 42 and 43, NOT
0x42 and 0x43) and I suspect that the actual 7-bit I2C-address should be 0x21 (0b100001). That is if the ov7670 is compatibe with I2C at all. Im aware that it is using the SCCB-protocol but some claim to be
successful using the I2C with Omnivision chips.
3) Using only 10K pull-up resistors to 3.3V on the SDA (SIOD) and SCL (SIOC) lines instead of level shifting or protective resistors circuitry. I2C-lines should never be set to Vdd by the master or the slave if you
follow the original Philips specs. They should be left floating (so they can be pulled-up by the external resistors) or driven to the ground.
4) Using the Arduino to produce the 8 MHz clock signal for the ov7670 WITH voltage divider resistors (even 1K resistors seem to change the signal from a square wave to a sine wave).
If using the wire library is possible, could somebody please provide a simple ~ 10 lines of code example which reads a register value from the ov7670 WITH a description of the circuitry used. Im starting to
suspect that I have somehow broken the ov7670 or that Im just dumb :)

Title: Re: ov7670 with both arduino uno and now mega
Post by: AntonLH on Sep 15, 2014, 06:25 pm
I've been reading this thread for a long time, but i haven't clarified what i have to do if i have a non-fifo version and an arduino uno r3. In the github are some files and I don't know which of them i need for my
situation. Can anyone help me?
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Sep 18, 2014, 02:21 am
You know when I created this topic in 2013 I remember the felling of accomplishment that I had discovering how to get the module to work without any help but reading the datasheet and a few short code
examples showing undocumented registers and a few blog posts about the module. I also saw people saying this was impossible but they are wrong. The felling of accomplishment of getting it working without
someone holding my hand was great and I don't need that to get stuff to work. I like being self motivated but sadly not everyone does. I see these three questions and they are no different than anything else that
I have answered. Regardless of what they put I most likely still would have wrote this unless they wrote about what they discovered about the ov7670. I understand it is easy to ask the expert but sometimes, I
think people need to take the time to be problem solvers themselves. Anyways I have already done quite a bit and I think enough for me to call it good. I would like to hear about what you learned that I do not
know about the ov7670 not just repeat questions. The main reason I am bored and tired of this is because it feels very repetitive. So please lets keep this thread still active I am not saying I am leaving the forum
but if you have a question that I already answered don't expect a response from me. What would make me happy is if you had documentation or official code that I don't have already that would help me get
interested in answering questions again. Also I would like to point out that I have received help from some awesome arudino members when I was a newbie in the past and before I really was good at solving my
own issues and I think this and my other answers has more than repayed them for their efforts.
Title: Re: ov7670 with both arduino uno and now mega
Post by: ultranoob on Sep 26, 2014, 01:02 am
I was testing the code, but arduino drop me this error
Code: [Select]
Arduino: 1.5.6-r2 (Windows 7), Placa:"Arduino Uno"
V1.ino:
V1:132:
V1:132:
V1:133:
V1:133:

85 of 96

In function 'int main()':


error: 'qqvga' was not declared in this scope
error: 'setRes' was not declared in this scope
error: 'yuv422' was not declared in this scope
error: 'setColor' was not declared in this scope

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

This report would have more information with


"Show verbose output during compilation"
enabled in File > Preferences.

i try the OV7670 no ram no fifo, also where is stored the data that the pc gets from the OV7670?
this is the code that im using from you
Code: [Select]
#define F_CPU 16000000UL
#include <stdint.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/twi.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include "ov7670.h"
//resoluciones
//#define useVga
//#define useQvga
#define useQqvga
static inline void serialWrB(uint8_t dat){
while(!( UCSR0A & (1<<UDRE0)));//wait for byte to transmit
UDR0=dat;
while(!( UCSR0A & (1<<UDRE0)));//wait for byte to transmit
}
static void StringPgm(char * str){
do{
serialWrB(pgm_read_byte_near(str));
}while(pgm_read_byte_near(++str));
}
static void captureImg(uint16_t wg,uint16_t hg){
uint16_t lg2;
#ifdef useQvga
uint8_t buf[640];
#elif defined(useQqvga)
uint8_t buf[320];
#endif
StringPgm(PSTR("RDY"));
//Wait for vsync it is on pin 3 (counting from 0) portD
while(!(PIND&8));//wait for high
while((PIND&8));//wait for low
#ifdef useVga
while(hg--){
lg2=wg;
while(lg2--){
while((PIND&4));//wait for low
UDR0=(PINC&15)|(PIND&240);
while(!(PIND&4));//wait for high
}
}
#elif defined(useQvga)
/*We send half of the line while reading then half later */
while(hg--){
uint8_t*b=buf,*b2=buf;
lg2=wg/2;
while(lg2--){
while((PIND&4));//wait for low
*b++=(PINC&15)|(PIND&240);
while(!(PIND&4));//wait for high
while((PIND&4));//wait for low
*b++=(PINC&15)|(PIND&240);
UDR0=*b2++;
while(!(PIND&4));//wait for high
}
/* Finish sending the remainder during blanking */
lg2=wg/2;
while(!( UCSR0A & (1<<UDRE0)));//wait for byte to transmit
while(lg2--){
UDR0=*b2++;
while(!( UCSR0A & (1<<UDRE0)));//wait for byte to transmit
}
}
#else
/* This code is very similar to qvga sending code except we have even more blanking time to take advantage of */
while(hg--){
uint8_t*b=buf,*b2=buf;
lg2=wg/5;
while(lg2--){
while((PIND&4));//wait for low
*b++=(PINC&15)|(PIND&240);
while(!(PIND&4));//wait for high
while((PIND&4));//wait for low
*b++=(PINC&15)|(PIND&240);
while(!(PIND&4));//wait for high
while((PIND&4));//wait for low
*b++=(PINC&15)|(PIND&240);
while(!(PIND&4));//wait for high
while((PIND&4));//wait for low
*b++=(PINC&15)|(PIND&240);
while(!(PIND&4));//wait for high
while((PIND&4));//wait for low
*b++=(PINC&15)|(PIND&240);
UDR0=*b2++;
while(!(PIND&4));//wait for high
}
/* Finish sending the remainder during blanking */
lg2=320-(wg/5);
while(!( UCSR0A & (1<<UDRE0)));//wait for byte to transmit
while(lg2--){
UDR0=*b2++;
while(!( UCSR0A & (1<<UDRE0)));//wait for byte to transmit
}
}
#endif
}
int main(void){
cli();//disable interrupts
/* Setup the 8mhz PWM clock
* This will be on pin 11*/
DDRB|=(1<<3);//pin 11
ASSR &= ~(_BV(EXCLK) | _BV(AS2));
TCCR2A=(1<<COM2A0)|(1<<WGM21)|(1<<WGM20);
TCCR2B=(1<<WGM22)|(1<<CS20);
OCR2A=0;//(F_CPU)/(2*(X+1))
DDRC&=~15;//low d0-d3 camera
DDRD&=~252;//d7-d4 and interrupt pins
_delay_ms(3000);
//set up twi for 100khz
TWSR&=~3;//disable prescaler for TWI
TWBR=72;//set to 100khz
//enable serial
UBRR0H=0;
UBRR0L=1;//0 = 2M baud rate. 1 = 1M baud. 3 = 0.5M. 7 = 250k 207 is 9600 baud rate.
UCSR0A|=2;//double speed aysnc
UCSR0B = (1<<RXEN0)|(1<<TXEN0);//Enable receiver and transmitter
UCSR0C=6;//async 1 stop bit 8bit char no parity bits
//camInit();
#ifdef useVga
setRes(vga);
setColor(bayerRGB);
wrReg(0x11,25);

86 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

#elif defined(useQvga)
setRes(qvga);
setColor(yuv422);
wrReg(0x11,12);
#else
setRes(qqvga);
setColor(yuv422);
wrReg(0x11,3);
#endif
while (1){
/* captureImg operates in bytes not pixels in some cases pixels are two bytes per pixel
* So for the width (if you were reading 640x480) you would put 1280 if you are reading yuv422 or rgb565 */
/*uint8_t x=63;//Uncomment this block to test divider settings note the other line you need to uncomment
do{
wrReg(0x11,x);
_delay_ms(1000);*/
#ifdef useVga
captureImg(640,480);
#elif defined(useQvga)
captureImg(320*2,240);
#else
captureImg(160*2,120);
Serial.println("Captura realizada");
#endif
//}while(--x);//Uncomment this line to test divider settings
}
}

Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Sep 28, 2014, 01:41 am
There are multiple files you need to look at all of them. Also I posted the receiver code. The no [external] ram code does not store the image it just sends data to uart while it is being received.
Title: Re: ov7670 with both arduino uno and now mega
Post by: ultranoob on Sep 28, 2014, 02:26 am
I read all and try to understand all of them, but some code i dont know what do they do x.x, and since that code was more suitable for my components that i own at the moment, i try it, but it didnt work for me, try
to search on libraries to see if there was something missing, but i could not find nothing
Title: Re: ov7670 with both arduino uno and now mega
Post by: dasaki on Oct 01, 2014, 01:25 pm
Quote from: josephchrzempiec on Sep 04, 2014, 08:31 am
Hello i know this is a told topic but can someone help me out i bought this camera from ebay with 18 pins on it got all kinda of pinout on it i don't understand trying to get this to work on my arduino mega not sure how to wire it up to video from my pc or what sketch and
library to use can someone help me out not very good at coding or wiring but trying.

Joseph

I think you have a module like the one's I'm using (either http://www.lxxtech.com/ov7670-30w-fifo-camera-module-p820.html (http://www.lxxtech.com/ov7670-30w-fifo-camera-module-p820.html) or
http://www.alientek.com/product/showproduct.php?lang=cn&id=20 (http://www.alientek.com/product/showproduct.php?lang=cn&id=20)).
First of all, you have to work with 3.3v signals, at least for the lines that are connected directly to the image sensor (SDA, SCL, and VSYNC). Arduino mega works at 5v, so you need a logic level converter, that
converts the arduino 5v signals to 3.3v, and the module's 3.3v (output) signals to 5v. Search for "bidirectional logic level converter" or "bidirectional logic level shifter", and make sure it has enough channels for
your needs. If you don't need to read the sensors registers you may try Nicolas Frey's wiring with voltage dividers: http://nicolasfley.fast-page.org/?page_id=35.
In my case, I'm using a 3.3v arduino, so the connections are much simpler (at the cost of performance drop of running at 8MHz ).
You can have a look at my setup and code here: arduvision.com (http://arduvision.com) (NOTE: I'm working on the page, so at the moment it will direct you to my blog ).
Title: Re: ov7670 with both arduino uno and now mega
Post by: s_black on Oct 04, 2014, 07:18 pm
I worked with this camera. Article 1 (http://www.embed.com.ua/mikrokontrollernyiy-konstruktor/ov7670-atmega48-udisp320240/) and article 2 (http://www.embed.com.ua/mikrokontrollernyiy-konstruktor/ov7670atmega48-udisp320240-chast-2/). ATmega48 + discrete logic elements
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Oct 04, 2014, 07:55 pm
s_black that is a nice post. I do not speak russian and had to use google translate so I may be misunderstanding you but it appears that you gated HREF with PCLK. There is no need to do that. The ov7670 can
do that for you. In register 0x15 make sure bit 5 is true.
dasaki I do not see the need for a bidirectioal shifter. 3.3v will still register as true even when the microcontroller is powered with 5v. I do agree that using a 3.3v micontroller is better. Also it looks like you too do
have a nice project going.
Title: Re: ov7670 with both arduino uno and now mega
Post by: dasaki on Oct 04, 2014, 11:31 pm
Quote from: Mr_arduino on Oct 04, 2014, 07:55 pm
I do not see the need for a bidirectioal shifter. 3.3v will still register as true even when the microcontroller is powered with 5v.

Mr_arduino You are right, what I really wanted to say is that I think the most convenient level shifter is one single circuit that lets bidireccional data flow, avoiding any possible 5v reach the sensor, but allowing to
read its registers. By the way, thank you for you contribution to the community. With my project I'd like just to give back what I've learnt from people like you and others.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Oct 05, 2014, 05:57 pm
Yes I do see your point. However as long as you never set what should be an input as an output and then set it's output to true you will be fine. Maybe if you are making a camera module for beginners then you
may want to consider that. Also I am glad that you appreciate my work.
Title: Re: ov7670 with both arduino uno and now mega

87 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Post by: s_black on Oct 09, 2014, 05:54 pm


Thank you Mr_arduino! I have already dealt with this problem. All you good! Good luck )))
Title: Re: ov7670 with both arduino uno and now mega
Post by: shaileshswankhede on Oct 11, 2014, 09:55 am
Hello all,
I am facing difficulty in establishing communication between OV9653 and arduino uno. I know I have to change register set for OV9653 in OV7670_regs.h. But first I am trying SCCB connection. I am using
'ov7670-no-ram-arduino-uno' code to test. I made connection of SDA,SCL,3.3V power from Arduino,GND and XCLK. SDA and SCL are pulled up 3.3V with 1K. Arduino gives XCLK on 5V. I was converting it to
3.3V by using 2n2222 transistor circuit but arduino stucks in
while ((TWCR & _BV(TWINT)) == 0); /* wait for transmission */ in twiAddr(0x60,TW_MT_SLA_ACK) function.
I thought there would be problem with transistor switching so tried giving direct 3.3V, 14MHz from another atmel Eval-board but same problem. Tried shortening I2C wire with no luck.
What I am doing wrong? Please help me solve this problem at earliest. =(
Thanks,
Shailesh
Title: Re: ov7670 with both arduino uno and now mega
Post by: shamiulrain on Oct 16, 2014, 05:43 am
Recently i work with the Arduino Mega 2560 r3 and ov 7670 . Can you please tell the pin connection of Arduino Mega 2560 r3 and ov 7670 and also please tell me which code is better for me ,i don't have the
seeedstudio tft v1.0 and no fifo in ov7670.If you answer it will be helpful to me.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Superfred on Oct 16, 2014, 03:00 pm
Hello,
I solved my color problems by writing into OV7670 Register 0xB0 the value 0x84.
C# Code to convert the YUYV pair (y1/u/y2/v) in a RGB pair:
r1 = (int)((float)y1 - 1.4075 * (float)(v - 128));
g1 = (int)((float)y1 - 0.3455 * (float)(u - 128) + 0.7169 * (float)(v - 128));
b1 = (int)((float)y1 + 1.7790 * (float)(u - 128));
r2 = (int)((float)y2 - 1.4075 * (float)(v - 128));
g2 = (int)((float)y2 - 0.3455 * (float)(u - 128) + 0.7169 * (float)(v - 128));
b2 = (int)((float)y2 + 1.7790 * (float)(u - 128));
Title: Re: ov7670 with both arduino uno and now mega
Post by: shamiulrain on Oct 20, 2014, 07:04 am
Mr.Arduino if you make a video tutorial it will be more clear for us who are new in this site . Please make a video tutorial for us if u have some time.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Clorofilla on Oct 23, 2014, 09:22 am
hi,
i mainly used Arduino IDE, is just possible to use it to compile the sample code in the first post or is better to use something else?
What about these libraries:
#include <stdint.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/twi.h>
#include <util/delay.h>
#include <avr/pgmspace.h>

are there by default or where do i get them otherwise?


Thanks
Title: Re: ov7670 with both arduino uno and now mega
Post by: shamiulrain on Oct 27, 2014, 09:06 am
is the source code Mr_arduino shared work on ov7660+arduino mega 2560 r3??
Title: Re: ov7670 with both arduino uno and now mega
Post by: thehellaye on Oct 28, 2014, 07:36 am
i need software to display images from the camera are transmitted through the circus ov7670 arduino interface to PC.
Can you tell me the name of the software need to use for this topic ?
Title: Re: ov7670 with both arduino uno and now mega
Post by: Rojam06 on Oct 31, 2014, 03:28 am
Have you tried interfacing the OV5642 camera with arduino mega?
Title: Re: ov7670 with both arduino uno and now mega
Post by: thehellaye on Oct 31, 2014, 04:33 am

88 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

I tried but the Arduino does not support display


Who knows ?
i need software to display images from the camera are transmitted through the circus ov7670 arduino interface to PC.
Can you tell me the name of the software need to use for this topic ?
Title: Re: ov7670 with both arduino uno and now mega
Post by: thehellaye on Nov 02, 2014, 09:57 am
I bought the camera ov7670 fifo and I have a chip Arduino uno r3
I need a diagram to connect the camera to the Arduino to be able to transfer images from camera to computer screen
Title: Re: ov7670 with both arduino uno and now mega
Post by: bigolbug on Nov 20, 2014, 06:12 pm
Currently i am trying to establish I2C/TWI/SCCB communication with the OV7670 module. I am using the Wire.h library. I am using the code below to attempt to read some of the registers. I am running the below
code on a Arduino DUE, inside the setup loop, after XCLK creation and with 10k pull-up resisters to 3v3.
The OV7670 is not responding. All i get when i Serial.println(val) is 0. Do you have any suggestions?
Code: [Select]

//step 1: Select slave and register pointer


Wire.beginTransmission(43);
Wire.write(byte(0x01));
Wire.endTransmission();
// step 2: request reading from OBV7670
Wire.requestFrom(43, 1);
// step 3: receive reading from OBV7670
while(Wire.available())
{
byte val = Wire.read();
Serial.println(val);
}

Title: Re: ov7670 with both arduino uno and now mega
Post by: bigolbug on Nov 21, 2014, 09:19 pm
I am pretty sure i figured it out. I am getting readings from the OV7670. Thing is the readings are not what the datasheet says they should be.
0x0A returns 118
Code: [Select]
//TWI/I2C COMMUNICATION
Wire.begin();
delay(15);
// step 1: instruct OBV7670 to return a particular reading
Wire.beginTransmission(0x21);
Wire.write(byte(0x0A));
Wire.endTransmission();
// step 2: request reading from OBV7670
Wire.requestFrom(0x21, 1);
// step 3: receive reading from OV7670
while(!Wire.available()){}
int val = Wire.read();
Serial.println(val);

Title: Re: ov7670 with both arduino uno and now mega
Post by: edgaras on Nov 22, 2014, 07:23 pm
Hello, lately I tried to make my OV7670 camera work with Arduino Uno and read entire 30 pages to find solution for my problem since it doesnt work. It shows nothing (camera is definately working)
http://postimg.org/image/yfnwtxz3h/
Heres is photo of camera and Arduino.
Also used this schematic
http://i167.photobucket.com/albums/u157/cookiebal/OV7670ArduinoUno.jpg
And this code from Mr_Arduino example. Also didnt forgot to include other stuff like stdint.h and others.
https://github.com/ComputerNerd/ov7670-no-ram-arduino-uno
Any suggestions.
Title: Re: ov7670 with both arduino uno and now mega
Post by: KrakenProg on Nov 30, 2014, 12:05 am
Quote from: Mr_arduino on Apr 12, 2013, 01:30 am
Edit I had to move down the first revision of my inital post to here to work ardound a character limition below that I explained how I conntect the ov7670 to the arduino uno.
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 it would 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 additionally it 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 in this 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 of the 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 output both rgb565 or
yuv422 I found that yuv422 is better quality so I made a converter for that and you can get the source code here https://github.com/ComputerNerd/RawCamera-data-converter. Here is code for the capture program. http://pastebin.com/1nnRc5qL I used sdfatlib to write and
based 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 stop the capture hold down the button and wait for the led to blink very fast make sure that the button sinks the pin
to ground. If you do not define useLed then it uses 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 registers online 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 it gives the name but the description is blank. If someone could explain with a reply or PM what these:
Code: [Select]
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.

89 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

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 will have 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 to work. 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 the ov7670.
(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
Below here lies my response (the original aspect of the post).
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 you have 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 remove them
Code: [Select]
// 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 d4 to 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 exactly the same except enable 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 the sensor. The sd card and spi ram is just standard spi wiring
nothing special.

(Sorry, my english is not the best)


I dont understand something, i need to put a resistor in the sioc and the sioc?
Title: Re: ov7670 with both arduino uno and now mega
Post by: thehellaye on Nov 30, 2014, 08:13 am
I have to connect the Arduino to the camera, but I do not know how to display images on the computer to determine the camera is working or not, I need to show a simple software to connect to the Arduino Uno.
my english is bad, sorry about that
Title: Re: ov7670 with both arduino uno and now mega
Post by: acg2226 on Nov 30, 2014, 11:04 pm
OK, I have read a lot through these pages. I believe my connections are right. But I am new to Arduino environment and couldn't figure out what is wrong with my code, because I keep getting compilation errors.
I am trying to use a version of the code that Mr. Arduino presented. (code of: ov7670-no-ram-arduino-uno-master)

I am sure I imported the right libraries. How should I redeclare these functions?
And these are the errors I got:
Code: [Select]
sketch_dec01a.ino: In function 'int main()':
sketch_dec01a.ino:121:9: error: 'camInit' was not declared in this scope
sketch_dec01a.ino:123:8: error: 'vga' was not declared in this scope
sketch_dec01a.ino:123:11: error: 'setRes' was not declared in this scope
sketch_dec01a.ino:124:10: error: 'bayerRGB' was not declared in this scope
sketch_dec01a.ino:124:18: error: 'setColor' was not declared in this scope
Error compiling.

Title: Connecting OV7670_FIFO to Arduino UNO R3


Post by: taylanpince on Dec 14, 2014, 11:45 pm
Hello everyone, I read through the whole topic, and I spent the past few hours researching a precise documentation or tutorial on how to connect OV7670 with FIFO to an Arduino UNO. Unfortunately, I am still
quite confused.
All I would like to do at this stage is to capture frames from the camera and display them on a Mac app. I am quite proficient on the software side, but I am not clear on how to connect the camera module to the
Arduino board.
Can anyone provide me with a Fritzing file or a clear photo of a similar setup? I mainly need to understand whether I should use a resistor between some pins. I don't want to damage the board or the camera.
Here is a photo of my OV7670_FIFO module: http://cl.ly/image/0P3B1T1w0O3V (http://cl.ly/image/0P3B1T1w0O3V)
I know that this question sounds like a repeated one, but despite all the information on this thread, it's really not clear how to use this module. I am not a complete beginner at this and I haven't been able to figure
it out after hours of research. Once I get this working, I am going to put together some very precise documentation and code examples on how to use it for posterity.
Thank you for your assistance!
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Dec 23, 2014, 01:37 am
Wow I cannot keep up. I feel burnt out so to say. I would like to help you, taylanpince since you seem like one who would be good at creating precise documentation and hopefully others with questions can read
that first.
Title: Re: ov7670 with both arduino uno and now mega
Post by: EvIl_DeViL on Dec 27, 2014, 03:50 pm
hi all! I have a similar problem of shaileshswankhede talked about in the previous page.
I'm using arduino uno v3 with 18 pin no sram ov7670 camera module. (even without spi external ram)
wired as described in the readme found with the code I'm using (https://github.com/ComputerNerd/ov7670-no-ram-arduino-uno)
to convert pin11 from 5v to 3.3v to wire it up in xclk, I used a voltage divider with the following configuration
pin11 -> 4.7Kohm -> xclk pin -> 10Kohm -> arduino gnd
nothing else (no divider on sioc/siod)
the code hangs in
twiStart -> while (!(TWCR & (1 << TWINT)));
twiWriteByte -> while (!(TWCR & (1 << TWINT)));
twiAddr -> while ((TWCR & _BV(TWINT)) == 0);
if I comment out those lines it gets in the following if condition (fail).
if I comment out all the wrReg function it gets strange random colours (so the module isn't completely dead)
I'm sure I'm missing something stupid :)
thank you!
Title: Re: ov7670 with both arduino uno and now mega

90 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Post by: Mr_arduino on Dec 28, 2014, 07:49 pm


I presume you solely went by the README file and did not notice on the first page that you needed pullup resistors on A5 and A4. I updated the README to fix this issue.
Title: Re: ov7670 with both arduino uno and now mega
Post by: EvIl_DeViL on Dec 29, 2014, 12:18 am
good! I put my wires in this order: A5 -> SIOC -> 10K -> arduino 3v3 (same for A4 pin) and now it passes the "wait for start" point in the three previous functions but I get half white pictures from the camera
(attached)
I tried 4k7 and 10k resistors but I get quite same result.
I'm using 57600 baud rate (UBRR0L = 34;), realterm for capturing and your convert.exe to convert the captured terminal output (removing "RDY" string).
I used this scheme to connect my pullups resistor (http://blog.codeblack.nl/image.axd?picture=2011%2F7%2FNetduino.I2C.png)
what seem strange to me is the "" sequence of chars (should be 0xff) and the fact that I get a file of 24.576 bytes while 640x480 = 307.200 :smiley-eek:
p.s. felt honored you fixed the readme for me :D (just kidding). Thank you for the help!
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Dec 29, 2014, 03:49 am
The baud rate you are using is too slow to keep up with the image rate I have the ov7670 set to output. If you want to use a slower baud rate you will need to mess with register 0x11 which is the clock divider
using a larger value will make data output at a slower rate. I have found best results using a baud rate of 1Mbaud. Also your schematic is correct and it is good that you got very similar results when using both
4.7k and 10k that is what is supposed to happen. SIOC and SIOD are connections only for I2C which is used only to "configure" the camera.
Title: Re: ov7670 with both arduino uno and now mega
Post by: EvIl_DeViL on Dec 29, 2014, 10:10 am
this is what i get at 1M baud (attachment 1). it looks like the image is "almost" complete and the black part is the "non-written" part.
could it be by the clock "slipping" due to the voltage divider I put up on the XCLK?
could it be because I need a voltage divider AND a pullup resistor on the XCLK?
the second attachment is what I get without connecting RESET and PWDN.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Dec 29, 2014, 11:21 pm
It looks like you are missing a few bytes every line. I am not sure what the cause it. I will note my code is very timing dependent. If you suspect that this is a signal integrity issue check the clock frequency with an
oscilloscope.
Title: Re: ov7670 with both arduino uno and now mega
Post by: EvIl_DeViL on Dec 30, 2014, 04:37 pm
ok I have good news!
1. I don't have an oscilloscope yet: I'm trying to understand my requirements about it. For example, I read that if I want to analyze a 16Mhz frequency like in this case I need almost three times faster ADC
sampler to have an error under 5%;
So a 50Mhz oscilloscope would be good but the cost is over 250 and I don't want to spend so much to discover after a couple of projects that it's not sufficent to suit my needs. I'm studying to make the right buy
:)
2. I thought during my previous tests I burned the sensor using the wire library so I switched to a new one and I got a plausible (distorted) image. I think the voltage divider is ok for low freq but at high freq the
signal has not enough time to overcome the parasite currents; I dealt with this recently when I used a voltage divider to plug the micro sd module to arduino UNO. full speed -> nada / half speed -> only partition
spec / quarter speed -> full compatibility. Nevertheless on the due it gets full speed because it's directly plugged (which is why my next thing to do is to port the module on the DUE and plug it directly). I don't
know if the sensor is burned but I'll check better one day.
3. Mr_arduino I saw you used 74AHC125 buffer to step down to 3v3. It seems a nice solution... what about voltage regulator to step down? shouldn't it be faster? is there any case which a 74AHC125 would not
fit to step up/down voltage levels?
4. on the left you can see a strange band: to me it looks like the signal is "slipping" because of the voltage divider (I think/hope that's the reason also for the other artifacts)
5. It seems like the sensor "suffer" of so called "eye adaptation": the first frames are white (highly exposed) and then it "adapts" the exposure. I made a short video of 100 frames palyed at 10fps in which you
could notice that. http://youtu.be/RFRfMFxNqgI (http://youtu.be/RFRfMFxNqgI)
6. I made a little windows utils that split the terminal recorded file into n.RAW files. if someone is interested let me know and I'll post it with source code.
next stop: DUE!
p.s. Mr_arduino I read you started to work on the ov5642 module! it looks cool! how's doing?
p.p.s. just for the record: you are seing my chair and my electronic drum rotated by 90 deg.s :D (random subject)
p.p.p.s. I changed the RDY to *RDY* because RDY collide causing wrong split (if based on characters) o.O (for everyone: in the captured data can happen "RDY" char sequence: it happened to me 115 times in
the same capture of 100 frames XD)
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Dec 30, 2014, 09:21 pm
I personally purchased a used oscilloscope from a university. It was cheap but that comes at the cost of one of the channels not working. I have yet to look at the issue however the other channel works very
good. You don't have to pay too much depending on what you buy.
I would be sorry for you burning out your sensor except I have a warning on the first page telling you to remove two lines of code that are part of the Wire library. However I made the same mistake when I first
got my ov7670 and my ov7670 still works even i2c. I do not think a voltage regulator would be faster. Voltage regulators are designed to output a stable voltage. The best way to find out would be to read the
datasheet and test it. Also yes the ov7670 does auto exposure which is nice to have. If you want you can make it faster if you don't like the default speed.
Title: Re: ov7670 with both arduino uno and now mega
Post by: EvIl_DeViL on Jan 01, 2015, 04:43 pm
Finally I got clean images at low speed ( wrReg(0x11, 63); ) so I decided to move the project to the DUE.

91 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

for the oscilloscope I think I'll go for the RIGOL DS1102E which seems to be a good oscilloscope to start with, also because suits also this case and I should be good at least until frequency at 33Mhz.
I'm going to open a thread soon asking for a couple of advices :)
Auto exposure it's ok for me but I feel to advise other users that the first few frames taken could be over-exposed! (thought might be the issue of the user vvavepacket)
If you did output 5v and didn't burn, shouldn't I also. I think might be the light or dust on the sensor when I take out the lens to see how the sensor looks like.
I doubt it's screwed. I'll check when I'll finish the port on the DUE, speaking of which:
I wired DUE like so for now
SCL -> SIOC (10Kohm to 3v3)
SDA -> SIOD (10Kohm to 3v3)
PIN7 -> XCLK
3v3 -> 3v3
GND -> GND
and nothing more, just to see if this little devil answer.
to generate the clock on the DUE I found many techniques which involves PWM.
I liked this (http://www.kerrywong.com/2014/09/21/on-arduino-due-pwm-frequency/) because it can achieve the highest possible PWM on the DUE which is a clean 84Mhz waveform,
but I didn't know if setting
Code: [Select]
uint32_t
uint32_t
uint32_t
uint32_t

pwmPin = 7;
maxDutyCount = 2;
clkAFreq = 20000000ul;
pwmFreq = 20000000ul;

was enough to get a 20 Mhz clock on pin 7 for the camera module.
So I tryied this other code which I found here http://forum.arduino.cc/index.php?topic=184799.0 (http://forum.arduino.cc/index.php?topic=184799.0) which I'm (quite) sure generate a 10.5Mhz clock;
the OV7670 say that wrReg is ok but when I try to read the registers it answer that the value is 0 (with three different methods).
I also tried the pwm01 library which is an "official" alpha library to generate a pwm on the DUE but it seems ok until 100000hz, then "Serial.print" screw up and begins to throw out random stuff.
BEWARE! only pin 6, 7, 8, 9 can be used for PWM on the DUE!
Code: [Select]
#include <Arduino.h>
#include <Wire.h>
#define camAddr_WR
#define camAddr_RD
#define REGISTERS

0x91

0x42
0x43
// Define # of Registesr on OV7076

byte wrReg(unsigned char regID, unsigned char regDat){


Wire.beginTransmission(camAddr_WR >> 1);
Wire.write(regID);
Wire.write(regDat);
if (Wire.endTransmission()){
return 0;
while (1);
}
delay(1);
return 1;
}
void readRegisterBank()
{
uint8_t count = 0x12;
int address = 0x12;
Wire.beginTransmission(camAddr_WR);
Wire.write(address);
Wire.endTransmission();
Wire.requestFrom(camAddr_RD, 1);
while (!Wire.available())
{
}
int c = Wire.read();
Serial.println(c);
//while (count<REGISTERS)
//{
byte highByte = 0;
Serial.print("\r\n Register num: ");
Serial.print(count, HEX);
Serial.print(" val: ");
Wire.beginTransmission(camAddr_WR);
Wire.write(count);
Wire.endTransmission();
Wire.requestFrom(camAddr_RD, 1);
while (Wire.available() < 1);
highByte = Wire.read();
Serial.print(highByte, HEX);
delay(25);
//count++;
//}

//Start communication with cmps03


//Send the register we wish to read
//Request high byte
//While there is a byte to receive
//Read the byte as an integer

Serial.print("\r\n Register num: ");


Serial.print(count, HEX);
Serial.print(" val: ");
Wire.beginTransmission(camAddr_WR);
Wire.write(count);
Wire.endTransmission();
Wire.requestFrom(camAddr_RD, 2);
byte LSB = Wire.read();
byte MSB = Wire.read();
uint16_t touched = ((MSB << 8) | LSB); //16bits that make up the touch states
Serial.print(touched);
Wire.beginTransmission((uint8_t)camAddr_WR);
Wire.write(count);
Wire.endTransmission(false);
Wire.requestFrom((uint8_t)camAddr_RD, (uint8_t)1, (uint8_t)true);
if (Wire.available() >= 1)
{
int result = Wire.read();
Serial.println(result, HEX);
}
}
void setup() {
int32_t mask_PWM_pin = digitalPinToBitMask(7);
REG_PMC_PCER1 = 1 << 4;
// activate clock for PWM controller
REG_PIOC_PDR |= mask_PWM_pin; // activate peripheral functions for pin (disables all PIO functionality)
REG_PIOC_ABSR |= mask_PWM_pin; // choose peripheral option B
REG_PWM_CLK = 0;
// choose clock rate, 0 -> full MCLK as reference 84MHz
REG_PWM_CMR6 = 0 << 9;
// select clock and polarity for PWM channel (pin7) -> (CPOL = 0)
REG_PWM_CPRD6 = 8;
// initialize PWM period -> T = value/84MHz (value: up to 16bit), value=8 -> 10.5MHz
REG_PWM_CDTY6 = 4;
// initialize duty cycle, REG_PWM_CPRD6 / value = duty cycle, for 8/4 = 50%
REG_PWM_ENA = 1 << 6;
// enable PWM on PWM channel (pin 7 = PWML6)
Serial.begin(115200);
Wire.begin();

92 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Serial.print("wrReg: "); Serial.println((wrReg(0x12, 0x80)));


delay(1000);
readRegisterBank();
}
void loop()
{
}

I know that the camera has already been ported on the DUE by user aturcitu but I didn't like he used
#define RCLK_SET
PIOC->PIO_SODR=1<<15
#define RCLK_CLR
PIOC->PIO_CODR=1<<15
because in the previous article I linked states that with this technique (slightly different) you can reach 16.8 Mhz. It looks like an hack to me. I want to use wire library (disabling internal pullups) and the SAM
PWM to generate the clock to unleash the full potential of the OV7670 and then try to move to the ov5642 with an 8M sram module (hoping DUE keep up)
when I get the camera working with DUE I'm willing to make a C# program to toggle the settings of the module runtime so you don't need to recompile each time and allow you to see the register settings change
in real-time.
Mr_Arduino thank you for your time and your patience which allow other user to grow their knowledge!
Title: Re: ov7670 with both arduino uno and now mega
Post by: taylanpince on Jan 03, 2015, 03:56 am
Quote from: Mr_arduino on Dec 23, 2014, 01:37 am
Wow I cannot keep up. I feel burnt out so to say. I would like to help you, taylanpince since you seem like one who would be good at creating precise documentation and hopefully others with questions can read that first.

Hi Mr_arduino, I am sorry to hear that you feel burnt out. Hope you feel better soon!
I made some progress over the holidays. I now have the OV7670 FIFO module working with a test Mac application, rendering the color bars. Unfortunately it doesn't look completely right.
Here is the latest image I have: http://cl.ly/image/283b1V3R2B3F (http://cl.ly/image/283b1V3R2B3F)
And here is my current implementation: https://gist.github.com/taylanpince/736a111a6eec1100d7c9 (https://gist.github.com/taylanpince/736a111a6eec1100d7c9)
I assume this is related to my current configuration settings. My current implementation is heavily influenced by Arndt Jenssen's version here: https://github.com/arndtjenssen/ov7670 (https://github.com
/arndtjenssen/ov7670)
Any help anyone can give me is much appreciated. Thanks and happy new year!
Title: Re: ov7670 with both arduino uno and now mega
Post by: EvIl_DeViL on Jan 03, 2015, 12:00 pm
@taylanpince: I know user drkblog in the first pages got the fifo module working with uno. you could find your answer there ;)
Title: Re: ov7670 with both arduino uno and now mega
Post by: taylanpince on Jan 03, 2015, 04:09 pm
Quote from: EvIl_DeViL on Jan 03, 2015, 12:00 pm
@taylanpince: I know user drkblog in the first pages got the fifo module working with uno. you could find your answer there ;)

Thanks! I am actually in contact with him and he has been super helpful. Unfortunately it seems like the FIFO module isn't the most useful one. I am going to try reading the data from FIFO to SRAM since I can't
get it out to Serial without dropping below 1mhz.
I'll report back if I am successful. :-)
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jan 03, 2015, 11:38 pm
Looking at your code there are many changes that need to made not all of which relate to if you get a correct image or not but there are many choices in your code that is making reading slower.
First of all make functions used only in the same source code file static. This allows for best constant propagation and allows the compiler to do more extensive optimizations based on usage of the function.
Second of all read_one_byte is not inline so there may be function call overhead.
The third and hugest mistake is all the conversions you are doing on the arduino that should be done on the PC. That is horrible for performance. Do not do yuv422->rgb888 on the arduino. There is no
advantage of doing so and it wastes many CPU cycles when they are needed. It also increases the amount of bytes you need to send which makes the transfer even slower. Your PC in contrast has plenty of
extra cpu time to do yuv422->rgb888. Also you should not use floating point math on the AVR and expect high performance. The compiler will generate software floating point code which is slower than if you had
an FPU to do such work which your computer does. Try fixed point math instead.
The reason you are getting a weird deformed image is due to the fact that you are not correctly doing yuv422 to rgb. To properly do yuv422 -> rgb you need to read four bytes which I shall call y1,u,v,y2 then you
do (this is in pseudo code)
Code: [Select]
pixel1=yuvToRgb(y1,u,v);
pixel2=yuvToRgb(y2,u,v);

So for every four bytes you get two pixels. It would be a good idea to rewrite your capturing code to just send the data without any conversions. Also I cannot tell but it looks like you convert the pixel to ASCII. Do
not do that it just waste CPU time. You will need to convert it back anyway so why not just send the byte and then read the byte on the PC.
Also I looked at your post http://forum.arduino.cc/index.php?topic=288933 and it reveals that you may have two different solutions mixed up together. When you are using the fifo there isn't really a need for any
external ram. The fifo already stores an image in it's own memory. So on the ov7670 camera module pcb do you see an IC that contains the words AL422? If so you do not need SPI ram. You can read the pixels
are whatever rate needed. Even then if you just want to send pixel data on the serial port and you do not have a fifo you can still just send the pixels as they arrive. The external ram is needed if you want to save
the image to an SD card and you do not have a FIFO. I hope this helps. If not post what happens when you make these changes I suggest.
Title: Re: ov7670 with both arduino uno and now mega
Post by: taylanpince on Jan 04, 2015, 12:16 am
Quote from: Mr_arduino on Jan 03, 2015, 11:38 pm
Looking at your code there are many changes that need to made not all of which relate to if you get a correct image or not but there are many choices in your code that is making reading slower.
First of all make functions used only in the same source code file static. This allows for best constant propagation and allows the compiler to do more extensive optimizations based on usage of the function.
Second of all read_one_byte is not inline so there may be function call overhead.
The third and hugest mistake is all the conversions you are doing on the arduino that should be done on the PC. That is horrible for performance. Do not do yuv422->rgb888 on the arduino. There is no advantage of doing so and it wastes many CPU cycles when they are
needed. It also increases the amount of bytes you need to send which makes the transfer even slower. Your PC in contrast has plenty of extra cpu time to do yuv422->rgb888. Also you should not use floating point math on the AVR and expect high performance. The
compiler will generate software floating point code which is slower than if you had an FPU to do such work which your computer does. Try fixed point math instead.
The reason you are getting a weird deformed image is due to the fact that you are not correctly doing yuv422 to rgb. To properly do yuv422 -> rgb you need to read four bytes which I shall call y1,u,v,y2 then you do (this is in pseudo code)
Code: [Select]
pixel1=yuvToRgb(y1,u,v);
pixel2=yuvToRgb(y2,u,v);

93 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

So for every four bytes you get two pixels. It would be a good idea to rewrite your capturing code to just send the data without any conversions. Also I cannot tell but it looks like you convert the pixel to ASCII. Do not do that it just waste CPU time. You will need to convert it
back anyway so why not just send the byte and then read the byte on the PC.
Also I looked at your post http://forum.arduino.cc/index.php?topic=288933 and it reveals that you may have two different solutions mixed up together. When you are using the fifo there isn't really a need for any external ram. The fifo already stores an image in it's own
memory. So on the ov7670 camera module pcb do you see an IC that contains the words AL422? If so you do not need SPI ram. You can read the pixels are whatever rate needed. Even then if you just want to send pixel data on the serial port and you do not have a fifo
you can still just send the pixels as they arrive. The external ram is needed if you want to save the image to an SD card and you do not have a FIFO. I hope this helps. If not post what happens when you make these changes I suggest.

Mr_arduino, thank you for your detailed response. I spoke about this at length with drkblog, who had experimented with the FIFO version earlier. He specifically mentioned that I can never get the data fast
enough out of FIFO to the serial. I tried everything, including transferring bytes directly and I used your direct to serial code for this. I also integrated your raw image converter into a Mac app so it's all done on the
Mac side where it makes more sense. Unfortunately, none of it works with the module I have.
I'm aware that this version of the code is not even close to being optimized. However, it's also the first version that rendered color bars on my Mac app. That said drkblog thinks that this is misleading, it's still
sending corrupt data.
After 2 weeks of trying to make this work with the OV7670 FIFO module with Arduino UNO, I'm giving up. I got a MEGA today and I will be pushing the data from FIFO to SRAM and reading from there. I couldn't
do this on UNO since I am 1 pin short.
Between my own experiments and drkblog' comments, I'm convinced that the FIFO module is inferior to non-FIFO. I just couldn't find a way to read from AL422B fast enough out to serial.
I'll report here again when I hooefully make this work with MEGA.
Title: Re: ov7670 with both arduino uno and now mega
Post by: taylanpince on Jan 05, 2015, 02:14 am
Quote from: Mr_arduino on Jan 03, 2015, 11:38 pm
Looking at your code there are many changes that need to made not all of which relate to if you get a correct image or not but there are many choices in your code that is making reading slower.
First of all make functions used only in the same source code file static. This allows for best constant propagation and allows the compiler to do more extensive optimizations based on usage of the function.
Second of all read_one_byte is not inline so there may be function call overhead.
The third and hugest mistake is all the conversions you are doing on the arduino that should be done on the PC. That is horrible for performance. Do not do yuv422->rgb888 on the arduino. There is no advantage of doing so and it wastes many CPU cycles when they are
needed. It also increases the amount of bytes you need to send which makes the transfer even slower. Your PC in contrast has plenty of extra cpu time to do yuv422->rgb888. Also you should not use floating point math on the AVR and expect high performance. The
compiler will generate software floating point code which is slower than if you had an FPU to do such work which your computer does. Try fixed point math instead.
The reason you are getting a weird deformed image is due to the fact that you are not correctly doing yuv422 to rgb. To properly do yuv422 -> rgb you need to read four bytes which I shall call y1,u,v,y2 then you do (this is in pseudo code)
Code: [Select]
pixel1=yuvToRgb(y1,u,v);
pixel2=yuvToRgb(y2,u,v);

So for every four bytes you get two pixels. It would be a good idea to rewrite your capturing code to just send the data without any conversions. Also I cannot tell but it looks like you convert the pixel to ASCII. Do not do that it just waste CPU time. You will need to convert it
back anyway so why not just send the byte and then read the byte on the PC.
Also I looked at your post http://forum.arduino.cc/index.php?topic=288933 and it reveals that you may have two different solutions mixed up together. When you are using the fifo there isn't really a need for any external ram. The fifo already stores an image in it's own
memory. So on the ov7670 camera module pcb do you see an IC that contains the words AL422? If so you do not need SPI ram. You can read the pixels are whatever rate needed. Even then if you just want to send pixel data on the serial port and you do not have a fifo
you can still just send the pixels as they arrive. The external ram is needed if you want to save the image to an SD card and you do not have a FIFO. I hope this helps. If not post what happens when you make these changes I suggest.

Hello again, I finally have some progress to report!


I got the MEGA yesterday and hooked everything up this morning. I finally have an image, at least I can see the correct pattern of the Arduino box in front of the camera:
http://cl.ly/image/0u2U2M3U3I45 (http://cl.ly/image/0u2U2M3U3I45)
It's a bit easier to see with YUV mode: http://cl.ly/image/1e2439431f0W (http://cl.ly/image/1e2439431f0W)
This is how the color bars look: http://cl.ly/image/2q1Y1e1Z2d2p (http://cl.ly/image/2q1Y1e1Z2d2p)
This is using Mr_arduino's raw data converter so it should be working properly on the Mac side. But I tried using both Mr_arduino's camera settings as well as others, it always seems to have the greenish hue or
just weird colors.
And here is my current implementation: https://gist.github.com/taylanpince/d1b1a5b03dd9cb1c58a8 (https://gist.github.com/taylanpince/d1b1a5b03dd9cb1c58a8)
I am going to keep playing with settings to see if I can get a better version. Any tips are appreciated!
Title: Re: ov7670 with both arduino uno and now mega
Post by: scano on Jan 05, 2015, 05:28 pm
hi,i have ov7670 camera module with fifo.The camera has 22 pins.
this is camera's pin schema:
(http://i.hizliresim.com/g4qkdO.png) (http://hizliresim.com/g4qkdO)
And i have Arduino Mega.I want to use my camera with mega on Arduino IDE.
But i dont have any information.
Do you know connection schema and arduino code ?
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jan 05, 2015, 11:11 pm
taylanpince you are getting valid data The reason for the green color is either because my converter is using a different byte order or you are missing one byte. Try my converter using the parameter -o 1 that
should fix the colors.
scano No I have not made a schematic but I do have the fifo version but I have not tried anything with that I plan to at some point however. Just been a bit busy lately.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Jannex on Jan 06, 2015, 11:32 am
Hi,
I am new to programming.. Especially for camera module...
I plan to use the SCCB in ov7670 to interact with I2C, but there is a few problems that i want to ask..
1. Do i still need to connect a clock to XCLK even i already connected the I2C SCL pin to SIOC pin?
2. Can i get the image data from SIOD pin by using SCCB and I2C?
3. How does ov7670 data collection work? Because i don't see any variable to read the data from when i read the datasheet. Or it starts automatically?
Sorry i am really new to this.
Thank you.
P/S : I am using ov7670 without FIFO

94 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

Title: Re: ov7670 with both arduino uno and now mega
Post by: taylanpince on Jan 06, 2015, 11:07 pm
Quote from: Mr_arduino on Jan 05, 2015, 11:11 pm
taylanpince you are getting valid data The reason for the green color is either because my converter is using a different byte order or you are missing one byte. Try my converter using the parameter -o 1 that should fix the colors.

Thank you Mr_arduino, that worked! Here is the image rendered with -o1: http://cl.ly/image/0k021a3G3B3J (http://cl.ly/image/0k021a3G3B3J)
That's my jeans on the left and a lemon on the right. Still a bit faded, but I can play with config options and improve that I think.
Thanks again!
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jan 07, 2015, 12:46 am
That looks like natural light. The ov7670 is sensitive to IR light this could be affecting the color. You could try putting an IR cut filter on the lens if needed. There is also register 0xC9 which lets you set saturation
it may be set to automatic. You can disable automatic saturation by clearing bit 6 in register 0x3D. Try seeing if the colors are still washed out using artificial light. The ov7670 does surprising well indoor auto
white balance in fact maybe there is some undocumented configuration that makes the settings tuned to artificial indoor lighting. I really would like a more detailed datasheet. Omnivision lies about the meaning of
some "Reserved" registers. They are not reserved what that really means is undocumented. Those "Reserved" registers do have a function. I have made requests like this before but if anyone is sitting on more
ov7670 documents I would like them. All I have is "Advanced Information Preliminary Datasheet" Version 1.4 and "OV7670 Implementation Guide" Version 1.0. Also newer versions are welcome especially the
implementation guide Version 1.0 has mistakes.
Title: Re: ov7670 with both arduino uno and now mega
Post by: weibogege on Jan 07, 2015, 05:21 am
Mr arduino,
Can I use this codes for my arduino due. ;D ;D :D
Title: Re: ov7670 with both arduino uno and now mega
Post by: EvIl_DeViL on Jan 07, 2015, 06:16 pm
Quote from: Jannex on Jan 06, 2015, 11:32 am
Hi,
I am new to programming.. Especially for camera module...
I plan to use the SCCB in ov7670 to interact with I2C, but there is a few problems that i want to ask..
1. Do i still need to connect a clock to XCLK even i already connected the I2C SCL pin to SIOC pin?
2. Can i get the image data from SIOD pin by using SCCB and I2C?
3. How does ov7670 data collection work? Because i don't see any variable to read the data from when i read the datasheet. Or it starts automatically?
Sorry i am really new to this.
Thank you.
P/S : I am using ov7670 without FIFO

1. yes. otherwise you'll get no answer from the module


2. no you need all the Dn pin 'cause the output is parallel
3. it outputs data through the Dn parallels pins
refer to this for further reference (wiring + code) https://github.com/ComputerNerd/ov7670-no-ram-arduino-uno (https://github.com/ComputerNerd/ov7670-no-ram-arduino-uno)
you need to get lower voltage on the XCLK pin. I used a voltage divider 4.7-10k (slower), Mr_arduino used a driver, cleaner solution would be a LLC (logic level converter).
you also need a 4.7K o 10K resistor as pullup for the I2C pins.
Quote from: weibogege on Jan 07, 2015, 05:21 am
Mr arduino,
Can I use this codes for my arduino due. ;D ;D :D

no it's AVR based. User aturcitu did it but manually changed the clock pin status. I whish to implement a steady/automatic/reliable clock solution based on PWM when my DSO will arrive (matter of days I hope).
Don't count too much on it anyway XD
Title: Re: ov7670 with both arduino uno and now mega
Post by: vovabraga on Jan 09, 2015, 07:01 pm
What LLC are You used? Do you know simple for 11-> (convert 5v to 3.3v) XCLK ?
voltage regulator (slower) ? what is this?
Title: Re: ov7670 with both arduino uno and now mega
Post by: honeybadger8 on Jan 10, 2015, 07:32 am
Arduino mega 2560 has two resistors on the i2c pin 20, 21 pulled to 5v. So it's impossible to disable it from software. How does everyone solve this problem?
Title: Re: ov7670 with both arduino uno and now mega
Post by: EvIl_DeViL on Jan 10, 2015, 11:01 am
Quote from: vovabraga on Jan 09, 2015, 07:01 pm
What LLC are You used? Do you know simple for 11-> (convert 5v to 3.3v) XCLK ?
voltage regulator (slower) ? what is this?

I meant voltage divider. I fixed my previous post!


Title: Re: ov7670 with both arduino uno and now mega
Post by: vovabraga on Jan 10, 2015, 03:01 pm
Quote from: EvIl_DeViL on Jan 10, 2015, 11:01 am
I meant voltage divider. I fixed my previous post!

So I can use voltage divider for SIOC,SIOD and XCLK& Am I right ?


Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jan 10, 2015, 03:29 pm
honeybadger8 you are blatantly. Please really ought to read this topic more closely, instructions on how to disable the internal pull up resistors if you are using the Wire library are on the first page.

95 of 96

01/19/2015 08:49 PM

Print Page - ov7670 with both arduino uno and n...

http://forum.arduino.cc/index.php?action=printpa...

vovabraga you do not need a voltage divider for SIOC and SIOD just XCLK. For SIOC and SIOD you use a pullup resistor connected to 3.3v.
Title: Re: ov7670 with both arduino uno and now mega
Post by: vovabraga on Jan 10, 2015, 03:50 pm
Quote from: Mr_arduino on Jan 10, 2015, 03:29 pm
honeybadger8 you are blatantly. Please really ought to read this topic more closely, instructions on how to disable the internal pull up resistors if you are using the Wire library are on the first page.
vovabraga you do not need a voltage divider for SIOC and SIOD just XCLK. For SIOC and SIOD you use a pullup resistor connected to 3.3v.

What voltage divider for XCLK you used or recomend? (scheme if You can, please)!?
Title: Re: ov7670 with both arduino uno and now mega
Post by: honeybadger8 on Jan 10, 2015, 06:09 pm
FYI, Mr_arduino, I read the instruction. I also read information from http://www.varesano.net/blog/fabio/how-disable-internal-arduino-atmega-pullups-sda-and-scl-i2c-bus#comment-22396 which says comment
those 2 lines code from twi.c won't work for 2560. Am I wrong.
Title: Re: ov7670 with both arduino uno and now mega
Post by: vovabraga on Jan 10, 2015, 09:14 pm
Made assembly as on photo, everything seems to be ok ??? !!!, I2C must work, launched an ordinary scanner I2C devices to detect the camera, but nothing found. Tried to make a request for 0x21, answer from
WireEndTransmission - 2 - no such device. Use the library Wire. What's wrong?
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on Jan 11, 2015, 02:49 am
honeybadger8 It will work. Those pullup resistors appear to for something else. You can remove the line and it will work. I have had the ov7670 running for quite a while attached to an arduino mega 2560 r3
myself.
vovabraga the reason it does not work is most likely due to the fact that you don't have enough wired up yet, you need to connect XCLK for i2c to work.
Title: Re: ov7670 with both arduino uno and now mega
Post by: vovabraga on Jan 11, 2015, 10:28 am
Quote from: Mr_arduino on Jan 11, 2015, 02:49 am
vovabraga the reason it does not work is most likely due to the fact that you don't have enough wired up yet, you need to connect XCLK for i2c to work.

Is it ok?
D11 instead of D6 :)

Title: Re: ov7670 with both arduino uno and now mega
Post by: EvIl_DeViL on Jan 11, 2015, 09:42 pm
Quote from: vovabraga on Jan 10, 2015, 03:50 pm
What voltage divider for XCLK you used or recomend? (scheme if You can, please)!?

I advise you to carefully read and understand this https://learn.sparkfun.com/tutorials/voltage-dividers (https://learn.sparkfun.com/tutorials/voltage-dividers)


Secondly I can say I used a 4.7k and a 10k resistor and it's working with register 0x11 at 63 (veeery slow) if you want to speed the things up use a buffer like Mr_arduino did!
In your scheme I don't see the 4.7k resistor to make the voltage divider.
Title: Re: ov7670 with both arduino uno and now mega
Post by: mja2000 on Jan 15, 2015, 03:13 am
Hey guys,
I'm working on a school project where we need to connect the OVR 7670 + FIFO to an Arduino Uno to hopefully operate at around 30fps at whatever resolution works.
I'm new to all this, and would like some of your guy's advise. I tried some sample code earlier from the website at the bottom but I was unable to get it to work.
If I can get some help that would be great, as at the moment I'm stuck.

Thanks

link: http://nicolasfley.fast-page.org/?page_id=35#comment-104048
SMF 2.1 Beta 1 2014, Simple Machines

96 of 96

01/19/2015 08:49 PM

You might also like