Вы находитесь на странице: 1из 60

3/15/2014

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

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

registers do that would be awesome. To solve the 5v issue I use a buffer. To solve the fact that the arduino is slow I set the divider to 9 also I am getting the clock with the CLKOUT pin you will have to change your fuse settings for that. Also for twi communication the ov7670 is picky about what pullup resistor values you use I found 4.7k and 10k to work. I tried 1k and 2.2k and those do NOT work. You will need twi to write to the registers the image out is parallel. Here are some images taken with the ov7670. (http://img812.imageshack.us/img812/696/v5w6.png) (http://img51.imageshack.us/img51/7659/blinds.png) Here is the arduino uno itself. Image is very large click here to view http://imageshack.com/a/img849/4632/zuvj.jpg Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: nonzung on April 11, 2013, 01:21:02 am Hello, I would like to see your connection in detail. I want the camera to be used in image processing by arduino. Thanks for answer and sorry for my English. Nice job. Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: Mr_arduino on April 11, 2013, 07:30:22 pm The connections are simple. Start by plugging in SIO_C to A5 and SIO_D to A4 since this is i2c/twi you must have a 4k7 resistor 10k also works. Make sure you have the resistor to pull up 3.3v not 5v. Also edit twi.c in the arduino ide folder/libraries/Wire/utility search for these lines and comment them out or remove them
C ode : / /a c t i v a t ei n t e r n a lp u l l u p sf o rt w i . d i g i t a l W r i t e ( S D A ,1 ) ; d i g i t a l W r i t e ( S C L ,1 ) ;

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

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

1/60

3/15/2014

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

Print Page - ov7670 with both arduino uno and now mega

Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: nonzung on April 12, 2013, 01:10:57 am Thanks for the answer, I will try. :) :) Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: Mr_arduino on April 12, 2013, 04:06:02 pm I wish you the best of luck if anything does not work right just reply and I will help you. Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: michinyon on April 13, 2013, 01:57:23 am Could you post a photo of your device sometime ? I got one of these and the connections were so tiny that I could not see then with a magnifying glass and certainly not actually connect anything to them. Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: Saren on April 13, 2013, 06:20:47 pm Hi, I'm working on a project at university about computer vision and Arduino. I'm trying to capture an image using Arduino Uno and OV7670 camera without FIFO. Other components like SD card, LCD, additional RAM, shields, etc. are unfortunately not available at this time (I've read some tutorials about this, but they were using special shields or some stuff I don't have or camera with FIFO...). Is it possible to directly communicate with camera from Arduino and get some images? It doesn't have to be fast, the point is to get some results. Since I'm just a beginner with Arduino, I'm a little bit confused about how to connect my camera to it, when I don't use RAM that was mentioned above. I really don't want to damage it... Could you please describe it or provide some connection schema for a case like mine? Could you please also give me some advice how to change the code for the capture program? Any help is appreciated. Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: Mr_arduino on April 13, 2013, 09:03:23 pm michinyon I bought an ov7670 camera module that means some of the pins are routed to a 2.54mm pitch header I think you have bought just the sensor. I am busy right now I will take a picture soon. Saren it is possible I will have to get back with you on this one though. I am busy right now and don't have any code written right now for using no ram. I do however have a program that is compiled with avr-gcc that sends the image to a frame grabber program that I wrote. Here is the sender program it is in 3 files main.c ov7670.h ov7670.c main.c: http://pastebin.com/dF3pc23T I will warn you that I made some changes to the code but forgot to change the comments like the captureImg function says it missed a byte but now it does not I posted it to paste bin before realising this. ov7670.h http://pastebin.com/CqYTwNqn ov7670.c http://pastebin.com/T1nN5Ni4 Here is the frame grabber source code http://pastebin.com/dxMJhZTq This one is only one file. If on Gnu/Linux you will need to install the development package of SDL or if gentoo just emerge sdl. If on windows get the development library from http://www.libsdl.org/download-1.2.php Also I made an update to my program that captures an image to the sd card it nows saves raw bayer data. http://pastebin.com/zV0ahzPv The link is different than the previous code that I posted. Here is a program to debayer/demosaic the data it is still in very beta needs work It will also convert yuv422 to rgb (the old image to sd card program saved data in that format)
C ode : / / t oc o m p i l et y p eg c cW a l lW e x t r al ml p n goy u vm a i n . c # i n c l u d e< i n t t y p e s . h > # i n c l u d e< s t d i o . h > # i n c l u d e< s t d l i b . h > # i n c l u d e< s t r i n g . h > # i n c l u d e< p n g . h > # i n c l u d e< z l i b . h > # i n c l u d e< s y s / s t a t . h > # d e f i n ei m g _ w6 4 0 # d e f i n ei m g _ w _ 21 2 8 0 # d e f i n ei m g _ h4 8 0 # d e f i n eC L I P ( X )(( X )>2 5 5?2 5 5:( X )<0?0:X ) # d e f i n eC ( Y )(( Y )-1 6 ) # d e f i n eD ( U )(( U )-1 2 8) # d e f i n eE ( V )(( V )-1 2 8) # d e f i n eY U V 2 R ( Y ,U ,V )C L I P ( (2 9 8*C ( Y ) +4 0 9*E ( V )+1 2 8 )> >8 ) # d e f i n eY U V 2 G ( Y ,U ,V )C L I P ( (2 9 8*C ( Y )-1 0 0*D ( U )-2 0 8*E ( V )+1 2 8 )> >8 ) # d e f i n eY U V 2 B ( Y ,U ,V )C L I P ( (2 9 8*C ( Y )+5 1 6*D ( U ) +1 2 8 )> >8 ) c h a rb u f [ 1 0 2 4 ] ; v o i ds h o w H e l p ( ) { p u t s ( " Y u v 4 2 2r a wi m a g ed a t at op n g " ) ; p u t s ( " nxr e p l a c exw i t ht h ei m a g en u m b e ry o uw a n tt oc o n v e r t " ) ; p u t s ( " hs h o w st h i sh e l pf i l e " ) ; p u t s ( " oxr e p l a c exw i t har e a li n t e g e rb e t w e e n0a n d7t h i ss e t st h eo f f s e t " ) ; } i n ts a v e P N G ( c h a r*f i l e N a m e , u i n t 3 2 _ tw i d t h , u i n t 3 2 _ th e i g h t , v o i d*p t r ) { / / s a v e sa2 4 b i tp n gw i t hr g bb y t eo r d e r p n g _ b y t e*d a t = p t r ; / / c o n v e r tt ou i n t 8 _ t / / p n g _ b y t e* * r o w _ p o i n t e r s=m a l l o c ( h e i g h t * s i z e o f ( p n g _ b y t e ) ) ; / / i f( r o w _ p o i n t e r s = = 0 ) / / r e t u r n1 ; F I L E*f p = f o p e n ( f i l e N a m e , " w b " ) ; i f( f p = = 0 ) r e t u r n1 ; p n g _ s t r u c t pp n g _ p t r=p n g _ c r e a t e _ w r i t e _ s t r u c t ( P N G _ L I B P N G _ V E R _ S T R I N G ,( p n g _ v o i d p ) 0 , 0 , 0 ) ;

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

p n g _ s t r u c t pp n g _ p t r=p n g _ c r e a t e _ w r i t e _ s t r u c t ( P N G _ L I B P N G _ V E R _ S T R I N G ,( p n g _ v o i d p ) 0 , 0 , 0 ) ; i f( ! p n g _ p t r ) r e t u r n1 ; p n g _ i n f o pi n f o _ p t r=p n g _ c r e a t e _ i n f o _ s t r u c t ( p n g _ p t r ) ; i f( ! i n f o _ p t r ) { p n g _ d e s t r o y _ w r i t e _ s t r u c t ( & p n g _ p t r , ( p n g _ i n f o p p ) N U L L ) ; r e t u r n1 ; } i f( s e t j m p ( p n g _ j m p b u f ( p n g _ p t r ) ) ) { p n g _ d e s t r o y _ w r i t e _ s t r u c t ( & p n g _ p t r ,& i n f o _ p t r ) ; f c l o s e ( f p ) ; r e t u r n1 ; } p n g _ i n i t _ i o ( p n g _ p t r ,f p ) ; p n g _ s e t _ I H D R ( p n g _ p t r ,i n f o _ p t r ,w i d t h ,h e i g h t , 8 ,P N G _ C O L O R _ T Y P E _ R G B ,P N G _ I N T E R L A C E _ N O N E , P N G _ C O M P R E S S I O N _ T Y P E _ D E F A U L T ,P N G _ F I L T E R _ T Y P E _ D E F A U L T ) ; / / m u s tb ec a l l e db e f o r e o t h e rp n g _ s e t _ * ( )f u n c t i o n s / / p n g _ s e t _ c o m p r e s s i o n _ l e v e l ( p n g _ p t r , Z _ B E S T _ C O M P R E S S I O N ) ; / / s i n c ew ea r ed o i n gt i m e l a p s e sw em a yb ed e a l i n gw i t hm a n yf i l e si ti sg o o dt ok e e pd i s ks p a c eu s a g ed o w n u i n t 3 2 _ ty ; / / f o r( y = 0 ; y < h e i g h t ; y + + ) / / r o w _ p o i n t e r s [ y ] = & d a t [ ( y * w i d t h * 3 ) ] ; / / t h er o w sa r ec o n t i g u o u s p n g _ s e t _ u s e r _ l i m i t s ( p n g _ p t r ,w i d t h ,h e i g h t ) ; p n g _ w r i t e _ i n f o ( p n g _ p t r ,i n f o _ p t r ) ; / / p u t s ( " s a v i n gd a t a2 " ) ; / / p n g _ w r i t e _ i m a g e ( p n g _ p t r ,r o w _ p o i n t e r s ) ; f o r( y = 0 ; y < h e i g h t ; y + + ) p n g _ w r i t e _ r o w ( p n g _ p t r ,& d a t [ ( y * w i d t h * 3 ) ] ) ; / / p n g _ w r i t e _ p n g ( p n g _ p t r ,i n f o _ p t r ,P N G _ T R A N S F O R M _ I D E N T I T Y ,N U L L ) ; p n g _ w r i t e _ e n d ( p n g _ p t r ,i n f o _ p t r ) ; p n g _ d e s t r o y _ w r i t e _ s t r u c t ( & p n g _ p t r ,& i n f o _ p t r ) ; / / f r e e ( r o w _ p o i n t e r s ) ; f c l o s e ( f p ) ; / / d o n ew i t hf i l e r e t u r n0 ; / / w i l lr e t u r n0o ns u c c e s sn o n z e r oi ne r r o r } v o i dy u v 2 r g b ( u i n t 8 _ t*y u v D a t , u i n t 8 _ t*o u t ) { u i n t 6 4 _ tx y ; f o r( x y = 0 ; x y < ( i m g _ w / 2 ) * i m g _ h ; x y + + ) { * o u t + + = Y U V 2 R ( y u v D a t [ 0 ] , y u v D a t [ 1 ] , y u v D a t [ 3 ] ) ; * o u t + + = Y U V 2 G ( y u v D a t [ 0 ] , y u v D a t [ 1 ] , y u v D a t [ 3 ] ) ; * o u t + + = Y U V 2 B ( y u v D a t [ 0 ] , y u v D a t [ 1 ] , y u v D a t [ 3 ] ) ; * o u t + + = Y U V 2 R ( y u v D a t [ 2 ] , y u v D a t [ 1 ] , y u v D a t [ 3 ] ) ; * o u t + + = Y U V 2 G ( y u v D a t [ 2 ] , y u v D a t [ 1 ] , y u v D a t [ 3 ] ) ; * o u t + + = Y U V 2 B ( y u v D a t [ 2 ] , y u v D a t [ 1 ] , y u v D a t [ 3 ] ) ; y u v D a t + = 4 ; } } v o i dd e B a y e r N ( u i n t 8 _ t*i n , u i n t 8 _ t*o u t ) { u i n t 3 2 _ tx , y ; f o r( y = 0 ; y < i m g _ h ; y + = 2 ) { f o r( x = 0 ; x < i m g _ w ; x + = 2 ) { / / t h i sw i l ld oa2 x 2p i x e lr e c t a n g l e / * RG GB * / o u t [ ( x * 3 ) ] = i n [ x ] ; / / c o p yr e d o u t [ ( x * 3 ) + 1 ] = i n [ x + 1 ] ; / / g r e e n o u t [ ( x * 3 ) + 2 ] = i n [ x + 1 + i m g _ w ] ; / / b l u e o u t [ ( x * 3 ) + 3 ] = i n [ x ] ; / / r e d o u t [ ( x * 3 ) + 4 ] = i n [ x + 1 ] ; / / g r e e n o u t [ ( x * 3 ) + 5 ] = i n [ x + 1 + i m g _ w ] ; / / b l u e o u t [ ( ( x + i m g _ w ) * 3 ) ] = i n [ x ] ; / / r e d o u t [ ( ( x + i m g _ w ) * 3 ) + 1 ] = i n [ x + i m g _ w ] ; / / g r e e n o u t [ ( ( x + i m g _ w ) * 3 ) + 2 ] = i n [ x + 1 + i m g _ w ] ; / / b l u e o u t [ ( ( x + i m g _ w ) * 3 ) + 3 ] = i n [ x ] ; / / r e d o u t [ ( ( x + i m g _ w ) * 3 ) + 4 ] = i n [ x + i m g _ w ] ; / / g r e e n o u t [ ( ( x + i m g _ w ) * 3 ) + 5 ] = i n [ x + i m g _ w + 1 ] ; / / b l u e } o u t + = i m g _ w * 6 ; i n + = i m g _ w * 2 ; } } v o i dd e B a y e r L( u i n t 8 _ t*i n , u i n t 8 _ t*o u t ) { / / t h i si sa ni m p l e m e n t a t i o no fh t t p : / / w w w . i p o l . i m / p u b / a r t / 2 0 1 1 / g _ m h c d / u i n t 3 2 _ tx , y ; f o r( y = 0 ; y < i m g _ h ; y + = 2 ) { f o r( x = 0 ; x < i m g _ w ; x + = 2 ) { / / t h i sw i l ld oa2 x 2p i x e lr e c t a n g l e / *BG b G rR * / / * RGT H I SI SW R O N GB U TS T A N D A R DT h er o w sa r er e v e r s e do no m n i v i s i o ns e n s o r sk e e pt h i si nm i n dl a t e rj u s tg e ta l gw o r k i n gf o rn o w GB * / / / i f( x > = 2& &x < = i m g _ w 2& &y > = 2& &y < = i m g _ h 2 ) / / s e ei fw ea r ea b l et og r a bp i x e l sf r o mn e i g h b o o r s / / { / / p r i n t f ( " X% dY% dx i m g _ w% d \ n " , x , y , x i m g _ w ) ; o u t [ x * 3 ] = i n [ x ] ; / / r e dj u s tn e e d st ob ec o p i e d / / o u t [ ( x * 3 ) + 1 ] = ( ( i n [ x ] * 4 ) + ( i n [ x 1 ] * 2 ) + ( i n [ x + 1 ] * 2 ) + ( * ( i n + x i m g _ w ) * 2 ) + ( i n [ x + i m g _ w ] * 2 ) ( i n [ x 2 ] ) ( i n [ x + 2 ] ) ( * ( i n + x i m g _ w _ 2 ) ) i n [ x + i m g _ w _ 2 ] ) / 8 ; / / g r e e n a tr e dl o c a t i o n s / / o u t [ ( x * 3 ) + 2 ] = ( ( i n [ x ] * 6 ) + ( * ( i n + x 1 i m g _ w ) * 2 ) + ( * ( i n + x + 1 i m g _ w ) * 2 ) + ( * ( i n + x 1 + i m g _ w ) * 2 ) + ( i n [ x + 1 + i m g _ w ] * 2 ) ( i n [ x 2 ] / 3 * 2 ) ( i n [ x + 2 ] / 3 * 2 ) ( * ( i n + x i m g _ w _ 2 ) / 3 * 2 ) ( i n [ x + i m g _ w _ 2 ] / 3 * 2 ) ) / 8 ; / / B l u ea tr e d / / o u t [ ( x * 3 ) + 4 ] = o u t [ ( x * 3 ) + 4 ] = i n [ x + 1 ] ; / / c o p yg r e e n o u t [ ( ( i m g _ w + x ) * 3 ) + 1 ] = i n [ x + i m g _ w ] ; / / c o p yg r e e n o u t [ ( ( i m g _ w + x ) * 3 ) + 5 ] = i n [ x + i m g _ w + 1 ] ; / / c o p yb l u e / * } e l s e / / w ea r eo nt h ee d g ed e f u a l tt oe d g es a f ea l g o r t h i m { o u t [ ( x * 3 ) ] = i n [ x ] ; / / c o p yr e d o u t [ ( x * 3 ) + 1 ] = i n [ x + 1 ] ; / / g r e e n o u t [ ( x * 3 ) + 2 ] = i n [ x + 1 + i m g _ w ] ; / / b l u e o u t [ ( x * 3 ) + 3 ] = i n [ x ] ; / / r e d o u t [ ( x * 3 ) + 4 ] = i n [ x + 1 ] ; / / g r e e n o u t [ ( x * 3 ) + 5 ] = i n [ x + 1 + i m g _ w ] ; / / b l u e o u t [ ( ( x + i m g _ w ) * 3 ) ] = i n [ x ] ; / / r e d o u t [ ( ( x + i m g _ w ) * 3 ) + 1 ] = i n [ x + i m g _ w ] ; / / g r e e n o u t [ ( ( x + i m g _ w ) * 3 ) + 2 ] = i n [ x + 1 + i m g _ w ] ; / / b l u e

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

o u t [ ( ( x + i m g _ w ) * 3 ) + 3 ] = i n [ x ] ; / / r e d

3/60

3/15/2014

Print Page - ov7670 with both arduino uno and now mega
o u t [ ( ( x + i m g _ w ) * 3 ) + 3 ] = i n [ x ] ; / / r e d o u t [ ( ( x + i m g _ w ) * 3 ) + 4 ] = i n [ x + i m g _ w ] ; / / g r e e n o u t [ ( ( x + i m g _ w ) * 3 ) + 5 ] = i n [ x + i m g _ w + 1 ] ; / / b l u e } * / } o u t + = i m g _ w * 6 ; i n + = i m g _ w * 2 ;

} } u i n t 8 _ tr e a d I m g ( u i n t 3 2 _ tn u m , u i n t 8 _ t*d a t ) { s p r i n t f ( b u f , " F % d . Y U V " , n u m ) ; F I L E*m y f i l e=f o p e n ( b u f , " r b " ) ; i f( m y f i l e = = 0 ) { p r i n t f ( " C a n n o to p e nf i l e% s \ n " , b u f ) ; r e t u r n1 ; } f r e a d ( d a t , 2 , i m g _ w * i m g _ h , m y f i l e ) ; f c l o s e ( m y f i l e ) ; r e t u r n0 ; } u i n t 8 _ tp r o c e s s I m g ( u i n t 8 _ t*i n , u i n t 8 _ t*o u t , u i n t 3 2 _ tn u m , u i n t 8 _ ta l g , u i n t 1 6 _ to f f s e t ) { i f( r e a d I m g ( n u m , i n ) ) r e t u r n1 ; u i n t 3 2 _ tw , h ; s w i t c h( a l g ) { c a s e2 : d e B a y e r L ( i n + o f f s e t , o u t ) ; / / l i n e a r b r e a k ; c a s e1 : d e B a y e r N ( i n + o f f s e t , o u t ) ; / / n e a r e s tn e i g h b o o rl o wq u a l i t yt r yt oa v o i du s i n g b r e a k ; c a s e0 : y u v 2 r g b ( i n + o f f s e t , o u t ) ; b r e a k ; d e f a u l t : p u t s ( " Y o um u s tp i c ka na l g o r i t h mt os a v et h ei m a g ea s " ) ; r e t u r n1 ; } s p r i n t f ( b u f , " f r a m e% d . p n g " , n u m ) ; i f( s a v e P N G ( b u f , i m g _ w , i m g _ h , o u t ) ) { r e t u r n1 ; p u t s ( " E r r o rw h i l es a v i n gP N G " ) ; } r e t u r n0 ; } i n tm a i n ( i n ta r g c , c h a r* *a r g v ) { u i n t 8 _ tu s e N u m = 0 ; u i n t 3 2 _ tu s e I m g ; u i n t 1 6 _ to f f s e t = 0 ; u i n t 8 _ td e b a y e r = 1 ; i f( a r g c > 1 ) { / / h a n d l ea r g u m e n t s i n ta r g ; f o r( a r g = 0 ; a r g < a r g c ; a r g + + ) { i f( s t r c m p ( a r g v [ a r g ] , " n " )= =0 ) { a r g + + ; u s e I m g = a t o i ( a r g v [ a r g ] ) ; u s e N u m = 1 ; c o n t i n u e ; } i f( s t r c m p ( a r g v [ a r g ] , " o " )= =0 ) { a r g + + ; o f f s e t = a t o i ( a r g v [ a r g ] ) ; i f( o f f s e t > i m g _ w ) { p r i n t f ( " y o um u s ts p e c i f yan u m b e rb e t w e e n0a n d% df o ra r g u m e n to \ n " , i m g _ w ) ; s h o w H e l p ( ) ; r e t u r n1 ; } c o n t i n u e ; } i f( s t r c m p ( a r g v [ a r g ] , " h " )= =0 ) { s h o w H e l p ( ) ; c o n t i n u e ; } } } u i n t 8 _ t*D a t ; / / i nc a s es o m eo ft h ef i l ew a sn o ts a v e dw eu s ec a l l o ci n s t e a do fm a l l o ct og a r e n t t et h a tt h eu n s a v e dp i x e l sa r es e tt o0 i f( d e b a y e r ! = 0 ) D a t=c a l l o c ( i m g _ w * i m g _ h + i m g _ w , 1 ) ; e l s e D a t=c a l l o c ( i m g _ w * i m g _ h + i m g _ w , 2 ) ; u i n t 8 _ t*o u t I m g=m a l l o c ( i m g _ w * i m g _ h * 3 ) ; / / a l lb y t e si nt h ea r r a yw i l lb eo v e r w r i t t e nn on e e df o rc a l l o c i f( u s e N u m ) { p r o c e s s I m g ( D a t , o u t I m g , u s e I m g , d e b a y e r , o f f s e t ) ; } e l s e { u i n t 3 2 _ ti m g C ; f o r( ; ; i m g C + + ) { p r i n t f ( " S a v i n gi m a g e% d \ n " , i m g C ) ; i f( p r o c e s s I m g ( D a t , o u t I m g , i m g C , d e b a y e r , o f f s e t ) ) r e t u r n1 ; } } f r e e ( D a t ) ; f r e e ( o u t I m g ) ; r e t u r n0 ; }

Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: nonzung on April 16, 2013, 01:49:37 am I forget that. I bought the camera ov7670 fifo. Sorry and thank you so much.

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

Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: Mr_arduino on April 16, 2013, 05:53:08 pm
Q uote from : nonzung on April 16, 2013, 01:49:37 am I forge t that. I bought the cam e ra ov7670 fifo. Sorry and thank you so m uch.

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 : D D R L | = 8 ; A S S R& =~ ( _ B V ( E X C L K )|_ B V ( A S 2 ) ) ; / / g e n e r a t e8 m h zc l o c k T C C R 5 A= 6 7 ; T C C R 5 B = 1 7 ;

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.

I think there has been a misunderstanding. My camera is without fifo... Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: Mr_arduino on April 30, 2013, 08:39:04 pm
Q uote from : Sare n on April 30, 2013, 02:54:07 pm I think the re has be e n a m isunde rstanding. My cam e ra is without fifo...

So is mine so will need the same connections as I use and the external sram. Also the reason d0-d7 not need shifting is the arduino will never drive those pins so it is up to you to make sure that those pins are always set to input on the arduino. Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: sherry254 on May 11, 2013, 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

Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: Mr_arduino on May 11, 2013, 09:43:09 am This is the old school eprom with UV erase. There are several reason why this would not work. First of all how are you going to erase it in a reasonable time. Even if you had a UV led driven by the arduino it would still take awhile to erase and UV is bad for your eyes so you would need to cover it with something. Also you would not have enough pins are the eprom is parallel. Also how fast are the write speed will it even accept data fast enough. Another problem is that you would wear it out fast. Eproms only have a certain amount of writes (They do have unlimited reads though). Also this Eprom has only 64kb of memory you would have to break the frame up even more which would reduce performance even more. In short the Eprom would not work for this purpose save it for repairing a bios or make your own NES cartridge or do something fun with it but not in a camera. Just buy or sample the 23LC1024 it is kinda cheap at $2.59 if you only order one at digi-key and you will not regret it. It is even in dip package. The dip package one is called 23LC1024-I/P by the way Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: sherry254 on May 11, 2013, 11:28:08 am Clearly getting the eprom was a wrong move. My other option(or idea, but might not be a very good one) is to connect the camera to a SIM5216E 3g shield. the datasheet indicates that its possible to connect the camera pins on the shield but the pins are marked 'NC'. this is the shield i have ftp://imall.iteadstudio.com/Shield/IM121026002/DS_IM121026002_3G_Shield.pdf this is its schematic ftp://imall.iteadstudio.com/Shield/IM121026002/SCH_IM121026002_3G_Shield.pdf Could i connect the camera to the shield instead of using the arduino directly? Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: hlankoande on May 11, 2013, 06:10:49 pm Hello Mr_arduino I have planed to use the OV7670 camera module to capture picture with arduino mega 2560 R3. I m using it to drive robot and get few data from robot. I m using arduino programming IDE to write code. The code you gave is compiled with another compiler and as I do not have deep kwnowledge on this it is liltle bit hard for me. Is it possible to give us(I guess I m not alone in that case) a hello world example to capture picture and store it in an array( in order to save it in SD card or send it other serial) written with arduino IDE. Thanks lot in advance. Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: isaiful on May 16, 2013, 11:36:48 pm hye...i wanna ask if this camera is same with JPEG TTL CMOS camera???

Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: Mr_arduino on May 17, 2013, 06:59:24 pm @hlankoande I made some code for the arduino mega awhile ago check it out it uses the arduino ide http://www.youtube.com/watch?v=sEsZeDC6co0 @isaiful It is no were near the jpeg TTL camera. The Jpeg TTL CMOS camera is way easier to use but cost more money. Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: rebelion on May 22, 2013, 06:20:40 am Hello I have the same problem with OV7670 v2 + Mega R3, a lack of experience stops me to get those things work together.. Mr_arduino it would be really great if could share the code and wiring with us? Thank you. Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: drkblog on May 24, 2013, 07:27:59 am
Q uote from : Mr_arduino on April 28, 2013, 02:18:29 pm I think the 74HC 245 would work just fine also a unidire ctional one would work too. Pre tty m uch any buffe r that is fast e nough to handle a 16m hz signal and can acce pt 3.3v as a supply voltage which the 74HC 245 can. ... O nly the clock signal ne e ds to go though the buffe r as that is an input and the sd card if you are using it. From twi just disable inte rnal pullup re sistors and have the m to 3.3v inste ad of 5v...

Hello, I'm trying too to get the ov7670 communicate with Arduino UNO. I read this post a week ago, I bought some 74HC245 but I realized they are not fully bidirectional, you have to choose the direction using a pin. So they can't be used with SIO_D and SIO_C, as far as I know. As I'm reading this post again, I guess A5 and A4 pins, using the code supplied, will output 3.3V instead of 5V (assuming internal pullup is OFF). Am I right? Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: Mr_arduino on May 25, 2013, 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
Thank you again!

Print Page - ov7670 with both arduino uno and now mega

Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: Mr_arduino on May 28, 2013, 08:07:23 pm First verify that CLKOUT is correct connected to the buffer and the output from the buffer does not exceed 3.3v and is correctly connected to XCLK then verify that with an osciloscope (you should see a square wave) after that see if SIO_C and SIO_D work it may just be a quick burst but that is normal. Then see if you get a most square wave from PCLK there should be a very brief burst where PCLK stops every so often. This is because by default the ov7670 outputs unwanted dummy pixels that serve no good we don't want those dummy pixels. If PCLK never stops it may not be communicating properly but the part where it stops may be too fast to see I can not remember off the top of my head. Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: drkblog on May 31, 2013, 07:21:35 pm Thank you! I'm doing better now. Yet it isn't working. I had a communication problem between Arduino and the sensor. Now that's working and I'm able to configure the sensor. I'm having a somewhat coherent reading. I read 512 bytes blocks from the sensor, but I get blocks of zeroes every two or three blocks. I'm configuring a 3MHz PCLK but I guess it's too fast for arduino. What do you think? Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: Mr_arduino on June 01, 2013, 10:48:20 am I set the divider to 4 see this code wrReg(0x11,4);//using pre-scaler for divider Also what you can do to verify communication is increment the divider and wait awhile and increment again in a loop and see if the OUTPUT PCLK changes on an oscilopsoce. Also you MUST have this register
C ode : w r R e g ( 0 x 1 5 , 3 2 ) ; / / p c l kd o e sn o tt o g g l eo nH B L A N KC O M 1 0v s y n cf a l l i n g

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 : $. / f f m p e gfr a w v i d e os6 4 0 * 5 0p i x _ f m ty u v j 4 2 2 pif r a m e 0 . y u vfi m a g e 2v c o d e cp n gi m g . p n g

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 : g c cW a l lW e x t r al ml p n goy u vm a i n . c

As you may have noticed you need libpng installed. The only thing is that the file name must be called F(x).YUV replace (x) with a number this was because I made it for time lapses originally and need to may pictures at once. If you don't specify which number x is when running the program it will start from 0 and count up until a file is not found note that if you have F0.YUV and F2.YUV it will stop at F0.YUV as F1.YUV does not exist so in this case if you wanted to convert F2.YUV you would need to use the -n x argument so in this case do ./yuv -n 2 to convert it. Also speaking of missing a byte glitch I found out that sometimes at the beginning of capture a byte would be missed I fixed this by waiting for PCLK to go low read the pixel then wait for it to go high and then loop. I previously had it backwards. Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: drkblog on June 17, 2013, 06:40:00 pm Wow... thank you. I thought I was configuring the sensor for YUV output. After reading your reply I went to check that. I think I'm misreading the documentation or the document is wrong. Because I can't manage to change the output. What I'm doing now:
C ode : / /M a xp r e s c a l e rd i v i d e r o v c a m . t o g g l e ( R E G _ C L K R C ,N O N E ,C L K R C _ P R E S C A L E R _ M A S K&3 1 ) ; o v c a m . t o g g l e ( R E G _ D B L V ,N O N E ,D B L V _ P L L _ B Y P A S S ) ; / /N oP C L Kd u r i n gH B L A N K o v c a m . t o g g l e ( R E G _ C O M 1 0 ,N O N E ,C O M 1 0 _ P C L K _ N O _ T O G G L E ) ; / /S e tu pc a m e r a o v c a m . w r i t e ( R E G _ C O M 7 ,0 x 0 0 ) ; / /Y U V o v c a m . w r i t e ( R E G _ C O M 1 5 ,0 x C 0 ) ; / /S e tn o r m a lr g bw i t hF u l lr a n g e o v c a m . t o g g l e ( R E G _ A B L C 1 ,N O N E ,A B L C _ E N A B L E ) ;/ /A u t ob l a c kl e v e l o v c a m . w r i t e ( R E G _ C O M 1 3 ,0 x 8 8 ) ; o v c a m . w r i t e ( R E G _ T S L B ,0 x 0 5 ) ;

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

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?

Print Page - ov7670 with both arduino uno and now mega

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

Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: drkblog on June 17, 2013, 07:49:34 pm Here is a picture taken in three stages of 640x100 pixels:

Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: Mr_arduino on June 17, 2013, 09:05:46 pm Ok I think you were configuring the output for yuv however here is what I use for yuv also I am having the same problem with raw bayer data it lacks color. Yuv is much more colorful Here is what I use for yuv422. Also the documentation for the ov7670 is very bad don't blame yourself. Although here is a newer version 1.4 that may help abit http://www.haoyuelectronics.com/Attachment/OV7670%20+%20AL422B%28FIFO%29%20Camera%20Module%28V2.0%29/OV7670%20datasheet%28V1.4%29.pdf If you noticed in the changelog of the 1.4 from 1.3 they changed the TSLB and COM13 documentation.
C ode : w r R e g ( 0 x b 0 , 0 x 8 4 ) ; / / U n d o c u m e n t e db u tw r i t i n gt h i sf i x e sc o l o r sId on o tk n o ww h y w r R e g ( R E G _ C O M 7 ,0 x 0 0 ) ; / /Y U V w r R e g ( R E G _ C O M 1 5 ,0 x C 0 ) ; / / F u l lr a n g e w r R e g ( R E G _ T S L B , 0 x 0 4 ) ; / /0 D=U Y V Y 0 4=Y U Y V w r R e g ( R E G _ C O M 1 3 , 0 x C 8 ) ; / /c o n n e c tt oR E G _ T S L B

Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: drkblog on June 17, 2013, 09:39:51 pm I keep getting the RAW data. I will keep trying tomorrow morning (it's 11:40PM here). Thank you again. Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: Mr_arduino on June 17, 2013, 10:04:11 pm Also did you look at the linux driver it has a complete register configuration which has parts based on official registers provided by omnivison http://dev.openaos.org/browser/trunk/buildroot/gen7/linux/drivers/media/video/ov7670.c Also at the bottom of the page click download as plain text to copy paste without the line numbers. And with my program are you telling it to yuv422 conversion try passing the argument '-c y' without the quotes. Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: drkblog on June 18, 2013, 08:33:51 am I'm going to check that link with the registers. I tried your program with "-c y" and "-c d". I only get a reasonable image with D (debayer). But I don't like having something like this sensor, and not be able to configure it correctly. As a mater of fact, RAW bayer could be the best choice for my project. I don't need color information and I see bayer format is one byte per pixel, which takes half space and time. Have you tried the FIFO version of this module? I'm going to buy one, because I will save a lot of space if the RAM is on the sensor itself. Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: Mr_arduino on June 18, 2013, 09:06:26 am There are several advantages of the fifo version however it is the same exact sensor the ov7670 so you will still have the same register issues.Here are some advantages of the fifo version you control when pixels are read out and you have enough ram to read the entire pixel at once. What I would do is just use the linux driver registers copy paste the entire large struct before the large struct add
C ode : s t r u c tr e g v a l _ l i s t{ u i n t 8 _ tr e g _ n u m ; u i n t 8 _ tv a l u e ; } ;

After that replace


C ode : s t a t i cs t r u c tr e g v a l _ l i s to v 7 6 7 0 _ d e f a u l t _ r e g s [ ]={

with
C ode : c o n s ts t r u c tr e g v a l _ l i s to v 7 6 7 0 _ d e f a u l t _ r e g s [ ]P R O G M E M={

Also make sure you #include <avr/pgmspace.h> and use this function to write the registers
C ode : v o i dw r S e n s o r R e g s 8 _ 8 ( c o n s ts t r u c tr e g v a l _ l i s tr e g l i s t [ ] ) { u i n t 8 _ tr e g _ a d d r , r e g _ v a l ; c o n s ts t r u c tr e g v a l _ l i s t* n e x t=r e g l i s t ; w h i l e( ( r e g _ a d d r! =0 x f f )|( r e g _ v a l! =0 x f f ) ) { r e g _ a d d r=p g m _ r e a d _ b y t e ( & n e x t > r e g _ n u m ) ; r e g _ v a l=p g m _ r e a d _ b y t e ( & n e x t > v a l u e ) ; / / w r R e g ( r e g _ a d d r ,r e g _ v a l ) ; o v c a m . w r i t e ( r e g _ a d d r , r e g _ v a l ) ; n e x t + + ; } }

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 : s t a t i cs t r u c tr e g v a l _ l i s to v 7 6 7 0 _ f m t _ y u v 4 2 2 [ ]={

And adapt it to your code Also if you want change


C ode : {R E G _ C O M 9 ,0 x 1 8} ,/ *4 xg a i nc e i l i n g ;0 x 8i sr e s e r v e db i t* /

to
C ode : {R E G _ C O M 9 ,0 x 6 A} ,/ *1 2 8 xg a i nc e i l i n g ;0 x 8i sr e s e r v e db i t* /

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.

Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: Mr_arduino on June 19, 2013, 08:59:51 pm Sorry I forgot to mention that it changes CLCK speed. I have uploaded the registers I use here https://github.com/ComputerNerd/arduino-camera-tft/blob/master/twicam.c They are pretty much the ones from the linux driver with some slight changes that may help what you described. Note that init_cam() takes one parameter uint8_t useBayer what this means is if you pass 1 to it then it will set the camera to use raw bayer data Note that when useing bayer after this function add a 200 millosecond delay and rewrite the clock value (register 0x11).pass 0 to make it use something other than bayer data. You can use setColor() to pick what you want. SetRes() sets what resolution you want. SetRes() changes the clock divider speed (register 0x11). You may need to change that. Also for setRes() and setColor() you will some of the #defines here https://github.com/ComputerNerd/arduino-camera-tft/blob/master/config.h or you could just add
C ode : # d e f i n ev g a0 # d e f i n eq v g a1 # d e f i n eq q v g a2 # d e f i n ey u v 4 2 20 # d e f i n er g b 5 6 51 # d e f i n eb a y e r R G B2

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

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

Print Page - ov7670 with both arduino uno and now mega

Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: Mr_arduino on June 19, 2013, 10:56:45 pm You could disable digital gain. For some reason your image reminds me of what digital gain enabled looks like. Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: drkblog on June 19, 2013, 11:01:02 pm Ok! I will try that tomorrow and will let you know. I have to get some sleep now :) Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: Mr_arduino on June 20, 2013, 10:00:04 am Hint to disable digital gain change register 0x74 to 0x10 I just edited the struct https://github.com/ComputerNerd/arduino-camera-tft/commit/7809cb37eb072d6325f33b6491284c6615a13bff Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: drkblog on June 20, 2013, 11:16:46 am Digital gain was disabled already. Now I'm using day light and commented the Gamma matrix setting from the linux driver code... Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: Mr_arduino on June 20, 2013, 05:07:50 pm I am glad to see that it is working well for you. Something seems different about the image noise/artifacts you posted I just cannot place my finger on it. Did you change some registers or something? Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: drkblog on June 20, 2013, 07:48:27 pm Nope. I mean, I copied the basic configuration and the YUV configuration sets, from the source you posted. Here is what I'm running:
C ode : s t a t i cs t r u c tr e g v a l _ l i s to v 7 6 7 0 _ d e f a u l t _ r e g s [ ]={ / / {R E G _ C O M 7 ,C O M 7 _ R E S E T} , / / / /C l o c ks c a l e :3=1 5 f p s / / 2=2 0 f p s / / 1=3 0 f p s {R E G _ C L K R C ,2 0} , / /O V :c l o c ks c a l e( 3 0f p s )[ 2 6f u n c i o n a ] {R E G _ T S L B , 0 x 0 4} , / /O V {R E G _ C O M 7 ,0} , / /V G A / / / /S e tt h eh a r d w a r ew i n d o w . T h e s ev a l u e sf r o mO Vd o n ' te n t i r e l y / /m a k es e n s e-h s t o pi sl e s st h a nh s t a r t . B u tt h e yw o r k . . . / / {R E G _ H S T A R T ,0 x 1 3} , {R E G _ H S T O P ,0 x 0 1} , {R E G _ H R E F ,0 x b 6} , {R E G _ V S T A R T ,0 x 0 2} , {R E G _ V S T O P ,0 x 7 a} , {R E G _ V R E F ,0 x 0 a} , {R E G _ C O M 3 ,0} , {R E G _ C O M 1 4 ,0} , / /M y s t e r ys c a l i n gn u m b e r s {0 x 7 0 ,0 x 3 a} , {0 x 7 1 ,0 x 3 5} , {0 x 7 2 ,0 x 1 1} , {0 x 7 3 ,0 x f 0} , {0 x a 2 ,0 x 0 2} , {R E G _ C O M 1 0 ,C O M 1 0 _ P C L K _ H B} ,/ /N oP C L Kd u r i n gH B L A N K / /G a m m ac u r v ev a l u e s/ / {0 x 7 a ,0 x 2 0} , {0 x 7 c ,0 x 1 e} , {0 x 7 e ,0 x 5 a} , {0 x 8 0 ,0 x 7 6} , {0 x 8 2 ,0 x 8 8} , {0 x 8 4 ,0 x 9 6} , {0 x 8 6 ,0 x a f} , {0 x 8 8 ,0 x d 7} , {0 x 7 b ,0 x 1 0} , {0 x 7 d ,0 x 3 5} , {0 x 7 f ,0 x 6 9} , {0 x 8 1 ,0 x 8 0} , {0 x 8 3 ,0 x 8 f} , {0 x 8 5 ,0 x a 3} , {0 x 8 7 ,0 x c 4} , {0 x 8 9 ,0 x e 8} ,

/ /A G Ca n dA E Cp a r a m e t e r s . N o t ew es t a r tb yd i s a b l i n gt h o s ef e a t u r e s , / /t h e nt u r nt h e mo n l ya f t e rt w e a k i n gt h ev a l u e s . {R E G _ C O M 8 ,C O M 8 _ F A S T A E C|C O M 8 _ A E C S T E P|C O M 8 _ B F I L T} , {R E G _ G A I N ,0} , {R E G _ A E C H ,0} , {R E G _ C O M 4 ,0 x 4 0} ,/ /m a g i cr e s e r v e db i t {R E G _ C O M 9 ,0 x 1 8} ,/ /4 xg a i n+m a g i cr s v db i t {R E G _ B D 5 0 M A X ,0 x 0 5} , {R E G _ B D 6 0 M A X ,0 x 0 7} , {R E G _ A E W ,0 x 9 5} , {R E G _ A E B ,0 x 3 3} , {R E G _ V P T ,0 x e 3} , {R E G _ H A E C C 1 ,0 x 7 8} , {R E G _ H A E C C 2 ,0 x 6 8} , {0 x a 1 ,0 x 0 3} ,/ /m a g i c {R E G _ H A E C C 3 ,0 x d 8} , {R E G _ H A E C C 4 ,0 x d 8} , {R E G _ H A E C C 5 ,0 x f 0} , {R E G _ H A E C C 6 ,0 x 9 0} , {R E G _ H A E C C 7 ,0 x 9 4} , {R E G _ C O M 8 ,C O M 8 _ F A S T A E C | C O M 8 _ A E C S T E P | C O M 8 _ B F I L T | C O M 8 _ A G C | C O M 8 _ A E C} , / /A l m o s ta l lo ft h e s ea r em a g i c" r e s e r v e d "v a l u e s . {R E G _ C O M 5 ,0 x 6 1} , {R E G _ C O M 6 ,0 x 4 b} , {0 x 1 6 ,0 x 0 2} , {R E G _ M V F P ,0 x 0 7} , {0 x 2 1 ,0 x 0 2} , {0 x 2 2 ,0 x 9 1} , {0 x 2 9 ,0 x 0 7} , {0 x 3 3 ,0 x 0 b} , {0 x 3 5 ,0 x 0 b} , {0 x 3 7 ,0 x 1 d} , {0 x 3 8 ,0 x 7 1} , {0 x 3 9 ,0 x 2 a} , {R E G _ C O M 1 2 ,0 x 7 8} , {0 x 4 d ,0 x 4 0} , {0 x 4 e ,0 x 2 0} , {R E G _ G F I X ,0} , {R E G _ D B L V ,0 x 0 0} , {0 x 7 4 ,0 x 1 0} , / /D V L0 x 4 A? ? {0 x 8 d ,0 x 4 f} , {0 x 8 e ,0} , {0 x 8 f ,0} , {0 x 9 0 ,0} , {0 x 9 1 ,0} , {0 x 9 6 ,0} , {0 x 9 a ,0} , {0 x b 0 ,0 x 8 4} , {0 x b 1 ,0 x 0 c} , {0 x b 2 ,0 x 0 e} , {0 x b 3 ,0 x 8 2} , {0 x b 8 ,0 x 0 a} ,

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

10/60

3/15/2014

{0 x b 3 ,0 x 8 2} ,

{0 x b 8 ,0 x 0 a} ,

Print Page - ov7670 with both arduino uno and now mega

/ /M o r er e s e r v e dm a g i c ,s o m eo fw h i c ht w e a k sw h i t eb a l a n c e {0 x 4 3 ,0 x 0 a} , {0 x 4 4 ,0 x f 0} , {0 x 4 5 ,0 x 3 4} , {0 x 4 6 ,0 x 5 8} , {0 x 4 7 ,0 x 2 8} , {0 x 4 8 ,0 x 3 a} , {0 x 5 9 ,0 x 8 8} , {0 x 5 a ,0 x 8 8} , {0 x 5 b ,0 x 4 4} , {0 x 5 c ,0 x 6 7} , {0 x 5 d ,0 x 4 9} , {0 x 5 e ,0 x 0 e} , {0 x 6 c ,0 x 0 a} , {0 x 6 d ,0 x 5 5} , {0 x 6 e ,0 x 1 1} , {0 x 6 f ,0 x 9 f} ,/ /" 9 ef o ra d v a n c eA W B " {0 x 6 a ,0 x 4 0} , {R E G _ B L U E ,0 x 4 0} , {R E G _ R E D ,0 x 6 0} , {R E G _ C O M 8 ,C O M 8 _ F A S T A E C | C O M 8 _ A E C S T E P | C O M 8 _ B F I L T | C O M 8 _ A G C | C O M 8 _ A E C | C O M 8 _ A W B} , / /M a t r i xc o e f f i c i e n t s {0 x 4 f ,0 x 8 0} , {0 x 5 0 ,0 x 8 0} , {0 x 5 1 ,0} , {0 x 5 2 ,0 x 2 2} , {0 x 5 3 ,0 x 5 e} , {0 x 5 4 ,0 x 8 0} , {0 x 5 8 ,0 x 9 e} , {R E G _ C O M 1 6 ,C O M 1 6 _ A W B G A I N} , {R E G _ E D G E ,0} , {0 x 7 5 ,0 x 0 5} , {0 x 7 6 ,0 x e 1} , {0 x 4 c ,0} , {0 x 7 7 ,0 x 0 1} , {R E G _ C O M 1 3 ,0 x c 3} , {0 x 4 b ,0 x 0 9} , {0 x c 9 ,0 x 6 0} , {R E G _ C O M 1 6 ,0 x 3 8} , {0 x 5 6 ,0 x 4 0} , {0 x 3 4 ,0 x 1 1} , {0 x a 4 ,0 x 8 8} , {0 x 9 7 ,0 x 3 0} , {0 x 9 9 ,0 x 3 0} , {0 x 9 b ,0 x 2 9} , {0 x 9 d ,0 x 4 c} , {0 x 7 8 ,0 x 0 4} , {R E G _ C O M 1 1 ,C O M 1 1 _ E X P | C O M 1 1 _ H Z A U T O | C O M 1 1 _ 5 0 H Z} , {0 x 9 6 ,0} , {0 x 9 8 ,0 x 2 0} , {0 x 9 a ,0 x 8 4} , {0 x 9 c ,0 x 0 3} , {0 x 9 e ,0 x 3 f} ,

/ /E x t r a w e i r ds t u f f . S o m es o r to fm u l t i p l e x o rr e g i s t e r {0 x 7 9 ,0 x 0 1} , {0 x c 8 ,0 x f 0} , {0 x 7 9 ,0 x 0 f} , {0 x c 8 ,0 x 0 0} , {0 x 7 9 ,0 x 1 0} , {0 x c 8 ,0 x 7 e} , {0 x 7 9 ,0 x 0 a} , {0 x c 8 ,0 x 8 0} , {0 x 7 9 ,0 x 0 b} , {0 x c 8 ,0 x 0 1} , {0 x 7 9 ,0 x 0 c} , {0 x c 8 ,0 x 0 f} , {0 x 7 9 ,0 x 0 d} , {0 x c 8 ,0 x 2 0} , {0 x 7 9 ,0 x 0 9} , {0 x c 8 ,0 x 8 0} , {0 x 7 9 ,0 x 0 2} , {0 x c 8 ,0 x c 0} , {0 x 7 9 ,0 x 0 3} , {0 x c 8 ,0 x 4 0} , {0 x 7 9 ,0 x 0 5} , {0 x c 8 ,0 x 3 0} , {0 x 7 9 ,0 x 2 6} , / * * / {0 x f f ,0 x f f} , } ;

s t a t i cs t r u c tr e g v a l _ l i s to v 7 6 7 0 _ f m t _ y u v 4 2 2 [ ]={ {R E G _ C O M 7 ,0 x 0} , / *S e l e c t sY U Vm o d e* / {R E G _ R G B 4 4 4 ,0} , / *N oR G B 4 4 4p l e a s e* / {R E G _ C O M 1 ,0} , {R E G _ C O M 1 5 ,C O M 1 5 _ R 0 0 F F} , {R E G _ C O M 9 ,0 x 1 8} ,/ *4 xg a i nc e i l i n g ;0 x 8i sr e s e r v e db i t* / {0 x 4 f ,0 x 8 0} , / *" m a t r i xc o e f f i c i e n t1 "* / {0 x 5 0 ,0 x 8 0} , / *" m a t r i xc o e f f i c i e n t2 "* / {0 x 5 1 ,0 } , / *v b* / {0 x 5 2 ,0 x 2 2} , / *" m a t r i xc o e f f i c i e n t4 "* / {0 x 5 3 ,0 x 5 e} , / *" m a t r i xc o e f f i c i e n t5 "* / {0 x 5 4 ,0 x 8 0} , / *" m a t r i xc o e f f i c i e n t6 "* / {R E G _ C O M 1 3 ,C O M 1 3 _ G A M M A | C O M 1 3 _ U V S A T} , {0 x f f ,0 x f f} , } ;

My changes are for PCLK speed only...


C ode : {R E G _ C L K R C ,2 0} , {R E G _ D B L V ,0 x 0 0} / /O V :c l o c ks c a l e( 3 0f p s )[ 2 6f u n c i o n a ]

Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: Mr_arduino on June 20, 2013, 08:51:50 pm Your problem is writting 0x38 to COM16 that is a very bad idea.It should be 0x08 instead. Here is why that is bad is because it enables edge enhancement and de-noising this sounds good but it actually makes the image worse it makes it blurry and gives it hard edges. Another problem is you left in the 4x gain ceiling. You want 128x. Check out my tweaked structs here https://github.com/ComputerNerd/arduino-camera-tft/blob/master/twicam.c Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: drkblog on June 21, 2013, 06:19:21 pm Nice! Now it's much better. I copied your values for YUV422 Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: Mr_arduino on June 21, 2013, 06:50:40 pm It does look better. No more outline on the edges. I noticed the drawing on the music stand changed colors. Is that because it is a different picture or is it because of the camera? Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: drkblog on June 21, 2013, 07:08:38 pm No, it's the same book. I guess the change in colors has to do with commenting COM13_GAMMA. I'm feeding the OV7670 with 16MHz clock from Arduino, but that implies modifying fuse configuration. How are you feeding the XCLK (clock in) of your sensor? Here is another take.

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

11/60

3/15/2014

Here is another take.

Print Page - ov7670 with both arduino uno and now mega

Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: Mr_arduino on June 21, 2013, 10:21:54 pm On the arduino uno version I am feeding it with the CLKOUT from the avr (modified fuse setting). However after I posted this topic I found an easier way to give it an 8mhz clock using pwm this is half of the 16mhz clock you are getting out right now if you modified your fuse settings On the mega vs uno it is slightly different. Here is what I have in my code for the arduino mega with tft screen version
C ode : D D R L | = 8 ; A S S R& =~ ( _ B V ( E X C L K )|_ B V ( A S 2 ) ) ; / / g e n e r a t e8 m h zc l o c k T C C R 5 A= 6 7 ; T C C R 5 B = 1 7 ; O C R 5 A=0 ;

You will have to modify this abit though. Here is what I did for the uno.
C ode : D D R B | = ( 1 < < 3 ) ; / / p i n1 1 A S S R& =~ ( _ B V ( E X C L K )|_ B V ( A S 2 ) ) ; T C C R 2 A = ( 1 < < C O M 2 A 0 ) | ( 1 < < W G M 2 1 ) | ( 1 < < W G M 2 0 ) ; / / t h i sa l s or e s u l t si n6 7b u tIw a n t e dt oc l e a nu pm a g i cn u m b e r s T C C R 2 B = ( 1 < < W G M 2 2 ) | ( 1 < < C S 2 0 ) ; O C R 2 A = 0 ;

Sorry I do not have time right now to test the arduino uno values. Also what color should the guy on the book be? Edit never mind found it on google images. I wonder why enabling gamma correction makes the image so much worse. I have encountered the same thing too. That is why I disabled gamma correction. I personally think that it is best to disable as many in camera effects as possible and instead do stuff similar to what the sensor does but better in post production. Lot of times the sensor's de-noising algorithm is not as good as what you may find on the computer. Edit2: Also when you asked about XCLK did you mean that you were interested in reading pixels faster if so here is some faster code that may help you. This code is from my original arduino uno + spi ram setup. I think this will be most relevant to you.
C ode : i n l i n ev o i ds p i C S t ( v o i d ) / / s e l e c t st h eR A Mc h i pa n dr e s e t si t { / / t o g g l e ss p iC Su s e df o rr e s e t i n gs r a m P O R T B | = 4 ; / / c sh i g h P O R T B & = ~ 4 ; / / c sl o w } i n l i n ev o i ds p i W r B ( u i n t 8 _ td a t ) { S P D R=d a t ; / /W a i tf o rt r a n s m i s s i o nc o m p l e t e w h i l e ( ! ( S P S R&( 1 < < S P I F ) ) ){ } } v o i dc a p t u r e I m g ( u i n t 1 6 _ tw s , u i n t 1 6 _ th s , u i n t 1 6 _ tw g , u i n t 8 _ th g ) { / / s k i p1m u l t i p l i e ss k i p2s a m ew i t hg e t 1a n dg e t 2 / / f i r s tw a i tf o rv s y n ci ti so np i n3( c o u n t i n gf r o m0 )p o r t D / / s t a r ts p ir a m u i n t 1 6 _ tl s 2 , l g 2 ; s p i C S t ( ) ; s p i W r B ( 2 ) ; / / s e q u e n t a lw r i t em o d e s p i W r B ( 0 ) ; / / 2 4b i ta d d r e s s s p i W r B ( 0 ) ; s p i W r B ( 0 ) ; w h i l e( ! ( P I N D & 8 ) ) { } / / w a i tf o rh i g h w h i l e( ( P I N D & 8 ) ) { } / / w a i tf o rl o w i f( h s! =0 ) { w h i l e( h s ) { l s 2 = w s ; w h i l e( l s 2 ) { w h i l e( ( P I N D & 4 ) ){ } / / w a i tf o rl o w w h i l e( ! ( P I N D & 4 ) ){ } / / w a i tf o rh i g h } } } w h i l e( h g ) { l g 2 = w g ; w h i l e( l g 2 ) { w h i l e( ( P I N D & 4 ) ){ } / / w a i tf o rl o w S P D R = ( P I N C & 1 5 ) | ( P I N D & 2 4 0 ) ; w h i l e( ! ( P I N D & 4 ) ){ } / / w a i tf o rh i g h } } }

Here is how to enable spi at maximum speed


C ode : / / e n a b l es p i S P C R = 8 0 ; / / s p ie n a b l em a s t e r S P S R = 1 ; / / d o u b l es p e e d

To read the full 640x480 image do this


C ode : c a p t u r e I m g ( 0 , 0 , 1 2 8 0 , 9 6 ) ; / / e a c hp i x e li s2b y t e ss o1 2 8 0i n s t e a do f6 4 0f o rw i d t h s e n d R a m ( 1 2 8 0 , 9 6 ) ; c a p t u r e I m g ( 1 2 8 0 , 9 6 , 1 2 8 0 , 9 6 ) ; s e n d R a m ( 1 2 8 0 , 9 6 ) ; c a p t u r e I m g ( 1 2 8 0 , 1 9 2 , 1 2 8 0 , 9 6 ) ; s e n d R a m ( 1 2 8 0 , 9 6 ) ; c a p t u r e I m g ( 1 2 8 0 , 2 8 8 , 1 2 8 0 , 9 6 ) ; s e n d R a m ( 1 2 8 0 , 9 6 ) ; c a p t u r e I m g ( 1 2 8 0 , 3 8 4 , 1 2 8 0 , 9 6 ) ; s e n d R a m ( 1 2 8 0 , 9 6 ) ;

The sendRam function just sends the image to the computer


C ode : v o i ds e n d R a m ( u i n t 1 6 _ tw , u i n t 1 6 _ th ) { s p i C S t ( ) ; s p i W r B ( 3 ) ; / / s e q u e n t a lr e a dm o d e s p i W r B ( 0 ) ; / / 2 4b i ta d d r e s s s p i W r B ( 0 ) ; s p i W r B ( 0 ) ; u i n t 1 6 _ tw l , h l ; f o r( h l = 0 ; h l < h ; + + h l ) { f o r( w l = 0 ; w l < w ; + + w l ) { w h i l e(! (U C S R 0 A&( 1 < < U D R E 0 ) )){ }/ / w a i tf o rb y t et ot r a n s m i t S P D R = 0 ; / / s e n dd u m m yv a l u et og e tb y t eb a c k w h i l e ( ! ( S P S R&( 1 < < S P I F ) ) ){ } U D R 0 = S P D R ; } } w h i l e(! (U C S R 0 A&( 1 < < U D R E 0 ) )){ }/ / w a i tf o rb y t et ot r a n s m i t

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

Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: drkblog on June 22, 2013, 11:40:50 am Well. That's pretty much what I'm doing right now. But, with the 16MHz clock. During the initial tests I tried the "software" clock but later I found out the sensor datasheet said the minimum clock had to be 10MHz. Now I see it works with 8MHz too. At that moment I had other problems and blamed the clock. So I went to the 16MHz again, and I made it work using that clock, in the end. I have to use a divider of at least 20 for the PCLK out put, or else I'm unable to read the image. That makes sense, because I'm using a 16MHz clock, so dividing by 20 in my scheme is like dividing by 10 in your case. Right now I left the sensor because I have to go on with another part of my project. With the tests I've made I know I will be able to meet the requirements. All I need is to take gray scale images at five FPS, maybe eight FPS but no more, for the space of five seconds. I'll be using the FIFO version and will store the frames on an SD card. I'm going to use the ArduinoMEGA instead of the UNO version. Because I ran out of digital outputs now. Most probably I will be back here, within a couple of weeks, as I start testing it again with the ArduinoMEGA and the FIFO version of the sensor. :) Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: Mr_arduino on June 22, 2013, 12:37:00 pm You can go faster than 20. I got 8 in the old 16mhz version. Also once the fifo version arives you will not have to worry about the XCLK because it has a built in one and you can read at any speed you want. I think your goal of 5-8fps is possible but I do not currently own the fifo version I got another sensor to play with right now the MT9D111 it outputs jpeg data but it does not any fifo versions and I am going to try to get it to work with my raspberry pi anyways as it is much faster. Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: drkblog on June 22, 2013, 12:57:50 pm I'm trying to stay within the Arduino because I have already solved other requirements with it. And it would be a lot of work migrating other stuff to Raspberry Pi, for example. I want to keep this as simple as possible, also. Raspberry Pi is awesome but it's a complexity level above Arduino, you have a whole operating system there, as far as I know. And that leads to some side effects. So, for this project I'm trying to stay in this platform, even knowing that Raspberry would solve the camera issue with ease. Anyway, I would like to know whatever comes out of your testing. You never know when you will have to implement the Plan B. :) Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: Mr_arduino on June 22, 2013, 01:30:52 pm The problem with the raspberry pi is interrupts the arduino has nothing going other than what the program does. Also the arduino takes less power and does not get hot. For MT9D11 that I am working on I have tried getting it to work but I keep missing pixels. I will have to write a linux driver that way I can disable interrupts while taking the picture but I still have a whiles away to go before doing that. Also what I meant by my previous post is that I do not have the fifo version as I already have enough sensors to play with though I am still willing to help with the fifo version. But I think your goal of 5-8fps is possible. Using sdfatlib you get write to the sd card really fast if you create a contiguous file first then using the writeData() function that saves 512 bytes at a time. Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: drkblog on June 22, 2013, 06:09:11 pm Yes. I read the program you wrote, which creates the contiguous block first, the writes down the information. I don't even have to worry about the format, as I will have to write the software which is going to read the SD on the PC for downloading information from my device. That will save me some overhead that could have if I were to write an AVI or MPEG file. I will post here as soon as I start testing the FIFO version. By the way, where are you from? Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: Mr_arduino on June 22, 2013, 07:05:37 pm I am from the USA. Why do you ask is it related to my posting abilities? I did just notice a mistake in my previous post that made it not make sense. Also speaking of contiguous files actually creating the contiguous file is slow so try creating a big file then re-sizing it. Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: drkblog on June 22, 2013, 07:38:57 pm haha no, I just asked out of curiosity. Don't worry I didn't see any non-sense in your posts. And, in the end, It's a forum. We aren't writing a book here :) Besides, knowing the place you are from, I have an idea how easy is to access technology for you. For example, here in Argentina it is hard to get some components. I had to buy the RAM 23LC1024 at Mouser in USA and send it to a friend who was vacationing in Boston. So he brought it back here. Otherwise I would have paid 100USD shipping for an order of 20 bucks, which is senseless. Fortunately, we have a several big shops here were you can find a lot of stuff. Even some rare pieces. But there is some stuff we have to buy in USA, Hong Kong, China. Specially for testing purposes. Title: Re: arduino uno + ov7670 (vga cmos sensor) = awesome Post by: Mr_arduino on June 22, 2013, 08:06:56 pm International shipping can be expensive It is annoying when shipping cost make up a high percentage of the order. Lots of chinese ebay sellers offer free shipping is that you mean by buying from Hong Kong? I do that alot for modules also they have much better deals on zif sockets. Title: Re: ov7670 with both arduino uno and now mega Post by: xKoldFuzionx on July 10, 2013, 11:37:14 pm I'm new to all this electronics stuff and finally coming to terms with my inner nerd. Lol, I've fallen in love with the idea of creating things that anyone can use . I bought an ov7670 on ebay a few weeks back and after reading this thread, I'm completely in the dark. So, I was hoping you could shed some light on some things for me? Obviously, you're using C to code all this, but do you know of any tutorials that will help me learn about registers? I get that you call them with hex, though hex and bin math are way over my head, I kinda sorta follow it. Im absorbing as much as i can through google/wikipedia as often as i can and picking up any book i can find on arduino and coding it. I understand the basics of it and it feels very comfortable, so switching over to C right now would be a bit much.

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

try to understand why the transistor do this. At least by now. Yes, logic is implemented in circuits using 5V or zero volt. But that's a convention and depends whether you are using TTL or CMOS, you can use a different value, like 3.3V (very common today). And you can't easily mix this kind of signals, if you connect a 5V output to a 3.3V input you will likely damage the device. Unless otherwise stated in the datasheet. Logical gates are predecessors to microprocessors, but of course, they are widely used today. Again, you have to learn its behavior as an enclosed unit. You don't need to learn how they work inside. If you have an two-input AND gate, you will get a 1 at the output if and only if you have 1 at the two inputs. A practical use could be: "You have a digital output from arduino and another digital output from a light sensor. You have a 1 from the sensor if there is light detected. And you want to turn a LED on and off according to the sensor BUT, you want to turn the LED off from the Arduni at any given time. If you connect the led to the sensor it will work all the time, and Arduni won't be able to turn the LED off. Then you place a AND gate connecting the sensor and the arduino output to its input and the LED to the gate output. Now, if the Arduino output is 1, the LED will turn on and off according to the sensor. But if Arudino's output is 0, then the LED will be off no matter if the sensor outputs a 1 or a 0". You can connect the module you bought according to the circuits and code from this post. Making it work isn't easy anyway. And you are working with a 3.3V module, so be careful about the outputs from Arduino going into the camera inputs. You could damage the sensor forever. If money is an issue, I would recommend you start playing with cheaper stuff. So you can understand what you are doing. And you start by breaking cheaper things. It's really unusual you start learning electronics without burning some stuff. Do you have an oscilloscope? Title: Re: ov7670 with both arduino uno and now mega Post by: xKoldFuzionx on July 11, 2013, 02:50:11 pm Ok, I understand that, but with an Arduino, why would I ever need to use a transistor or a gate. Through code, I can program the same actions. For instance:
Q uote if ((12 == HIGH) && (10 == HIGH)) { digitalW rite (13, HIGH); } e lse { digitalW rite (13, LO W ); }

[/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
Hey all,

Print Page - ov7670 with both arduino uno and now mega

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 : w r i t e R e g ( 0 x 1 5 ,3 2 ) ; / /P C L Kd o e sn o tt o g g l eo nH B L A N KC O M 1 0v s y n cf a l l i n g w r i t e R e g ( R E G _ T S L B ,0 x 0 4 ) ;/ /0 D=U Y V Y ,0 4=Y U Y V w r i t e R e g ( R E G _ C O M 1 3 ,0 x 8 8 ) ;/ /w i t hR E G _ T S L B w r i t e R e g ( R E G _ C O M 7 ,0 x 0 8 ) ; w r i t e R e g ( R E G _ C O M 1 7 ,0 x 0 0 ) ; w r i t e R e g ( R E G _ C O M 1 5 ,0 x C 0 ) ; w r i t e R e g ( R E G _ C O M 3 ,0 x 0 8 ) ;

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

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

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 : v o i dc a p t u r e C h u n k ( u n s i g n e dl o n gw a i t ,u n s i g n e dl o n gc h u n k ,u i n t 8 _ t* p i x e l s ){ u n s i g n e di n tn=0 ; w h i l e ( ! ( P I N D&8 ) ){ }/ /W a i tf o rV S Y N Ch i g h w h i l e ( P I N D&8 ){ }/ /W a i tf o rV S Y N Cl o w w h i l e ( w a i t ){ w h i l e ( ! ( P I N D&4 ) ){ } ; w h i l e ( P I N D&4 ){ } ; } w h i l e ( c h u n k ){ w h i l e ( ! ( P I N D&4 ) ){ } ; p i x e l s [ n + + ]=( u i n t 8 _ t ) ( ( P I N C&0 x 0 F )|( P I N D&0 x F 0 ) ) ; w h i l e ( P I N D&4 ){ } ; } / / . . . .w r i t et os e r i a l }

@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 : W i r e . b e g i n T r a n s m i s s i o n ( s e n s o r _ a d d r> >1 ) ; W i r e . w r i t e ( 0 x 0 1&0 x 0 0 F F ) ; S e r i a l . p r i n t l n ( W i r e . e n d T r a n s m i s s i o n ( ) ) ;

Also, the following code (which sampullman provided) returns the address of the register instead of the actual value stored inside the register:
C ode : # i n c l u d e< W i r e . h > u i n t 8 _ ts e n s o r _ a d d r=0 x 4 2 ; v o i ds e t u p ( ) { W i r e . b e g i n ( ) ; S e r i a l . b e g i n ( 1 1 5 2 0 0 ) ; } v o i dl o o p ( ) { u i n t 8 _ t *d a t ; r e a d R e g 8 ( 0 x 0 1 ,d a t ) ; S e r i a l . p r i n t l n ( * d a t ) ; d e l a y ( 1 0 0 0 ) ; } / *W r i t e2b y t ev a l u er e g D a tt ot h ec a m e r ar e g i s t e ra d d r e s s e db yr e g I D* / b y t ew r i t e R e g ( i n tr e g I D ,i n tr e g D a t ){ W i r e . b e g i n T r a n s m i s s i o n ( s e n s o r _ a d d r> >1 ) ; W i r e . w r i t e ( r e g I D&0 x 0 0 F F ) ; W i r e . w r i t e ( r e g D a t&0 x 0 0 F F ) ; b y t er e s u l t=W i r e . e n d T r a n s m i s s i o n ( ) ; d e l a y ( 1 ) ; r e t u r nr e s u l t ; } / *R e a da2b y t ev a l u ef r o mt h ec a m e r aa d d r e s s e da tr e g I D ,a n ds t o r ei ta t *m e m o r yl o c a t i o np o i n t e dt ob yr e g D a t .R e t u r n1o ns u c c e s s ,0o nf a i l u r e .* / b y t er e a d R e g 8 ( u i n t 8 _ tr e g I D ,u i n t 8 _ t *r e g D a t ){ W i r e . b e g i n T r a n s m i s s i o n ( s e n s o r _ a d d r> >1 ) ; W i r e . w r i t e ( r e g I D&0 x 0 0 F F ) ;

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

17/60

3/15/2014
W i r e . e n d T r a n s m i s s i o n ( ) ; W i r e . r e q u e s t F r o m ( ( s e n s o r _ a d d r> >1 ) , 1 ) ; i f ( W i r e . a v a i l a b l e ( ) ){ * r e g D a t=W i r e . r e a d ( ) ; d e l a y ( 1 ) ; r e t u r n1 ; }e l s e{ r e t u r n0 ; } }

Print Page - ov7670 with both arduino uno and now mega

Could you please give me a hand? Title: Re: ov7670 with both arduino uno and now mega Post by: Mr_arduino on July 17, 2013, 12:49:30 pm Actully my latest code does not use the wire library see https://github.com/ComputerNerd/arduino-camera-tft/blob/master/twicam.c or if you feel the need to use the Wire library my very old code uses it see http://pastebin.com/1nnRc5qL Also the ov7670 is picky about which pullup resitors you use. I found that 4.7k and 10k work but 1k and 2.2k do NOT work. And make sure that you are using the pullup resistor to 3.3v and if you use the Wire library you must edit twi.c which is located in (arduino ide folder)/libraries/Wire/Utility And remove these lines:
C ode : / /a c t i v a t ei n t e r n a lp u l l u p sf o rt w i . d i g i t a l W r i t e ( S D A ,1 ) ; d i g i t a l W r i t e ( S C L ,1 ) ;

By not doing that you could damage the ov7670 although when I first got the ov7670 I made the mistake of not removing those lines and nothing happened however your millage may vary. After removing those lines be sure to recompile your program. Title: Re: ov7670 with both arduino uno and now mega Post by: giantsfan3 on 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 : T W S R& =~ 3 ;/ /D i s a b l eT W Ip r e s c a l e r T W B R=7 2 ;/ /C L O C K/( 1 6+2 * T W B R * P r e s c a l e r )

This should set up the wire library to transmit at ~100Khz. Other than that, it's important to follow Mr_arduino's advice for disabling the internal pull up resistors for twi. You need to add your own (4.7Kohm or 10k should work like he said) to pull up to 3.3v instead of 5v. I still haven't pulled a reasonable image off the module, but hopefully with some external spi ram coming in today and switching from QCIF to QQVGA I'll have better luck. Title: Re: ov7670 with both arduino uno and now mega Post by: Mr_arduino on July 18, 2013, 08:12:35 pm I have the same values here that sampullman posted. https://github.com/ComputerNerd/arduino-camera-tft/blob/master/main.c Also if you are using my register read and write code you don't want to use Wire.begin() if you are using the wire library you don't need to use the code that sampullman posted (I think). Title: Re: ov7670 with both arduino uno and now mega

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

18/60

3/15/2014
Title: Re: ov7670 with both arduino uno and now mega Post by: Mr_arduino on July 24, 2013, 06:23:54 pm

Print Page - ov7670 with both arduino uno and now mega

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 : / /a c t i v a t ei n t e r n a lp u l l u p sf o rt w i . d i g i t a l W r i t e ( S D A ,1 ) ; d i g i t a l W r i t e ( S C L ,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

I'm trying to get an YUV frame. These are relevant registers:


C ode : / / {R E G _ C O M 7 ,C O M 7 _ R E S E T} , / / / /C l o c ks c a l e :3=1 5 f p s / / 2=2 0 f p s / / 1=3 0 f p s {R E G _ C L K R C ,0 x 8 0 } , / /O V :c l o c ks c a l e( 3 0f p s )[ 2 6f u n c i o n a ] {R E G _ T S L B , T S L B _ Y V Y U} , {R E G _ C O M 7 ,C O M 7 _ R G B _ Y U V} ,/ /Y U VV G A / / / /S e tt h eh a r d w a r ew i n d o w . T h e s ev a l u e sf r o mO Vd o n ' te n t i r e l y / /m a k es e n s e-h s t o pi sl e s st h a nh s t a r t . B u tt h e yw o r k . . . / / {R E G _ H S T A R T ,0 x 1 3} ,{R E G _ H S T O P ,0 x 0 1} , {R E G _ H R E F ,0 x b 6} ,{R E G _ V S T A R T ,0 x 0 2} , {R E G _ V S T O P ,0 x 7 a} , {R E G _ V R E F ,0 x 0 a} , {R E G _ C O M 3 ,0} , {R E G _ C O M 1 4 ,0} , / /M y s t e r ys c a l i n gn u m b e r s {0 x 7 0 ,0 x 3 a} , {0 x 7 1 ,0 x 3 5} , {0 x 7 2 ,0 x 1 1} , {0 x 7 3 ,0 x f 0} , {0 x a 2 ,0 x 0 2} , {R E G _ C O M 1 0 ,0 x 0 0} ,/ /U s a rC O M 1 0 _ P C L K _ H Bp a r af r e n a re lc l o c ke ne lb l a n k . . . . . . s t a t i cs t r u c tr e g v a l _ l i s to v 7 6 7 0 _ f m t _ y u v 4 2 2 [ ]={ {R E G _ C O M 7 ,C O M 7 _ R G B _ Y U V} , / *S e l e c t sY U Vm o d e* / {R E G _ C O M 1 7 ,C O M 1 7 _ D S P _ C O L O R B A R} , {R E G _ R G B 4 4 4 ,0} , / *N oR G B 4 4 4p l e a s e* / {R E G _ C O M 1 ,0} , {R E G _ C O M 1 5 ,C O M 1 5 _ R A N G E _ T O F F} ,/ /O J O {R E G _ C O M 9 ,0 x 6 A} ,/ *1 2 8 xg a i nc e i l i n g ;* / {0 x 4 f ,0 x 8 0} , / *" m a t r i xc o e f f i c i e n t1 "* / {0 x 5 0 ,0 x 8 0} , / *" m a t r i xc o e f f i c i e n t2 "* / {0 x 5 1 ,0 } , / *v b* / {0 x 5 2 ,0 x 2 2} , / *" m a t r i xc o e f f i c i e n t4 "* / {0 x 5 3 ,0 x 5 e} , / *" m a t r i xc o e f f i c i e n t5 "* / {0 x 5 4 ,0 x 8 0} , / *" m a t r i xc o e f f i c i e n t6 "* / {R E G _ C O M 1 3 ,/ * C O M 1 3 _ G A M M A | * / C O M 1 3 _ U V S A T} , {0 x f f ,0 x f f} , } ;

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
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

Print Page - ov7670 with both arduino uno and now mega

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
C ode : { 0 x 3 0 , 0 } , { 0 x 3 1 , 0 } , / / d i s a b l es o m ed e l a y s

Print Page - ov7670 with both arduino uno and now mega

What it does is remove a delay in HSYNC raising and falling. Try removing those two registers. This is in the struct format {register,value} if you are storing registers in a different order take note of the above. Title: Re: ov7670 with both arduino uno and now mega Post by: drkblog on October 12, 2013, 09:41:38 am Nope. I mean, I have that line (I'm using the register configuration from your github repo) but nothing changes if I comment that out. In my circuit I have another potential issue: as I'm running under Linux there is a chance that my program run out of CPU time during the FIFO reading. If that happens I'll get a broken image. I haven't thought of a way of telling when that happens. If I get random unsynced images, it must be the CPU issue. If the unsynced images are consistent with something (like pointing to a light) then it must be something else. I'm attaching two pictures: Both images point to the window but in ventana-oos.png the window occupies the while picture. I guess that results in lines of white, which in turn end up getting the FIFO out of sync during write (somehow). I tried changing the clock register to something else than 0x80. But it doesn't help with this problem, and messes up the other cases where I'm getting the good ones. Title: Re: ov7670 with both arduino uno and now mega Post by: Mr_arduino on October 14, 2013, 07:43:47 pm I think you are correct linux, the kernel may be to blame. With linux, the kernel there are various interupts for various things running in the background such as redrawing the screen and other stuff. What you may need to do is write a linux kernel module so that you can disable interrupts while reading the the pixels data. I really wish I can find time to try this myself. Title: Re: ov7670 with both arduino uno and now mega Post by: drkblog on October 14, 2013, 09:13:50 pm Creating a Linux kernel module is a lot of work. Specially because any error results in having to reboot. I'm going to do it eventually. Right now I'm using some tricks to induce the kernel to let my program run during the critical stages of execution. For example I specifically give up the CPU right before reading the ov7670. That way I reduce the chances of losing it for timeout. And it works pretty well. Of course it's not a real solution, but I can go with it by now. Title: Re: ov7670 with both arduino uno and now mega Post by: Mr_arduino on October 15, 2013, 05:40:38 pm Alright that makes sense anyways I hope that this weekend I can find time to write my own kernel module yes it is lots of work. I have never wrote a module before but I think it is good experience to have. Also I fixed Bi-linear demosaicing in my converter program the quality is slightly better. Title: Re: ov7670 with both arduino uno and now mega Post by: NEPRIBE on October 16, 2013, 04:40:31 pm hi! i am a beginner in this topic so i would like receive some advice about OV7670+arduino uno. I have a OV7670 device without FIFO. Also, I have a SD. Nowadays I generated a 8MHz signal and i introduce its in XCLK. I obtained the principal signal (VSYN,HREF,D0-D7). So my main problem is that i don't sure how to put the data(D0-D7) on the SD. On the other hand, I tried to used the code that you posted : #include <Wire.h> #include <SdFat.h> #include <SdFatUtil.h> // file system uint8_t buf2[512]; SdFat sd; //uint8_t* buf; // test file SdFile file; // SD chip select pin const uint8_t chipSelect = 9; uint8_t sensor_addr = 0x42; ..... But when i compile i recieved the following error: void readImgSerial(uint16_t, uint16_t): invalid conversion from const char* to char* However i don't sure how to correct that. I hope some advice. Thanks!

Title: Re: ov7670 with both arduino uno and now mega Post by: drkblog on 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

program and it should fix your issue. Also was that the whole error log if not please post the entire error log.

Print Page - ov7670 with both arduino uno and now mega

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
Title: Re: ov7670 with both arduino uno and now mega Post by: drkblog on October 28, 2013, 10:57:37 am

Print Page - ov7670 with both arduino uno and now mega

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
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?

Print Page - ov7670 with both arduino uno and now mega

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 : s t a t i cs t r u c tr e g v a l _ l i s to v 7 6 7 0 _ d e f a u l t _ r e g s [ ]={ / / {R E G _ C O M 7 ,C O M 7 _ R E S E T} , / / / /C l o c ks c a l e :3=1 5 f p s / / 2=2 0 f p s / / 1=3 0 f p s {R E G _ C L K R C ,0 x 8 0} , / /O V :c l o c ks c a l e( 3 0f p s )[ 2 6f u n c i o n a ] {R E G _ T S L B , T S L B _ Y V Y U} , / /O V {R E G _ C O M 7 ,C O M 7 _ R G B _ Y U V} , / /Y U VV G A {R E G _ C O M 1 7 ,C O M 1 7 _ D S P _ C O L O R B A R} , / / / /S e tt h eh a r d w a r ew i n d o w . T h e s ev a l u e sf r o mO Vd o n ' te n t i r e l y / /m a k es e n s e-h s t o pi sl e s st h a nh s t a r t . B u tt h e yw o r k . . . / / {R E G _ H S T A R T ,0 x 1 3} , {R E G _ H S T O P ,0 x 0 1} , {R E G _ H R E F ,0 x b 6} , {R E G _ V S T A R T ,0 x 0 2} , {R E G _ V S T O P ,0 x 7 a} , {R E G _ V R E F ,0 x 0 a} , {R E G _ C O M 3 ,0} , {R E G _ C O M 1 4 ,0} , / /M y s t e r ys c a l i n gn u m b e r s {0 x 7 0 ,0 x 3 a} , {0 x 7 1 ,0 x 3 5} , {0 x 7 2 ,0 x 1 1} , {0 x 7 3 ,0 x f 0} , {0 x a 2 ,0 x 0 2} , {R E G _ C O M 1 0 ,0 x 0 0} ,/ /U s a rC O M 1 0 _ P C L K _ H Bp a r af r e n a re lc l o c ke ne lb l a n k / /G a m m ac u r v ev a l u e s/ / {0 x 7 a ,0 x 2 0} , {0 x 7 c ,0 x 1 e} , {0 x 7 e ,0 x 5 a} , {0 x 8 0 ,0 x 7 6} , {0 x 8 2 ,0 x 8 8} , {0 x 8 4 ,0 x 9 6} , {0 x 7 b ,0 x 1 0} , {0 x 7 d ,0 x 3 5} , {0 x 7 f ,0 x 6 9} , {0 x 8 1 ,0 x 8 0} , {0 x 8 3 ,0 x 8 f} , {0 x 8 5 ,0 x a 3} ,

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

28/60

3/15/2014
{0 x 8 4 ,0 x 9 6} , {0 x 8 6 ,0 x a f} , {0 x 8 8 ,0 x d 7} , {0 x 8 5 ,0 x a 3} , {0 x 8 7 ,0 x c 4} , {0 x 8 9 ,0 x e 8} ,

Print Page - ov7670 with both arduino uno and now mega

/ /A G Ca n dA E Cp a r a m e t e r s . N o t ew es t a r tb yd i s a b l i n gt h o s ef e a t u r e s , / /t h e nt u r nt h e mo n l ya f t e rt w e a k i n gt h ev a l u e s . {R E G _ C O M 8 ,C O M 8 _ F A S T A E C|C O M 8 _ A E C S T E P|C O M 8 _ B F I L T} , {R E G _ G A I N ,0} , {R E G _ A E C H ,0} , {R E G _ C O M 4 ,0 x 4 0} ,/ /m a g i cr e s e r v e db i t {R E G _ C O M 9 ,0 x 1 8} ,/ /4 xg a i n+m a g i cr s v db i t {R E G _ B D 5 0 M A X ,0 x 0 5} , {R E G _ B D 6 0 M A X ,0 x 0 7} , {R E G _ A E W ,0 x 9 5} , {R E G _ A E B ,0 x 3 3} , {R E G _ V P T ,0 x e 3} , {R E G _ H A E C C 1 ,0 x 7 8} , {R E G _ H A E C C 2 ,0 x 6 8} , {0 x a 1 ,0 x 0 3} ,/ /m a g i c {R E G _ H A E C C 3 ,0 x d 8} , {R E G _ H A E C C 4 ,0 x d 8} , {R E G _ H A E C C 5 ,0 x f 0} , {R E G _ H A E C C 6 ,0 x 9 0} , {R E G _ H A E C C 7 ,0 x 9 4} , {R E G _ C O M 8 ,C O M 8 _ F A S T A E C | C O M 8 _ A E C S T E P | C O M 8 _ B F I L T | C O M 8 _ A G C | C O M 8 _ A E C} , / /A l m o s ta l lo ft h e s ea r em a g i c" r e s e r v e d "v a l u e s . {R E G _ C O M 5 ,0 x 6 1} , {R E G _ C O M 6 ,0 x 4 b} , {0 x 1 6 ,0 x 0 2} , {R E G _ M V F P ,0 x 0 7} , {0 x 2 1 ,0 x 0 2} , {0 x 2 2 ,0 x 9 1} , {0 x 2 9 ,0 x 0 7} , {0 x 3 3 ,0 x 0 b} , {0 x 3 5 ,0 x 0 b} , {0 x 3 7 ,0 x 1 d} , {0 x 3 8 ,0 x 7 1} , {0 x 3 9 ,0 x 2 a} , {R E G _ C O M 1 2 ,0 x 7 8} , {0 x 4 d ,0 x 4 0} , {0 x 4 e ,0 x 2 0} , {R E G _ G F I X ,0} , {R E G _ D B L V ,0 x 4 A} , {0 x 7 4 ,0 x 1 0} , / /D V L0 x 4 A? ?0 x 0 4 {0 x 8 d ,0 x 4 f} , {0 x 8 e ,0} , {0 x 8 f ,0} , {0 x 9 0 ,0} , {0 x 9 1 ,0} , {0 x 9 6 ,0} , {0 x 9 a ,0} , {0 x b 0 ,0 x 8 4} , {0 x b 1 ,0 x 0 c} , {0 x b 2 ,0 x 0 e} , {0 x b 3 ,0 x 8 2} , {0 x b 8 ,0 x 0 a} , / /M o r er e s e r v e dm a g i c ,s o m eo fw h i c ht w e a k sw h i t eb a l a n c e {0 x 4 3 ,0 x 0 a} , {0 x 4 4 ,0 x f 0} , {0 x 4 5 ,0 x 3 4} , {0 x 4 6 ,0 x 5 8} , {0 x 4 7 ,0 x 2 8} , {0 x 4 8 ,0 x 3 a} , {0 x 5 9 ,0 x 8 8} , {0 x 5 a ,0 x 8 8} , {0 x 5 b ,0 x 4 4} , {0 x 5 c ,0 x 6 7} , {0 x 5 d ,0 x 4 9} , {0 x 5 e ,0 x 0 e} , {0 x 6 c ,0 x 0 a} , {0 x 6 d ,0 x 5 5} , {0 x 6 e ,0 x 1 1} , {0 x 6 f ,0 x 9 f} ,/ /" 9 ef o ra d v a n c eA W B " {0 x 6 a ,0 x 4 0} , {R E G _ B L U E ,0 x 4 0} ,/ /0 x 4 0 {R E G _ R E D ,0 x 6 0} , {R E G _ C O M 8 ,C O M 8 _ F A S T A E C | C O M 8 _ A E C S T E P | C O M 8 _ B F I L T | C O M 8 _ A G C | C O M 8 _ A E C | C O M 8 _ A W B} , / /M a t r i xc o e f f i c i e n t s {0 x 4 f ,0 x 8 0} , {0 x 5 0 ,0 x 8 0} , {0 x 5 1 ,0} , {0 x 5 2 ,0 x 2 2} , {0 x 5 3 ,0 x 5 e} , {0 x 5 4 ,0 x 8 0} , {0 x 5 8 ,0 x 9 e} , {R E G _ C O M 1 6 ,C O M 1 6 _ A W B G A I N} , {R E G _ E D G E ,0} , {0 x 7 5 ,0 x 0 5} , {0 x 7 6 ,0 x e 1} , {0 x 4 c ,0} , {0 x 7 7 ,0 x 0 1} , {R E G _ C O M 1 3 ,0 x c 3} , {0 x 4 b ,0 x 0 9} , {0 x c 9 ,0 x 6 0} , / * {R E G _ C O M 1 6 ,0 x 3 8} , * / {0 x 5 6 ,0 x 4 0} , {0 x 3 4 ,0 x 1 1} , {0 x a 4 ,0 x 8 8} , {0 x 9 7 ,0 x 3 0} , {0 x 9 9 ,0 x 3 0} , {0 x 9 b ,0 x 2 9} , {0 x 9 d ,0 x 4 c} , {0 x 7 8 ,0 x 0 4} , {R E G _ C O M 1 1 ,C O M 1 1 _ E X P | C O M 1 1 _ H Z A U T O | C O M 1 1 _ 5 0 H Z} , {0 x 9 6 ,0} , {0 x 9 8 ,0 x 2 0} , {0 x 9 a ,0 x 8 4} , {0 x 9 c ,0 x 0 3} , {0 x 9 e ,0 x 3 f} ,

/ /E x t r a w e i r ds t u f f . S o m es o r to fm u l t i p l e x o rr e g i s t e r {0 x 7 9 ,0 x 0 1} , {0 x c 8 ,0 x f 0} , {0 x 7 9 ,0 x 0 f} , {0 x c 8 ,0 x 0 0} , {0 x 7 9 ,0 x 1 0} , {0 x c 8 ,0 x 7 e} , {0 x 7 9 ,0 x 0 a} , {0 x c 8 ,0 x 8 0} , {0 x 7 9 ,0 x 0 b} , {0 x c 8 ,0 x 0 1} , {0 x 7 9 ,0 x 0 c} , {0 x c 8 ,0 x 0 f} , {0 x 7 9 ,0 x 0 d} , {0 x c 8 ,0 x 2 0} , {0 x 7 9 ,0 x 0 9} , {0 x c 8 ,0 x 8 0} , {0 x 7 9 ,0 x 0 2} , {0 x c 8 ,0 x c 0} , {0 x 7 9 ,0 x 0 3} , {0 x c 8 ,0 x 4 0} , {0 x 7 9 ,0 x 0 5} , {0 x c 8 ,0 x 3 0} , {0 x 7 9 ,0 x 2 6} , / * * / {0 x f f ,0 x f f} , } ; / * *H e r ew e ' l lt r yt oe n c a p s u l a t et h ec h a n g e sf o rj u s tt h eo u t p u t *v i d e of o r m a t . * *R G B 6 5 6a n dY U V 4 2 2c o m ef r o mO V ;R G B 4 4 4i sh o m e b r e w e d . * *I M P O R T A N TR U L E :t h ef i r s te n t r ym u s tb ef o rC O M 7 ,s e eo v 7 6 7 0 _ s _ f m tf o rw h y . * / s t a t i cs t r u c tr e g v a l _ l i s to v 7 6 7 0 _ f m t _ y u v 4 2 2 [ ]={ {R E G _ C O M 7 ,0 x 0} , / *S e l e c t sY U Vm o d e* / {R E G _ R G B 4 4 4 ,0} , / *N oR G B 4 4 4p l e a s e* / {R E G _ C O M 1 ,0} , {R E G _ C O M 1 5 ,C O M 1 5 _ R A N G E _ T O F F} ,/ /O J O {R E G _ C O M 9 ,0 x 6 A} ,/ *1 2 8 xg a i nc e i l i n g ;* / {0 x 4 f ,0 x 8 0} , / *" m a t r i xc o e f f i c i e n t1 "* / {0 x 5 0 ,0 x 8 0} , / *" m a t r i xc o e f f i c i e n t2 "* / {0 x 5 1 ,0 } , / *v b* / {0 x 5 2 ,0 x 2 2} , / *" m a t r i xc o e f f i c i e n t4 "* / {0 x 5 3 ,0 x 5 e} , / *" m a t r i xc o e f f i c i e n t5 "* / {0 x 5 4 ,0 x 8 0} , / *" m a t r i xc o e f f i c i e n t6 "* / {R E G _ C O M 1 3 ,/ * C O M 1 3 _ G A M M A | * / C O M 1 3 _ U V S A T} , {0 x f f ,0 x f f} , } ;

Title: Re: ov7670 with both arduino uno and now mega Post by: Mr_arduino on November 22, 2013, 03:44:33 pm

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

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

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 : # i n c l u d e< W i r e . h > # i n c l u d e< V G A . h > # i n c l u d e< O v 7 6 7 0 . h > O v 7 6 7 0o v 7 6 7 0 ; v o l a t i l eu n s i g n e di n tp i x e l C o u n t ,l i n e C o u n t ; b o o l e a ns t a r t L i n e , s t a r t F r a m e ; b y t el i n e D a t a [ C O L S * 2 ] ; v o i ds e t u p ( ) { S e r i a l . b e g i n ( 1 1 5 2 0 0 ) ; W i r e . b e g i n ( ) ; o v 7 6 7 0 . b e g i n ( ) ; / / o v 7 6 7 0 . r e a d A l l ( ) ; a t t a c h I n t e r r u p t ( H R E F _ P I N ,h r e f R i s i n g ,R I S I N G ) ; a t t a c h I n t e r r u p t ( V S Y N C _ P I N ,v s y n c F a l l i n g ,F A L L I N G ) ; / / V G A . b e g i n ( 3 2 0 , 2 4 0 , V G A _ C O L O U R ) ; } v o i dl o o p ( ) { i f( s t a r t L i n e ) { s t a r t L i n e=f a l s e ; w h i l e( p i x e l C o u n t<C O L S ) { / /F i r s tb y t e w h i l e ( ! P C L K ) ; l i n e D a t a [ p i x e l C o u n t * 2 ]=D A T A ; w h i l e ( P C L K ) ; / /S e c o n db y t e w h i l e ( ! P C L K ) ; l i n e D a t a [ p i x e l C o u n t * 2 + 1 ]=D A T A ; w h i l e ( P C L K ) ; p i x e l C o u n t + + ; } / / H E R ES E N DAL I N E } } v o i dh r e f R i s i n g ( ) { n o I n t e r r u p t s ( ) ; s t a r t L i n e=t r u e ; l i n e C o u n t + + ; p i x e l C o u n t=0 ; i n t e r r u p t s ( ) ; } v o i dv s y n c F a l l i n g ( ) { n o I n t e r r u p t s ( ) ; / / S e r i a l . p r i n t ( 0 x 4 6 , H E X ) ; s t a r t F r a m e = t r u e ; l i n e C o u n t=0 ; i n t e r r u p t s ( ) ; }

/ /S t a r ts e r i a lc o m u n i c a t i o n / /E n a b l eI 2 C / /P r e p a r eC a m e r a / /R e a dt h ec a m e r a ' sB a n kR e g i s t e r / /A c t i v a t ea ni n t e r r u p tw h e nH R E Fg o e su p / /A c t i v a t ea ni n t e r r u p tw h e nV S Y N Cg o e sd o w n / /E n a b l eV G AO u t p u t

where <Ov7670.h> is my own library I have been doing Thanks in advance, Aitor Title: Re: ov7670 with both arduino uno and now mega Post by: Animat on November 26, 2013, 02:41:32 am Hello, I tried Your settings Bayer_Raw_VGA. And here is a picture. Settings: const struct sensor_reg ov7670_default_regs_DRK[] PROGMEM = { //{ REG_COM7, COM7_RESET }, // // Clock scale: 3 = 15fps // 2 = 20fps // 1 = 30fps

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

// AGC and AEC parameters. Note we start by disabling those features, // then turn them only after tweaking the values. { REG_COM8, COM8_FASTAEC | COM8_AECSTEP | COM8_BFILT }, { REG_GAIN, 0 }, { REG_AECH, 0 }, { REG_COM4, 0x40 }, // magic reserved bit { REG_COM9, 0x18 }, // 4x gain + magic rsvd bit { REG_BD50MAX, 0x05 }, { REG_BD60MAX, 0x07 }, { REG_AEW, 0x95 }, { REG_AEB, 0x33 }, { REG_VPT, 0xe3 }, { REG_HAECC1, 0x78 }, { REG_HAECC2, 0x68 }, { 0xa1, 0x03 }, // magic { REG_HAECC3, 0xd8 }, { REG_HAECC4, 0xd8 }, { REG_HAECC5, 0xf0 }, { REG_HAECC6, 0x90 }, { REG_HAECC7, 0x94 }, { REG_COM8, COM8_FASTAEC|COM8_AECSTEP|COM8_BFILT|COM8_AGC|COM8_AEC }, // Almost all of these are magic "reserved" values. { REG_COM5, 0x61 }, { REG_COM6, 0x4b }, { 0x16, 0x02 }, { REG_MVFP, 0x07 }, { 0x21, 0x02 }, { 0x22, 0x91 }, { 0x29, 0x07 }, { 0x33, 0x0b }, { 0x35, 0x0b }, { 0x37, 0x1d }, { 0x38, 0x71 }, { 0x39, 0x2a }, { REG_COM12, 0x78 }, { 0x4d, 0x40 }, { 0x4e, 0x20 }, { REG_GFIX, 0 }, { REG_DBLV, 0x4A }, { 0x74, 0x10 }, // DVL 0x4A ?? 0x04 { 0x8d, 0x4f }, { 0x8e, 0 }, { { { { { 0x8f, 0 }, { 0x90, 0 }, 0x91, 0 }, { 0x96, 0 }, 0x9a, 0 }, { 0xb0, 0x84 }, 0xb1, 0x0c }, { 0xb2, 0x0e }, 0xb3, 0x82 }, { 0xb8, 0x0a },

// More reserved magic, some of which tweaks white balance { 0x43, 0x0a }, { 0x44, 0xf0 }, { 0x45, 0x34 }, { 0x46, 0x58 }, { 0x47, 0x28 }, { 0x48, 0x3a }, { 0x59, 0x88 }, { 0x5a, 0x88 }, { 0x5b, 0x44 }, { 0x5c, 0x67 }, { 0x5d, 0x49 }, { 0x5e, 0x0e }, { 0x6c, 0x0a }, { 0x6d, 0x55 }, { 0x6e, 0x11 }, { 0x6f, 0x9f }, // "9e for advance AWB" { 0x6a, 0x40 }, { REG_BLUE, 0x40 }, // 0x40 { REG_RED, 0x60 }, { REG_COM8, COM8_FASTAEC|COM8_AECSTEP|COM8_BFILT|COM8_AGC|COM8_AEC|COM8_AWB }, // Matrix coefficients { 0x4f, 0x80 }, { 0x50, 0x80 }, { 0x51, 0 }, { 0x52, 0x22 }, { 0x53, 0x5e }, { 0x54, 0x80 }, { 0x58, 0x9e }, { { { { { { REG_COM16, COM16_AWBGAIN }, { REG_EDGE, 0 }, 0x75, 0x05 }, { 0x76, 0xe1 }, 0x4c, 0 }, { 0x77, 0x01 }, REG_COM13, 0xc3 }, { 0x4b, 0x09 }, 0xc9, 0x60 }, /*{ REG_COM16, 0x38 },*/ 0x56, 0x40 }, { REG_COM11, COM11_EXP|COM11_HZAUTO|COM11_50HZ }, { 0x96, 0 },

{ 0x34, 0x11 }, { 0xa4, 0x88 },

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

31/60

3/15/2014
{ { { { { 0x97, 0x99, 0x9b, 0x9d, 0x78, 0x30 0x30 0x29 0x4c 0x04 }, }, }, }, }, { { { { 0x98, 0x9a, 0x9c, 0x9e, 0x20 }, 0x84 }, 0x03 }, 0x3f },

Print Page - ov7670 with both arduino uno and now mega

// Extra-weird stuff. Some sort of multiplexor register { 0x79, 0x01 }, { 0xc8, 0xf0 }, { 0x79, 0x0f }, { 0xc8, 0x00 }, { 0x79, 0x10 }, { 0xc8, 0x7e }, { 0x79, 0x0a }, { 0xc8, 0x80 }, { 0x79, 0x0b }, { 0xc8, 0x01 }, { 0x79, 0x0c }, { 0xc8, 0x0f }, { 0x79, 0x0d }, { 0xc8, 0x20 }, { 0x79, 0x09 }, { 0xc8, 0x80 }, { 0x79, 0x02 }, { 0xc8, 0xc0 }, { 0x79, 0x03 }, { 0xc8, 0x40 }, { 0x79, 0x05 }, { 0xc8, 0x30 }, { 0x79, 0x26 }, /* */ { 0xff, 0xff }, }; Title: Re: ov7670 with both arduino uno and now mega Post by: Animat on November 26, 2013, 05:39:24 am Can't understand what sequence set to get a good image. Title: Re: ov7670 with both arduino uno and now mega Post by: drkblog on November 26, 2013, 06:22:39 am Can you post the RAW data so I can test that with my decoder? Title: Re: ov7670 with both arduino uno and now mega Post by: Animat on November 26, 2013, 07:17:17 am Settings: const struct sensor_reg ov7670_default_regs_DRK[] PROGMEM = { //{ REG_COM7, COM7_RESET }, // // Clock scale: 3 = 15fps // 2 = 20fps // 1 = 30fps { REG_CLKRC, 0x80 }, // OV: clock scale (30 fps) [26 funciona] { REG_TSLB, 0x0D/* TSLB_YVYU */ }, // OV { REG_COM7, 0x01 }, // YUV VGA { REG_COM17, 0x08 }, //color_bar // // Set the hardware window. These values from OV don't entirely // make sense - hstop is less than hstart. But they work... // { REG_HSTART, 0x13 }, { REG_HSTOP, 0x01 }, { REG_HREF, 0xb6 }, { REG_VSTART, 0x02 }, { REG_VSTOP, 0x7a }, { REG_VREF, 0x0a }, { REG_COM3, 0 }, { REG_COM14, 0 }, // Mystery scaling numbers { 0x70, 0x3a }, { 0x71, 0x35 }, { 0x72, 0x11 }, { 0x73, 0xf0 }, { 0xa2, 0x02 }, { REG_COM10, 0x00 }, // Usar COM10_PCLK_HB para frenar el clock en el blank // Gamma curve values // { { { { { { { { 0x7a, 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

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

32/60

3/15/2014

Print Page - ov7670 with both arduino uno and now mega

{ REG_HAECC5, 0xf0 }, { REG_HAECC6, 0x90 }, { REG_HAECC7, 0x94 }, { REG_COM8, COM8_FASTAEC|COM8_AECSTEP|COM8_BFILT|COM8_AGC|COM8_AEC }, // Almost all of these are magic "reserved" values. { REG_COM5, 0x61 }, { REG_COM6, 0x4b }, { 0x16, 0x02 }, { REG_MVFP, 0x07 }, { 0x21, 0x02 }, { 0x22, 0x91 }, { 0x29, 0x07 }, { 0x33, 0x0b }, { 0x35, 0x0b }, { 0x37, 0x1d }, { 0x38, 0x71 }, { 0x39, 0x2a }, { REG_COM12, 0x78 }, { 0x4d, 0x40 }, { 0x4e, 0x20 }, { REG_GFIX, 0 }, { REG_DBLV, 0x4A }, { 0x74, 0x10 }, // DVL 0x4A ?? 0x04 { 0x8d, 0x4f }, { 0x8e, 0 }, { 0x8f, 0 }, { 0x90, 0 }, { 0x91, 0 }, { 0x96, 0 }, { 0x9a, 0 }, { 0xb0, 0x84 }, { 0xb1, 0x0c }, { 0xb2, 0x0e }, { 0xb3, 0x82 }, { 0xb8, 0x0a }, // More reserved magic, some of which tweaks white balance { 0x43, 0x0a }, { 0x44, 0xf0 }, { 0x45, 0x34 }, { 0x46, 0x58 }, { 0x47, 0x28 }, { 0x48, 0x3a }, { 0x59, 0x88 }, { 0x5a, 0x88 }, { 0x5b, 0x44 }, { 0x5c, 0x67 }, { 0x5d, 0x49 }, { 0x5e, 0x0e }, { 0x6c, 0x0a }, { 0x6d, 0x55 }, { 0x6e, 0x11 }, { 0x6f, 0x9f }, // "9e for advance AWB" { 0x6a, 0x40 }, { REG_BLUE, 0x40 }, // 0x40 { REG_RED, 0x60 }, { REG_COM8, COM8_FASTAEC|COM8_AECSTEP|COM8_BFILT|COM8_AGC|COM8_AEC|COM8_AWB }, // Matrix coefficients { 0x4f, 0x80 }, { 0x50, 0x80 }, { 0x51, 0 }, { 0x52, 0x22 }, { 0x53, 0x5e }, { 0x54, 0x80 }, { 0x58, 0x9e }, { { { { { { { { { { { { { REG_COM16, COM16_AWBGAIN }, { REG_EDGE, 0 }, 0x75, 0x05 }, { 0x76, 0xe1 }, 0x4c, 0 }, { 0x77, 0x01 }, REG_COM13, 0xc3 }, { 0x4b, 0x09 }, 0xc9, 0x60 }, /*{ REG_COM16, 0x38 },*/ 0x56, 0x40 }, 0x34, 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 },

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

Title: Re: ov7670 with both arduino uno and now mega Post by: Animat on 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
Post by: aturcitu on November 26, 2013, 08:56:02 am

Print Page - ov7670 with both arduino uno and now mega

Hi drkblog, sorry if I'm too daring But I have seen that you also have great background with this project, maybe you could help me with my post above ? Thank you ! Title: Re: ov7670 with both arduino uno and now mega Post by: drkblog on November 26, 2013, 09:05:48 am
Q uote from : aturcitu on Nove m be r 26, 2013, 08:56:02 am Hi drk blog, sorry if I'm too daring But I have se e n that you also have gre at back ground with this proje ct, m aybe you could he lp m e with m y post above ?

No problem! As far as I understand, you have successfully passed images from the sensor to RAM. You said you have enough RAM, which RAM are you talking about? Then you tried to pass images to the PC (how?) For storing the image to an SD card, you will have to start by having the entire frame in RAM because SD is slow (compared to the image sensor) and write speed in the card isn't constant. And you have to write blocks of 512 bytes, even if you don't use FAT file system. So, the best approach here is you start by creating a separated project for writing to the SD card. That's very easy, you have a lot of sample code out there. Once you have the SD module working, you can think of merging both projects: the one which passes images to RAM, and the one which writes to SD. I've made two assumptions here so I will wait your answer before going further. Title: Re: ov7670 with both arduino uno and now mega Post by: aturcitu on 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.

Yes, if you use two bytes per pixel.


Q uote I trie d with Proce ssing through Se rial port. But I fail.

That can be tricky but it's possible if you are passing data from RAM to serial port. It won't work from OV7670 to serial port because it isn't fast enough.
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

No. Where do the text thing come from? If you have a frame in RAM, all you have is a bunch of bytes (let say 160 x 120 x 2 bytes), a big block of 38,400 bytes. In whatever format the sensor can output (Bayer, bayer raw, RGB, etc). Then you can save this block on a SD card, as a file. It won't be a text file because you are not saving a block of text, but

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?

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

That's good to know. So essentially, since the OV7670/OV5642 family mostly does RAW, YUV, etc, I should be able to find a library that will convert them to JPEG? Which brings me to my next question, compression. Less compression provides better quality JPEG images? So, like on the VC0706 I can set the compression ratio from 0-255(00 - FF, in HEX), so a setting of 0 would be no compression and a higher quality pic, where as FF would be a lower quality due to compression causing some loss in data?
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 : D D R B | = ( 1 < < 3 ) ; / / p i n1 1 A S S R& =~ ( _ B V ( E X C L K )|_ B V ( A S 2 ) ) ; T C C R 2 A = ( 1 < < C O M 2 A 0 ) | ( 1 < < W G M 2 1 ) | ( 1 < < W G M 2 0 ) ; / / t h i sa l s or e s u l t si n6 7b u tIw a n t e dt oc l e a nu pm a g i cn u m b e r s T C C R 2 B = ( 1 < < W G M 2 2 ) | ( 1 < < C S 2 0 ) ; O C R 2 A = 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 : W i r e . r e q u e s t F r o m ( 0 x 4 2 ,6 ) ; w h i l e ( W i r e . a v a i l a b l e ( ) ){ c h a rc=W i r e . r e a d ( ) ; S e r i a l . p r i n t ( c ) ; }

Will this work for getting the image data from d0-7?

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

C ode : w h i l e( d i g i t a l R e a d ( H R E F )= =1 ) {

36/60

3/15/2014
w h i l e( d i g i t a l R e a d ( H R E F )= =1 ) { w h i l e ( d i g i t a l R e a d ( P C L K )= =1 ) { } f o r( i n ti = 0 ;i<=7 ;i + + ) { / / g e ts t u f ff r o me a c hp a r a l l e ld a t ap i n }

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

Q uote

Print Page - ov7670 with both arduino uno and now mega

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

I use pin up/ pin down approach:


C ode : d i g i t a l W r i t e ( O E ,L O W ) ;/ / ? d i g i t a l W r i t e ( R R S T ,L O W ) ; P O R T E& =B 1 1 1 0 1 1 1 1 ;/ /d i g i t a l W r i t e ( R C L K ,L O W ) ; P O R T E| =B 0 0 0 1 0 0 0 0 ;/ /d i g i t a l W r i t e ( R C L K ,H I G H ) ; P O R T E& =B 1 1 1 0 1 1 1 1 ;/ /d i g i t a l W r i t e ( R C L K ,L O W ) ; P O R T E| =B 0 0 0 1 0 0 0 0 ;/ /d i g i t a l W r i t e ( R C L K ,H I G H ) ; d i g i t a l W r i t e ( R R S T ,H I G H ) ; d i g i t a l W r i t e ( O E ,H I G H ) ; d i g i t a l W r i t e ( O E ,L O W ) ; f o r ( u i n t 1 6 _ ti=0 ;i< =( W*B*H ) ;i + + ){ P O R T E| =B 0 0 0 1 0 0 0 0 ;/ /d i g i t a l W r i t e ( R C L K ,H I G H ) ; u n s i g n e dc h a rd a t a=( u i n t 8 _ t ) P I N A ; P O R T E& =B 1 1 1 0 1 1 1 1 ;/ /d i g i t a l W r i t e ( R C L K ,L O W ) ; / /d os o m e t h i n gw i t hd a t a } d i g i t a l W r i t e ( O E ,H I G H ) ; }

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. :)

Wow, a frame per second? That's crazy! So, by a multitasking environment, you're saying that if I had a camera, clock, lcd, and temp sensor(all just for example), I could read/write to all of them at the exact same time? Sorry for the stupidity in this question, I'm just a little slow sometimes understanding things, so I have to break it down so I can understand. Plus, I tend to misunderstand a lot, this way I ensure I'm on the same page. Title: Re: ov7670 with both arduino uno and now mega Post by: drkblog on November 29, 2013, 02:11:29 pm
Q uote from : x KoldFuzionx on Nove m be r 29, 2013, 01:28:40 pm W ow, a fram e pe r se cond? That's crazy!

Up to five frames per second, actually.


Q uote from : x KoldFuzionx on Nove m be r 29, 2013, 01:28:40 pm So, by a m ultitask ing e nvironm e nt, you're saying that if I had a cam e ra, clock , lcd, and te m p se nsor(all just for e x am ple ), I could re ad/write to all of the m at the exact sam e tim e ? Sorry for the stupidity in this que stion, I'm just a little slow som e tim e s unde rstanding things, so I have to bre ak it down so I can unde rstand. Plus, I te nd to m isunde rstand a lot, this way I e nsure I'm on the sam e page .

Nope. Multitasking is sharing the CPU among several programs, one program at a time. When a given program is using the CPU, all the rest are paused. And from the program point of view, you don't know when that happens. So if you are polling an input pin for a level, and waiting for a change. You could miss one or several level changes if you were paused by the kernel. http://en.wikipedia.org/wiki/Computer_multitasking (http://en.wikipedia.org/wiki/Computer_multitasking) Title: Re: ov7670 with both arduino uno and now mega Post by: xKoldFuzionx on 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
Q uote from : drk blog on Nove m be r 29, 2013, 02:11:29 pm Up to five fram e s pe r se cond, actually.

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 : d i g i t a l W r i t e ( O E ,L O W ) ; f o r ( u i n t 1 6 _ ti=0 ;i< =( W*B*H ) ;i + + ){ P O R T E| =B 0 0 0 1 0 0 0 0 ;/ /d i g i t a l W r i t e ( R C L K ,H I G H ) ; u n s i g n e dc h a rd a t a=( u i n t 8 _ t ) P I N A ; P O R T E& =B 1 1 1 0 1 1 1 1 ;/ /d i g i t a l W r i t e ( R C L K ,L O W ) ; / /d os o m e t h i n gw i t hd a t a } d i g i t a l W r i t e ( O E ,H I G H ) ;

But not that one:


C ode : d i g i t a l W r i t e ( O E ,L O W ) ;/ / ? d i g i t a l W r i t e ( R R S T ,L O W ) ; P O R T E& =B 1 1 1 0 1 1 1 1 ;/ /d i g i t a l W r i t e ( R C L K ,L O W ) ; P O R T E| =B 0 0 0 1 0 0 0 0 ;/ /d i g i t a l W r i t e ( R C L K ,H I G H ) ; P O R T E& =B 1 1 1 0 1 1 1 1 ;/ /d i g i t a l W r i t e ( R C L K ,L O W ) ; P O R T E| =B 0 0 0 1 0 0 0 0 ;/ /d i g i t a l W r i t e ( R C L K ,H I G H ) ; d i g i t a l W r i t e ( R R S T ,H I G H ) ; d i g i t a l W r i t e ( O E ,H I G H ) ;

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 : v o i dl o o p ( ) { / / W R I T I N GO NF I F O O E _ S E T ; / /O u t p u th i g hi m p e d a n c e W E N _ C L R ; o n F r a m e = f a l s e ; w h i l e ( ! o n F r a m e ) ; o n F r a m e = f a l s e ; w h i l e ( ! o n F r a m e ) ; W E N _ S E T ; R R S T _ C L R ; R C L K _ C L R ; R C L K _ S E T ; R C L K _ C L R ; / /E n a b l ew r i t i n g / /N e wf r a m es t a r t s / /A ne n t i r ef r a m eh a v eb e e nw r i t i n go nF I F O / /D i s a b l ew r i t i n g / /R e s e tr e a d i n gp o i n t e r / /W a i t sf o r2R C L K

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

39/60

3/15/2014
R C L K _ S E T ; R R S T _ S E T ; O E _ C L R ; / /P o i n t e ri sR e s e t / /E n a b l e sr e a d i n g

Print Page - ov7670 with both arduino uno and now mega

/ / P U L L I N GD A T A f o r ( i n ti = 0 ;i < C O L S * R O W S * B Y T E S ; i + + ) { R C L K _ S E T ; f r a m e [ i ] = D A T A ; R C L K _ C L R ; } / / D os o m i t h i n gw i t hd a t a } v o i dv s y n c _ r i s i n g ( ) { n o I n t e r r u p t s ( ) ; o n F r a m e=t r u e ; i n t e r r u p t s ( ) ; }

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 : # i n c l u d e< W i r e . h > / / O V 7 6 7 0 # d e f i n eA D D R E S S # d e f i n eR E G I S T E R S / / A R D U I N OD U EP I N T O U T # d e f i n eO E _ P I N # d e f i n eV S Y N C _ P I N # d e f i n eW E N _ P I N # d e f i n eR R S T _ P I N # d e f i n eR C L K _ P I N # d e f i n eH R E F _ P I N / / C A M E R AI N P U T S # d e f i n eO E _ S E T # d e f i n eO E _ C L R # d e f i n eW E N _ S E T # d e f i n eW E N _ C L R # d e f i n eR R S T _ S E T # d e f i n eR R S T _ C L R # d e f i n eR C L K _ S E T # d e f i n eR C L K _ C L R / / C A M E R AO U T P U T S # d e f i n eV S Y N C # d e f i n eH R E F # d e f i n eD A T A / / R E S O L U T I O N # d e f i n eC O L S # d e f i n eR O W S # d e f i n eB Y T E S 0 x 2 1 0 x 9 1 4 4 4 5 4 6 4 7 4 8 4 9 P I O C > P I O _ S O D R = 1 < < 1 9 P I O C > P I O _ C O D R = 1 < < 1 9 P I O C > P I O _ S O D R = 1 < < 1 7 P I O C > P I O _ C O D R = 1 < < 1 7 P I O C > P I O _ S O D R = 1 < < 1 6 P I O C > P I O _ C O D R = 1 < < 1 6 P I O C > P I O _ S O D R = 1 < < 1 5 P I O C > P I O _ C O D R = 1 < < 1 5 R E G _ P I O C _ P D S R > > 1 8 & 0 x 1 R E G _ P I O C _ P D S R > > 1 4 & 0 x 1 R E G _ P I O C _ P D S R > > 2 & 0 x F F 1 6 0 1 2 0 2 / /C . 1 9 / /C . 1 7 / /C . 1 6 / /C . 1 5 f o rw r i t i n g f o rw r i t i n g f o rw r i t i n g f o rw r i t i n g / /D e f i n ea d d r e s so fO V 7 6 7 0 / /D e f i n e#o fR e g i s t e s ro nO V 7 0 7 6

/ /C . 1 8 f o rr e a d i n g / /C . 1 4 f o rr e a d i n g / /C . 2t oC . 9f o rr e a d i n g

v o l a t i l eb o o l e a no n F r a m e ; b y t ef r a m e [ C O L S * R O W S * B Y T E S ] ; v o i ds e t u p ( v o i d ) { / / I N I T I A L I Z A T I O N W i r e . b e g i n ( ) ; S e r i a l . b e g i n ( 1 1 5 2 0 0 ) ; c a m e r a S e t U p ( ) ; / / r e a d R e g i s t e r B a n k ( ) ; } v o i dl o o p ( ) { / / W R I T I N GO NF I F O O E _ S E T ; / /O u t p u th i g hi m p e d a n c e W E N _ C L R ; o n F r a m e = t r u e ; w h i l e ( o n F r a m e ) ; / /E n a b l ew r i t i n g / /T h ep r e s e n tf r a m ee n d s

/ /E n a b l eI 2 C / /S t a r ts e r i a lc o m u n i c a t i o n

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

40/60

3/15/2014
o n F r a m e = t r u e ; w h i l e ( o n F r a m e ) ; W E N _ S E T ; R R S T _ C L R ; R C L K _ C L R ; R C L K _ S E T ; R C L K _ C L R ; R C L K _ S E T ; R C L K _ C L R ; R R S T _ S E T ; O E _ C L R ;

Print Page - ov7670 with both arduino uno and now mega
/ /A ne n t i r ef r a m eh a v eb e e ns a v e do nt h eF I F O / /D i s a b l ew r i t i n g / /R e s e tr e a d i n gp o i n t e r / /W a i t sf o r2R C L K

/ /P o i n t e ri sR e s e t / /E n a b l e sr e a d i n g

/ / P U L L I N GD A T A f o r ( i n ti = 0 ;i < C O L S * R O W S * B Y T E S ; i + + ) { R C L K _ S E T ; f r a m e [ i ] = D A T A ; R C L K _ C L R ; } f o r ( i n ti = 0 ;i < C O L S * R O W S * B Y T E S ; i + + ) { S e r i a l . p r i n t ( f r a m e [ i ] , H E X ) ; S e r i a l . p r i n t l n ( " ," ) ; d e l a y ( 2 ) ; } S e r i a l . p r i n t l n ( ) ; } v o i dv s y n c _ f a l l i n g ( )/ /Af r a m ee n d s { n o I n t e r r u p t s ( ) ; o n F r a m e=f a l s e ; i n t e r r u p t s ( ) ; } v o i dc a m e r a S e t U p ( ) { / / R E G I S T E R SI N I C I A L I Z A T I O N w r i t e ( 0 x 1 2 , 0 x 8 0 ) ; w r i t e ( 0 x 1 5 , 0 x 0 2 ) ; w r i t e ( 0 x 1 1 , 0 x 8 2 ) ; / / Q Q V G A( 1 6 0 x 1 2 0 ) w r i t e ( 0 x 1 2 , 0 x 0 0 ) ; w r i t e ( 0 x 0 C , 0 x 0 4 ) ; w r i t e ( 0 x 3 E , 0 x 1 A ) ; w r i t e ( 0 x 7 0 , 0 x 3 A ) ; w r i t e ( 0 x 7 1 , 0 x 3 5 ) ; w r i t e ( 0 x 7 2 , 0 x 2 2 ) ; w r i t e ( 0 x 7 3 , 0 x F 2 ) ; w r i t e ( 0 x A 2 , 0 x 0 2 ) ; / / S E TF I F O ' SC O N T R O L SA SA NO U T P U T S p i n M o d e ( O E _ P I N , O U T P U T ) ; p i n M o d e ( W E N _ P I N , O U T P U T ) ; p i n M o d e ( R R S T _ P I N ,O U T P U T ) ; p i n M o d e ( R C L K _ P I N ,O U T P U T ) ; / / A C T I V A T EH R E F ,V S Y N CA N DP C L KI N T E R R U P T S a t t a c h I n t e r r u p t ( V S Y N C _ P I N ,v s y n c _ f a l l i n g ,F A L L I N G ) ; } v o i dr e a d R e g i s t e r B a n k ( ) { i n tc o u n t = 0 ; b y t et m p ; w h i l e ( c o u n t < R E G I S T E R S ) { b y t eh i g h B y t e = 0 ; S e r i a l . p r i n t ( " \ nR e g i s t r on u m :" ) ; S e r i a l . p r i n t l n ( c o u n t , H E X ) ; W i r e . b e g i n T r a n s m i s s i o n ( A D D R E S S ) ; W i r e . w r i t e ( c o u n t ) ; W i r e . e n d T r a n s m i s s i o n ( ) ; W i r e . r e q u e s t F r o m ( A D D R E S S ,1 ) ; w h i l e ( W i r e . a v a i l a b l e ( )<1 ) ; h i g h B y t e=W i r e . r e a d ( ) ; S e r i a l . p r i n t l n ( h i g h B y t e , H E X ) ; d e l a y ( 2 5 ) ; c o u n t + + ; } } v o i dw r i t e ( b y t ea d d r e s s ,b y t ev a l ) { d e l a y ( 5 ) ; W i r e . b e g i n T r a n s m i s s i o n ( A D D R E S S ) ; W i r e . w r i t e ( a d d r e s s ) ; W i r e . w r i t e ( v a l ) ; W i r e . e n d T r a n s m i s s i o n ( ) ; } / / S t a r tc o m m u n i c a t i o nw i t hc m p s 0 3 / / S e n dt h er e g i s t e rw ew i s ht or e a d / / R e q u e s th i g hb y t e / / W h i l et h e r ei sab y t et or e c e i v e / / R e a dt h eb y t ea sa ni n t e g e r

/ /R e s e ta l lt h ev a l u e s / /V S Y N Ci n v e r t e d / /P e s c a l e rx 3( 1 0f p s )

/ /S t a r tt r a n s m i s s i o nt od e v i c e / /S e n dr e g i s t e ra d d r e s s / /S e n dv a l u et ow r i t e / /E n dt r a n s m i s s i o n

And doing this I got this through serial: 1,80,1,81,1,80,2,81,1,80,1,81,1,80,1,80,1,80,1,81,1,80,1,81,1,80,..... That it is almost the same that 0,81... I don't know why ! I'll revise the wires... Title: Re: ov7670 with both arduino uno and now mega Post by: drkblog on December 03, 2013, 11:30:48 am Actually, now that you mention it, it should be 0x00 0x80 so check the LSB Title: Re: ov7670 with both arduino uno and now mega Post by: pgibbons66 on December 06, 2013, 08:07:42 pm Hi, I'm trying to follow your setup step for step. I'm using a mega, an ethernet/sd shield and a non FIFO Ov7670. Im going to borrow some 23LC1024 ram from the lab.

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

41/60

3/15/2014
regarding your code for clock output.: DDRL|=8; ASSR &= ~(_BV(EXCLK) | _BV(AS2)); //generate 8mhz clock TCCR5A =67; TCCR5B=17;

Print Page - ov7670 with both arduino uno and now mega

Where does that go in the code? does it replace digitalWrite(10,HIGH); DDRB|=47;//clock as output and SPI pins as output except MISO PORTB|=6;//set both CS pins to high DDRC&=~15;//low d0-d3 camera DDRD&=~252;//d7-d4 and interupt pins #ifdef useLed DDRD|=1;//pin 0 as output PORTD&=~1;//turn off led //set pin 1 as input DDRD&=~2; PORTB|=2;//enable pullup Finally a really amatuer question, when you pull up to A4 &A5 do you just add a 4.7k resistor between the line and the 3.3v pin on the arduino? thanks in advance. Title: Re: ov7670 with both arduino uno and now mega Post by: drkblog on December 06, 2013, 09:23:13 pm This is a question for Mr_arduino, but as he isn't posting a lot lately, I'm going to offer you my own opinion: The code you refer to as "for clock output" is for generating an 8MHz clock with Arduino timer. In the first experiments both (Mr_ardunio and me) used the 16MHz clock from Arduino xtal instead of 8MHz generated clock. Doing that required to change microcontroller fuses in order to output the clock on pin 8 (Arduino UNO). Then Mr_arduino tried the 8MHz approach. Which is a little under the theoretical minimum clock for OV7670 which is 10MHz according to datasheet. But 8MHz works ok so far. So you have to use both codes. In my case I didn't use direct connection to the OV7670, I used this level conversion circuit (http://blog.drk.com.ar/2013/interfaz-logica-bidireccional-entre-5vy-3-3v) (it's in spanish but you can check the figures). But yes, you have to pull up to 3.3V those outputs and 4.7k should do. Don't forget to disable any Arduino buil-in pull up! Title: Re: ov7670 with both arduino uno and now mega Post by: xKoldFuzionx on December 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!

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
Title: Re: ov7670 with both arduino uno and now mega Post by: aturcitu on December 11, 2013, 07:22:41 pm

Print Page - ov7670 with both arduino uno and now mega

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 : / / R E G I S T E R SI N I C I A L I Z A T I O N w r i t e ( 0 x 1 2 , 0 x 8 0 ) ; w r i t e ( 0 x 1 5 , 0 x 0 2 ) ; w r i t e ( 0 x 1 1 , 0 x 8 2 ) ; / / Q Q V G A( 1 6 0 x 1 2 0 ) w r i t e ( 0 x 1 2 , 0 x 0 0 ) ; w r i t e ( 0 x 0 C , 0 x 0 4 ) ; w r i t e ( 0 x 3 E , 0 x 1 A ) ; w r i t e ( 0 x 7 0 , 0 x 3 A ) ; w r i t e ( 0 x 7 1 , 0 x 3 5 ) ; w r i t e ( 0 x 7 2 , 0 x 2 2 ) ; w r i t e ( 0 x 7 3 , 0 x F 2 ) ; w r i t e ( 0 x A 2 , 0 x 0 2 ) ;

/ /R e s e ta l lt h ev a l u e s / /V S Y N Ci n v e r t e d / /P e s c a l e rx 3( 1 0f p s )

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
Title: Re: ov7670 with both arduino uno and now mega Post by: aturcitu on December 12, 2013, 05:38:30 pm

Print Page - ov7670 with both arduino uno and now mega

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 : # i f n d e fb m p _ h # d e f i n eb m p _ h # i n c l u d e" A r d u i n o . h " c l a s sB m p { p u b l i c : B m p ( ) ; v o i di n i t ( u n s i g n e di n tp x ,u n s i g n e di n tp y ) ; c h a rb m p F i l e H e a d e r [ 1 4 ] ; c h a rb m p I n f o H e a d e r [ 4 0 ] ; u n s i g n e di n tr o w S i z e ; u n s i g n e di n tf i l e S i z e ; i n tp a d ; } ; e x t e r nB m pb m p ; # e n d i f

/ /H o wm a n yb y t e si nt h er o w( u s e dt oc r e a t ep a d d i n g ) / /H e a d e r s( 5 4b y t e s )+p i x e ld a t a / /M a xp a d d i nn e e d e dw i l lb e3z e r o s

bmp.cpp
C ode : # i n c l u d e" b m p . h " B m p : : B m p ( ){ b m p F i l e H e a d e r={ ' B ' , ' M ' ,0 , 0 , 0 , 0 ,0 , 0 ,0 , 0 ,5 4 , 0 , 0 , 0 } ; b m p I n f o H e a d e r={ 4 0 , 0 , 0 , 0 ,0 , 0 , 0 , 0 ,0 , 0 , 0 , 0 ,1 , 0 ,2 4 , 0 } ; } v o i dB m p : : i n i t ( u n s i g n e di n tp x ,u n s i g n e di n tp y ) { r o w S i z e=4*( ( 3 * p x+3 ) / 4 ) ;

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

44/60

3/15/2014
r o w S i z e=4*( ( 3 * p x+3 ) / 4 ) ; f i l e S i z e=5 4+p y * r o w S i z e ; p a d=r o w S i z e 3 * p x ; / / N u m b e ro fz e r o sn e e d e d ;

Print Page - ov7670 with both arduino uno and now mega

b m p F i l e H e a d e r [2 ]=( b y t e ) ( f i l e S i z e ) ; b m p F i l e H e a d e r [3 ]=( b y t e ) ( f i l e S i z e> > 8 ) ; b m p F i l e H e a d e r [4 ]=( b y t e ) ( f i l e S i z e> >1 6 ) ; b m p F i l e H e a d e r [5 ]=( b y t e ) ( f i l e S i z e> >2 4 ) ; b m p I n f o H e a d e r [4 ]=( b y t e ) ( b m p I n f o H e a d e r [5 ]=( b y t e ) ( b m p I n f o H e a d e r [6 ]=( b y t e ) ( b m p I n f o H e a d e r [7 ]=( b y t e ) ( b m p I n f o H e a d e r [8 ]=( b y t e ) ( b m p I n f o H e a d e r [9 ]=( b y t e ) ( b m p I n f o H e a d e r [ 1 0 ]=( b y t e ) ( b m p I n f o H e a d e r [ 1 1 ]=( b y t e ) ( } B m pb m p ; p x ) ; p x> > 8 ) ; p x> >1 6 ) ; p x> >2 4 ) ; p y ) ; p y> > 8 ) ; p y> >1 6 ) ; p y> >2 4 ) ;

Then for instance, if working with rgb444 would be:


C ode : i f( ! s d . b e g i n ( C H I P _ S E L E C T ,S P I _ H A L F _ S P E E D ) )s d . i n i t E r r o r H a l t ( ) ; i f( ! m y F i l e . o p e n ( f i l e N a m e ,O _ W R I T E|O _ C R E A T) ) s d . e r r o r H a l t ( " o p e n i n gf i l ef o rw r i t ef a i l e d " ) ; S e r i a l . p r i n t ( " W r i t i n gt o" ) ; S e r i a l . p r i n t ( f i l e N a m e ) ; S e r i a l . p r i n t ( " . . ." ) ; b m p . i n i t ( C O L S , R O W S ) ; m y F i l e . w r i t e ( b m p . b m p F i l e H e a d e r ,s i z e o f ( b m p . b m p F i l e H e a d e r ) ) ; m y F i l e . w r i t e ( b m p . b m p I n f o H e a d e r ,s i z e o f ( b m p . b m p I n f o H e a d e r ) ) ; b y t et m p [ C O L S * 3 ] ; b y t ep a d d i n g [ b m p . p a d ] ; f o r (i n ti = 0 ;i <b m p . p a d ;i + + ) p a d d i n g [ i ] = 0 ; / / R o ww i t hR G B( 3b p p ) / /W r i t ef i l eh e a d e r / /W r i t ei n f oh e a d e r

f o r( i n ty = 0 ;y < R O W S ;y + + ){ f o r( i n tx = 0 ;x < ( C O L S ) ;x + + ){ t m p [ x * 3 + 0 ]=( b y t e ) ( ( 0 x 0 F&b u f f e r [ 2 * y * C O L S+2 * x ] ) < < 4 ) ; t m p [ x * 3 + 1 ]=( b y t e ) ( 0 x F 0&b u f f e r [ 2 * y * C O L S+2 * x + 1 ] ) ;

/ /R / /G

t m p [ x * 3 + 2 ]=( b y t e ) ( ( 0 x 0 F&b u f f e r [ 2 * y * C O L S+2 * x + 1 ] )< < 4 ) ; / /B } m y F i l e . w r i t e ( t m p ,s i z e o f ( t m p ) ) ; / /W r i t et m pd a t a m y F i l e . w r i t e ( p a d d i n g ,s i z e o f ( p a d d i n g ) ) ; / /P a d d i n ga sn e e d e d } S e r i a l . p r i n t l n ( " D o n e " ) ; m y F i l e . c l o s e ( ) ;

I hope it would be helpfull for someone!

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 : . / c o n v e r tfC b a r . R A Ww1 7 4H1 4 4 cy a l t

And you get the right colors The source to my program is located at https://github.com/ComputerNerd/RawCamera-data-converter The reason you are getting the wrong colors is because the first byte is swapped because a register was not set. The yuv422 alternative mode Also from what I have noticed it seems that yuv422 is higher quality than rgb565. Title: Re: ov7670 with both arduino uno and now mega Post by: Mr_arduino on December 24, 2013, 02:01:53 pm
Q uote from : drk blog on De ce m be r 11, 2013, 05:53:59 pm Gre at! Mr_arduino poste d a github link to his conve rte r in the first m e ssage in this thre ad (from YUV/BAYER to PNG). I use that program . O f course , you have to com pile and run that ove r a PC with Linux or C ygwin.

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 : c l i ( ) ; u i n t 8 _ tw , w w ; u i n t 8 _ th ; w = 1 6 0 ; / / T h er e a s o nt h i si s1 6 0i n s t e a do f6 4 0i sb e c a u s eIh a v eu n r o l l e dl o o py o uw i l ls e el a t e r h = 2 4 0 ;

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

46/60

3/15/2014
h = 2 4 0 ;

Print Page - ov7670 with both arduino uno and now mega

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 : t f t _ s e t X Y ( 0 , 0 ) ; C S _ L O W ; R S _ H I G H ; R D _ H I G H ;

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 : s p i C S t ( ) ; s p i W r B ( 2 ) ; / / s e q u e n t a lw r i t em o d e s p i W r B ( 0 ) ; / / 2 4b i ta d d r e s s s p i W r B ( 0 ) ; s p i W r B ( 0 ) ;

You will need these platform dependent functions


C ode : s t a t i ci n l i n ev o i ds p i W r B ( u i n t 8 _ td a t ) { S P D R=d a t ; w h i l e ( ! ( S P S R&( 1 < < S P I F ) ) ){ } / /W a i tf o rt r a n s m i s s i o nc o m p l e t e } s t a t i ci n l i n ev o i ds p i C S t ( v o i d ) { / / s e l e c t st h eR A Mc h i pa n dr e s e t si t / / t o g g l e ss p iC Su s e df o rr e s t i n gs r a m P O R T B | = ( 1 < < 2 ) ; / / c sh i g h P O R T B & = ~ ( 1 < < 2 ) ; / / c sl o w }

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 : s p i C S t ( ) ; s p i W r B ( 1 ) ; s p i W r B ( 6 4 ) ; / / s e q u e n t i a lm o d e

The next part of void capImg(void) is this


C ode : D D R A = 0 x F F ;

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 : # i f d e fM T 9 D 1 1 1 w h i l e( P I N E & 3 2 ) { } / / w a i tf o rl o w w h i l e( ! ( P I N E & 3 2 ) ) { } / / w a i tf o rh i g h # e l s e w h i l e( ! ( P I N E & 3 2 ) ) { } / / w a i tf o rh i g h w h i l e( P I N E & 3 2 ) { } / / w a i tf o rl o w # e n d i f

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 : w h i l e( h ) { w w = w ; w h i l e( w w ) {

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 : W R _ L O W ; w h i l e( P I N E & 1 6 ) { } / / w a i tf o rl o w P O R T A = P I N C ; W R _ H I G H ;

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 : w h i l e( ( P I N D & 4 ) ){ } / / w a i tf o rl o w S P D R = ( P I N C & 1 5 ) | ( P I N D & 2 4 0 ) ; w h i l e( ! ( P I N D & 4 ) ){ } / / w a i tf o rh i g h

I close the loop with


C ode : } } C S _ H I G H ; s e i ( ) ;

This sets the tft's CS pin to high and re-enables interrupts. Also your converter ignores the color information as I have told you before here are some of your images that you posted the raw data for converted with my converter. Title: Re: ov7670 with both arduino uno and now mega Post by: Mr_arduino on December 24, 2013, 03:09:02 pm
Q uote from : C hocobot on Nove m be r 27, 2013, 02:42:45 pm So far I'm think ing this: The sche m atic, is this ok ? http://i167.photobuck e t.com /album s/u157/cook ie bal/O V7670ArduinoUno.jpg

The schematic looks good to me.


Q uote As for the code , I've be e n look ing at http://paste bin.com /1nnR c5qL , I'm not ve ry fam iliar with the language so I don't re ally unde rstand e ve rything. But so far I'm think ing that I'd ne e d to add this (from page 4, re ply 57) som e whe re at the start to ge t the clock work ing.

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 : D D R B | = ( 1 < < 3 ) ; / / p i n1 1 A S S R& =~ ( _ B V ( E X C L K )|_ B V ( A S 2 ) ) ; T C C R 2 A = ( 1 < < C O M 2 A 0 ) | ( 1 < < W G M 2 1 ) | ( 1 < < W G M 2 0 ) ; / / t h i sa l s or e s u l t si n6 7b u tIw a n t e dt oc l e a nu pm a g i cn u m b e r s T C C R 2 B = ( 1 < < W G M 2 2 ) | ( 1 < < C S 2 0 ) ; O C R 2 A = 0 ;

Yes do add that at the beginning The simple sample should make it easier for you to understand the operation of the ov7670. Title: Re: ov7670 with both arduino uno and now mega Post by: Mr_arduino on December 24, 2013, 03:37:56 pm

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

47/60

3/15/2014
Q uote from : drk blog on Nove m be r 27, 2013, 08:12:07 am

Print Page - ov7670 with both arduino uno and now mega

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 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 : . / c o n v e r tfC b a r . R A Ww1 7 4H1 4 4 cy a l t 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

Here is register another quote found at register 0x3D


Q uote Bit[0]: UV swap (use with re giste r TSLB [3] (0x 3A)) 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

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

Print Page - ov7670 with both arduino uno and now mega

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 : S e r i a l . p r i n t l n ( w r R e g ( r e g I D ,r e g D a t ) ) ;

this would print out what you sent? Sorry, most everything I've seen just uses a Serial.print() function to debug, this whole byte thing is a bit new to me. Title: Re: ov7670 with both arduino uno and now mega Post by: Mr_arduino on December 29, 2013, 07:42:49 pm Yes you can do that but it returns 0 or 1 it does not return what was sent in this case. What you are seeing is a function returning a value. Returning an error/success value is just one application for functions returning a value you should read https://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp? topic=%2Fcom.ibm.xlcpp8l.doc%2Flanguage%2Fref%2Fcplr240.htm Title: Re: ov7670 with both arduino uno and now mega Post by: xKoldFuzionx on December 29, 2013, 07:59:33 pm Ok, gotcha, so, like the old school days of computing when that's all it would return is a 1 or 0. I'm learning. I saved that page, I'll probably end up reading it tomorrow and if I have more questions, I'll be sure to send them your way. On a side note, after looking over your code, I think I see (for the most part) what you did to get results from the camera. I think I see now how to program the 0V5642. I'm just gonna have to figure out the wiring for it. The datasheet I was looking at only has (from what I can see, so far) the wiring for hooking up the actual sensor instead of the module. I didn't see anything yet about pullups, but I'm not done looking through it, and I also have another datasheet for it, so I need to look that one over still. Seems like this camera won't be too difficult. Also, according to that calculation you gave me, the 7670 is only .3MP? I could

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

50/60

3/15/2014

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.

Print Page - ov7670 with both arduino uno and now mega

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

The pins D0 to D7 is output that I read pixels. what will I do with SCCB_C and SCCB_D pins? Could you please explain the procedure little bit? (How to save image into fifo and read from there)

Title: Re: ov7670 with both arduino uno and now mega Post by: nomiz on 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
C ode : / /a c t i v a t ei n t e r n a lp u l l u p sf o rt w i . d i g i t a l W r i t e ( S D A ,1 ) ;/ / t os u p p r e s s d i g i t a l W r i t e ( S C L ,1 ) ;/ / t os u p p r e s s

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)

And put 2 resistors to 3.3V To take the picture, you have a procedure with the WEN_PIN and synchronization with the VSYNC. Title: Re: ov7670 with both arduino uno and now mega Post by: Mr_arduino on January 08, 2014, 04:40:48 pm Yes nomiz you are correct about the i2c part you must somehow suppress the two lines. As for the WEN_PIN I am not sure what you are talking about. Also yes angeleye9 you will be using i2c to configure the camera otherwise you will get a low quality image out of the camera module. Title: Re: ov7670 with both arduino uno and now mega Post by: nomiz on January 08, 2014, 04:56:40 pm Hi Mr_arduino, I was talking about the procedure to take a picture. But I'm probably missing something because I didn't success to take a good picture. Actually, to take a picture I'm using this function :
C ode : v o i dt a k e _ p i c t u r e ( ) { d i g i t a l W r i t e ( O E _ P I N ,H I G H ) ; / /O u t p u th i g hi m p e d a n c e w h i l e ( d i g i t a l R e a d ( V S Y N C _ P I N ) ! = H I G H ) ; w h i l e ( d i g i t a l R e a d ( V S Y N C _ P I N ) ! = L O W ) ; / /T h ep r e s e n tf r a m ee n d s d i g i t a l W r i t e ( R R S T _ P I N ,L O W ) ; d i g i t a l W r i t e ( R C L K _ P I N ,L O W ) ; d i g i t a l W r i t e ( R C L K _ P I N ,H I G H ) ; d i g i t a l W r i t e ( R C L K _ P I N ,L O W ) ; d i g i t a l W r i t e ( R C L K _ P I N ,H I G H ) ; d i g i t a l W r i t e ( R C L K _ P I N ,L O W ) ; d i g i t a l W r i t e ( R R S T _ P I N ,H I G H ) ; / /R e s e tw r i t i n gp o i n t e r( R R S T&W R S T )

:smiley-roll-sweat:

/ /P o i n t e ri sR e s e t

d i g i t a l W r i t e ( W E N _ P I N ,H I G H ) ; / /E n a b l ew r i t i n g S e r i a l . p r i n t l n ( " E N A B L EW R I T I N G " ) ; w h i l e ( d i g i t a l R e a d ( V S Y N C _ P I N ) ! = H I G H ) ; d e l a y ( 1 ) ; d i g i t a l W r i t e ( W E N _ P I N , L O W) ; / /D i s a b l ew r i t i n g S e r i a l . p r i n t l n ( " AC O M P L E T EI M A G EI SC A P T U R E D " ) ; d i g i t a l W r i t e ( R R S T _ P I N ,L O W ) ; d i g i t a l W r i t e ( R C L K _ P I N ,L O W ) ; d i g i t a l W r i t e ( R C L K _ P I N ,H I G H ) ; d i g i t a l W r i t e ( R C L K _ P I N ,L O W ) ; d i g i t a l W r i t e ( R C L K _ P I N ,H I G H ) ; d i g i t a l W r i t e ( R C L K _ P I N ,L O W ) ; d i g i t a l W r i t e ( R R S T _ P I N ,H I G H ) ; d i g i t a l W r i t e ( O E _ P I N ,L O W ) ; d e l a y ( 1 ) ; } / /R e s e tr e a d i n gp o i n t e r( R R S T&W R S T )

/ /P o i n t e ri sR e s e t / /E n a b l e sr e a d i n g

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 : / / R E G I S T E R SI N I T I A L I Z A T I O N w r i t e ( 0 x 1 1 , 0 x 8 2 ) ; w r i t e ( 0 x 1 2 , 0 x 0 0 ) ; w r i t e ( 0 x 1 2 , 0 x 0 1 ) ; w r i t e ( 0 x 0 C , 0 x 0 0 ) ; w r i t e ( 0 x 3 E , 0 x 0 0 ) ; w r i t e ( 0 x 7 0 , 0 x 3 A ) ; w r i t e ( 0 x 7 1 , 0 x 3 5 ) ; w r i t e ( 0 x 7 2 , 0 x 1 1 ) ; w r i t e ( 0 x 7 3 , 0 x F 0 ) ; w r i t e ( 0 x A 2 , 0 x 0 2 ) ; / /P e s c a l e rx 3( m ) / /R e s e ta l lt h ev a l u e s

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
Title: Re: ov7670 with both arduino uno and now mega Post by: sakeear on January 14, 2014, 09:59:02 pm

Print Page - ov7670 with both arduino uno and now mega

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 : T C C R 0 B=T C C R 0 B&0 b 1 1 1 1 1 0 0 0|0 x 0 1 ;

But dont work. Title: Re: ov7670 with both arduino uno and now mega Post by: Fadik on January 20, 2014, 02:51:27 pm Hi All I fear that I share the frustration most of you had here, and unfortunately I am stuck. Can someone help point me in the right direction? (I literally went through the whole thread and because of the non-fifo, fifo v1, fifo v2 variances and different arduino products it is getting much confusing!!) What would your guess if the following is the output of a QQVGA, YUV...etc (basically the array of settings provided here in the forum). I am running only uint8_t init_yuv_qqvga(); void init_camera_reset(); uint8_t init_default_values(); and commented out void init_negative_vsync(); as I have Version 1. I added the Color bars of course, and reading two bytes, discarding the first one and sending the 2nd one (Y-values = grayscale) Feedback is much appreciated, and sorry for not putting out any bits and pieces of code, i will do so as you ask as it iwll be difficult to put everything at once. Title: Re: ov7670 with both arduino uno and now mega Post by: sakeear on January 21, 2014, 10:50:08 am hello mr Arduino. I bought arducam shiel and i used it with aduino uno. and its work perfectly. but i want to change it to take several pictures at a single push in a button. like a picture serious. this is the program // ArduCAM demo (C)2013 Lee // web: http://www.ArduCAM.com // This program is a demo of how to use most of the functions // of the library with a supported camera modules. // // This demo was made for Omnivision OV2640 sensor.

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

53/60

3/15/2014
// // // // // // //

This demo was made for Omnivision OV2640 sensor. 1. Set the sensor to JPEG output mode. 2. Capture and buffer the image to FIFO. 3. Store the image to Micro SD/TF card with JPEG format. 4. Resolution can be changed by myCAM.OV2640_set_JPEG_size() function. This program requires the ArduCAM V3.0.0 (or above) library and Rev.C ArduCAM shield and use Arduino IDE 1.5.2 compiler

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
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 ??

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 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 : i n tC a m e r a A L 4 2 2 B : : r e a d F r a m e ( / * O u t p u t S t r e a m* o u t * / ){ i n ti ,n=0 ; r e s e t R e a d P o i n t e r ( ) ; f o r( i=0 ;i<h e i g h t ;i + + ){ n+ =r e a d R o w ( / * o u t * / ) ; } / / O Ea l w a y sL O Wa si ti sG R O U N E D E D / / h a n d l er e a d C l o c k P i n d i g i t a l W r i t e F a s t ( r e a d C l o c k P i n , H I G H ) ; d i g i t a l W r i t e F a s t ( r e a d C l o c k P i n , L O W ) ; d i g i t a l W r i t e F a s t ( r e a d C l o c k P i n , H I G H ) ; r e t u r nn ; } i n tC a m e r a A L 4 2 2 B : : r e a d R o w ( / * O u t p u t S t r e a m* o u t * / ){ i n ti ; u i n t 8 _ tb , b 1 , b 2 ; u i n t 8 _ tb 3 , b 4 , b 5 , b 6 , b 7 , b 8 ; f o r( i=0 ;i<w i d t h ;i + + ){ d i g i t a l W r i t e F a s t ( r e a d C l o c k P i n , H I G H ) ; / / o u t > w r i t e ( r e a d ( ) ) ; / / r e a d ( ) ; f / / Iw a n tt ow a s t et h eU / Vc o m p o n e n ta n dt a k eo n l yt h eYf o rg r a ys c a l e . / / F a k ear e a df o rt h ef i r s tb y t e ,t a k et h es e c o n db y t ed o w nb e l o w d i g i t a l W r i t e F a s t ( r e a d C l o c k P i n , L O W ) ; / / d e l a y M i c r o s e c o n d s ( 1 ) ; d i g i t a l W r i t e F a s t ( r e a d C l o c k P i n , H I G H ) ; / / L o wB y t ei nP I N B / / H i g hB y t ei nP I N D b 1=( P I N B&( 0 b 0 0 0 0 1 1 1 1 ) ) ; b 2=( P I N D&( 0 b 1 1 1 1 0 0 0 0 ) ) ; d i g i t a l W r i t e F a s t ( r e a d C l o c k P i n , L O W ) ; / / c o m b i n ea n ds e n dt oP C b=b 1|b 2 ;

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

55/60

3/15/2014
b=b 1|b 2 ; S e r i a l . w r i t e ( b ) ; } r e t u r ni ; }

Print Page - ov7670 with both arduino uno and now mega

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 : # i n c l u d e< W i r e . h > # i n c l u d e< S d F a t . h > # i n c l u d e< S d F a t U t i l . h > c o n s ti n ts d _ s e l e c t=4 ; u i n t 8 _ ts e n s o r _ a d d r=0 x 4 2 ; S d F a ts d ; S d F i l ef i l e ;

v o i ds e t u p ( ) { W i r e . b e g i n ( ) ; S e r i a l . b e g i n ( 1 1 5 2 0 0 ) ;

D D R B | = 4 7 ; / / c l o c ka so u t p u ta n dS P Ip i n sa so u t p u te x c e p tM I S O P O R T B | = 6 ; / / s e tb o t hC Sp i n st oh i g h D D R C & = ~ 1 5 ; / / l o wd 0 d 3c a m e r a D D R D & = ~ 2 5 2 ; / / d 7 d 4a n di n t e r u p tp i n s / / s e tu pt w if o r1 0 0 k h z T W S R & = ~ 3 ; / / d i s a b l ep r e s c a l e rf o rT W I T W B R = 7 2 ; / / s e tt o1 0 0 k h z P g m P r i n t l n ( " C a m e r ai n i t ! " ) ; / /w r R e g ( 0 x 1 5 , 3 2 ) ; / / p c l kd o e sn o tt o g g l eo nH B L A N KC O M 1 0v s y n cf a l l i n g w r R e g ( 0 x 1 2 , 0 x 8 0 ) ; w r R e g ( 0 x 1 1 , 0 x 0 1) ; w r R e g ( 0 x 3 a , 0 x 0 4) ; w r R e g ( 0 x 1 2 , 0 x 0 1) ; w r R e g ( 0 x 1 7 , 0 x 1 2) ; w r R e g ( 0 x 1 8 , 0 x 0 0) ; w r R e g ( 0 x 3 2 , 0 x b 6) ; w r R e g ( 0 x 1 9 , 0 x 0 2) ; w r R e g ( 0 x 1 a , 0 x 7 a) ; w r R e g ( 0 x 0 3 , 0 x 0 0) ;

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

56/60

3/15/2014
w r R e g ( 0 x 0 3 , 0 x 0 0) ; w r R e g ( 0 x 0 c , 0 x 0 0) ; w r R e g ( 0 x 3 e , 0 x 0 0) ; w r R e g ( 0 x 7 0 , 0 x 3 a) ; w r R e g ( 0 x 7 1 , 0 x 3 5) ; w r R e g ( 0 x 7 2 , 0 x 1 1) ; w r R e g ( 0 x 7 3 , 0 x f 0) ; w r R e g ( 0 x a 2 , 0 x 0 2) ; w r R e g ( 0 x 1 3 , 0 x e 0) ; w r R e g ( 0 x 0 0 , 0 x 0 0) ; w r R e g ( 0 x 1 0 , 0 x 0 0) ; w r R e g ( 0 x 0 d , 0 x 4 0) ; w r R e g ( 0 x 1 4 , 0 x 3 8) ; w r R e g ( 0 x a 5 , 0 x 0 7) ; w r R e g ( 0 x a b , 0 x 0 8) ; w r R e g ( 0 x 2 4 , 0 x 9 5) ; w r R e g ( 0 x 2 5 , 0 x 3 3) ; w r R e g ( 0 x 2 6 , 0 x e 3) ; w r R e g ( 0 x 9 f , 0 x 7 8) ; w r R e g ( 0 x a 0 , 0 x 6 8) ; w r R e g ( 0 x a 1 , 0 x 0 b) ; w r R e g ( 0 x a 6 , 0 x d 8) ; w r R e g ( 0 x a 7 , 0 x d 8) ; w r R e g ( 0 x a 8 , 0 x f 0) ; w r R e g ( 0 x a 9 , 0 x 9 0) ; w r R e g ( 0 x a a , 0 x 9 4) ; w r R e g ( 0 x 1 3 , 0 x e 5) ; w r R e g ( 0 x 0 e , 0 x 6 1) ; w r R e g ( 0 x 0 f , 0 x 4 b) ; w r R e g ( 0 x 1 6 , 0 x 0 2) ; w r R e g ( 0 x 2 1 , 0 x 0 2) ; w r R e g ( 0 x 2 2 , 0 x 9 1) ; w r R e g ( 0 x 2 9 , 0 x 0 7) ; w r R e g ( 0 x 3 3 , 0 x 0 3) ; w r R e g ( 0 x 3 5 , 0 x 0 b) ; w r R e g ( 0 x 3 7 , 0 x 1 c) ; w r R e g ( 0 x 3 8 , 0 x 7 1) ; w r R e g ( 0 x 3 c , 0 x 7 8) ; w r R e g ( 0 x 3 d , 0 x 0 8) ; w r R e g ( 0 x 4 1 , 0 x 3 a) ; w r R e g ( 0 x 4 d , 0 x 4 0) ; w r R e g ( 0 x 4 e , 0 x 2 0) ; w r R e g ( 0 x 6 9 , 0 x 5 5) ; w r R e g ( 0 x 6 b , 0 x 4 a) ; w r R e g ( 0 x 7 4 , 0 x 1 9) ; w r R e g ( 0 x 7 6 , 0 x 6 1) ; w r R e g ( 0 x 8 d , 0 x 4 f) ; w r R e g ( 0 x 8 e , 0 x 0 0) ; w r R e g ( 0 x 8 f , 0 x 0 0) ; w r R e g ( 0 x 9 0 , 0 x 0 0) ; w r R e g ( 0 x 9 1 , 0 x 0 0) ; w r R e g ( 0 x 9 6 , 0 x 0 0) ; w r R e g ( 0 x 9 a , 0 x 8 0) ; w r R e g ( 0 x b 0 , 0 x 8 c) ; w r R e g ( 0 x b 1 , 0 x 0 c) ; w r R e g ( 0 x b 2 , 0 x 0 e) ; w r R e g ( 0 x b 3 , 0 x 8 2) ; w r R e g ( 0 x b 8 , 0 x 0 a) ; w r R e g ( 0 x 4 3 , 0 x 1 4) ; w r R e g ( 0 x 4 4 , 0 x f 0) ; w r R e g ( 0 x 4 5 , 0 x 3 4) ; w r R e g ( 0 x 4 6 , 0 x 5 8) ; w r R e g ( 0 x 4 7 , 0 x 2 8) ; w r R e g ( 0 x 4 8 , 0 x 3 a) ; w r R e g ( 0 x 5 9 , 0 x 8 8) ; w r R e g ( 0 x 5 a , 0 x 8 8) ; w r R e g ( 0 x 5 b , 0 x 4 4) ; w r R e g ( 0 x 5 c , 0 x 6 7) ; w r R e g ( 0 x 5 d , 0 x 4 9) ; w r R e g ( 0 x 5 e , 0 x 0 e) ; w r R e g ( 0 x 6 c , 0 x 0 a) ; w r R e g ( 0 x 6 d , 0 x 5 5) ; w r R e g ( 0 x 6 e , 0 x 1 1) ; w r R e g ( 0 x 6 f , 0 x 9 f) ; w r R e g ( 0 x 6 a , 0 x 4 0) ; w r R e g ( 0 x 0 1 , 0 x 4 0) ; w r R e g ( 0 x 0 2 , 0 x 4 0) ; w r R e g ( 0 x 1 3 , 0 x e 7) ; w r R e g ( 0 x 3 4 , 0 x 1 1) ; w r R e g ( 0 x 9 2 , 0 x 6 6) ; w r R e g ( 0 x 3 b , 0 x 0 a) ; w r R e g ( 0 x a 4 , 0 x 8 8) ; w r R e g ( 0 x 9 6 , 0 x 0 0) ; w r R e g ( 0 x 9 7 , 0 x 3 0) ; w r R e g ( 0 x 9 8 , 0 x 2 0) ; w r R e g ( 0 x 9 9 , 0 x 2 0) ; w r R e g ( 0 x 9 a , 0 x 8 4) ; w r R e g ( 0 x 9 b , 0 x 2 9) ; w r R e g ( 0 x 9 c , 0 x 0 3) ; w r R e g ( 0 x 9 d , 0 x 4 c) ; w r R e g ( 0 x 9 e , 0 x 3 f) ; w r R e g ( 0 x 7 8 , 0 x 0 4) ; w r R e g ( 0 x 7 9 , 0 x 0 1) ; w r R e g ( 0 x c 8 , 0 x f 0) ; w r R e g ( 0 x 7 9 , 0 x 0 f) ; w r R e g ( 0 x c 8 , 0 x 2 0) ; w r R e g ( 0 x 7 9 , 0 x 1 0) ; w r R e g ( 0 x c 8 , 0 x 7 e) ; w r R e g ( 0 x 7 9 , 0 x 0 b) ; w r R e g ( 0 x c 8 , 0 x 0 1) ; w r R e g ( 0 x 7 9 , 0 x 0 c) ; w r R e g ( 0 x c 8 , 0 x 0 7) ; w r R e g ( 0 x 7 9 , 0 x 0 d) ; w r R e g ( 0 x c 8 , 0 x 2 0) ; w r R e g ( 0 x 7 9 , 0 x 0 9) ; w r R e g ( 0 x c 8 , 0 x 8 0) ; w r R e g ( 0 x 7 9 , 0 x 0 2) ; w r R e g ( 0 x c 8 , 0 x c 0) ; w r R e g ( 0 x 7 9 , 0 x 0 3) ; w r R e g ( 0 x c 8 , 0 x 4 0) ; w r R e g ( 0 x 7 9 , 0 x 0 5) ; w r R e g ( 0 x c 8 , 0 x 3 0) ; w r R e g ( 0 x 7 9 , 0 x 2 6) ;

Print Page - ov7670 with both arduino uno and now mega

i f( ! s d . b e g i n ( s d _ s e l e c t ,S P I _ F U L L _ S P E E D ) )s d . i n i t E r r o r H a l t ( ) ; P g m P r i n t l n ( " R D Y 2 B ! " ) ; ; p i n M o d e ( 8 , I N P U T ) ; }

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

57/60

3/15/2014
v o i dl o o p ( ) { / / P g m P r i n t l n ( " S e n dO n ek e yt os t a r ti m a g es a v e " ) ; i n tb u t t o n S t a t e = 1 ; b u t t o n S t a t e=d i g i t a l R e a d ( 8 ) ;

Print Page - ov7670 with both arduino uno and now mega

i f ( b u t t o n S t a t e = = 0 ) { P g m P r i n t l n ( " I m gC a p t u r eO k " ) ; c a p t u r e I m g ( 0 , 0 , 1 9 2 0 , 5 ) ; / / e a c hp i x e li s2b y t e ss o1 2 8 0i n s t e a do f6 4 0f o rw i d t h / * c a p t u r e I m g ( 1 9 2 0 , 9 6 , 1 9 2 0 , 9 6 ) ; c a p t u r e I m g ( 1 9 2 0 , 1 9 2 , 1 9 2 0 , 9 6 ) ; c a p t u r e I m g ( 1 9 2 0 , 2 8 8 , 1 9 2 0 , 9 6 ) ; c a p t u r e I m g ( 1 9 2 0 , 3 8 4 , 1 9 2 0 , 9 6 ) ; * / } } b y t ew r R e g ( i n tr e g I D ,i n tr e g D a t ) { / / S e r i a l . p r i n t l n ( " S t a r t e d " ) ; W i r e . b e g i n T r a n s m i s s i o n ( s e n s o r _ a d d r> >1 ) ; / / S e r i a l . p r i n t l n ( " B e g a n " ) ; W i r e . w r i t e ( r e g I D&0 x 0 0 F F ) ; W i r e . w r i t e ( r e g D a t&0 x 0 0 F F ) ; i f ( W i r e . e n d T r a n s m i s s i o n ( ) ) { r e t u r n0 ; P O R T B | = 3 2 ; w h i l e( 1 ){ } } / / S e r i a l . p r i n t l n ( " D o n e ! " ) ; d e l a y ( 1 ) ; r e t u r n ( 1 ) ; } v o i dc a p t u r e I m g ( u i n t 1 6 _ tw s , u i n t 1 6 _ th s , u i n t 1 6 _ tw g , u i n t 8 _ th g ) { / / T O D O :s p e e du pt h i sl o o pi tm i s s e so n eb y t ep a r t w a yt h r o u g ht h ef i r s tl i n e / / r i g h tn o wIa mc o r r e c t i n gt h i si nt h ei m a g ec o n v e r t e rs o f t w a r ei ti sj u s to n eb y t ea n dn o tv e r y / / n o t i c a b l eb u ti tw o u l ds t i l lb en i c et of i xi nm yo p i o nId on o th a v et h i si s s u ew h e nt h i sl o o pi sc o m p i l e dw i t ha v r g c cw i t has e t t i n go fO 2 S e r i a l . e n d ( ) ; d e l a y ( 2 0 0 ) ; S e r i a l . b e g i n ( 1 1 5 2 0 0 ) ; S e r i a l . p r i n t l n ( " O K " ) ; u i n t 1 6 _ tl s 2 , l g 2 ; / / s k i p1m u l t i p l i e ss k i p2s a m ew i t hg e t 1a n dg e t 2 / / f i r s tw a i tf o rv s y n ci ti so np i n3( c o u n t i n gf r o m0 )p o r t D / / s t a r ts p ir a m / / c l i ( ) ; / / m a k es u r ei n t e r u p t sa r eo f f c h a r *s t r ; c h a rt m p ; s t r = ( c h a r * ) m a l l o c ( 1 2 * s i z e o f ( c h a r ) ) ; w h i l e( ! ( P I N D & 8 ) ){ } / / w a i tf o rh i g h w h i l e( ( P I N D & 8 ) ){ } / / w a i tf o rl o w s t r [ 3 ] = ' ; ' ; s t r [ 7 ] = ' ; ' ; s t r [ 3 ] = ' ; ' ; / / f o r( l g 1 = 0 ; l g 1 < h g ; l g 1 + + ) w h i l e( ( u i n t 8 _ t ) h g ) { / / f o r( l g 2 = 0 ; l g 2 < w g ; l g 2 + + ) l g 2 = w g ; w h i l e( l g 2 ) { w h i l e( ! ( P I N D & 4 ) ){ } / / w a i tf o rh i g h / /S P D R = ( u i n t 8 _ t ) ( P I N C & 1 5 ) | ( P I N D & 2 4 0 ) ; t m p = ( P I N C & 1 5 ) | ( P I N D & 2 4 0 ) ; w h i l e( ( P I N D & 4 ) ){ } / / w a i tf o rl o w s t r [ 0 ] = t m p / 1 0 0 ; s t r [ 1 ] = ( t m p % 1 0 0 ) / 1 0 ; s t r [ 2 ] = t m p % 1 0 ; / * w h i l e( ! ( P I N D & 4 ) ){ } / / w a i tf o rh i g h / /S P D R = ( u i n t 8 _ t ) ( P I N C & 1 5 ) | ( P I N D & 2 4 0 ) ; t m p = ( P I N C & 1 5 ) | ( P I N D & 2 4 0 ) ; w h i l e( ( P I N D & 4 ) ){ } / / w a i tf o rl o w s t r [ 4 ] = t m p / 1 0 0 ; s t r [ 5 ] = ( t m p % 1 0 0 ) / 1 0 ; s t r [ 6 ] = t m p % 1 0 ; w h i l e( ! ( P I N D & 4 ) ){ } / / w a i tf o rh i g h / /S P D R = ( u i n t 8 _ t ) ( P I N C & 1 5 ) | ( P I N D & 2 4 0 ) ; t m p = ( P I N C & 1 5 ) | ( P I N D & 2 4 0 ) ; w h i l e( ( P I N D & 4 ) ){ } / / w a i tf o rl o w s t r [ 8 ] = t m p / 1 0 0 ; s t r [ 9 ] = ( t m p % 1 0 0 ) / 1 0 ; s t r [ 1 0 ] = t m p % 1 0 ; * / s t r [ 3 ] = ' \ 0 ' ; / / s t r [ 4 ] = ' \ 0 ' ; f o r ( i n ti = 0 ; i < 3 ; i + + ) s t r [ i ] + = 4 8 ; f o r ( i n ti = 4 ; i < 7 ; i + + ) s t r [ i ] + = 4 8 ; f o r ( i n ti = 8 ; i < 1 1 ; i + + ) s t r [ i ] + = 4 8 ; / /s t r [ 4 ] = ' \ 0 ' ; / / P g m P r i n t l n ( s t r ) ; S e r i a l . p r i n t l n ( s t r ) ; } / * s t r [ 1 ] = ' \ 0 ' ; s t r [ 0 ] = ' \ r ' ; S t r i n g P g m ( s t r ) ; s t r [ 0 ] = ' \ n ' ; S t r i n g P g m ( s t r ) ; * / } }

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

58/60

3/15/2014
u i n t 8 _ tR d S e r i a l ( v o i d ) { / *W a i tf o rd a t at ob er e c e i v e d* / w h i l e(! ( U C S R 0 A&( 1 < < R X C 0 ) )) ; / *G e ta n dr e t u r nr e c e i v e dd a t af r o mb u f f e r* / r e t u r nU D R 0 ; } v o i ds p i C S t ( v o i d ) { / / t o g g l e ss p iC Su s e df o rr e s e t i n gs r a m P O R T B | = 6 ; / / c sh i g h / / _ d e l a y _ m s ( 1 ) ; P O R T B & = ~ 4 ; / / c sl o w } v o i ds p i W r B ( u i n t 8 _ td a t ) { S P D R=d a t ; / /W a i tf o rt r a n s m i s s i o nc o m p l e t e w h i l e ( ! ( S P S R&( 1 < < S P I F ) ) ){ } } v o i dS t r i n g P g m ( c h a r*s t r ) { d o{ s e r i a l W r B ( p g m _ r e a d _ b y t e _ n e a r ( s t r ) ) ; }w h i l e ( p g m _ r e a d _ b y t e _ n e a r ( + + s t r ) ) ; }

Print Page - ov7670 with both arduino uno and now mega

v o i ds e r i a l W r B ( u i n t 8 _ td a t ) { w h i l e(! (U C S R 0 A&( 1 < < U D R E 0 ) )){ } U D R 0 = d a t ; w h i l e(! (U C S R 0 A&( 1 < < U D R E 0 ) )){ }/ / w a i tf o rb y t et ot r a n s m i t }

I generate XCLOCK an external source and its 13MHz. This is what send on serial:
C ode : C a m e r ai n i t ! R D Y 2 B ! I m gC a p t u r eO k O K 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 6 0 1 7 0 2 8 0 1 6 0 1 7 0 2 2 0 2 3 0 1 6 0 1 6 0 2 3 . . . . .e t c .

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.

At the very least, I needed to know the answer to the first. Background: no queue (fifo), 20MHz XCLK (no PCKL signal at the moment - due to open circuit), 2v9 for logic high and power (330ohm/R:470ohm/R for voltage divider), using Arduino Uno R3 for prototyping and debugging Source references: SCCB Code: https://github.com/una1veritas/ARMWork/blob/master/stm32f3x_OV7670/sccb.cpp SCCB Specification: http://www.ovt.com/download_document.php?type=document&DID=63 Title: Re: ov7670 with both arduino uno and now mega Post by: rock5566r on March 08, 2014, 01:37:02 pm Hi! I'm a beginner of electronics. I'm wondering that can I use uno3 to control OV7670 with FIFO to take a picture and save it as a file. Then send it to my PC by using Ethernet shell. Is it possible to do that? Thanks in advance. rock5566r Title: Re: ov7670 with both arduino uno and now mega Post by: Koepi on March 09, 2014, 10:07:01 am I'm also absolutely new to Arduino, will shortly have 5 different Arduino Nano versions. But I also ordered the cheap non-FIFO OV7670 (http://www.ebay.ca/itm/CMOS-Camera-Module-OV7670-Display-Active-Size-640X480-SCCB-Compatible-I2C-36-m-/400578369245) (and also the FIFO version which seems only to be usable with different platform like RasPi). After reading through this thread I realized that the 2k SRAM definitly is insufficient. Thus I also ordered 5 pieces of 16MBit SPI eeproms (http://www.ebay.com/itm/5PCS-W25Q16BVSSIG-16M-BIT-SERIALFLASH-MEMORY-WITH-DUAL-AND-QUAD-SPI-SOP8-/321165418730), and SOIC8-to-DIP sockets (http://www.ebay.com/itm/New-5pcs-SOP8-SO8-SOIC8-TODIP8-adapter-pcb-conveter-board-/180952961067) to carry them. Quite cheap, actually altogether about 7 Euros. If I understand SPI/I2C correctly, I share the MISO/MOSI/SCK line and only need one pin for addressing each of the different devices like EEPROM and SDCARD. My idea is to fetch the image without the FIFO byte-by-byte and directly write through to the EEPROM (it supports writing even single bytes according to the data sheet (http://www.winbond.com/NR/rdonlyres/7EB3B29C-1B35-421C-AA24-F430B51C776A/0/W25Q16BV.pdf)) which could even hold 2 images in 640x480x3 RAW format (921KByte x 2). As soon as it is stored in EEPROM, I have all the time in the world to copy that over to SDcard. My project is a long-time observation with 1 image per day, for example each evening at 18h one image (RTC (http://www.ebay.com/itm/New-Arduino-RTCDS1302-Real-Time-Clock-Module-For-AVR-ARM-PIC-SMD-/200931981696) is also on the way). I would put the Arduino-timelapse-cam somewhere where it is dry but the nature is well visible. From theory, the Arduino needs so little power, for one image per day, that with a single LiIon 18650 battery charge it should give me 365 images without needing any service. ;) Do you have any suggestions if I'm on the right track? Is there maybe some 8 MBit RAM module out there which could be used via SPI? Is this camera a total loss and I should spend the money on a JPEG camera, about triple to quadruple the price? I hope I won't need to stress your help too much and too often as soon as the items arrive :D Another thought about the FIFO version. A friend suggested - if I need to pause read-out for writing the data, instead of using the /RE pin which isn't available in pinout, set the RCLK (read clock) to 0. Sounds plausible as solution. Thanks a million, Best regards, Koepi Edit4: Some major cleanup with properly using links, additional info about FIFO camera module... Title: Re: ov7670 with both arduino uno and now mega Post by: angeleye9 on March 11, 2014, 11:03:39 pm Hi Mr arduino; I am getting an completeley white image from OV7670+fifo driven by Arduino mega. Do you have any idea why this is happen? Title: Re: ov7670 with both arduino uno and now mega Post by: marcioferrari on March 12, 2014, 07:12:14 pm
Q uote from : ne rdroide on De ce m be r 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, m y function that se nds the pix e ls to the se rve r is slow? W e ll, I will change this, I just ne e d to finish the article about the proje ct... he he And the shie ld e the rne t is using the pins 10,11,12 and 13. I think that just this. The pin 4 is use d for the sdC ard, so I disable d it. The re giste rs are right?

Powe re d by SMF 1.1.19 | SMF 2013, Sim ple Machine s

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

60/60

Вам также может понравиться