Adafruit JPEG Snapshot sample coding

Hi everyone im using Adafruit's JPEG camera for my project where im using the snapshot example code for my project in that im transmitting the captured image via bluetooth to an android phone. In the sample code it has several "Serial.print" messages i wanted to get rid of that in order to only transmit the image using Serial.write function in arduino below SD card saving. When i try to ignore these "Serial.print" the camera is not functioning and the SD saving is not done. If anyone can help me with this problem it would be a great help. Thanks

#include <Adafruit_VC0706.h>
#include <SD.h>
#include <SoftwareSerial.h>         
#define chipSelect 10
File myFile;



#if ARDUINO >= 100

SoftwareSerial cameraconnection = SoftwareSerial(2, 3);

#else
NewSoftSerial cameraconnection = NewSoftSerial(2, 3);
#endif

Adafruit_VC0706 cam = Adafruit_VC0706(&cameraconnection);
char val;



void setup() {


#if !defined(SOFTWARE_SPI)
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  if(chipSelect != 53) pinMode(53, OUTPUT); // SS on Mega
#else
  if(chipSelect != 10) pinMode(10, OUTPUT); // SS on Uno, etc.
#endif
#endif

  Serial.begin(38400);
  Serial.println("VC0706 Camera snapshot test");
  
  
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }  
  
  // Try to locate the camera
} 

void loop() {
  
  if(Serial.available())
  {
    val = Serial.read();
    if(val=='a')
    {
    if (cam.begin()) {
    Serial.println("Camera Found:");
  } else {
    Serial.println("No camera found?");
    return;
  }
  // Print out the camera version information (optional)
  char *reply = cam.getVersion();
  if (reply == 0) {
    Serial.print("Failed to get version");
  } else {
    Serial.println("-----------------");
    Serial.print(reply);
    Serial.println("-----------------");
  }

 
  
  //cam.setImageSize(VC0706_640x480);        // biggest
  //cam.setImageSize(VC0706_320x240);        // medium
  cam.setImageSize(VC0706_160x120);          // small

  // You can read the size back from the camera (optional, but maybe useful?)
  uint8_t imgsize = cam.getImageSize();
  Serial.print("Image size: ");
  if (imgsize == VC0706_640x480) Serial.println("640x480");
  if (imgsize == VC0706_320x240) Serial.println("320x240");
  if (imgsize == VC0706_160x120) Serial.println("160x120");

  Serial.println("Snap in 3 secs...");
  delay(3000);

  if (! cam.takePicture()) 
    Serial.println("Failed to snap!");
  else 
    Serial.println("Picture taken!");
  
  // Create an image with the name IMAGExx.JPG
  char filename[13];
  strcpy(filename, "IMAGE00.JPG");
  for (int i = 0; i < 100; i++) {
    filename[5] = '0' + i/10;
    filename[6] = '0' + i%10;
    // create if does not exist, do not open existing, write, sync after write
    if (! SD.exists(filename)) {
      break;
    }
  }
  
  // Open the file for writing
  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();

  time = millis() - time;
  Serial.println("done!");
  Serial.print(time); Serial.println(" ms elapsed");
  
   myFile = SD.open("IMAGE00.JPG");
   
   if (myFile) {
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    myFile.close();
  } else {
  	// if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
 
}
//Serial.println("No BT connections");
}
  }

So how are we to know which print statements you removed? Try posting both the
working and non-working sketches in full so the difference can be seen...

The working code is the one i have attached before,

And the code that doesnt work is,

#include <Adafruit_VC0706.h>
#include <SD.h>
#include <SoftwareSerial.h>         
#define chipSelect 10
File myFile;



#if ARDUINO >= 100

SoftwareSerial cameraconnection = SoftwareSerial(2, 3);

#else
NewSoftSerial cameraconnection = NewSoftSerial(2, 3);
#endif

Adafruit_VC0706 cam = Adafruit_VC0706(&cameraconnection);
char val;



void setup() {


#if !defined(SOFTWARE_SPI)
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  if(chipSelect != 53) pinMode(53, OUTPUT); // SS on Mega
#else
  if(chipSelect != 10) pinMode(10, OUTPUT); // SS on Uno, etc.
#endif
#endif

  Serial.begin(38400);
} 

void loop() {
  
  if(Serial.available())
  {
    val = Serial.read();
    if(val=='a')
    {
  //cam.setImageSize(VC0706_640x480);        // biggest
  //cam.setImageSize(VC0706_320x240);        // medium
  cam.setImageSize(VC0706_160x120);          // small

  // You can read the size back from the camera (optional, but maybe useful?)
  uint8_t imgsize = cam.getImageSize();
  delay(3000);
  
  // Create an image with the name IMAGExx.JPG
  char filename[13];
  strcpy(filename, "IMAGE00.JPG");
  for (int i = 0; i < 100; i++) {
    filename[5] = '0' + i/10;
    filename[6] = '0' + i%10;
    // create if does not exist, do not open existing, write, sync after write
    if (! SD.exists(filename)) {
      break;
    }
  }
  
  // Open the file for writing
  File imgFile = SD.open(filename, FILE_WRITE);

  // Get the size of the image (frame) taken  
  uint16_t jpglen = cam.frameLength();

  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();

  time = millis() - time;
  Serial.println("done!");
  Serial.print(time); Serial.println(" ms elapsed");
  
   myFile = SD.open("IMAGE00.JPG");
   
   if (myFile) {
    while (myFile.available()) {
      //Serial.println("sending in progress");
      Serial.write(myFile.read());
      //Serial.write(HEX); 
    }
    //Serial.println("done");
    myFile.close();
  } else {
  	// if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
 
}
//Serial.println("No BT connections");
}
  }

Why did you remove this?

  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;

Yes, it only does a Serial.println() inside the if, but there is one more thing it does that is absolutely necessary if you want to read/write an SD card. Can you think of what it is?

Oh, and there's no reason for a return there.

Ohh yea i made a mistake and now i corrected to begin the SD. Thanks for the comment.
And also im facing a problem when transmitting an image from arduino to android through bluetooth. Actually im receiving the bytes and it is stored in the android SD card. But i cannot view the received image but when i compare the bytes of the two image they are exactly the same but still i could not view the received image. Please anyone help me to solve this problem ASAP please.

Please anyone help me to solve this problem ASAP please.

"This problem" being that some undefined application on your phone can't display an image. Is that correct?

How is that related to the Arduino code?

Well in PC also i cannot view the image :frowning:

So, using some mysterious application on the PC, you can't view the image. Is that correct?

How is that related to the Arduino code?

Sooner or later, I know that you'll quit tap-dancing around, and start getting specific. Your dancing isn't all that good. :slight_smile:

Ashuk:
... when i compare the bytes of the two image they are exactly the same but still i could not view the received image. Please anyone help me to solve this problem ASAP please.

How are you comparing the two files? If, as you say, they are identical, then either one should display on the same viewer software. Can you send the one captured on the Arduino's SD card to the Android via your PC (copy, etc.). If so, does THAT one display on your Android?