Need help with Arducam

I am working on an Arducam. I try to use the following code to take image and store in SD card but nothing was found inside after taking image. I don’t know where my problem is. Also may I know is it possible to use a smart phone to control the camera to take an image and send the image back to smartphone via bluetooth? Thank you for help.

Hardware:
Arducam shield F
Camera OV 2640

//#include <UTFT.h>
#include <SD.h>
#include <Wire.h>
#include <ArduCAM.h>
#include <avr/pgmspace.h>

#define SD_CS 9 


//UTFT(byte model, int RS, int WR, int RD, int CS)
//UTFT myGLCD(ITDB32S,A2,A1,A0,10);   // Remember to change the model parameter to suit your display module!
//ArduCAM(byte model,int RS, int WR, int RD, int REG_CS, int FIFO_CS)
ArduCAM myCAM(OV2640,A2,A1,A0,A3,10);  // Remember to change the model parameter to suit your canera module!

void setup()
{
  //Initialize I2C Bus
  Wire.begin();   
  //Switch to FIFO Mode
  myCAM.write_reg(ARDUCHIP_TIM, MODE_MASK);
  //Set sensor to JPEG mode. Note don't all the camera modules support JPEG mode
  myCAM.OV2640_set_format(JPEG);
  //Initialize Camera Module
  myCAM.InitCAM();
  myCAM.OV2640_set_JPEG_size(OV2640_320x240);
  
  //Initialize SD Card
  if (!SD.begin(SD_CS)) 
  {
    //while (1);		//If failed, stop here
  }
}

void loop()
{
  char str[8];
  File outFile;
  static int k = 0;
  uint8_t temp,temp_last;
  uint8_t start_capture = 0;
  
  //Wait trigger from shutter buttom   
  if(myCAM.read_reg(ARDUCHIP_TRIG) & SHUTTER_MASK)	
  {
    //Wait until buttom released
    while(myCAM.read_reg(ARDUCHIP_TRIG) & SHUTTER_MASK);
    start_capture = 1;
  }
  
  //Start capture when detect a valid shutter press  
  if(start_capture)
  {
    //Flush the FIFO 
    myCAM.flush_fifo();		 
    //Start capture
    myCAM.start_capture();		 
  }
  
  if(myCAM.read_reg(ARDUCHIP_TRIG) & CAP_DONE_MASK)
  {
    //Construct a file name
    k = k + 1;
    itoa(k, str, 10); 
    strcat(str,".jpg");
    //Open the new file  
    outFile = SD.open(str,FILE_WRITE);
    if (! outFile) 
      return;
    //Enable FIFO
    myCAM.enable_fifo();
    //Read the first dummy byte from FIFO
    temp = myCAM.read_fifo();
    //Read JPEG data from FIFO
    while( (temp != 0xD9) | (temp_last != 0xFF) )
    {
      temp_last = temp;
      temp = myCAM.read_fifo();
      //Write image data to file
      outFile.write(temp);
    }
    //Disable FIFO when all the image data is saved to the file
    myCAM.disable_fifo(); 
    //Close the file 
    outFile.close(); 
    
    //Clear the capture done flag 
    myCAM.clear_fifo_flag();
    //Clear the start capture flag
    start_capture = 0;
  }
}

no experience with the arducam myself, but there seem several demo sketches on their website, have you tried these?

A possible issue can always be the power supply, shields as heavy as the Arducam can draw more current than the Arduino can supply.

  //Initialize SD Card
  if (!SD.begin(SD_CS)) 
  {
    //while (1);		//If failed, stop here
  }

The comment and code are not in sync, the function continues if there is an error with SD.
you should at least offer some feedback that the code blocks, eg make a loop to blink a LED or so.

    outFile = SD.open(str,FILE_WRITE);
    if (! outFile) 
      return;

Similar problem, you provide no feedback there is a failure

so please get your feedback right so you can track the cause of the error.

Thank you for reply. The code posted in fact is the demo from http://www.arducam.com/
I have tried to add Serial.print() to check the error but there is nothing printed out.
I doubt if I need to specify the route of SD card for storage

Try this (not tested) I added some printing to serial. Please set the baud rate to 115200

//#include <UTFT.h>
#include <SD.h>
#include <Wire.h>
#include <ArduCAM.h>
#include <avr/pgmspace.h>

#define SD_CS 9 


//UTFT(byte model, int RS, int WR, int RD, int CS)
//UTFT myGLCD(ITDB32S,A2,A1,A0,10);   // Remember to change the model parameter to suit your display module!
//ArduCAM(byte model,int RS, int WR, int RD, int REG_CS, int FIFO_CS)
ArduCAM myCAM(OV2640,A2,A1,A0,A3,10);  // Remember to change the model parameter to suit your canera module!

void setup()
{
  Serial.begin(115200); // <<<<<<<<<<<<<<<<<<<<<<<
  Serial.println("Start arducam test");

  //Initialize I2C Bus
  Wire.begin();   
  //Switch to FIFO Mode
  myCAM.write_reg(ARDUCHIP_TIM, MODE_MASK);
  //Set sensor to JPEG mode. Note don't all the camera modules support JPEG mode
  myCAM.OV2640_set_format(JPEG);
  //Initialize Camera Module
  myCAM.InitCAM();
  myCAM.OV2640_set_JPEG_size(OV2640_320x240);

  Serial.println("SD.begin");
  //Initialize SD Card
  if (!SD.begin(SD_CS)) 
  {
    Serial.println("SD card failed");
    //while (1);		//If failed, stop here
  }
  Serial.println("SD card success");
  Serial.println("End setup");
}

void loop()
{
  Serial.print(millis());
  Serial.println("\tstart loop");

  char str[8];
  File outFile;
  static int k = 0;
  uint8_t temp,temp_last;
  uint8_t start_capture = 0;

  Serial.print(millis());
  Serial.println("\tWait trigger from shutter buttom");

  //Wait trigger from shutter buttom   
  if(myCAM.read_reg(ARDUCHIP_TRIG) & SHUTTER_MASK)	
  {
    //Wait until buttom released
    while(myCAM.read_reg(ARDUCHIP_TRIG) & SHUTTER_MASK);
    start_capture = 1;
  }


  Serial.print(millis());
  Serial.println("\tStart capture I");
  //Start capture when detect a valid shutter press  
  if(start_capture)
  {
    //Flush the FIFO 
    myCAM.flush_fifo();		 
    //Start capture
    myCAM.start_capture();		 
  }

  if(myCAM.read_reg(ARDUCHIP_TRIG) & CAP_DONE_MASK)
  {
    //Construct a file name
    k = k + 1;
    itoa(k, str, 10); 
    strcat(str,".jpg");
    //Open the new file  
    outFile = SD.open(str,FILE_WRITE);
    if (! outFile) 
    {
      Serial.print(millis());
      Serial.println("\tfailure outfile");
      return;
    }

    Serial.print(millis());
    Serial.println("\toutfile succes");

    //Enable FIFO
    myCAM.enable_fifo();

    uint32_t bytecounter = 0;
    //Read the first dummy byte from FIFO
    temp = myCAM.read_fifo();

    //Read JPEG data from FIFO
    while( (temp != 0xD9) | (temp_last != 0xFF) )
    {
      bytecounter++;
      if (bytecounter % 32 == 0) Serial.print('.');
      if (bytecounter %  1024 == 0) Serial.println;
      temp_last = temp;
      temp = myCAM.read_fifo();
      //Write image data to file
      outFile.write(temp);
    }
    Serial.println();

    //Disable FIFO when all the image data is saved to the file
    myCAM.disable_fifo(); 
    //Close the file 
    outFile.close(); 

    //Clear the capture done flag 
    myCAM.clear_fifo_flag();
    //Clear the start capture flag
    start_capture = 0;
  }
}

Thank you for help.
Output:

SD.begin
SD card success
End setup
405 start loop
405 Wait trigger from shutter buttom
406 Start capture I
408 start loop
409 Wait trigger from shutter buttom
413 Start capture I
414 start loop
416 Wait trigger from shutter buttom
419 Start capture I
421 start loop

The SD card was indicated "success" but "Serial.println("\toutfile succes");" was not printed out.

check if the name of the file is valid...

The SD card was indicated "success" but "Serial.println("\toutfile succes");" was not printed out.

There is a lot that has to happen between the two statements, not the least of which is a positive response from the camera.

Thank you for replies.
I feel sorry that I am not sure what the file name is.
I try to create a file "arducam" in SD and declare char str[8]="arducam" but get nothing

coconut:
I feel sorry that I am not sure what the file name is.

The file name is built with the variable k, converted to a string, with the string ".jpg"tacked on to it. Thus, your first filename will be "1.jpg". The second will be "2.jpg", and so on.

To show the generated file name, add Serial.println(str); // in the right spot.

Thank you for replies.
I tried to create file name "1.jpg" but I still couldn't find captured image.
I tried to add Serial.println(str); but nothing is printed out on serial monitor. I think I need to indicate the SD path in variable str ?

You don’r need to create file name “1.jpg”. It’s already been generated. Comments in the code

  if(myCAM.read_reg(ARDUCHIP_TRIG) & CAP_DONE_MASK)
  {
    //Construct a file name     <---------------- HERE!
    k = k + 1;                                  // k was 0, now it's 1
    itoa(k, str, 10);                      // converts k to ASCII
    strcat(str,".jpg");                  // tavk ".jpg" onto the end of "1"
    //Open the new file  
    outFile = SD.open(str,FILE_WRITE);

Serial.println(outfile);             // <----------------- Put this line in to see if you open the file

    if (! outFile) 
    {
      Serial.print(millis());
      Serial.println("\tfailure outfile");
      return;
    }

I recommend loading up the “File.ino” sketch in the SD\examples directory, and testing with that . Do not proceed until you get that runnng, and preferably, not until you understand the Files.ino code.

I am trying to capture an image using ArduCam and send it to iPhone.
My method is first capturing an image and then storing in local SD card. After that, send from SD to iPhone.
I try to use the following code to perform the first step. When I press the button to take photo, the output from the Serial Monitor is as below. Also no file is open. Could anyone tell me what the problem is? Thank you.

Start capture I
start loop
Wait trigger from shutter buttom

#include <UTFT.h>
#include <SD.h>
#include <Wire.h>
#include <ArduCAM.h>
#include <avr/pgmspace.h>

#define SD_CS 9 


//UTFT(byte model, int RS, int WR, int RD, int CS)
UTFT myGLCD(ITDB32S,A2,A1,A0,10);   // Remember to change the model parameter to suit your display module!
//ArduCAM(byte model,int RS, int WR, int RD, int REG_CS, int FIFO_CS)
ArduCAM myCAM(OV2640,A2,A1,A0,A3,10);  // Remember to change the model parameter to suit your canera module!

void setup()
{
  Serial.begin(115200); // <<<<<<<<<<<<<<<<<<<<<<<
  Serial.println("Start arducam test");

  //Initialize I2C Bus
  Wire.begin();   
  //Switch to FIFO Mode
  myCAM.write_reg(ARDUCHIP_TIM, MODE_MASK);
  //Set sensor to JPEG mode. Note don't all the camera modules support JPEG mode
  myCAM.OV2640_set_format(JPEG);
  //Initialize Camera Module
  myCAM.InitCAM();
  myCAM.OV2640_set_JPEG_size(OV2640_320x240);

  Serial.println("SD.begin");
  //Initialize SD Card
  while (!SD.begin(SD_CS)) 
  {
    Serial.println("SD card failed");
    //while (1);		//If failed, stop here
  }
  Serial.println("SD card success");
  Serial.println("End setup");
}

void loop()
{
  Serial.print(millis());
  Serial.println("\tstart loop");

  char str[8];
  File outFile;
  static int k = 0;
  uint8_t temp,temp_last;
  uint8_t start_capture = 0;

  Serial.print(millis());
  Serial.println("\tWait trigger from shutter buttom");
  Serial.println(str);
  
  //Wait trigger from shutter buttom   
  if(myCAM.read_reg(ARDUCHIP_TRIG) & SHUTTER_MASK)	
  {
    //Wait until buttom released
    while(myCAM.read_reg(ARDUCHIP_TRIG) & SHUTTER_MASK);
    start_capture = 1;
  }


  Serial.print(millis());
  Serial.println("\tStart capture I");
  //Start capture when detect a valid shutter press  
  if(start_capture)
  {
    //Flush the FIFO 
    myCAM.flush_fifo();		 
    //Start capture
    myCAM.start_capture();		 
  }

  if(myCAM.read_reg(ARDUCHIP_TRIG) & CAP_DONE_MASK)
  {
    //Construct a file name
    k = k + 1;
    itoa(k, str, 10); 
    strcat(str,".jpg");
    //Open the new file  
    outFile = SD.open(str,FILE_WRITE);
    Serial.println(outFile);             // <----------------- Put this line in to see if you open the file

    if (! outFile) 
    {
      Serial.print(millis());
      Serial.println("\tfailure outfile");
      return;
    }

    Serial.print(millis());
    Serial.println("\toutfile succes");

    //Enable FIFO
    myCAM.enable_fifo();

    uint32_t bytecounter = 0;
    //Read the first dummy byte from FIFO
    temp = myCAM.read_fifo();

    //Read JPEG data from FIFO
    while( (temp != 0xD9) | (temp_last != 0xFF) )
    {
      bytecounter++;
      if (bytecounter % 32 == 0) Serial.print('.');
      if (bytecounter %  1024 == 0) Serial.println('?');
      temp_last = temp;
      temp = myCAM.read_fifo();
      //Write image data to file
      outFile.write(temp);
    }
    Serial.println();

    //Disable FIFO when all the image data is saved to the file
    myCAM.disable_fifo(); 
    //Close the file 
    outFile.close(); 

    //Clear the capture done flag 
    myCAM.clear_fifo_flag();
    //Clear the start capture flag
    start_capture = 0;
  }
}
  Serial.begin(115200); // <<<<<<<<<<<<<<<<<<<<<<<

Is this comment supposed to be useful to anybody?

The messages on the Serial Monitor are not shown in the order you displayed them. Why should we wade through the code guessing what else you snipped?

//UTFT(byte model, int RS, int WR, int RD, int CS)
UTFT myGLCD(ITDB32S,A2,A1,A0,10);   // Remember to change the model parameter to suit your display module!
//ArduCAM(byte model,int RS, int WR, int RD, int REG_CS, int FIFO_CS)
ArduCAM myCAM(OV2640,A2,A1,A0,A3,10);  // Remember to change the model parameter to suit your canera module!

Are you really using pins A2, A1, A0 and 10 for two different purposes each?

PaulS:

  Serial.begin(115200); // <<<<<<<<<<<<<<<<<<<<<<<

Is this comment supposed to be useful to anybody?

It comes from my remark #3 - to set a higher baud rate,

It comes from my remark #3 - to set a higher baud rate,

I don't think that blindly copy and pasting code was your intent.

Thank you for replies. The serial.begin is to set the data rate.
Sorry for the copy and paste comment. I will be careful next time.
"failure outfile" or "outfile succes" are not printed.
Yes, I use pins A2, A1, A0 and 10 for the ArduCAM.
The output :

Start arducam test
SD.begin
SD card success
End setup
405 start loop
405 Wait trigger from shutter buttom

424 Start capture I
446 start loop
463 Wait trigger from shutter buttom

424 Start capture I
446 start loop
463 Wait trigger from shutter buttom

504 Start capture I
527 start loop
543 Wait trigger from shutter buttom

585 Start capture I
607 start loop
623 Wait trigger from shutter buttom


Yes, I use pins A2, A1, A0 and 10 for the ArduCAM.

But, you are also using them here:

UTFT myGLCD(ITDB32S,A2,A1,A0,10);   // Remember to change the model parameter to suit your display module!

Until you stop trying to use pins A2, A1, A0 and 10 for two different purposes, I don't think you will ever have success.

Video and source code to use ArduCAM with an ESP8266-12E.