OV7670 Camera + mbed LPC1768 over Ethernet

Introduction

This project is an upgrade of THIS work and it works by taking a image from the ov7670 camera and send it over an ethernet connection to a pc.
You need a camera OV7670 with FIFO buffer and a ethernet connector (I used a SI-60002-F Jack Connector).



Table of Contents

  1. Product Specifications
    1. OV7670 + AL422
    2. RJ45 SI-60002-F
  2. Pin Description
  3. Test Code for mbed
  4. Example
    1. View the images on Android phone
    2. View the images on PC
  5. Commands for OV7670 Grabber
    1. INIT
    2. SNAP
  6. Some important informations
    1. Image Format
    2. Oscilloscope Screens



1. Product Specifications


1.1 OV7670 + AL422

Datasheet: OV7670 + AL422:

  • Array Size: 640x480
  • 8bit Output Format (YUV/ YCbCr 4:2:2/RGB565-555-444/RAW RGB Data)
  • Serial Camera Control Bus (SCCB)
  • Rolling shutter
  • 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.


1.2 RJ45 SI-60002-F

Datasheet: SI-60002-F

This is a RJ45 connector without leds.



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



3. Test Code for mbed

Import programOV7670_Test_Code_with_ethernet

Test Code for OV7670 Camera module. The images are sent over ethernet link.


Now the program is using a "Static IP" but if you want to use a DHCP is necessary change this code in main.cpp

Static IP

eth.init(ip, mask, gateway);


with this

DHCP

eth.init();



4. Example


4.1 View the images on Android phone (Apk OV7670 Grabber)


You can download it by google play here: OV7670 Grabber for Android


- First you have to connect the phone Android and the mbed to the same local network through a router.

/media/uploads/edodm85/guida.png


- Then you have to set the IP and PORT of the mbed board in TCP CONSOLE Settings:

/media/uploads/edodm85/ovgrabber0_1.png /media/uploads/edodm85/ovgrabber1_1.png


- In "Grabber" Settings you can select the image resolution and format.

For the FREE version:

  • Image resolution
    • QQVGA: 160x120
    • QVGA: 320x240
  • Image format
    • BAW: Black and White


For the PRO version:

  • Image resolution
    • QQVGA: 160x120
    • QVGA: 320x240
  • Image format
    • BAW: Black and White
    • RGB: RGB565
    • YUV: YUV to ARGB8888

/media/uploads/edodm85/ovgrabber0_2.png /media/uploads/edodm85/ovgrabber4.png


- Then you can start the connection with mbed. The black ball will turn green color when the connection is established.

/media/uploads/edodm85/ovgrabber2.png


- In the second tab "Grabber" first you have to initialize the board with the "INIT" button.
If the initialization is OK you can acquire images with "SNAP" button.

/media/uploads/edodm85/ovgrabber3.png


- Ok now you can acquire images by android.




4.2 View the images on PC (Software OV7670 Grabber v2.0)


You can download the program here: OV7670 Grabber v2.0

Info!

Is required Microsoft .NET Framework 4.5 or above.


- First you have to press the button "INIT" and set the IP address and Port in a right property box.
In the end you can press the button "Connect" (if the connection is established with success a green ball appear).

/media/uploads/edodm85/ov2_1.jpg


- In the right box you can select the Image format and some properties and then press the button "INIT" for initialize the camera.
Now if you press the button "SNAP" the program acquires a image while if you press "GRAB" the program acquires continuously.

/media/uploads/edodm85/ov2_3.jpg


- The grab function is limited for the format 160x120. The maximum frame rate is 10FPS.

/media/uploads/edodm85/ov2_2.jpg


- If you press the button "Refresh" you can monitor all registers.

/media/uploads/edodm85/ov2_4.jpg



5. Commands for OV7670 Grabber


5.1 INIT

The initialization sets the correct registers of the OV7670 sensor.

INIT CMD: "init " + Image_Format + " " + (width * height);

Image_Format = BAW or RGB or YUV or RAW


If the initialization finished with success the mbed return: "OV Init OK".


5.2 SNAP

The snap button send this string: "snap".


The mbed board respond with a Start Condition string: "sRt" followed by the image data.



6. Some important informations


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


6.2 Oscilloscope Screens

The camera needs 33ms to acquire a 160x120 image and the double time for read and send the frame from FIFO memory to pc over ethernet (screens below).

/media/uploads/edodm85/d004_we33ms.jpg

/media/uploads/edodm85/d005_we_sta_basso_2_vsync.jpg

So the Frame rate is FPS_TCP = 1000 / (3 * 33) = 10FPS

In this screen is shown the pin OE.

/media/uploads/edodm85/d014.jpg


13 comments on OV7670 Camera + mbed LPC1768 over Ethernet:

22 Mar 2014

Hello,

Your project is very impressive especially the grabber utility. I am using a DSP processor to capture the image data from Omnivision sensor, and I am transferring the image data using MAC address, I do not know how to implement TCP or UDP protocol and I believe it might make the code at the processor end a little complicated, so I would like to develop a Camera Image Grabber similar to OV7670 Grabber, which recieves the image data based on MAC address, but I am not well versed in VB, so can you please help me out with the development process? or Can you please provide the VB source code for OV7670 Grabber?

Thank you.

03 Apr 2014

I would like to thanks cause your project helped myself a lot to understand how ov7670 and mbed works together.

So I analised your code and i have 2 conclusions. The first lost frame is because of latency between each request over tcp. If you put numbering each on frame or line you can solve it. Second you have a fail in your code. I think you need to include Busy=false and done=true in the camera.Readstop() and put all bytes captured inside the "while" in the main.cpp

congratulation, I will do some tests with 7725 too. bye

03 Apr 2014

Ashik P wrote:

but I am not well versed in VB, so can you please help me out with the development process? or Can you please provide the VB source code for OV7670 Grabber?

Hi Ashik, sorry for the late reply but I didn't see the mail notification of your comment.

The source code of my programm is not open but you can find a lot of example of Tcp communication writen in vb in google..

For example here

Fabio Bastos wrote:

I would like to thanks cause your project helped myself a lot to understand how ov7670 and mbed works together.

So I analised your code and i have 2 conclusions. The first lost frame is because of latency between each request over tcp. If you put numbering each on frame or line you can solve it. Second you have a fail in your code. I think you need to include Busy=false and done=true in the camera.Readstop() and put all bytes captured inside the "while" in the main.cpp

Thanks. Yes the problem is the latency of the tcp but you intend to activate the 'segment numbering' over tcp?

04 Apr 2014

Hi Edoardo. I will not activate segment numbering over tcp protocol, just include one first byte as control frame, so you dont need start snapshot over and over.. you will send one comand and in your grabber, with field control number information you can synchronize all frames without latency anymore.

05 Apr 2014

Hi Fabio, thanks for the advice.
In the next days I will try to understand if in lwip is possible disable the segment numbering..if you have already disabled it you can post the code.
Best regards

Fabio Bastos wrote:

Hi Edoardo. I will not activate segment numbering over tcp protocol, just include one first byte as control frame, so you dont need start snapshot over and over.. you will send one comand and in your grabber, with field control number information you can synchronize all frames without latency anymore.

16 Apr 2014

Dear Edoardo,

At moment I just have your code translated to OV7725 model, so I still didnt have tested because I m waiting for the shippment arrives at my home. But I can send you if you want. I am not planning to do any changes at transport layer of protocol, because your buffer is only 4096 and you still took one frame perfectly , so i will include numbering together with data video, because you can disable 00 and FF and use these bytes to signaling the starting frame/row, and after them you put sequence frame number.

:)

18 May 2014

Hello Edoardo,

Amazing project!

I have a question, AL422 datasheet recommend to have WCLK and RCLK running at least at 1MHz at all times. From camera module WCLK is running from OV7670 PCLK, but RCLK is controlled by mbed and by looking at your code I understand that during the byte reading you switch RCLK, and so is irregular in frequency.

I am wondering if some fault can occur by using this approach, instead of using OE and RE control signals.

Best,

25 Aug 2014

Hello nice working, I have a question, can ov7670 send a video instead of picture on ethernet?

19 Oct 2014

Have someone tried this setup but with v3 of the camera?

13 Jan 2015

There is hope. ov7670_grabber_v2.0.rar source program you want to upload.

This sentence I'm writing using Google Translate.

18 Dec 2016

Hi, Can I use this method for video streaming ? and how FPS I will get for VGA resolution ? Thanks.

17 Aug 2017

Hi Edoardo,

How long time? I am here to thanks your post, So now I got 40fps with OV7725 + some tricks . Tell me If you want know. Is free for you that helped me a lot. Thanks mister_bastos@hotmail.com

24 Aug 2017

Hi Edoardo,

i have a question in this application function. Does this application work when wirelessly connecting a WiFi module to a mobile phone and tcp / ip without ethernet?

Please log in to post comments.