Serial Streaming

Not very happy with the performance I get from Processing in displaying the images coming from my Arduino Module I decided to build a dedicated application to “see” the image instead. Is part of a bigger project, my “stereoscopic vision” project ^_^ Kind of a long shot, but sounds like a lot of fun.

Anyway, I start learning VB and for the past 2 days I tried to code a small application that connects to the serial port, retrieve the data streamed by the camera and display it at high-speed (hmm… sort of anyway) in a window.

First, I am planning to use 8 bit per pixel, however, not happy with the 256 color per pixel option, looking more for a 4096 colors per pixel instead, so I decided to get pump 12 bits per pixel in only 8 bits… Cool, right? The trick is simple: for each pixel I stream 8 bits, each bit contain 4 bits for green (G) and 4 bits for blue (B) and next one 4 bits for green and 4 bits for red (R) so 2 adjacent pixels share the same B or R information at 12 bits per pixels, voila! got 50% compression of the data sent while getting 16 times more colors and images looks much better.

Next step is to understand how the VB 2010 works and how to handle the serial port and then… how to draw pixels… Last was the worse part, basically could not find much about it and when I could I realized that was damn simple…

Anyway, while is not yet extremely stable and fast (320 x 240 = 76,800 bytes + some synchronization data, around 80+ Kbytes of data over serial port at 600,000 Bps take a bit less than 2 seconds per frame) is kind of working, however need to work a bit on the speed and to detect the errors and drop the lines that are not received properly.


13 thoughts on “Serial Streaming

  1. Hello,

    You’ve done very inspiring project! Your blog is only source of information about OV7670 and Arduino.

    I want to connect OV7670 to Arduino and send images over serial connection to computer. I’ve bought camera on Ebay: I have a couple of questions. Can you help me?

    The camera is very similar to yours, but it doesn’t have chip on back side. It has ten pins: VCC, GND, SIO_D, SIO_C, HREF, VSYNC, XCLK, PCLK and D0…D7. Does it mean that my camera doesn’t have FIFO module? Can I operate it with my arduino in this case?
    If I understand general idea, I need to provide clock frequency on XCLK and read PCLK, HREF, VSYNC for sync and D0…D7 for color. Also I can read/write camera settings with SIO_D and SIO_C (SCCB). Am I right?

    In this case what frequency should Arduino generate on XCLK pin? Can I use 5V Arduino UNO if I connect camera’s VCC to 3.3V on Arduino, use some 5V-to-3V converter for XCLK, SIO_D, SIO_C and connect other pins directly?

    Connecting this camera is not easy task for newbies like me :) I think if you publish sample code for getting frame and schematics community will be very grateful.

    I will be grateful for any information you can provide.

    P.S. Sorry for my English

    • Hi Vlad, your camera module is the basic one and will be a bit more trickier to get it working as you will need to process everything within a frame.
      Basically you will need to set up one external interrupt to capture VSYNC or beginning of a new frame, another external interrupt to capture HREF or beginning of a new line, then either use a third external interrupt on PCLK to capture the pixel clock, but this will require to set the clock divider to a very low frame rate or you shoul just read two times number of pixels per line you want to capture and use NOPE to “tune” your code to match the timing. Last one is explained pretty well on the AvrCam project documentation available online.

    • @Cesare: i used the one with FIFO, will be much easier to write code for it and even do some image processing. Not sure what you want to achieve with the streaming, however, if you do the math you are better using a “serial jpeg camera” already available online. Will only recomend using OV7670 module only if you do image processing…

  2. Hi Claudiu!
    I´m big fan of your work here(especially with OV7670).
    I´m building a robot and I want to ask, what is the best solution for taking photos or live video on the robot´s side and transfer it to the PC.
    If you would release some kind of library with simple commands(take photo etc.) it would be very great.
    If is the wireless live video streaming too difficult for my arduino mega 1280 i will be satisfied only with taking pictures.

    P.s.: I´m considering to buy this one.

    there is also a library but I´m using arduino IDE and I dont know how to use it.

    Thank you very much


    • @Tomas: Thank you! If you are looking for images/picture streaming and simple solution, you should be looking for a serial jpeg camera (see uCAM TTL from 4D Systems) and xBee. This will give you something like 2-4 fps maybe. Please do note that the biggest limitation is the wifi speed (anything above 115.2 kbps over xBee is not really reliable. If you are actually doing the image processing and color detection or any other simple image processing, can use a OV7670 with FIFO.

      To get the OV7670 working, you will need to write few libraries in C/C++ that will handle SCCB, communication with OV7670 and the streaming/image processing part, not sure if you can do this in Arduino IDE, but need to be careful with the timing of the signals to control OV7670. The libraries you mention are for a ST32 board with LCD display, but can use them as reference for your project.

  3. Hi Claudiu
    I’m working on a android project and i try to connect a camera from which i can send the data to the anroid-phone and from there to another android phone. I can connect diverse outputs, such as UART, SPI, I2C, PWM, Analog and pulse input, to an IOIO-Board from which i can transver the data to the Phone. Now I’m searching for a camera which can send at least 15 fps. The resolution is not that important. I found somme serial cameras but they normaly take only every two seconds one picture. Now i found the OV7670 but i don’t know how to connect it is it a serial signal and can i use it with my inputs(shown above).

    Thank you very much

  4. Hi Claudiu
    I’m working on a Android project in which i would send an image/stream from an external camera to another smart-phone. The capturing goes over an “IOIO-Board” from wich i can capturing different inputs from my Android-phone. Now I was searching for a camera with digital interface because i can’t decode an analog PAL signal. So i searched for serial cameras but i found only somme that take only one image per two seconds. But i want at least 15 fps and the resolution is not that important. Now i found a OV7670 camera module and i saw that you can capture a liveview with that. Now my question is, can you connect and read this module with one of the inputs of the IOIO board which are: UART,SPI,I2C, Pulse input, Analog in, digital in.

    Thank you very much

    • Hi Lorin, you can use OV7670 module to capture the image and stream it to ur Android system. If you just using the IOIO board, you will need about 10 IO pins at least to do this using OV7670 FIFO module (2 for SSCB, 4 for control signals and at least 4 for data) then a way to communicate with your phone (serial, SPI or parallel), not sure how IOIO talk with the phone. Is this what you are looking for?

  5. Hi Claudiu, thank you for the fast answer!
    Yes exactly. My problem is the connection of the FIFO and the IOIO-Board( I don’t know if it is possible to connect the module to dis board and what protokol it is, how can i read it and translate it back into a picture. Is it a form of a serial interface such as UART or SPI? The IOIO-Board then sends the data to the phone over USB or Bluetooth.

    Sry for dubble post i didn’t know that it was sended :)

    • Hi Lorin, is actually a parallel communication between OV7670 and your FIFO. However, you will need first to program OV7670 (done through SCCB bus) then handle the control signals for the FIFO chip, pretty much explained in the datasheet page of the FIFO chip. Details are also posted on the posts on OV7670 on this site. Do let me know if is helpful enough.

  6. Hi Claudiu
    Now i got finally a bit more time to work on my projekt. I looked at the datasheet but it seems very complicatet and it would be a lot of work only to get a running connection between the FIFI chip and the smartphone. But if you have any Idea how to transfer images of anykind of camera to a smartphone (realtime) please let me know!

    • Hi Lorin, I am using serial transfer between my camera module and PC and works. While is not very fast, can still get few frames per second @ 160 x120 resolution. Roughly, do the math, calculate how much data you need to transfer (e.g.: (120 bytes per line + additional control chars) x 240 + frame control char = 20 kbytes maybe) then multiply with 9 and based on your speed you’ll know how many frames you can get if all goes fine. In this case, if you can get your board dump 1000000 bps, you should be able to get up to 5-6 fps. Using SPI instead can get a better speed…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s