C328R camera and Arduino
December 6, 2009
Well I've decided to replace my 2.4 ghz wireless camera on Ardbot with this guy:
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.
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:
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!