NU32: VC0706 Serial Camera
THIS PAGE REFERS TO A PRE-RELEASE VERSION OF THE NU32 PIC32 DEVELOPMENT BOARD. FOR INFORMATION, SAMPLE CODE, AND VIDEOS RELATED TO THE PRODUCTION VERSION (2016 AND LATER), AND TO THE CORRESPONDING BOOK "EMBEDDED COMPUTING AND MECHATRONICS WITH THE PIC32 MICROCONTROLLER," VISIT THE NU32 PAGE.
Using the VC0706 Serial Camera Module
The VC0706 is a video module originally designed for surveillance purposes. It can be used to stream analog NTSC video to a monitor, or to take a snapshot and spit it out as a JPEG over a serial connection. It also has built in motion detection features. The camera can take pictures at 640x480, 320x240, or 160x200. Since using the module to stream video over an RCA connection is trivial, this tutorial will focus on retrieving snapshots.
Since the VC0706 is its own self-contained serial module, you could just connect the camera directly to a PC using an RS232 cable, and interact with it using some terminal software. A Python script is available to directly interface with the camera over serial. The VC0706 uses 3.3V TTL logic, so if you use a 5V RS232-USB cable, make sure you step down the voltage coming out of the computer using a voltage divider, to avoid frying the camera. This tutorial focuses on how to interact with the module from the perspective of a PIC32 microcontroller.
Simply connect the TX and RX pins on the VC0706 to any UART port on the NU32. I used UART2, which uses pins F4 and F5. Make sure you connect the camera’s TX to the PIC’s RX, and visa versa1. Also, connect VCC to 5V and GND to the PIC’s GND.
Open a UART port
The default baud is 38400. You can change the default baud rate in code once you have established communication.
Taking a picture
The basic flow of events is as follows: freeze the image buffer on the VC0706, transfer data from VC0706 to PIC, thaw image buffer, repeat.
If you don’t thaw the buffer after freezing it, freezing the buffer and transferring data from the buffer will just keep giving you the same picture!
After you have a picture
After the picture is on the PIC in some kind of buffer, you can do whatever you want with it. Write it to an SD card, spit it out over serial, whatever (if you choose this route, set your terminal app to record serial output to a text file, then just rename it as a .jpg). Unfortunately, this camera is not well suited for doing image processing onboard the PIC. The camera exports pictures as compressed JPEGs, meaning that the color values of each pixel (which you would want access to to analyze the image) are heavily compressed and encrypted. It is possible to decompress the JPEG to a bitmap, but the trouble is finding code to do that efficiently on an embedded platform. It would also probably be a time-consuming procedure onboard the PIC, meaning it would be difficult to use it for any sort of real-time application. But you’re welcome to try!
Make sure you handle incoming serial transmissions from the VC0706 in an interrupt with a very large incoming buffer, because the built in UART buffer (about 8 bytes) will quickly be overwhelmed from the camera if you’re polling instead. You can always make sure your camera is working by hooking it up directly to the PC using an RS232 cable, and using a Windows utility to interact with it.