TTL Serial Camera (VC0706) how to avoid bad photos saving to SD card/uploading?

Hi,

I'm doing a project of taking photos and saving to SD card or uploading to web server. I used Adafruit TTL Serial Camera (VC0706) and successfully saved photos to SD card using the VC0706 library they provided. The saving approach is to create a jpg file in SD card and transfer binary data through arduino serial to the file. The problem is: sometimes the photos saved are of bad quality, such as the photos I attached here, there are several pixels transferred incorrectly. When I go on trying to use CC3000 Wi-Fi board to upload photos to web server, although I used TCP, the photos saved are of even worse quality than SD card.

Does anyone know how to improve the photo saving quality?

The code clip is the photo saving.

File imgFile = SD.open(filename, FILE_WRITE);

  // Get the size of the image (frame) taken  
  uint16_t jpglen = cam.frameLength();
  Serial.print("Storing ");
  Serial.print(jpglen, DEC);
  Serial.print(" byte image.");

  int32_t time = millis();
  pinMode(8, OUTPUT);
  // Read all the data up to # bytes!
  byte wCount = 0; // For counting # of writes
  while (jpglen > 0) {
    // read 32 bytes at a time;
    uint8_t *buffer;
    uint8_t bytesToRead = min(32, jpglen); // change 32 to 64 for a speedup but may not work with all setups!
    buffer = cam.readPicture(bytesToRead);
    imgFile.write(buffer, bytesToRead);
    if(++wCount >= 64) { // Every 2K, give a little feedback so it doesn't appear locked up
      Serial.print('.');
      wCount = 0;
    }
    //Serial.print("Read ");  Serial.print(bytesToRead, DEC); Serial.println(" bytes");
    jpglen -= bytesToRead;
  }
  imgFile.close();

IMAGE047.jpg

CAM.JPG

Need help...

Sorry but there is nothing you can do in software to detect those faulty images. This is because you have not got enough memory in the arduino to store an image and look at it before you store it.

What you have to do is to stop the errors happening in the first place. The place to start would be to improve the decoupling of your system.

http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html