Let's Make Robots!

C328R camera and Arduino

Well I've decided to replace my 2.4 ghz wireless camera on Ardbot with this guy:

JPEG Color Camera - UART Interface

While it isn't as capable as the video camera I had planned to use, it has the advantage of having a serial interface that can communicate with the Arduino, uses 3.3v, so my hope is to be able to stream the JPEG images via XBEE to my PC.

For some examples of others using the same camera, see here (pre-build library for Arduino), here (example usage of the Arduino library), and here (DIY Drones).

I've used Sean Voisen's C++ code as a base and inspiration for most of my Arduino code. His example shows you how to use his Arduino library to take snapshots with the camera, store them to an EEPROM, and then send the data through a serial port to a Processing sketch that displays the picture - turning the Arduino into a camera. 

The problem that I wanted to solve was how to just immediately stream the image data out the serial port line on the Arduino. Sean's library uses the Arduino's built-in TX/RX lines to communicate with the camera and I need to have those available for other uses in the Ardbot. I've incorporated the NewSoftSerial Arduino library to allow me to control the camera using the other available digital pins on the Arduino and hopefully still use the built-in serial port for the XBEE communications.

I also wanted to learn about how the camera's communication protocol works at a low level so I've taken Sean's code and re-written it as an Arduino sketch.

The snapshot functionality is working in that I can capture the image and stream it back to the PC and see the resulting picture. It's only working at 9600 baud and I'm not sure if that is a limitation of the Arduino, the NewSoftSerial library, or my code :) I'm working now with how to stream video from the camera and capture/display on the pc.

I'm assuming that the maximum frames per second will be limited with this configuration but hopefully it will give my robot an 'eye' that doesn't suffer from the crowded 2.4 ghz band in his environment.

Here's an example picture taken at 160x128 resolution:








i've attached my Arduino sketch and the java code i'm running on the PC to capture the picture and write it to a file.

I run the "RunHandler" java class with the following command line args:

-Djava.library.path=/home/scott/rxtx-2.1-7-bins-r2/Linux/i686-unknown-linux-gnu -Dgnu.io.rxtx.SerialPorts=/dev/ttyUSB0

after plugging the Arduino in to the pc and making sure that it's using /dev/ttyUSB0. Pressing the reset button on the Arduino syncs everything up, takes the snapshot, sends it to the java program. When the data is completely received, the java program writes the picture to "test.jpeg" and closes.

As I mentioned, I can't get any baud rate other than 9600 to work at this point...more to follow!

C328_arduino_sketch.pde8.77 KB
RunHandler.java200 bytes
SerialPortDataHandler.java2.18 KB

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I got the same thing, I am soooo grateful for this post because I need some help in the coding area...

Muchos Gracias Signor!

You used a sketch. Is is possible for an Ard. that is not connected to the PC to process a sketch? I want image processing on my robot, so if I can get it to take a pic, then process it while unconnected, I'm set!

AVRcam uses a ATmega8 to process the image then sends the result over the UART to another micro or to the PC. So it is possible to do the same thing with this camera. How? I don't know the details, just the principle. But AVRcam has an open source C code available, one might study it and adapt it to this camera and Arduino. That wold be a great achievement.

On the other hand, there are other microcontrollers out there that are capable of USB Host functions, they may be used with regular webcams. The only thing that holds people off is the amount of lines of code and processing power needed for any serious object recognition.

So, I guess color blob tracking will soon be available directly in Arduino. Now you can see why I have designed R-Dev-Ino. One Arduino for each physical function, all talking through I2C bus. Makes sense?

I think the Arduino is too limited in terms of RAM etc, as you indicated, to do much processing "on board". I think I'm pushing the limits of what my poor Arduino board can handle! For my robot, I'm planning to just offload the intensive stuff to my PC, so as long as I can stream the raw image data wirelessly to the PC things should be good. I wonder if a more powerful board like the Arduino Mega or a Make controller could handle image processing?

Looking forward to trying out the R-Dev-Ino by the way, that looks like an interesting concept.

I would also like to try out the Leaf Labs Maple board, 72 Mhz ARM processor, 128k flash memory, all in an Arduino compatible format. 

Thanks for the comments!

LeafLabs person here - Wow, blast from the past post - 2009. The stable Maple design wasnt even released until summer 2010!

I was wiring up a c328 to a maple mini to beam some frames over wifi when I came across this post. Im so glad to see the community start to adopt the beefier processors, Maple, Due, mBed, etc. Hopefully we will start seeing a lot more camera plays with the improved hardware. By the way, the new stm32f2 or f4 chips have dedicated camera interface ports, for all your full-frame-rate fram-grabbing in hardware needs! Very cool.



I got the powar! Any clue if an XK-1 will work with the Camera, in terms of image processing?
the XMOS board does not have a "built-in" serial port available for you to program directly, so you would somehow need to emulate a serial port using the XMOS I/O pins. From looking at the way the NewSoftSerial library was done for Arduino, it would seem to be a pretty complex undertaking...perhaps someone out there has implemented a serial library for XMOS? Also you would need to somehow get 3.3 volt power supplied to the camera and it looks like the XMOS uses 5v...I'm certainly not an expert here though...anyone have any ideas?
Nice, I'm planning to test this camera with xk-1 dev kit, It is possible because xk-1 kit has a PORT_UART_RX and PORT_UART_TX, and also has 3v3 and 5V pins.

Wonderful project you are working on. I'm using a C328R camera connected to a module that converts from uart to rs232 to USB to connect directly to my pc as a virtual com port using an FTDI chip. I take a set of pictures, then do image processing on my pc then output to an arduino which controls a 16x16 dot matrix with a max7221 as well as an LCD and push buttons. For those who are wondering about the conversion from 5V to 3.3 there is a Logic Level Converter (LLC) you can buy from sparkfun.com than does the job well. 8 bit microprocessors are very limited and if you wanted to do the image processing it would have to be a 32bit micro which is a project of its own. I've seen a board that has the processing power but it would take some time to learn how to use it, I'll see if I can find it and post the link to the board. I was wondering if java can do image processing? the current setup uses a c sharp as a handler then opens another program to do the processing but it takes a long time. Is there any hope for increasing my speed?

Hi - sorry, I'm not an expert on image processing - Java does have various classes built for doing work with images (for example, see here and here). If you want to quickly experiment, you might try processing - it's an Arduino-like environment for doing media work in Java (it's Java under the hood). I would be interested in taking a look at your c-sharp code and learning some more about your setup - I was not able to get more than 9600 bps in my environment but I didn't dive too deeply into the code. Good luck!