Professional Documents
Culture Documents
Print Page Ov7670 With Both Arduino Uno and Now Mega
Print Page Ov7670 With Both Arduino Uno and Now Mega
Print Page - ov7670 with both arduino uno and now mega
Arduino Forum
Using Arduino => Sensors => Topic started by: Mr_arduino on April 09, 2013, 10:50:06 pm
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.
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
1/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
sensor. The sd card and spi ram is just standard spi wiring nothing special.
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
2/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
3/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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;
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;
}
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
4/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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 April 23, 2013, 01:01:18 pm
Mr_arduino: I didn't have much time lately, but now I'm going to try it. I have some questions about connection:
1. You mentioned that it's necessary to get the 5V signal down to 3.3V. Is it possible to do this without level shifter/buffer or do I have to get this stuff?
2. Are connections the same (as in one of your posts) even in my case (without RAM, etc)?
Thanks for your effort to help. I really appreciate it :)
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: Mr_arduino on April 26, 2013, 04:32:11 pm
The connections will be mostly the same but it could be abit different as I do not own the one with the fifo I am not sure but I think instead of PCLK you 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 April 27, 2013, 10:28:20 am
A recent discovery that I made is you can get an F_CPU/2 (8mhz in the arduino's case) clock output with pwm this removes the need to edit fuse bits. Note 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.
C ode :
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 April 27, 2013, 08:24:40 pm
There's a good page on generating clock signals at http://hekilledmywire.wordpress.com/2011/05/28/introduction-to-timers-tutorial-part-6/#more-57
I too have the question about level shifting; what sort of buffers are needed, would a 74HC245 do?
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: Mr_arduino on April 28, 2013, 02:18:29 pm
I think the 74HC245 would work just fine also a unidirectional one would work too. Pretty much any buffer that is fast enough to handle a 16mhz signal and can
accept 3.3v as a supply voltage which the 74HC245 can. You do not need to shift the d7-d0 as those are always output from the sensor and never input. 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 April 29, 2013, 03:42:43 am
Thanks, that's very helpful. I'd thought that the D0..D7 signals would need shifting and so lots of converters would be needed, but that's simplified things a lot.
Still waiting for my camera to turn up.
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: Saren on April 30, 2013, 02:54:07 pm
Q uote from : Mr_arduino on April 26, 2013, 04:32:11 pm
The conne ctions will be m ostly the sam e but it could be abit diffe re nt as I do not own the one with the fifo I am not sure but I think inste ad of PC LK you use R C LK and and R C LK is output you
strobe that to ge t data. C he ck you this for m ore info about the fifo ve rsion http://wik i.be yondlogic.org/inde x .php/O V7670_C am e ra_Module _with_AL422_FIFO _The ory_of_O pe ration Also you
could try a re sistor divide r but I have he ard that the y are too slow you m ay ne e d a buffe r/le ve l-shiftie r. Also this would not re quire the ram as you have the 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, 08:30:16 am
Hi, i have the ov7670 camera, an arduino uno rev 3 and ST M27C512-12F1 Eprom. Is it possible to take pictures with these components? and if so, how do 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.
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
5/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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, 12:24:25 pm
It said in the post it does not matter if they are bidirectional or not. Also you do not need a buffer for i2c if you disable the internal pull-up and make sure 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, 09:44:20 am
Mr_Arduino, thank you for your response.
I managed to connect SIO_C and SIO_D, I also changed atmega fuses to get the CLKOUT at pin 8. Yet, I don't have extra RAM chip and right now the only 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)?
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
6/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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 June 16, 2013, 11:47:37 am
Ok, I have been working and I see some advances now. Yet I'm not done.
I've incremented the prescaler and I realized there is a point (as I incremente PCLK frequency) where I start missing bytes. So I'm using the slower PCLK 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
C ode :
$ ./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 June 17, 2013, 10:51:24 am
Good job the only thing is that you have the sensor configured for raw bayer data. I attached the image I got.
Here is the source code to the program that converts the image it does both yuv422 and raw bayer data and saves it to a png file.
https://github.com/ComputerNerd/RawCamera-data-converter/blob/master/main.c
To compile it simply type
C ode :
gcc -Wall -Wextra -lm -lpng -o yuv main.c
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?
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
7/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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!
with
C ode :
const struct regval_list ov7670_default_regs[] PROGMEM = {
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
8/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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
C ode :
static struct regval_list ov7670_fmt_yuv422[] = {
to
C ode :
{ 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 June 19, 2013, 07:31:33 pm
I copied the configuration from the driver, pretty much in the way you suggested me. But I see voltage levels in the signaling change. And that messes up 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-entre-5v-y-3-3v
I guess I could make it work spending some time in it. But I have to go on with other parts of this project. I'm going to work in other stuff as I wait for the 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.
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 June 19, 2013, 10:21:17 pm
Great!
The default configuration was changing register 0x6B (DBLV) which has control over the PLL afecting the PCLK output. Which was causing all the problem 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 June 19, 2013, 10:33:58 pm
Update. I was missing a fix, in the reading logic... yet it isn't done...
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: drkblog on June 19, 2013, 10:45:29 pm
Sorry for the repeated posting. But there are great news... it's working now.
I'm getting just 640x200 portion of the frame for the sake of speed in the tests :)
THANK YOU!
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: Mr_arduino on June 19, 2013, 10:47:37 pm
Wow I am glad to see that it is working it makes me happy too. The colors look nice.
Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome
Post by: drkblog on June 19, 2013, 10:53:58 pm
I'm sure that could be improved. I didn't setup filter for 50Hz, and the camera is pointing a little towards the light. But what I really wanted was to be able to
configure the sensor. So it's great. Thank you again!
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
9/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
{ 0x7b, 0x10 },
{ 0x7d, 0x35 },
{ 0x7f, 0x69 },
{ 0x81, 0x80 },
{ 0x83, 0x8f },
{ 0x85, 0xa3 },
{ 0x87, 0xc4 },
{ 0x89, 0xe8 },
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
10/60
3/15/2014
{ 0xb3, 0x82 },
{ 0xb8, 0x0a },
Print Page - ov7670 with both arduino uno and now mega
{ REG_COM11, COM11_EXP|COM11_HZAUTO|COM11_50HZ },
{ 0x96, 0 },
{ 0x98, 0x20 },
{ 0x9a, 0x84 },
{ 0x9c, 0x03 },
{ 0x9e, 0x3f },
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
11/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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.
C ode :
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
}
}
}
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
12/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
13/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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 July 11, 2013, 09:35:20 am
Hello xKoldFuzionx, welcome to the electronics world. :)
Your questions is a little too broad to cover it up in one reply, so I guess I'm going to start with some basic stuff:
To really understand what's going on here, you will have to give it a lot of time. And you will have to start from the beginning. This module is really hard to 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 July 11, 2013, 10:22:56 am
Sorry for such a broad question. But, greatly appreciate the input.
I understand ohm's law, the fTransistors e books I started to read drilled it into me, though I don't entirely understand it's use. Let me clarify. I understand 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 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 July 11, 2013, 01:40:06 pm
In the first place you have to accept that learning electronics isn't easy. Specially if you want to really know what is going on there. A degree in 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/150px-Transistor_as_switch.svg.png)
When you make a small current flow through the base, the collector-emitter juncture behaves like a cable (conducting). When the base current disappears, 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
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
14/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
[/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 July 11, 2013, 05:11:32 pm
First note that a transistor is not a logical gate, and you can't replace one by another because they have different functionality. Of course, you can build 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 July 11, 2013, 05:41:39 pm
Ok, that makes complete sense. All the example sketches I've worked through so far have just been really basic as far as components. So, say motor A has 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.
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 July 11, 2013, 06:46:12 pm
You will have to do something like this:
(http://embedded-lab.com/blog/wp-content/uploads/2010/12/Circuit_SingleTransistorDCMotor.png)
The base resistor limits the base current when there is 5V on it. The base current will be (Vcc - Vbe) / R, in this case (5V - 0.7V) / 1k = 4.3mA which is 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 July 15, 2013, 10:07:27 pm
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
15/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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.
C ode :
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 July 15, 2013, 10:22:28 pm
In the first place you have to be sure your cam is working. If you have a problem with the clock you are feeding, you will waste a lot of time. In my case, I 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 July 15, 2013, 11:15:08 pm
Thanks for the response.
I do think the camera is working. I'm able to read and write to registers, and from my oscilloscope it seems like VSYNC is going high at a reasonable rate. I'm 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 July 16, 2013, 08:51:29 am
Ok, if the module is working, and you are able to read/write registers you are almost done. The next hard-to-do thing is, configuring all the 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.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on July 16, 2013, 11:48:30 am
About the 10mhz limit. I don't think that is true I have left the ov7670 on with an 8mhz clock for hours and nothing bad has happened. Also I have looked 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
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
16/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
Title: Re: ov7670 with both arduino uno and now mega
Post by: sampullman on July 16, 2013, 02:20:25 pm
@drkblog
Ok, I'm going to spend some time making sure my register setup is correct. I saw a few tutorials that didn't seem to bother with the defaults (such as 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).
C ode :
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 July 16, 2013, 04:04:59 pm
^^^ I made my own twi functions because I am not using the arduion ide. I don't like the arduion ide. Note that I am not forcing you to avoid using the 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 July 17, 2013, 12:09:06 pm
Hello Mr_arduino, drkblog, and sampullman!
I am working on a project for one of my university proffesors and I am ran into a problem with the OV7670 camera. I have been trying to read some registers 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.
C ode :
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:
C ode :
#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;
}
/* 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);
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
17/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
Wire.endTransmission();
Wire.requestFrom((sensor_addr >> 1),1);
if(Wire.available()) {
*regDat = Wire.read();
delay(1);
return 1;
} else {
return 0;
}
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 July 18, 2013, 09:40:08 am
@Mr_Arduino, Terrific effort by you on this code, as well as answering people's questions! I see you are also adding support for the MT9D111. I'm definitely 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
Q uote from : Mr_arduino on July 17, 2013, 12:49:30 pm
Actully m y late st code doe s not use the wire library se e https://github.com /C om pute rNe rd/arduino-cam e ra-tft/blob/m aste r/twicam .c or if you fe e l the ne e d to use the W ire library m y ve ry old
code use s it se e http://paste bin.com /1nnR c5qL
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on July 18, 2013, 04:06:00 pm
^^^ About creating an *.ino file Everyone has different needs I like to keep my files organized so that if someone has trouble with something for 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 July 18, 2013, 05:23:34 pm
@technonewb
I'm not sure if you posted all of your code, but you need to add something like this after the Wire.begin() call in order to set up TWI communication so that it
works with the OV7670:
C ode :
TWSR &= ~3; // Disable TWI prescaler
TWBR = 72; // CLOCK / (16 + 2*TWBR*Prescaler)
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
18/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on July 24, 2013, 06:23:54 pm
I am sorry for the double post but I would like add that if you have a question about the ov7670 please don't PM me post it in this topic instead that way
everyone will benefit.
Title: Re: ov7670 with both arduino uno and now mega
Post by: vichaz on August 09, 2013, 03:14:43 pm
Hi guys!
I'm new in Arduino and electronics but with 10 years of PHP programing experience. Not long ago I bought Arduino UNO with different modules and started to 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 August 10, 2013, 03:05:55 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 August 27, 2013, 10:02:00 am
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 September 01, 2013, 07:59:17 pm
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 September 14, 2013, 09:37:03 am
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 September 24, 2013, 10:14:26 am
Q uote from : Mr_arduino on April 11, 2013, 07:30:22 pm
The conne ctions are sim ple . Start by plugging in SIO _C to A5 and SIO _D to A4 since this is i2c/twi you m ust have a 4k 7 re sistor 10k also work s. Mak e sure you have the re sistor to pull up 3.3v
not 5v. Also e dit twi.c in the arduino ide folde r/librarie s/W ire /utility se arch for the se line s and com m e nt the m out or re m ove the m
C ode :
// activate internal pullups for twi.
digitalWrite(SDA, 1);
digitalWrite(SCL, 1);
This is to re m ove the inte rne l pullup re sistor by not re m oving the se 2 line s you could cause dam age to the se nsor. The n 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 PC LK to pin 2. Now change the fuse bits to be e x acly the sam e e x ce pt e nable the C LKO UT pin. This will output a clock run this through a
buffe r or le ve l shifte r to 3.3v if you do not ge t the 5v signal down to 3.3v it could dam age the se nsor. The sd card and spi ram is just standard spi wiring nothing spe cial.
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
19/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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.
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 September 24, 2013, 12:31:03 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 September 30, 2013, 09:06:43 pm
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 September 30, 2013, 10:53:34 pm
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.
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
20/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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 October 01, 2013, 08:50:44 am
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.
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 October 01, 2013, 10:35:37 am
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 October 01, 2013, 11:07:36 am
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 October 01, 2013, 11:34:51 am
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 October 01, 2013, 12:00:59 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 October 01, 2013, 12:35:32 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 October 01, 2013, 12:45:53 pm
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
21/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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 October 02, 2013, 08:39:42 pm
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.
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 October 04, 2013, 07:48:06 pm
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 October 04, 2013, 08:37:20 pm
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 October 04, 2013, 10:05:29 pm
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 October 05, 2013, 08:36:56 am
Q uote from : Mr_arduino on O ctobe r 04, 2013, 10:05:29 pm
Drk blog, ye s I agre e not having /R E is a de sign flaw. Having /R E is a ne e de d function /R E doe s e x actly what you ne e d it to do k e e p the data "alive " in the fifo while saving to the sd card and
the n continue we re you le ft off without re starting. R e garding your attachm e nt I think you m ay be sim ply m issing byte s.
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 October 06, 2013, 11:39:58 am
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.
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
22/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on October 06, 2013, 04:02:48 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 October 06, 2013, 10:09:20 pm
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 October 06, 2013, 10:16:39 pm
Q uote from : x KoldFuzionx on O ctobe r 06, 2013, 10:09:20 pm
That's a re ally cle ar look ing picture . I poste d e arlie r be fore I re ally unde rstood a whole lot and have be e n work ing through the Arduino C ook book since . I finally fe e l lik e Ihave a pre tty good
grasp of what iI ne e d to do to ge t m y proje ct up and running. I'm hoping to start work ing through the code soon, but I still ne e d to ge t m y hands on som e ram . Eithe r way, I m ight as we ll try
to figure out the code and se e what I can com e up with.
I hope you guys will continue to k e e p posting as I've le arne d a lot just from re ading 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 October 06, 2013, 10:34:49 pm
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 October 07, 2013, 02:22:30 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 ;)
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
23/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on October 07, 2013, 07:48:02 am
Q uote from : re lic1974 on O ctobe r 07, 2013, 02:22:30 am
He y guys, he re 's som e 3m bit x 8 FIFO m e m ory for ya from the US for a fair price . This FIFO has be e n sugge ste d on se ve ral forum s.
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 October 07, 2013, 10:57:53 am
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
Post by: drkblog on October 07, 2013, 12:07:20 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 October 09, 2013, 01:00:14 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 October 09, 2013, 02:06:27 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 October 10, 2013, 08:00:22 pm
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 October 10, 2013, 09:22:40 pm
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 October 11, 2013, 08:30:54 am
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 October 11, 2013, 08:59:07 pm
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 October 11, 2013, 09:01:00 pm
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 October 11, 2013, 09:57:56 pm
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?
C ode :
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
24/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
C ode :
{0x30,0},{0x31,0},//disable some delays
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on October 16, 2013, 07:01:17 pm
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 October 17, 2013, 06:01:33 pm
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.
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
25/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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 October 26, 2013, 11:46:19 am
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 October 26, 2013, 12:18:08 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 October 26, 2013, 12:52:06 pm
Hi drkblog,
You are not Mr_arduino, so I won't listen to you :P
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 October 26, 2013, 01:07:13 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 October 26, 2013, 09:11:13 pm
Q uote from : Tyranus on O ctobe r 26, 2013, 12:52:06 pm
Hi drk blog,
You are not Mr_arduino, so I won't liste n 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 October 26, 2013, 09:20:40 pm
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 October 27, 2013, 11:30:21 pm
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
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
26/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on October 28, 2013, 10:57:37 am
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 October 28, 2013, 05:32:29 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 November 07, 2013, 06:18:39 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 November 07, 2013, 09:24:41 pm
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 November 10, 2013, 12:19:17 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 November 21, 2013, 07:31:14 am
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);
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
27/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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 November 21, 2013, 07:41:38 am
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 November 21, 2013, 07:44:00 am
OV7670 with FIFO
Title: Re: ov7670 with both arduino uno and now mega
Post by: Animat on November 21, 2013, 07:46:38 am
All the same, but the Color Bar
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on November 21, 2013, 07:56:55 am
Try enabling color-bar pattern:
COM17 - bit3 ON
SCALING_XSC and SCALING_YSC default values
Then capture a frame and post it here.
Title: Re: ov7670 with both arduino uno and now mega
Post by: Animat on November 21, 2013, 08:06:07 am
Captured frame
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on November 21, 2013, 08:11:20 am
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.
C ode :
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, 0x20 },
{ 0x7c, 0x1e },
{ 0x7e, 0x5a },
{ 0x80, 0x76 },
{ 0x82, 0x88 },
{ 0x84, 0x96 },
{ 0x7b, 0x10 },
{ 0x7d, 0x35 },
{ 0x7f, 0x69 },
{ 0x81, 0x80 },
{ 0x83, 0x8f },
{ 0x85, 0xa3 },
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
28/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
{ 0x84, 0x96 },
{ 0x86, 0xaf },
{ 0x88, 0xd7 },
{ 0x85, 0xa3 },
{ 0x87, 0xc4 },
{ 0x89, 0xe8 },
{ REG_COM11, COM11_EXP|COM11_HZAUTO|COM11_50HZ },
{ 0x96, 0 },
{ 0x98, 0x20 },
{ 0x9a, 0x84 },
{ 0x9c, 0x03 },
{ 0x9e, 0x3f },
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on November 22, 2013, 03:44:33 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
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
29/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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 November 25, 2013, 06:13:30 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.
C ode :
#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();
// Prepare Camera
// Read the camera's Bank Register
//VGA.begin(320,240,VGA_COLOUR);
}
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();
}
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
30/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
{ 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,
0x7c,
0x7e,
0x80,
0x82,
0x84,
0x86,
0x88,
0x20 },
0x1e },
0x5a },
0x76 },
0x88 },
0x96 },
0xaf },
0xd7 },
{ 0x7b, 0x10 },
{ 0x7d, 0x35 },
{ 0x7f, 0x69 },
{ 0x81, 0x80 },
{ 0x83, 0x8f },
{ 0x85, 0xa3 },
{ 0x87, 0xc4 },
{ 0x89, 0xe8 },
0x8f, 0 },
{ 0x90, 0 },
0x91, 0 },
{ 0x96, 0 },
0x9a, 0 },
{ 0xb0, 0x84 },
0xb1, 0x0c },
{ 0xb2, 0x0e },
0xb3, 0x82 },
{ 0xb8, 0x0a },
{ 0x34, 0x11 },
{ 0xa4, 0x88 },
{ REG_COM11, COM11_EXP|COM11_HZAUTO|COM11_50HZ },
{ 0x96, 0 },
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
31/60
3/15/2014
{
{
{
{
{
Print Page - ov7670 with both arduino uno and now mega
0x97,
0x99,
0x9b,
0x9d,
0x78,
0x30
0x30
0x29
0x4c
0x04
},
},
},
},
},
{
{
{
{
0x98,
0x9a,
0x9c,
0x9e,
0x20 },
0x84 },
0x03 },
0x3f },
0x7a,
0x7c,
0x7e,
0x80,
0x82,
0x84,
0x86,
0x88,
0x20 },
0x1e },
0x5a },
0x76 },
0x88 },
0x96 },
0xaf },
0xd7 },
{ 0x7b, 0x10 },
{ 0x7d, 0x35 },
{ 0x7f, 0x69 },
{ 0x81, 0x80 },
{ 0x83, 0x8f },
{ 0x85, 0xa3 },
{ 0x87, 0xc4 },
{ 0x89, 0xe8 },
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
32/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
{
{
{
{
{
{
{
0x34,
0xa4,
0x97,
0x99,
0x9b,
0x9d,
0x78,
0x11
0x88
0x30
0x30
0x29
0x4c
0x04
},
},
},
},
},
},
},
{
{
{
{
{
{
REG_COM11, COM11_EXP|COM11_HZAUTO|COM11_50HZ },
0x96, 0 },
0x98, 0x20 },
0x9a, 0x84 },
0x9c, 0x03 },
0x9e, 0x3f },
Title: Re: ov7670 with both arduino uno and now mega
Post by: Animat on November 26, 2013, 07:37:25 am
With the other settings the picture
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on November 26, 2013, 08:09:11 am
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 November 26, 2013, 08:56:02 am
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
33/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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 November 26, 2013, 12:24:04 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 November 26, 2013, 12:44:30 pm
Q uote from : aturcitu on Nove m be r 26, 2013, 12:24:04 pm
Tahnk s!
Arduino DUE has 96 KByte s of SR AM.
Now I am work ing with Q Q VGA (160*120) that if I am not wrong would be m ore or le s 40 Kbyte s.
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.
Q uote
And what about que im age proce ssing? SD librarie s incloude the functions ne e de d to conve rt this am ount of byte s into a png/jpe g im age ?
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.
Q uote
Thank s Again! :)
No problem!
Title: Re: ov7670 with both arduino uno and now mega
Post by: aturcitu on November 26, 2013, 12:49:16 pm
Q uote
I don't think SD library doe s JPEG e ncoding but you could find a prope r library for that. Any way it would be be tte r if you can de le gate that task to anothe r part of your proje ct. Arduino
proce ssing powe r is lim ite d.
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 November 26, 2013, 07:19:49 pm
Q uote from : drk blog on Nove m be r 26, 2013, 12:44:30 pm
I don't think SD library doe s JPEG e ncoding but you could find a prope r library for that. Any way it would be be tte r if you can de le gate that task to anothe r part of your proje ct. Arduino
proce ssing powe r is lim ite d.
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 November 26, 2013, 08:17:33 pm
Q uote from : aturcitu on Nove m be r 26, 2013, 12:49:16 pm
W hat do you m e an? saving only the byte s as te x t and the m proce ss it on PC side ? :O
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
34/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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 November 26, 2013, 08:23:56 pm
Q uote from : x KoldFuzionx on Nove m be r 26, 2013, 07:19:49 pm
can you e laborate ? I was using the SD library for anothe r proje ct(VC 0706), but I've be e n think ing of trying the SdFat library, cuz as I unde rstand it, you can save the tim e /date the file was
writte n to the file , so it can be re ad by a com pute r. As soon as I ge t an R TC , I plan on trying to im ple m e nt 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).
Q uote from : x KoldFuzionx on Nove m be r 26, 2013, 07:19:49 pm
By doing JPEG e ncoding, you m e an tak ing it from the R AW Baye r and conve rting it to JPEG? O r am I m issing som e thing m ore on this?
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?
Q uote
W ork ing with the se se nsors is hard e ve n for som e one with k nowle dge about e le ctronics. It doe sn't m e an you won't m ak e it, but it isn't going to be e asy.
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. :)
Q uote
O ne good re com m e ndation is to split the proble m into parts which you can build and te st by its own. O nce you have parts work ing, you try to inte grate the m .
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 November 27, 2013, 06:43:02 am
Q uote from : x KoldFuzionx on Nove m be r 27, 2013, 06:24:21 am
Q uote from : drk blog on Nove m be r 26, 2013, 09:52:57 pm
A prope rly writte n SD card library shouldn't do som e thing lik e e ncoding JPEG.
That's good to k now. So e sse ntially, since the O V7670/O V5642 fam ily m ostly doe s R AW , YUV, e tc, I should be able to find a library that will conve rt the m to JPEG? W hich brings m e to m y
ne x t que stion, com pre ssion. Le ss com pre ssion provide s be tte r quality JPEG im age s? So, lik e on the VC 0706 I can se t the com pre ssion ratio from 0-255(00 - FF, in HEX), so a se tting of 0
would be no com pre ssion and a highe r quality pic, whe re as FF would be a lowe r quality due to com pre ssion causing som e 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
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
35/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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.
Q uote from : x KoldFuzionx on Nove m be r 27, 2013, 06:24:21 am
we ll, I've le arne d in 34 ye ars of Ex actly what I've be e n doing with this othe r m odule . I starte d with the cam e ra, se nding data, re ce iving, e tc. The n have be e n inte grating othe r com pone nts
once I'm happy twe ak ing the e x isting. For e x am ple , right now, I'm work ing on a m e nu syste m with a 16x 2 LC D scre e n(sm all, challe nging, but it's all I have at the m om e nt). I fail, the n ge t
back on the horse and k e e p on trying, whe n that fails, I try som e thing e lse .
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 November 27, 2013, 07:39:59 am
Almost did, image:
Title: Re: ov7670 with both arduino uno and now mega
Post by: xKoldFuzionx on November 27, 2013, 07:49:14 am
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 November 27, 2013, 08:12:07 am
Q uote from : x KoldFuzionx on Nove m be r 27, 2013, 07:49:14 am
Lm ao, glad you fix e d that. I'd have be e n pisse d whe n I couldn't figure out how to com pre ss JPEG with SdFat. Lol.
Big typo.
Q uote from : x KoldFuzionx on Nove m be r 27, 2013, 07:49:14 am
As for com pre ssion, thank s for e x plaining that. For now, JPEG is just e asie r. That's why I orde re d the O V5642 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 November 27, 2013, 02:42:45 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.
C ode :
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;
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:
C ode :
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?
C ode :
while (digitalRead(HREF) == 1){
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
36/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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 November 27, 2013, 04:16:52 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 November 28, 2013, 10:03:55 am
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 November 28, 2013, 10:17:36 am
Q uote from : aturcitu on Nove m be r 28, 2013, 10:03:55 am
I have the ne w v3 ve rsion but I can't find re le vant inform ation about this ve rsion, Doe s anybody k now if it has any im portant diffe re nt I would have to tak e into account?
Ask the seller for a datasheet. Do you have a link to the product on ebay or something?
Q uote from : aturcitu on Nove m be r 28, 2013, 10:03:55 am
Anyway, I also would lik e to ask if som e body could he lp m e unde srtanding with thre e line s of e x planation what is the fifo funcionality lik e . O nly e x plaining the diffe re nce s with the non-fifo
ve rsion re garding 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 November 28, 2013, 10:21:31 am
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!
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 November 28, 2013, 12:32:58 pm
Q uote from : drk blog on Nove m be r 27, 2013, 08:12:07 am
In the e nd, you have to use the right se nsor according to your proje ct. If you just want to save a JPEG im age to SD for using ove r a com pute r late r, using a JPEG-e nable d se nsor m ak e s
se nse . Be cause you save space and tim e .
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.
Q uote
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
37/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
Q uote
I didn't say this be fore : I don't think you will find a JPEG library for Arduino. As it isn't inte nde d for such job. Encoding/de coding JPEG ne e ds a lot of R AM. You have to k e e p in m ind the Arduino
isn't a com pute r. O f course , we tak e Arduino to its lim its all the tim e . That's the ide a. But you have to k e e p one foot on the e arth. And think about the proje ct 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 November 28, 2013, 06:16:04 pm
Q uote from : aturcitu on Nove m be r 28, 2013, 10:21:31 am
In the clk I have to use to re ad the data what it is the be st way to ge ne rate d?
W ith pwm and cre ating som e inte rrups? C an I cre ate inte rrupts with output signals? or I would have to re cone cte d to an input?
O r m aybe : (put pin up, re ad, put pin down... ) I suppose the first one ..haha
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 November 28, 2013, 06:21:32 pm
Q uote from : x KoldFuzionx on Nove m be r 28, 2013, 12:32:58 pm
Ye ah, I look e d be fore and couldn't find one . That m ak e s se nse . I thought about ge tting a Pi and trying that, but I've just inve ste d 6 m onths into le arning how to code with Arduino and I've
alm ost got a finishe d product. If I switch ove r, I have to le arn a ne w m e thod and go through it all ove r again. Lol, e ve ntually, I'd lik e to le arn to do both, but for now, the Arduino se e m s to
be able to handle what I ne e d it to do. I'm hoping that afte r this is built, I can produce and se ll the m . But, of course , I ne e d to ge t it into the fie ld for at le ast 6 m onths to te st it out and
twe ak it. I'm just quite hone stly im pre sse d with how quick ly this has all com e toge the r. I didn't e x pe ct that afte r I starte d 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 November 29, 2013, 01:28:40 pm
Q uote from : drk blog on Nove m be r 28, 2013, 06:21:32 pm
Be e n the re be fore . In m y case I have to work with 640x 480 fram e s without com pre ssion and save at le ast four or five fram e s pe r se cond during 6 se conds. I starte d using Arduino but switche d
to Pi be cause I was about to spe nd m ore m one y by staying in Arduino. I'm e x pe rie nce d with C /C ++ so switching be wte e n the m wasn't a proble m . Pi runs a m ultitask ing e nvironm e nt which in
turn com e s with its own issue s whe n you have to acce ss hardware in re al-tim e . But it's work ing now. :)
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 November 29, 2013, 02:22:32 pm
Q uote from : drk blog on Nove m be r 29, 2013, 02:11:29 pm
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
38/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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?
Q uote
Nope . Multitask ing is sharing the C PU am ong se ve ral program s, one program at a tim e . W he n a give n program is using the C PU, all the re st are pause d. And from the program point of vie w,
you don't k now whe n that happe ns. So if you are polling an input pin for a le ve l, and waiting for a change . You could m iss one or se ve ral le ve l change s if you we re pause d by the k e rne l.
http://e n.wik ipe dia.org/wik i/C om pute r_m ultitask ing (http://e n.wik ipe dia.org/wik i/C om pute r_m ultitask ing)
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 November 29, 2013, 04:09:26 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 November 29, 2013, 05:12:12 pm
Interesting.
Ok, that makes sense then.
Title: Re: ov7670 with both arduino uno and now mega
Post by: aturcitu on December 02, 2013, 10:30:36 am
Hello again !
I have some doubts drkblog,
First of all, this part of the code is clear:
C ode :
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);
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 December 02, 2013, 11:32:02 am
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 December 02, 2013, 06:15:03 pm
Perfect, I have written my code, the main core look like this:
C ode :
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;
RCLK_CLR;
RCLK_SET;
RCLK_CLR;
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
39/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
RCLK_SET;
RRST_SET;
// Pointer is Reset
OE_CLR;
// Enables reading
//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 December 02, 2013, 06:27:21 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 December 03, 2013, 06:14:40 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 December 03, 2013, 08:34:04 am
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 December 03, 2013, 09:20:57 am
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.
C ode :
#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
#define HREF
#define DATA
//RESOLUTION
#define COLS
#define ROWS
#define BYTES
0x21
0x91
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
REG_PIOC_PDSR>>14&0x1
REG_PIOC_PDSR>>2&0xFF
// C.19
for writing
// C.17
for writing
// C.16
for writing
// C.15
for writing
// C.18
for reading
// C.14
for reading
// C.2 to C.9 for reading
160
120
2
// Enable I2C
// Start serial comunication
void loop()
{
//WRITING ON FIFO
OE_SET;
// Output high impedance
WEN_CLR;
onFrame=true;
while(onFrame);
// Enable writing
// The present frame ends
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
40/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
onFrame=true;
while(onFrame);
WEN_SET;
RRST_CLR;
RCLK_CLR;
RCLK_SET;
RCLK_CLR;
RCLK_SET;
RCLK_CLR;
RRST_SET;
// Pointer is Reset
OE_CLR;
// Enables reading
//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);
//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++;
}
}
void write(byte address, byte val)
{
delay(5);
Wire.beginTransmission(ADDRESS);
Wire.write(address);
Wire.write(val);
Wire.endTransmission();
}
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
41/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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 December 07, 2013, 08:36:30 am
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 December 09, 2013, 01:42:56 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 December 11, 2013, 05:11:22 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 December 11, 2013, 05:53:59 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.
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
42/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
Title: Re: ov7670 with both arduino uno and now mega
Post by: aturcitu on December 11, 2013, 07:22:41 pm
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 December 11, 2013, 08:07:08 pm
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 December 12, 2013, 07:02:53 am
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
C ode :
//REGISTERS INICIALIZATION
write(0x12,0x80);
write(0x15,0x02);
write(0x11,0x82);
//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 December 12, 2013, 07:09:20 am
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 December 12, 2013, 08:34:17 am
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 December 12, 2013, 12:15:20 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 December 12, 2013, 12:32:39 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 December 12, 2013, 04: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 December 12, 2013, 04:13:58 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.
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
43/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
Title: Re: ov7670 with both arduino uno and now mega
Post by: aturcitu on December 12, 2013, 05:38:30 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)
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on December 12, 2013, 05:49:05 pm
Post the command line you are using now.
Title: Re: ov7670 with both arduino uno and now mega
Post by: aturcitu on December 12, 2013, 06:08:21 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 December 12, 2013, 06:24:22 pm
Can't be 173x144 (173 is an odd number)
Title: Re: ov7670 with both arduino uno and now mega
Post by: aturcitu on December 13, 2013, 03:40:51 am
Q uote from : drk blog on De ce m be r 12, 2013, 06:24:22 pm
C an't be 173x 144 (173 is an odd num be r)
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 December 13, 2013, 06:11:24 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 December 13, 2013, 11:25:33 am
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 December 13, 2013, 04:05:18 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 December 14, 2013, 01:00:01 pm
I have made a library in order to save directly in bmp the picture in the SD CARD.
bmp.h
C ode :
#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;
};
bmp.cpp
C ode :
#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);
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
44/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
bmpFileHeader[ 2] = (byte)(fileSize
);
bmpFileHeader[ 3] = (byte)(fileSize >> 8);
bmpFileHeader[ 4] = (byte)(fileSize >> 16);
bmpFileHeader[ 5] = (byte)(fileSize >> 24);
bmpInfoHeader[ 4] = (byte)(
bmpInfoHeader[ 5] = (byte)(
bmpInfoHeader[ 6] = (byte)(
bmpInfoHeader[ 7] = (byte)(
bmpInfoHeader[ 8] = (byte)(
bmpInfoHeader[ 9] = (byte)(
bmpInfoHeader[10] = (byte)(
bmpInfoHeader[11] = (byte)(
px
);
px >> 8);
px >> 16);
px >> 24);
py
);
py >> 8);
py >> 16);
py >> 24);
}
Bmp bmp;
// R
// G
Title: Re: ov7670 with both arduino uno and now mega
Post by: drkblog on December 14, 2013, 02:16:04 pm
Nice!
Title: Re: ov7670 with both arduino uno and now mega
Post by: sakeear on December 17, 2013, 11:12:05 am
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 December 17, 2013, 02:27:17 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 December 21, 2013, 11:52:53 pm
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 December 24, 2013, 11:07:03 am
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 December 24, 2013, 11:09:54 am
Q uote from : sak e e ar on De ce m be r 21, 2013, 11:52:53 pm
Mr Arduino,,,, can u plz te l m e , how the pin conne ction ne e d to use in arduino m e ga?? i re ad ur post.. but i cant find out. and im ne w to arduino..can plz he lp?
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.
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
45/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
Title: Re: ov7670 with both arduino uno and now mega
Post by: Mr_arduino on December 24, 2013, 12:52:57 pm
Q uote from : lbe re zinsk i on De ce m be r 17, 2013, 02:27:17 pm
He llo, all & Mr_Arduino
I'm a Arduino be ginne r and i ne e d som e he lp unde rstanding if m y conne ctions are corre ct.
I attache d a fritzing file that shows m y pin conne ctions (FYI m y ov7670 is a non buffe r unit).
I'm sure m y conne ctions are wrong ple ase advise
Thank s 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 December 24, 2013, 01:39:17 pm
Q uote from : aturcitu on De ce m be r 13, 2013, 11:25:33 am
Be fore a long day work ing on m y code and using the strucs with the re gs....
tax an! But Your's photos have quite a lot quality that m ine . I suppose that I can im prove the focus and play with othe rs re giste rs?
Thank s ! :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 December 24, 2013, 01:44:27 pm
Q uote from : aturcitu on De ce m be r 12, 2013, 05:38:30 pm
I have notice d one thing... My the orde r of the colors on m y colorbar are incorre nt. W hat could be the e x planation?
I have attach the color bar raw data. YUV422 Q C IF (176x 144)
I got the colors to appear normal I had to use "Alternative" yuv422 conversion with my program you can run it as
C ode :
./convert -f Cbar.RAW -w 174 -H 144 -c yalt
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 December 24, 2013, 02:04:00 pm
Q uote from : pgibbons66 on De ce m be r 06, 2013, 08:07:42 pm
Finally a re ally am atue r que stion, whe n you pull up to A4 &A5 do you just add a 4.7k re sistor be twe e n the line and the 3.3v pin on the arduino?
thank s 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 December 24, 2013, 02:05:59 pm
Q uote from : x KoldFuzionx on De ce m be r 06, 2013, 11:37:52 pm
Q uote from : drk blog on De ce m be r 06, 2013, 09:23:13 pm
Don't forge t to disable any Arduino buil-in pull up!
O ut of she e r curiousity, what would happe n if you didn't? If the built in are highe r re sistance , I could se e that be ing a proble m , but if the y're lowe r, you could just use a lowe r PU?
I re ally k now nothing about the pull-ups built into Arduino. I re ad about the m once , but don't re m e m be r anything. Lol, I just found out what a PU re sistor was ye ste rday.
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 December 24, 2013, 02:46:10 pm
Q uote from : Anim at on De ce m be r 03, 2013, 06:14:40 am
Hi, how to fix the im age with the right e dge ?
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
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
C ode :
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;
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
46/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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.
C ode :
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.
C ode :
spiCSt();
spiWrB(2);//sequental write mode
spiWrB(0);//24 bit address
spiWrB(0);
spiWrB(0);
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
C ode :
spiCSt();
spiWrB(1);
spiWrB(64);//sequential mode
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
C ode :
#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
C ode :
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:
C ode :
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)
C ode :
while ((PIND&4)) {}//wait for low
SPDR=(PINC&15)|(PIND&240);
while (!(PIND&4)) {}//wait for high
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.
C ode :
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;
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
47/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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 December 25, 2013, 01:47:55 pm
Q uote from : Mr_arduino on De ce m be r 24, 2013, 03:37:56 pm
Q uote from : drk blog on Nove m be r 27, 2013, 08:12:07 am
W e ll. Having a se nsor which outputs JPEG save s you the cost of proce ssing the e ncoding. But, as far as I k now, you won't ge t a fram e fre e of com pre ssion from such a se nsor. And if you have
to proce ss the im age in the Arduino, you have to de code JPEG first. W hich is why O V7670 is be tte r in such case s.
The O V5642 can output raw data in addition to the jpe g com pre sse d m ode .
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 December 26, 2013, 09:57:31 am
Q uote from : Mr_arduino on De ce m be r 24, 2013, 01:44:27 pm
Q uote from : aturcitu on De ce m be r 12, 2013, 05:38:30 pm
I have notice d one thing... My the orde r of the colors on m y colorbar are incorre nt. W hat could be the e x planation?
I have attach the color bar raw data. YUV422 Q C IF (176x 144)
I got the colors to appe ar norm al I had to use "Alte rnative " yuv422 conve rsion with m y program you can run it as
C ode :
./convert -f Cbar.RAW -w 174 -H 144 -c yalt
And you ge t the right colors
The source to m y program is locate d at https://github.com /C om pute rNe rd/R awC am e ra-data-conve rte r
The re ason you are ge tting the wrong colors is be cause the first byte is swappe d be cause a re giste r was not se t. The yuv422 alte rnative m ode Also from what I have notice d it se e m s that
yuv422 is highe r 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 December 26, 2013, 10:10:36 am
aturcitu I am not sure if you are actually missing bytes look at register 0x3A here is a quote from the datasheet
Q uote
Bit[3]: O utput se que nce
(use with re giste r
C O M13
[1] (0x 3D))
TSLB[3],
C O M13
[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 December 26, 2013, 10:34:00 am
Q uote from : x KoldFuzionx on De ce m be r 25, 2013, 01:47:55 pm
I just wish the coding and the docum e ntation was e asie r for m e to figure out. I'm re ally quite slow with unde rstanding all of this and don't have the e x pe rie nce .
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.
Q uote
I had be e n using a VC 0706 until it just crappe d out on m e ye ste rday(I put it to sle e p and now it won't re spond). Now all the work I put into it is garbage and I'm stuck scrapping all the work I
did and starting with som e thing diffe re nt. W ire confuse s m e , though I think I have a fairly de ce nt grasp of it.
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
48/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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.
Q uote
I gue ss I'm just going to have to go back through all your code on the 7670 and se e what I can figure out. I can't thank you e nough for all the work you've done on the se cam e ra m odule s.
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 December 26, 2013, 02:03:21 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.
Q uote from : Mr_arduino on De ce m be r 26, 2013, 10:34:00 am
Don't fe e l bad it took m e a long tim e to ge t the ov7670 to work m ost of this was m y silly e rrors I was a be ginne r at one point. W he n I starte d work ing with the ov7670 I could not e ve n
com m unicate with it using i2c it would not work . I did not re lize that for i2c (sccb) com m unication to work you ne e de d to fe e d a clock to it. I re m e m be r ge tting it work ing and the colors I got
out of the ov7670 we re purple and gre e n. I found out that the re was som e re giste r that fix e s this (it appe ars aturcitu is curre ntly e x pe rie ncing this issue ) Ye s it doe s affe ct rgb565 m ode too.
W ork ing with the se cam e ra se nsors have significantly advance d m y sk ill both at a hardware le ve l and a software le ve l. I hope you k e e p going with your proje ct se e ing it finally work fe e ls gre at
and that is part of the re ason why I m ade this topic so that othe r pe ople inte re ste d in cam e ra se nsors can ge t to se e the ir proje ct 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.
Q uote
W hat do you m e an "Put it to sle e p"? Maybe the re is a way to fix it. I can't im agine software causing dam age to the se nsor unle ss you disable the inte rnal re gulator or som e thing which is
unlik e ly 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.
Q uote
C ould you ple ase te ll us whe re you are ge tting ov5642 se nsor m odule s for the cost le st than an ov7670 m odule the che ape st ov5642 m odule I could find was $25.99 on e bay. The ov7670 can
be purchase d for $5.99 on e bay and include s fre e shipping just lik e the ov5642. I would lik e an ov5642 m odule m yse lf.
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.
Q uote
W e ll the ov5642 is quite a bit diffe re nt I am not sure if m uch of m y code will he lp you with that unfortunate ly.
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 December 27, 2013, 03:03:25 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 December 27, 2013, 06:16:13 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 December 28, 2013, 12:26:55 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
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
49/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
Title: Re: ov7670 with both arduino uno and now mega
Post by: xKoldFuzionx on December 28, 2013, 12:38:19 am
Q uote from : Mr_arduino on De ce m be r 27, 2013, 03:03:25 pm
O k that m ak e s m ore se nse now I though that whe n you we re talk ing about the vc7670 I though you we re talk ing about the ov7670 but now I re alize that the y are two diffe re nt things howe ve r
I assum e you are talk ing about this https://www.adafruit.com /products/397 if so you re lize it is only 0.3 MP not 2.0 MP. I agre e that it is too e x pe nsive .
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 December 28, 2013, 01:57:48 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 December 28, 2013, 10:02:32 am
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 December 28, 2013, 11:16:54 am
Q uote from : Mr_arduino on De ce m be r 28, 2013, 12:26:55 am
I subm itte d a pull re que st that m ay solve som e issue s but I doubt it will work . The re are two proble m s first of all the Ethe rne t shie ld that you are using use s pins 2,4,10,11,12,13 you appe ar
to have pins 2 and 4 hook e d up to the ov7670 also I think that the function you are using to se nd data to the wizne t 5100 is too slow try dire ctly se nding 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 December 29, 2013, 05:17:01 am
Q uote from : Mr_arduino on De ce m be r 28, 2013, 01:57:48 am
Is the m ax im um output re solution 640x 480 (vga) if so
640x 480/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
Post by: xKoldFuzionx on December 29, 2013, 02:06:25 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 December 29, 2013, 04:02:20 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 December 29, 2013, 04:07:00 pm
ok, Gotcha, so essentially, saving as a byte will allow you to say :
C ode :
Serial.println(wrReg(regID, regDat));
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
50/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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 December 29, 2013, 10:13:52 pm
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 December 29, 2013, 10:19:32 pm
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 January 02, 2014, 11:13:31 pm
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 January 06, 2014, 08:59:42 pm
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 January 07, 2014, 05:36:35 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 January 07, 2014, 08:30:28 am
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 January 07, 2014, 12:10:47 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
Post by: angeleye9 on January 08, 2014, 01:02:41 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
Title: Re: ov7670 with both arduino uno and now mega
Post by: nomiz on January 08, 2014, 05:48:07 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!
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
51/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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)
C ode :
// activate internal pullups for twi.
digitalWrite(SDA, 1); //to suppress
digitalWrite(SCL, 1); //to suppress
:smiley-roll-sweat:
// 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, LOW);
digitalWrite(RCLK_PIN, LOW);
digitalWrite(RCLK_PIN, HIGH);
digitalWrite(RCLK_PIN, LOW);
digitalWrite(RCLK_PIN, HIGH);
digitalWrite(RCLK_PIN, LOW);
digitalWrite(RRST_PIN, HIGH);
digitalWrite(OE_PIN, LOW);
delay(1);
// Enables reading
// Pointer is Reset
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 :
C ode :
//REGISTERS INITIALIZATION
write(0x11,0x82);
write(0x12,0x00);
write(0x12,0x01);
// Pescaler x3 (m)
// 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 January 09, 2014, 12:06:02 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 January 12, 2014, 08:50:46 am
Q uote
Having /R E is a ne e de d function /R E doe s e x actly what you ne e d it to do k e e p the data "alive " in the fifo while saving to the sd card and the n continue we re you le ft off without re starting.
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
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
52/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
Title: Re: ov7670 with both arduino uno and now mega
Post by: sakeear on January 14, 2014, 09:59:02 pm
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 January 15, 2014, 01:32:10 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 January 19, 2014, 08:44:40 am
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 January 19, 2014, 10:06:26 am
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 January 19, 2014, 10:34:38 am
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 January 19, 2014, 01:04:21 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-cameratft 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 January 19, 2014, 01:30:11 pm
I tryed with this in void setup():
C ode :
TCCR0B = TCCR0B & 0b11111000 | 0x01;
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
53/60
3/15/2014
//
//
//
//
//
//
//
Print Page - ov7670 with both arduino uno and now mega
#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];
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");
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
54/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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 January 21, 2014, 09:37:05 pm
@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 January 22, 2014, 06:50:55 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 January 23, 2014, 11:22:12 pm
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.
C ode :
int CameraAL422B::readFrame(/*OutputStream *out*/) {
int i, n = 0;
resetReadPointer();
for (i = 0; i < height; i++) {
n += readRow(/*out*/);
}
//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;
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
55/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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 January 23, 2014, 11:27:14 pm
oh and this is the latest image.
Title: Re: ov7670 with both arduino uno and now mega
Post by: WendelOS on January 25, 2014, 06:55:22 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 January 26, 2014, 12:16:00 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 January 26, 2014, 01:24:47 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 January 28, 2014, 10:03:58 am
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:
C ode :
#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);
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
56/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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!");
;
pinMode(8,INPUT);
}
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
57/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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);*/
}
}
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
58/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
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)
{
//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 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 February 04, 2014, 03:46:47 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,
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
59/60
3/15/2014
Print Page - ov7670 with both arduino uno and now mega
>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.
http://forum.arduino.cc/index.php?PHPSESSID=evsqg0gduo1obi4t319pq75c21&action=printpage;topic=159557.0
60/60