Go Down

Topic: C328 Camera - Blank Images (Read 858 times) previous topic - next topic


I am attempting to use a C328 camera to stream pictures from my Arduino to a base station, and from my base station to a web server.

I am using the C328R library from here: http://code.google.com/p/rogue-code/downloads/detail?name=CameraC328R-SerialBase.zip&can=2&q=arduinomods

Using this library, I can go through all the steps required to get a picture from this camera. It syncs, it initializes, I can change the baud rate, take a snapshot, and retrieve the picture. However, once the pictures have been saved to files on my computer, they are blank. They appear as valid JPEGs of the correct size, but no actual picture data.

Code: [Select]
  // Sync camera
  synced = camera.sync();
  // Run camera setup
  if (synced == true) {
    Serial.println("Camera synced.");
    // Initialize camera
    initialized = camera.initial(camera.CT_JPEG, camera.PR_80x60, camera.JR_320x240);
    if (initialized == true) {
      Serial.println("Camera initialized.");
    // Set camera data package size to 512B
    acked = camera.setPackageSize(64);
    if (acked == true) {
      Serial.println("Package size set.");
      acked = false;
    // Increase camera baud rate to 115200 bps
    acked = camera.setBaudRate(camera.BAUD115200);
    if (acked == true) {
      Serial.println("Baud rate set.");
      acked = false;
    // Take snapshot
    acked = camera.snapshot(camera.ST_COMPRESSED, 2);
    if (acked == true) {
      Serial.println("Snapshot taken.");
      acked = false;
    // Retrieve image and send to base station
    acked = camera.getJPEGPicture(camera.PT_SNAPSHOT, 1000, &transmitImageChunk);
    if (acked == true) {
      Serial.println("Image received.");
      acked = false;

Here is my callback function:
Code: [Select]
void transmitImageChunk(uint16_t picSize, uint16_t packPicDataSize, uint16_t packCount, byte* pack) {

  // Mark start of image transmission
  if (packCount < 1) {
    transmittedDataSize = 0;
  // Transmit current package
  Serial.write(pack, packPicDataSize);
  transmittedDataSize += packPicDataSize;
  // Mark end of image transmission
  if (transmittedDataSize == picSize) {

On the computer end, I use a perl script to send out the image data as it is received, and on my web server, the data is saved to a file. I have tested the perl scripts using other image files, and they worked fine, but I suppose reading the image data from a serial port rather than a file could mess with that, so here is my perl code to transmit the data:
Code: [Select]
while (1) {
$byte = $serial->read(1);
if ($byte) {
$string = $string . $byte;
if ($byte =~ "\n") {
if ($string =~ "s\r\n") {
print $handle "newImage\n";
$imageFlag = 1;
} elsif ($string =~ "e\r\n") {
print $handle "endImage\n";
$imageFlag = 0;
} elsif ($imageFlag == 1) {
$string =~ s/\r\n//;
print $handle $string;
} else {
print STDOUT $string;
$string = "";

Finally, here is my server code that receives and saves the image:
Code: [Select]
if ($line =~ "newImage\n") {
$imageName = time;
open FILE, ">", "imagesOut/$imageName.jpg" || die $!;
while (defined($line = <$client>)) {
if ($line =~ "endImage\n") {
} else {
print FILE $line;
close FILE;

The camera only successfully syncs about once every 20 or so attempts (I have to power cycle it each attempt), so given this and my blank image problem, I am beginning to suspect my camera may be broken.

If any could offer me any advice, I would be very grateful.


Go Up