OV7670 Camera + mbed LPC1768 over USB

Introduction

Note

The ethernet version is ready and you can find it in my new notebook page: HERE.

Last year I searched some camera module to connect to the mbed and finally I found on ebay this module: OV7670 Camera Module with FIFO AL422.
I searched some information and I found these interesting notebooks that given me a big help: Martin Smith notebook and Fuyuno Sakura notebook


Product Specifications

This camera is based on a CMOS Sensor OV7670 made by Omnivision and a FIFO buffer AL422. /media/uploads/edodm85/ov7670_front2.jpg

OV7670:

  • Array Size: 640x480
  • 8bit Output Format (YUV/ YCbCr 4:2:2/RGB565-555-444/RAW RGB Data)
  • Serial Camera Control Bus (SCCB)
  • Rolling shutter

AL422:

  • 3Mbit of DRAM
  • Read/write cycle time: 20ns

Warning!

There are two versions of this camera.

The difference is that in the model V2 the VSYNC from the OV7670 is connected directly to the AL422’s write reset (WRST).

The schematic is here: /media/uploads/edodm85/ov7670_fifo_sch_v2.pdf

In the back of my camera there is this code: CF7670C-V2.


Pin Description

NameOV7670 pinMBED pin
VCC1Vout
GND2GND
SCL_SCCB3P27
SDA_SCCB4P28
VSYNC5P23
HREF6NC
WEN7P25
XCLK8NC
RRST9P26
OE10P29
RCLK11P30
GND12GND

Note: you need a pull-up resistor on sda and scl.

NameOV7670 pinMBED MASK: 0x7878000MBED MASK: 0x78600C0
D013P13 (p0.15)P8 (p0.6)
D114P14 (p0.16)P7 (p0.7)
D215P12 (p0.17)P12 (p0.17)
D316P11 (p0.18)P11 (p0.18)
D417P15 (p0.23)P15 (p0.23)
D518P16 (p0.24)P16 (p0.24)
D619P17 (p0.25)P17 (p0.25)
D720P18 (p0.26)P18 (p0.26)


Image Format

This camera supports various formats, but I will comment only the three that I used:

  • YUV 4:2:2

The YUV model defines a color space. The Y component determines the brightness of the color, while the U and V components determine the color itself (the chroma). Y ranges from 0 to 255 in digital formats, while U and V range from -128 to 127.
One neat aspect of YUV is that you can throw out the U and V components and get a grey-scale image.

In the YUV 4:2:2 format the U and V channels are shared between two consecutive pixels. Therefore two pixels are composed from 4 bytes, this means that in average each pixel is stored as 2 bytes.

/media/uploads/edodm85/uyvy.gif

  • RGB 565

RGB Colorspace is one of the most common colorspaces used today. It is used for many uncompressed image formats and computer displays. In RGB, there are 3 channels, each one indicating how much of a given color the final color has. These channels indicate Redness (R channel), Blueness (B channel), and Greeness (G Channel). Combining these components allows us to make almost any color humans can see.

The RGB565 color format is composed by 5 bits for the red and blue value and 6 bits for the green value.

/media/uploads/edodm85/rgb565.jpg

  • RAW Bayer

This type of format doesn't have any image processing.


Test Code for mbed

Import programOV7670_Test_Code

Test Code for OV7670 Camera module with FIFO AL422


Test Grabber

I wrote a C# program that snap a image and send it to the pc.

You can download the program here: OV7670 Grabber USB V1.5
Is required Microsoft .NET Framework 3.5 or above.

Some screens:

/media/uploads/edodm85/imm_usb_1mod.jpg
First you need to set the correct COM Port (only the first time) and press the "Connect" button (1). You can reset the mbed with the "Reset ARM" button.
There is the possible to change the priority of the program to real time with the "Real Time" button.


/media/uploads/edodm85/imm_usb_2mod2.jpg
Then you can select the type of image format (8bit black&white or 16bit RGB or 24bit RGB or RAW) (2), press the "INIT" button (3) for initialize the camera and in the end press the "SNAP" button (4) for SNAP a image.


/media/uploads/edodm85/imm_usb_3mod.jpg
In this version of the software there is a possibility to decide to save or not of the images grabbed with the checkbox "Save Image" (5).


Update

  • U6: Updated OV7670 Grabber USB to V1.5
  • U5: Updated OV7670 Grabber USB
  • U4: Fixed 640x480 resolution
  • U3: Added RAW to RGB888 conversion
  • U2: Added YUV422 to RGB888 conversion
  • U1: Added 320x240 and 640x480 resolutions


45 comments on OV7670 Camera + mbed LPC1768 over USB:

09 Apr 2013

What is your format data when you send it to computer? I rewrite the code in AVR with Arduino language, but I want to use program OV7670 Grabber USB to V1.4 .

10 Apr 2013

Hi Marchi, I need to know format data send to computer. Can you help me. Ii very necessary for me.Thanks!

12 Apr 2013

Hi Edoardo, I don't understand data format send to computer. For instance, RGB565 have output data each pixel is 2 byte but OV7670 Grabber USB program see 1 pixel is 1 byte(HEX) . I do every times . For example, 120x160 frame it see 38400 pixel, the mean is each pixel contain the most 2 number(HEX) but I read datasheet of camera need 2 byte( 4 number(HEX)) .Can you help me! my email is tvden018@student.ctu.edu.vn

16 May 2013

Could we just use LPC1768 to access this 8-bit data without AL422 ?

16 May 2013

Filho Wu wrote:

Could we just use LPC1768 to access this 8-bit data without AL422 ?

Hi Filho Wu,
I think that is possible but with some limitations.
The ram size of the mbed is 64KByte so you can grab at most frames of 160x120 pixels.

Best regards,
Edoardo

05 Jun 2013

Hi all, I’ve a problem with read and write some register of the OV7670. If I read for example the register 0x0A or 0x0B I read the correct values, 0×76 and 0×73, if I write the register 0x0D with some value I read the correct value. I’ve a problem with the register COM7 0×12 because if I read the register I receive 0xFF ( and OV7670 ack correct ). Why? If I write it I have correct ACK from OV7670, but reading still receive 0xFF. Please help me.. thank you Emanuele

05 Jun 2013

Hi Emanuele,

I tried to change the value of the reg 0x12 and it is changed.
For example:
/media/uploads/edodm85/imm_ex.jpg

Best regards,
Edoardo

Emanuele Tavelli wrote:

Hi all, I’ve a problem with read and write some register of the OV7670. If I read for example the register 0x0A or 0x0B I read the correct values, 0×76 and 0×73, if I write the register 0x0D with some value I read the correct value. I’ve a problem with the register COM7 0×12 because if I read the register I receive 0xFF ( and OV7670 ack correct ). Why? If I write it I have correct ACK from OV7670, but reading still receive 0xFF. Please help me.. thank you Emanuele

12 Jun 2013

Hi Edoardo, I can aquire an image from OV7670! Great! The only mistake is that the image is in grayscale and not in color RGB. Any ideas?

thank you Emanuele

13 Jun 2013

Hi Emanuele,
are you using my program to capture the images? Did you press the button "Save Settings"?

Best regards,
Edoardo

Emanuele Tavelli wrote:

Hi Edoardo, I can aquire an image from OV7670! Great! The only mistake is that the image is in grayscale and not in color RGB. Any ideas?

thank you Emanuele

27 Jul 2013

Hi Edoardo,

Great work!! I am not aware of mbed platform, but I would like to use your PC software-OV7670 USB Grabber. I am trying to interface OV7670 with LPC2362 MCU, Could you pls let me know the format data (protocol) send to computer. Thanks in advance

27 Jul 2013

Hi Shabbir,

Thanks! The format data to send to pc are a sequence of 8 bit integer (0-255), checks this function:

pc.putc(camera.ReadOnebyte());

For other information you need to wait one week, because between a hours I leave for the holidays.

Best regards,
Edoardo

07 Aug 2013

Hi Please complete schematic for this project please email me.

19 Aug 2013

Hi Edoardo,

Thanks, can you pls let me know how you convert raw data to RGB in your grabber application, can you pls provide me the algorithm for this.

Thanks in advance NS

Edoardo De Marchi wrote:

Hi Shabbir,

Thanks! The format data to send to pc are a sequence of 8 bit integer (0-255), checks this function:

pc.putc(camera.ReadOnebyte());

For other information you need to wait one week, because between a hours I leave for the holidays.

Best regards,
Edoardo

22 Aug 2013

Hi, your project looks very cool! What's the highest FPS you can get with this camera module? (capturing and saving)

23 Aug 2013

Shabbir Nazar wrote:

Hi Edoardo,

Thanks, can you pls let me know how you convert raw data to RGB in your grabber application, can you pls provide me the algorithm for this.

Thanks in advance NS

Hi Shabbir,
The code of my application is not open. But might help you read this wiki page "BMP file format" and search for how create a bmp image with c# in google.
My function generete a BMP image from the raw data.


Robert Chen wrote:

Hi, your project looks very cool! What's the highest FPS you can get with this camera module? (capturing and saving)

Hi Robert,
Thanks! In this project the camera sends the data to the pc with USB so in this way the speed is low. So with USB you can just take a image.
Instead with Ethernet is possible make an aquisition (my notebook here) but I'm working. For the moment with resolution 160x120px and b&w I acquire to 10FPS.


Edoardo

07 Sep 2013

Hi Edoardo,

Thanks again, I want to use your library to put this camera for my robot.

I was looking through your code and am curious about the ReadOnebyte() function, why do you need to shift the bits around again?

B1 = (((data&0x07800000)>>19)|((data&0x078000)>>15));

I thought the Port0 was already masked in the declaration. So shouldn't "PortIn data" already give the 8 needed bits? Maybe I don't understand how PortIn works.

Thanks! Robert

09 Sep 2013

Robert Chen wrote:

Hi Edoardo,

Thanks again, I want to use your library to put this camera for my robot.

I was looking through your code and am curious about the ReadOnebyte() function, why do you need to shift the bits around again?

B1 = (((data&0x07800000)>>19)|((data&0x078000)>>15));

I thought the Port0 was already masked in the declaration. So shouldn't "PortIn data" already give the 8 needed bits? Maybe I don't understand how PortIn works.

Thanks! Robert

Hi Robert,
The function PortIn reads the bits 26-25-24-23 and 18-17-16-15 of Port0 (32bits) and you need the shift for create a byte.
Martin Smith has done a very cool robot that integrates this camera, if you want the notebook is HERE.


Best Regards,
Edoardo

28 Sep 2013

Can anybody tell whether input of XCLK in ov7670 is square or sinusoidal wave in nature???

Waiting for your answers eagerly !!!!!!!!!!!!

19 Nov 2013

Edoardo,

Great work! I appreciate your effort and have learned a great deal by you doing this. I do have one question. The data pin assignments did not work for me. The image that was captured was scrambled colored pixels. I re-read your posts and then found on Mr. Sakura's page the following data pin assignments. PortIn(p18,p17,p16,p15,p11,p12,p14,p13) is D7-D0. When I changed the wiring to these I immediately captured a proper image. What am I missing or mis understanding?

Thanks again, Joe LoSurdo

29 Jan 2014

Hi Edoardo, I've a ov7670 with FIFO cam module with different header pin names. Do you have any hint on how to connect these to mbed? Thanks.

My board have the following schematic:

/media/uploads/cylax/ov7670_fifo_sch_v1.pdf
/media/uploads/cylax/5591708c-5263-493e-a572-4e1448b77a88.jpg

30 Jan 2014

Hi Robson, the schematics that you posted are different.

What is the correct schematic of your board?

Robson Cardoso dos Santos wrote:

Hi Edoardo, I've a ov7670 with FIFO cam module with different header pin names. Do you have any hint on how to connect these to mbed? Thanks.

My board have the following schematic:

/media/uploads/cylax/ov7670_fifo_sch_v1.pdf
/media/uploads/cylax/5591708c-5263-493e-a572-4e1448b77a88.jpg

30 Jan 2014

This is the correct one.

/media/uploads/cylax/5591708c-5263-493e-a572-4e1448b77a88.jpg

Edoardo De Marchi wrote:

Hi Robson, the schematics that you posted are different.

What is the correct schematic of your board?

Robson Cardoso dos Santos wrote:

Hi Edoardo, I've a ov7670 with FIFO cam module with different header pin names. Do you have any hint on how to connect these to mbed? Thanks.

My board have the following schematic:

/media/uploads/cylax/ov7670_fifo_sch_v1.pdf
/media/uploads/cylax/5591708c-5263-493e-a572-4e1448b77a88.jpg

30 Jan 2014

Ok. You can try this pin configurations:

OV7670 - mbed
1 - 3.3v
2 - GND
3 - p29
4 - p26
5 - p23 (the pin 5 and pin 9 are connected to pin p23 of the mbed)
6 - p30
7 - p25
8 - NC
9 - p23
10 - p27
11 - p28
12 - NC
The others are the same.

Robson Cardoso dos Santos wrote:

This is the correct one.

07 Feb 2014

Thanks, but there is no HREF pin in my module! This signal is required by the library.

07 Feb 2014

In really, the href pin is present but not essential for the work of the library

Robson Cardoso dos Santos wrote:

Thanks, but there is no HREF pin in my module! This signal is required by the library.

14 Feb 2014

I have this board how i can use OV7670 with this board http://www.aliexpress.com/item/Brand-new-updated-version-8051-camera-with-a-2-8-screen-Ov7670-module-Sd-storage-usb/1439005792.html

any one used this board can you help me ?

10 Apr 2014

hi Edoardo thanks for information i want write a program like OV7670 Grabber USB V1.5, can you explain about your program how you wrote it,and how you convert RGB code to an image in c#(visual studio)?

11 Apr 2014

Hi Erfan, I wrote a class that create a bitmap from raw data with a BinaryWriter object (a bitmap is composed from: 14Byte header - 54Byte BitmapInfoHeader - the color palette - the raw data).
Probably you can use the bitmap class of the dot.net but I didn't try
Edoardo

erfan mansouri wrote:

hi Edoardo thanks for information i want write a program like OV7670 Grabber USB V1.5, can you explain about your program how you wrote it,and how you convert RGB code to an image in c#(visual studio)?

01 Jul 2014

Hi Edoardo, can you tell me what are the commands to get an image via serial protocol?

07 Jul 2014

Can this camera operate at low temperatures?

23 Feb 2015

Hi everyone, I have tried importing the library files and compile them for my KL25z microcontroller. To no avail of success, I realised that the mbed imported is different from the one for KL25z.

Can anyone advise on what are the modifications needed to be done for the library to work?

24 Feb 2015

I had a virus in the Grabber.exe !

03 Apr 2015

you are develop OV7670 module,right? Do you need buy OV7670 chips, we have sell CMOS camera module chips , include OV, Aptina, SONY,Sumsung etc sensor chips. If you need any products, you can contact me.

Could I become your China friend?

Best regards, Michella

I looking forward to building a long term friendly business relationship with you!

10 Apr 2015

I experiment follow the steps described above,The result is shown in figure. /media/uploads/zm1011/-s--jugvn6-ot2-ww1om4pw.png /media/uploads/zm1011/49-a-pqb1--o4-x-i5fuxip.jpg What can I do to solve this problem? Thank you very much!

21 Sep 2015

I have a problem interfacing my OV7670 to Nucleo-F401RE.

Since I don't have a LPC 1768 board, I had to use different pins, here is what I used:

vsync = PC_3

WEN = PC_2

RRST = PH_1

OE = PH_0

RCLK = PC_15

SCL_SCCB = D15 (I2C_SCL)

SDA_SCCB = D14 (I2C_SDA)

D0 = PA_0 D1 = PA_1 D2 = PA_4 D3 = PA_5 D4 = PA_6 D5 = PA_7 D6 = PA_8 D7 = PA_9

PortName is set to PortA and the Port Mask is 0x0000003F3 (binary : 0011 1111 0011 ), I triple checked all the wirings and read through the ov7670 library,

It seems there is a problem with I2C connection, because I can not read registers, and with OV7670 Grapper app, when initializing the camera, it says "Init Failed".

and of course, I changed the bit-shifting stuff to match my configs:

Bit shifting config

int OV7670::ReadOnebyte(void)
{
        int B1;
        rclk = 1;
        B1 = ((data&0x3F>>3)|((data&0x03)));
        rclk = 0;
        return B1; 
}

07 Apr 2016

/media/uploads/assad/imageov7670_1.bmp i am getting this image from camera pleas help

16 May 2016

m z wrote:

I experiment follow the steps described above,The result is shown in figure. /media/uploads/zm1011/-s--jugvn6-ot2-ww1om4pw.png /media/uploads/zm1011/49-a-pqb1--o4-x-i5fuxip.jpg What can I do to solve this problem? Thank you very much!

I also get the same graph, could you please tell me how did you deal with it?

15 Jan 2017

hello i can't download OV7670 Grabber USB V1.5 please help me! thank you

06 Mar 2018

Code "OV7670 Grabber USB V1.5" reuploaded.

27 May 2018

hi i bought another version of this camera can you help me to use your app with this version which dosen't have memory and oscillator /media/uploads/mohammad007/l141078339237362.jpg

25 Jun 2018

Hi,

I have a version of the OV7670 camera that has 22 pins (schematic attached below). I tried different configurations but I couldn't get it to work. Any tips on how I should connect the pins? Thanks!

/media/uploads/maspadaru/ov7670_fifo_22pin.png

24 Oct 2018

chuanqin qiu wrote:

m z wrote:

I experiment follow the steps described above,The result is shown in figure. /media/uploads/zm1011/-s--jugvn6-ot2-ww1om4pw.png /media/uploads/zm1011/49-a-pqb1--o4-x-i5fuxip.jpg What can I do to solve this problem? Thank you very much!

I also get the same graph, could you please tell me how did you deal with it?

hi did you solve it?

27 Oct 2018

.

27 Oct 2018

Mike Spadaru wrote:

Hi,

I have a version of the OV7670 camera that has 22 pins (schematic attached below). I tried different configurations but I couldn't get it to work. Any tips on how I should connect the pins? Thanks!

/media/uploads/maspadaru/ov7670_fifo_22pin.png

hi did you solve it?

27 Oct 2018

Muhammad Asad Iqbal wrote:

/media/uploads/assad/imageov7670_1.bmp i am getting this image from camera pleas help

hi did you solve it?

Please log in to post comments.