ArduCAM / Arduino

This is ArduCAM library for Arduino boards
MIT License
469 stars 347 forks source link

Error when using SD card with the ArduCAM 2MP (Capture2SD code) #285

Open Sunshine-Leona opened 6 years ago

Sunshine-Leona commented 6 years ago

Hello and Happy New Year to you @ArduCAM ,

I have a problem with the following code: "ArduCAM_Mini_Capture2SD"

I am using the Arduino MEGA 2560; the original Arduino Wi-Fi Shield mounted on it (this one https://www.arduino.cc/en/Guide/ArduinoWiFiShield) + the ArduCAM Mini 2MP without the camera shield. I added a small change which is initializing Pin 53 as an output:

` // ArduCAM demo (C)2017 Lee // Web: http://www.ArduCAM.com // This program is a demo of how to use most of the functions // of the library with a supported camera modules, and can run on any Arduino platform. // // This demo was made for Omnivision 2MP/5MP sensor. // It will run the ArduCAM 2MP/5MP as a real 2MP/5MP digital camera, provide both JPEG capture. // The demo sketch will do the following tasks: // 1. Set the sensor to JPEG mode. // 2. Capture and buffer the image to FIFO every 5 seconds // 3. Store the image to Micro SD/TF card with JPEG format in sequential. // 4. Resolution can be changed by myCAM.set_JPEG_size() function. // This program requires the ArduCAM V4.0.0 (or later) library and ArduCAM 2MP/5MP shield // and use Arduino IDE 1.6.8 compiler or above

include

include

include

include

include "memorysaver.h"

//This demo can only work on OV2640_MINI_2MP or OV5642_MINI_5MP or OV5642_MINI_5MP_BIT_ROTATION_FIXED platform.

if !(defined OV5642_MINI_5MP || defined OV5642_MINI_5MP_BIT_ROTATION_FIXED || defined OV2640_MINI_2MP || defined OV3640_MINI_3MP)

error Please select the hardware platform and camera module in the ../libraries/ArduCAM/memorysaver.h file

endif

define SD_CS 9

const int SPI_CS = 7;

if defined (OV2640_MINI_2MP)

ArduCAM myCAM( OV2640, SPI_CS );

elif defined (OV3640_MINI_3MP)

ArduCAM myCAM( OV3640, SPI_CS );

else

ArduCAM myCAM( OV5642, SPI_CS );

endif

void myCAMSaveToSDFile(){ char str[8]; byte buf[256]; static int i = 0; static int k = 0; uint8_t temp = 0,temp_last=0; uint32_t length = 0; bool is_header = false; File outFile; //Flush the FIFO myCAM.flush_fifo(); //Clear the capture done flag myCAM.clear_fifo_flag(); //Start capture myCAM.start_capture(); Serial.println(F("start Capture")); while(!myCAM.get_bit(ARDUCHIP_TRIG , CAP_DONE_MASK)); Serial.println(F("Capture Done."));
length = myCAM.read_fifo_length(); Serial.print(F("The fifo length is :")); Serial.println(length, DEC); if (length >= MAX_FIFO_SIZE) //384K { Serial.println(F("Over size.")); return ; } if (length == 0 ) //0 kb { Serial.println(F("Size is 0.")); return ; } //Construct a file name k = k + 1; itoa(k, str, 10); strcat(str, ".jpg"); //Open the new file outFile = SD.open(str, O_WRITE | O_CREAT | O_TRUNC); if(!outFile){ Serial.println(F("File open faild")); return; } myCAM.CS_LOW(); myCAM.set_fifo_burst(); while ( length-- ) { temp_last = temp; temp = SPI.transfer(0x00); //Read JPEG data from FIFO if ( (temp == 0xD9) && (temp_last == 0xFF) ) //If find the end ,break while, { buf[i++] = temp; //save the last 0XD9
//Write the remain bytes in the buffer myCAM.CS_HIGH(); outFile.write(buf, i);
//Close the file outFile.close(); Serial.println(F("Image save OK.")); is_header = false; i = 0; }
if (is_header == true) { //Write image data to buffer if not full if (i < 256) buf[i++] = temp; else { //Write 256 bytes image data to file myCAM.CS_HIGH(); outFile.write(buf, 256); i = 0; buf[i++] = temp; myCAM.CS_LOW(); myCAM.set_fifo_burst(); }
} else if ((temp == 0xD8) & (temp_last == 0xFF)) { is_header = true; buf[i++] = temp_last; buf[i++] = temp;
} } }

void setup(){ uint8_t vid, pid; uint8_t temp; Wire.begin(); Serial.begin(115200); Serial.println(F("ArduCAM Start!")); //set the CS as an output: pinMode(SPI_CS,OUTPUT); pinMode(53, OUTPUT): // initialize SPI: SPI.begin(); while(1){ //Check if the ArduCAM SPI bus is OK myCAM.write_reg(ARDUCHIP_TEST1, 0x55); temp = myCAM.read_reg(ARDUCHIP_TEST1);

if (temp != 0x55){ Serial.println(F("SPI interface Error!")); delay(1000);continue; }else{ Serial.println(F("SPI interface OK."));break; } } //Initialize SD Card while(!SD.begin(SD_CS)){ Serial.println(F("SD Card Error!"));delay(1000); } Serial.println(F("SD Card detected."));

if defined (OV2640_MINI_2MP)

while(1){ //Check if the camera module type is OV2640 myCAM.wrSensorReg8_8(0xff, 0x01); myCAM.rdSensorReg8_8(OV2640_CHIPID_HIGH, &vid); myCAM.rdSensorReg8_8(OV2640_CHIPID_LOW, &pid); if ((vid != 0x26 ) && (( pid != 0x41 ) || ( pid != 0x42 ))){ Serial.println(F("Can't find OV2640 module!")); delay(1000);continue; } else{ Serial.println(F("OV2640 detected."));break; } }

elif defined (OV3640_MINI_3MP)

while(1){ //Check if the camera module type is OV3640 myCAM.rdSensorReg16_8(OV3640_CHIPID_HIGH, &vid); myCAM.rdSensorReg16_8(OV3640_CHIPID_LOW, &pid); if ((vid != 0x36) || (pid != 0x4C)){ Serial.println(F("Can't find OV3640 module!")); delay(1000);continue; }else{ Serial.println(F("OV3640 detected."));break;
} }

else

while(1){ //Check if the camera module type is OV5642 myCAM.wrSensorReg16_8(0xff, 0x01); myCAM.rdSensorReg16_8(OV5642_CHIPID_HIGH, &vid); myCAM.rdSensorReg16_8(OV5642_CHIPID_LOW, &pid); if((vid != 0x56) || (pid != 0x42)){ Serial.println(F("Can't find OV5642 module!")); delay(1000);continue; } else{ Serial.println(F("OV5642 detected."));break; } }

endif

myCAM.set_format(JPEG); myCAM.InitCAM();

if defined (OV2640_MINI_2MP)

myCAM.OV2640_set_JPEG_size(OV2640_320x240);

elif defined (OV3640_MINI_3MP)

myCAM.OV3640_set_JPEG_size(OV3640_320x240);

else

myCAM.write_reg(ARDUCHIP_TIM, VSYNC_LEVEL_MASK); //VSYNC is active HIGH myCAM.OV5642_set_JPEG_size(OV5642_320x240);

endif

delay(1000); } void loop(){ myCAMSaveToSDFile(); delay(5000); }

`

My connections are as follows: MISO -> 50 MOSI -> 51 SCK -> 52 VCC -> 5V SDA -> 20 SCL -> 21 Pin 53 of the Arduino board is connected to Pin 9 ( the SD_CS Pin).

When I upload the code and check the serial monitor, I see reverse question marks. The ArduCAM host app just shows "ArduCAM Single Capture" when I open the port and click "Capture".

The "ArduCAM_Mini_2MP_OV2640_functions" code works fine with the same connections, excluding the SD pin, of course. I was hoping you would be able to point out my mistake. Thanks in advance!

This is the serial monitor display: 0f⸮⸮⸮\⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮\⸮⸮⸮޹⸮

supprot commented 6 years ago

@Sunshine-Leona Hi, Can you detected your SD card? On the Arduino WIFI Shield , the pin4 is used for SD cs. You can try to change the pin 9 to pin 4. Regards.

Sunshine-Leona commented 6 years ago

@supprot Thank you for the fast reply. I tried doing what you said. Here is the output of the serial monitor:

Ardu OV2640 detected. start Capture Capture Done. The fifo length is :8196 2b⸮E⸮⸮'⸮⸮⸮⸮⸮@⸮⸮⸮⸮#⸮⸮$⸮⸮y⸮⸮'⸮⸮⸮⸮⸮Y⸮⸮⸮⸮@⸮$⸮#⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮Y⸮⸮y⸮⸮⸮#⸮⸮⸮⸮⸮⸮⸮#⸮⸮'

SD_CS is now 4 and I left Pins 4 and 53 of the Arduino MEGA free. Also, the host app displays "COM open fail" when I try to open the port to take pictures.

supprot commented 6 years ago

@Sunshine-Leona Hi, From your serial monitor, we can't see the state of SD card. Have you init your SD card? //Initialize SD Card while(!SD.begin(SD_CS)){ Serial.println(F("SD Card Error!"));delay(1000); } Serial.println(F("SD Card detected.")); the host app can't be used on "ArduCAM_Mini_Capture2SD" demo. For "ArduCAM_Mini_2MP_OV2640_functions" demo,before opening the host app.You shoud close your serial monitor to prevent serial from being occupied.

Sunshine-Leona commented 6 years ago

@supprot Hello again,

I finally got some pictures on the SD card. But I am still getting the question marks. Why? Serial Monitor Output:

ArduCAMrface OK. SD Card detected. OV2640 detected. start Capture Capture Done. The fifo length is :6148 Image save OK. 0b⸮⸮2⸮⸮⸮⸮> >⸮H⸮0$⸮⸮⸮⸮݈I⸮⸮⸮⸮⸮⸮⸮⸮⸮ܘ!⸮⸮

supprot commented 6 years ago

@Sunshine-Leona

Hi,

Do you see the picture in your SD card? From the serial monitor,we think your SD card should work fine. About the question marks, mybe because of your wifi firmware. you can don't care it.

Let us know if you need more help. Regards,

Sunshine-Leona commented 6 years ago

Hello @supprot

I figured out why I was getting the reverse question marks. It was due to the baud rate. I set it as "9600" and now I am getting a different problem. Look at the Serial Monitor Output below:

ArduCAM Start! SPI interface OK. SD Card detected. OV2640 detected. start Capture Capture Done. The fifo length is :7172 start Capture Capture Done. The fifo length is :8196 start Capture

It captures twice and just stops when it should be taking the third picture. "start Capture" and nothing after.

If I close and re-open the serial monitor, this is what I see: ArduCAM Start! SPI interface OK. SD Card detected. Can't find OV2640 module! Can't find OV2640 module! Can't find OV2640 module! Can't find OV2640 module! Can't find OV2640 module! Can't find OV2640 module! Can't find OV2640 module! Can't find OV2640 module!

Also, something really weird happened to the SD card. I checked to see if the 2 captured pictures were saved onto the card. Instead, I found 0 KB pictures that were different from the ones I took. They were pictures taken by the ArduCAM from a previous date.

What could be the problem? Could it be the baud rate? Any help would be appreciated.

Thanks!

supprot commented 6 years ago

@Sunshine-Leona Hi, ’Can't find OV2640 module!‘ means your camera hardware connection unstable. If your picture is written to your SD card, you will see ‘Image save OK'. We sugguest you check your camera to Arduino connection carefully.

Regards. Arducam support team.

Sunshine-Leona commented 6 years ago

@supprot Hello again,

As I have had trouble with the Capture2SD ArduCam example, I searched and found an alternative. This code was made by Vernel and it streams the JPEG bytes to the computer via Serial, which are then captured by Processing. The code they made was for the OV5642 ArduCAM. I edited the code for the OV2640 as it is the only one I have. Here is my code: `

include

include

include

include "memorysaver.h"

//This code can only work on OV5642_MINI_5MP_PLUS platform.

if !(defined (OV2640_MINI_2MP))

endif

define FRAMES_NUM 0x00

// set pin 4 as the slave select for SPI:

const int CS1 = 4;

bool CAM1_EXIST = false;

bool stopMotion = false;

ArduCAM myCAM1(OV2640, CS1);

long int streamStartTime;

void setup() {

// put your setup code here, to run once:

uint8_t vid, pid;

uint8_t temp;

Wire.begin();

Serial.begin(250000); //921600

Serial.println(F("ArduCAM Start!"));

// set the CS output:

pinMode(CS1, OUTPUT);

// initialize SPI:

SPI.begin();

//Check if the 4 ArduCAM Mini 5MP PLus Cameras' SPI bus is OK

while (1) {

myCAM1.write_reg(ARDUCHIP_TEST1, 0x55);

temp = myCAM1.read_reg(ARDUCHIP_TEST1);

if (temp != 0x55)

{

  Serial.println(F("SPI1 interface Error!"));

} else {

  CAM1_EXIST = true;

  Serial.println(F("SPI1 interface OK."));

}

if (!(CAM1_EXIST)) {

  delay(1000); continue;

} else

  break;

}

while (1) {

//Check if the camera module type is OV5642

myCAM1.rdSensorReg16_8(OV2640_CHIPID_HIGH, &vid);

myCAM1.rdSensorReg16_8(OV2640_CHIPID_LOW, &pid);

if ((vid != 0x26) || (pid != 0x41)) {

  Serial.println(F("Can't find OV2640 module!"));

  delay(1000); continue;

} else {

  Serial.println(F("OV2640 detected.")); break;

}

}

//Change to JPEG capture mode and initialize the OV2640 module

myCAM1.set_format(JPEG);

myCAM1.InitCAM();

myCAM1.write_reg(ARDUCHIP_TIM, VSYNC_LEVEL_MASK); //VSYNC is active HIGH

myCAM1.clear_fifo_flag();

myCAM1.write_reg(ARDUCHIP_FRAMES, FRAMES_NUM);

//myCAM1.OV5642_set_JPEG_size(OV5642_640x480); delay(1000);

myCAM1.OV2640_set_JPEG_size(OV2640_320x240); delay(1000);

delay(1000);

myCAM1.clear_fifo_flag();

Serial.println("Ready:,1");

}

void loop() {

if (CAM1_EXIST && stopMotion) {

streamStartTime = millis();

myCAMSendToSerial(myCAM1);

double fps = ((millis() - streamStartTime) / 1000);

Serial.println("fps: " + String(1 / fps ));

}

}

void myCAMSendToSerial(ArduCAM myCAM) {

char str[8];

byte buf[5];

static int i = 0;

static int k = 0;

uint8_t temp = 0, temp_last = 0;

uint32_t length = 0;

bool is_header = false;

myCAM.flush_fifo(); //Flush the FIFO

myCAM.clear_fifo_flag(); //Clear the capture done flag

myCAM.start_capture();//Start capture

while (!myCAM.get_bit(ARDUCHIP_TRIG , CAP_DONE_MASK));

length = myCAM.read_fifo_length();

Serial.print(F("FifoLength:,"));

Serial.print(length, DEC);

Serial.println(",");

if (length >= MAX_FIFO_SIZE) //8M

{

Serial.println(F("Over size."));

return ;

}

if (length == 0 ) //0 kb

{

Serial.println(F("Size is 0."));

return ;

}

myCAM.CS_LOW();

myCAM.set_fifo_burst();

Serial.print("Image:,");

while ( length-- )

{

temp_last = temp;

temp =  SPI.transfer(0x00);

//Read JPEG data from FIFO

if ( (temp == 0xD9) && (temp_last == 0xFF) ) //If find the end ,break while,

{

  buf[i++] = temp;  //save the last  0XD9

  //Write the remain bytes in the buffer

  myCAM.CS_HIGH();

  for (int i = 0; i < sizeof(buf); i++) {

    Serial.print(buf[i]); Serial.print(",");

  }

  Serial.println();

  Serial.println(F("Image transfer OK."));

  is_header = false;

  i = 0;

}

if (is_header == true)

{

  //Write image data to buffer if not full

  if (i < 5) {

    buf[i++] = temp;

  } else

  {

    //Stream 5 bytes of raw image data to serial

    myCAM.CS_HIGH();

    for (int i = 0; i < sizeof(buf); i++) {

      Serial.print(buf[i]); Serial.print(",");

    }

    i = 0;

    buf[i++] = temp;

    myCAM.CS_LOW();

    myCAM.set_fifo_burst();

  }

}

else if ((temp == 0xD8) & (temp_last == 0xFF))

{

  is_header = true;

  buf[i++] = temp_last;

  buf[i++] = temp;

}

}

}

void serialEvent() {

if (Serial.available() > 0) {

uint8_t temp = 0xff, temp_last = 0;

uint8_t start_capture = 0;

temp = Serial.read();

switch (temp)

{

  case 0:

    temp = 0xff;

    myCAM1.OV2640_set_JPEG_size(OV2640_320x240);

    Serial.println(F("OV2640_320x240")); delay(1000);

    myCAM1.clear_fifo_flag();

    break;

  case 1:

    temp = 0xff;

    myCAM1.OV2640_set_JPEG_size(OV2640_640x480);

    Serial.println(F("OV2640_640x480")); delay(1000);

    myCAM1.clear_fifo_flag();

    break;

  case 2:

    temp = 0xff;

    myCAM1.OV2640_set_JPEG_size(OV2640_1024x768);

    Serial.println(F("OV2640_1024x768")); delay(1000);

    myCAM1.clear_fifo_flag();

    break;

  case 3:

    {

      if (stopMotion)

        stopMotion = false;

      else

        stopMotion = true;

      Serial.println("Stop Motion Enabled: " + String(stopMotion));

    }

    break;

  case 0x10:

    if (CAM1_EXIST) {

      streamStartTime = millis();

      myCAMSendToSerial(myCAM1);

      double fps = ((millis() - streamStartTime) / 1000);

      Serial.println("Total Time: " + String(fps));

    }

    break;

  default:

    break;

}

}

}

` When I run this sketch, the Arduino gives me these errors: " Arduino: 1.8.5 (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

ArduCAM_to_PC:129: error: 'VSYNC_LEVEL_MASK' was not declared in this scope

myCAM1.write_reg(ARDUCHIP_TIM, VSYNC_LEVEL_MASK); //VSYNC is active HIGH

                              ^

ArduCAM_to_PC:133: error: 'ARDUCHIP_FRAMES' was not declared in this scope

myCAM1.write_reg(ARDUCHIP_FRAMES, FRAMES_NUM);

                ^

exit status 1 'VSYNC_LEVEL_MASK' was not declared in this scope

This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.

Aren't these functions of the library? I don't know why the IDE gives me errors. Any help would be appreciated.

You will find Vernel's original code + the link below: `#include

include

include

include "memorysaver.h"

//This code can only work on OV5642_MINI_5MP_PLUS platform.

if !(defined (OV5642_MINI_5MP_PLUS))

error Please select the hardware platform and camera module in the ../libraries/ArduCAM/memorysaver.h file

endif

define FRAMES_NUM 0x00

// set pin 4 as the slave select for SPI:

const int CS1 = 4;

bool CAM1_EXIST = false;

bool stopMotion = false;

ArduCAM myCAM1(OV5642, CS1);

long int streamStartTime;

void setup() {

// put your setup code here, to run once:

uint8_t vid, pid;

uint8_t temp;

Wire.begin();

Serial.begin(250000); //921600

Serial.println(F("ArduCAM Start!"));

// set the CS output:

pinMode(CS1, OUTPUT);

// initialize SPI:

SPI.begin();

//Check if the 4 ArduCAM Mini 5MP PLus Cameras' SPI bus is OK

while (1) {

myCAM1.write_reg(ARDUCHIP_TEST1, 0x55);

temp = myCAM1.read_reg(ARDUCHIP_TEST1);

if (temp != 0x55)

{

  Serial.println(F("SPI1 interface Error!"));

} else {

  CAM1_EXIST = true;

  Serial.println(F("SPI1 interface OK."));

}

if (!(CAM1_EXIST)) {

  delay(1000); continue;

} else

  break;

}

while (1) {

//Check if the camera module type is OV5642

myCAM1.rdSensorReg16_8(OV5642_CHIPID_HIGH, &vid);

myCAM1.rdSensorReg16_8(OV5642_CHIPID_LOW, &pid);

if ((vid != 0x56) || (pid != 0x42)) {

  Serial.println(F("Can't find OV5642 module!"));

  delay(1000); continue;

} else {

  Serial.println(F("OV5642 detected.")); break;

}

}

//Change to JPEG capture mode and initialize the OV5640 module

myCAM1.set_format(JPEG);

myCAM1.InitCAM();

myCAM1.write_reg(ARDUCHIP_TIM, VSYNC_LEVEL_MASK); //VSYNC is active HIGH

myCAM1.clear_fifo_flag();

myCAM1.write_reg(ARDUCHIP_FRAMES, FRAMES_NUM);

//myCAM1.OV5642_set_JPEG_size(OV5642_640x480); delay(1000);

myCAM1.OV5642_set_JPEG_size(OV5642_320x240); delay(1000);

delay(1000);

myCAM1.clear_fifo_flag();

Serial.println("Ready:,1");

}

void loop() {

if (CAM1_EXIST && stopMotion) {

streamStartTime = millis();

myCAMSendToSerial(myCAM1);

double fps = ((millis() - streamStartTime) / 1000);

Serial.println("fps: " + String(1 / fps ));

}

}

void myCAMSendToSerial(ArduCAM myCAM) {

char str[8];

byte buf[5];

static int i = 0;

static int k = 0;

uint8_t temp = 0, temp_last = 0;

uint32_t length = 0;

bool is_header = false;

myCAM.flush_fifo(); //Flush the FIFO

myCAM.clear_fifo_flag(); //Clear the capture done flag

myCAM.start_capture();//Start capture

while (!myCAM.get_bit(ARDUCHIP_TRIG , CAP_DONE_MASK));

length = myCAM.read_fifo_length();

Serial.print(F("FifoLength:,"));

Serial.print(length, DEC);

Serial.println(",");

if (length >= MAX_FIFO_SIZE) //8M

{

Serial.println(F("Over size."));

return ;

}

if (length == 0 ) //0 kb

{

Serial.println(F("Size is 0."));

return ;

}

myCAM.CS_LOW();

myCAM.set_fifo_burst();

Serial.print("Image:,");

while ( length-- )

{

temp_last = temp;

temp =  SPI.transfer(0x00);

//Read JPEG data from FIFO

if ( (temp == 0xD9) && (temp_last == 0xFF) ) //If find the end ,break while,

{

  buf[i++] = temp;  //save the last  0XD9

  //Write the remain bytes in the buffer

  myCAM.CS_HIGH();

  for (int i = 0; i < sizeof(buf); i++) {

    Serial.print(buf[i]); Serial.print(",");

  }

  Serial.println();

  Serial.println(F("Image transfer OK."));

  is_header = false;

  i = 0;

}

if (is_header == true)

{

  //Write image data to buffer if not full

  if (i < 5) {

    buf[i++] = temp;

  } else

  {

    //Stream 5 bytes of raw image data to serial

    myCAM.CS_HIGH();

    for (int i = 0; i < sizeof(buf); i++) {

      Serial.print(buf[i]); Serial.print(",");

    }

    i = 0;

    buf[i++] = temp;

    myCAM.CS_LOW();

    myCAM.set_fifo_burst();

  }

}

else if ((temp == 0xD8) & (temp_last == 0xFF))

{

  is_header = true;

  buf[i++] = temp_last;

  buf[i++] = temp;

}

}

}

void serialEvent() {

if (Serial.available() > 0) {

uint8_t temp = 0xff, temp_last = 0;

uint8_t start_capture = 0;

temp = Serial.read();

switch (temp)

{

  case 0:

    temp = 0xff;

    myCAM1.OV5642_set_JPEG_size(OV5642_320x240);

    Serial.println(F("OV5642_320x240")); delay(1000);

    myCAM1.clear_fifo_flag();

    break;

  case 1:

    temp = 0xff;

    myCAM1.OV5642_set_JPEG_size(OV5642_640x480);

    Serial.println(F("OV5642_640x480")); delay(1000);

    myCAM1.clear_fifo_flag();

    break;

  case 2:

    temp = 0xff;

    myCAM1.OV5642_set_JPEG_size(OV5642_1024x768);

    Serial.println(F("OV5642_1024x768")); delay(1000);

    myCAM1.clear_fifo_flag();

    break;

  case 3:

    temp = 0xff;

    myCAM1.OV5642_set_JPEG_size(OV5642_1280x960);

    Serial.println(F("OV5642_1280x960")); delay(1000);

    myCAM1.clear_fifo_flag();

    break;

  case 4:

    temp = 0xff;

    myCAM1.OV5642_set_JPEG_size(OV5642_1600x1200);

    Serial.println(F("OV5642_1600x1200")); delay(1000);

    myCAM1.clear_fifo_flag();

    break;

  case 5:

    temp = 0xff;

    myCAM1.OV5642_set_JPEG_size(OV5642_2048x1536);

    Serial.println(F("OV5642_2048x1536")); delay(1000);

    myCAM1.clear_fifo_flag();

    break;

  case 6:

    temp = 0xff;

    myCAM1.OV5642_set_JPEG_size(OV5642_2592x1944);

    Serial.println(F("OV5642_2592x1944")); delay(1000);

    myCAM1.clear_fifo_flag();

    break;

  case 7:

    {

      if (stopMotion)

        stopMotion = false;

      else

        stopMotion = true;

      Serial.println("Stop Motion Enabled: " + String(stopMotion));

    }

    break;

  case 0x10:

    if (CAM1_EXIST) {

      streamStartTime = millis();

      myCAMSendToSerial(myCAM1);

      double fps = ((millis() - streamStartTime) / 1000);

      Serial.println("Total Time: " + String(fps));

    }

    break;

  default:

    break;

}

}

}`

https://github.com/Vernel/ArduCAM_OV562

supprot commented 6 years ago

@Sunshine-Leona Hi, Don't worry, Yes, If you enable 2MP, You should comment the below two codes such as: //myCAM1.write_reg(ARDUCHIP_TIM, VSYNC_LEVEL_MASK); //VSYNC is active HIGH //myCAM1.write_reg(ARDUCHIP_FRAMES, FRAMES_NUM);

Sunshine-Leona commented 6 years ago

@supprot Hello! I managed to get the code to work by changing what you told me and this part of the code: myCAM1.rdSensorReg16_8(OV2640_CHIPID_HIGH, &vid);

myCAM1.rdSensorReg16_8(OV2640_CHIPID_LOW, &pid);

to the following: myCAM1.rdSensorReg8_8(OV2640_CHIPID_HIGH, &vid);

myCAM1.rdSensorReg8_8(OV2640_CHIPID_LOW, &pid);

Thank you for all your help!

supprot commented 6 years ago

@Sunshine-Leona Hi, Great to hear you have solved your problems.

pkvader commented 6 years ago

I am having major difficulties with a similar issue. I have a SD breakout board and "Arducam Mini Module Camera Shield with OV2640 2 Megapixels Lens connected to my Arduino Mega board. The have it wired the same way and the app works with the first code in which I can take pictures and save to my computer. The problem is I am unable to save the pictures to the SD card. The second code for Capture2SD is not working for me and the app does not allow me to take photos it only states the COM is open. Please help!

UCTRONICS commented 6 years ago

@pkvader The Capture2SD demo can't support app, you should open your serial monitor and set the baud rate to 115200.

pkvader commented 6 years ago

Is there a certain way to connect the SD card breakout board? The output serial monitor shows unknown characters only. I have on the SD breakout board's CS connected to PIN 53 and the Arducam's CS connected to PIN 10.

pkvader commented 6 years ago

Update. It does work now Thank you for the quick responses. I appreciate the help!

UCTRONICS commented 6 years ago

@pkvader Do you test it on arduino UNO board? In the code , the SD CS is 9 and the camera CS is 7. You can try to change the CS pin

pkvader commented 6 years ago

I used the Arduino Mega and for the SD breakout board i connected it to the ICSP pins the 2x4 matrix next to the reset button. It seems to be working but some of the files are corrupt still in the works but seems to have decent progress

pkvader commented 6 years ago

Checked today and its not working again. getting "SD CARD ERROR" over and over again.

UCTRONICS commented 6 years ago

@pkvader What SD card module do you use, most of which is the design problem of the module, which cause the The SPI bus was not released.

pkvader commented 6 years ago

I am using Adafruit MicroSD card breakout board+ [ADA254].

pkvader commented 6 years ago

when it bypasses the SD CARD ERROR issue I run into "File open failed" in the serial monitor

UCTRONICS commented 6 years ago

@pkvader

The The capacity of SD card is less than 8G. You should format your SD card in fat 32

pkvader commented 6 years ago

Nevermind I found out the problem I had. It was the breakout board being connected to the ICSP's 5V pin. It seems to be functioning better now. If it continues to work properly I'll make a short video highlighting some things not mentioned for the Arducam community.

pkvader commented 6 years ago

Thank you again for the quick responses. I appreciate the time that you guys put in on this forum.

KlydeLencioco commented 6 years ago

@pkvader have you made a video about this? I'm having trouble using a SD card breakout board with the arducam mini.

pkvader commented 6 years ago

@KlydeLencioco Hey I currently do not have the project in hand but what is the issue that you are having. I can post the project in about a week when it is returned to me.

KlydeLencioco commented 6 years ago

@pkvader we have the same issue. I sd card cant work with the arducam. I dont know if it is on my connection or other else.

pkvader commented 6 years ago

Do the components work separately the SD Card reader / ArduCam? Also are you using an Arduino Mega Board?

pkvader commented 6 years ago

@KlydeLencioco

KlydeLencioco commented 6 years ago

@pkvader yes both of them work seperately. I am using arduino uno

pkvader commented 6 years ago

It could be your wiring, are you using a breadboard + a lot of cable extensions? If so try to make the connections much shorter.

pkvader commented 6 years ago

I used the sd breakout board by adafruit and the wiring needed to be pretty short otherwise it won’t work or work once in awhile. I used an arduino mega also not sure if you can use the uno but there are icsp pins on there so you can try it.

ArduCAM commented 6 years ago

You have to be very carefully with the SD card read adapter, because it shares the SPI bus with Arducam. If the SD card occupy the SPI bus constantly, they can't work together. A lot of SD card read adapter boards are bad designed, there is no tristate control for the SPI bus at all.

KlydeLencioco commented 6 years ago

I have also tried the icsp pins but it wont work also.

@ArduCAM what is your suggestion for the sd card module that I need to use?

pkvader commented 6 years ago

@KlydeLencioco What are you using exactly. List your project items. Plus what your goal is exactly. Mine was to only react to a Motion Detector to activate the ArduCam to take a picture then store that image onto an SD card through the AdaFruit SD breakout Board.

pkvader commented 6 years ago

@KlydeLencioco Also your code if you modified it and/or which sample code are u using from the ArduCam library.

KlydeLencioco commented 6 years ago

@pkvader

My components are: Micro sd module ArduCam ov5642 5mp plus arduino uno pir motion detector esp8266 wifi module

My project is the same as yours. The arducam need to capture an image when motion is detected and save it to the sd card. Right now, I did not hook up the esp8266 module because I have problem saving the image to the sd card.

I am using the ArduCam_Mini_5MP_Plus_Multi_Capture2SD program. I did not modify the code and used the pins for the cam cs and sd cs with respect to the ones declared in the program.

UCTRONICS commented 6 years ago

@KlydeLencioco If you are using the ESP8266 module, please use our ArduCAM_ESP8266_UNO_V2_Capture2SD demo.

KlydeLencioco commented 6 years ago

@UCTRONICS, currently I am not using the esp8266 since I am having a trouble saving the image to the sd card. Once I have solve that problem then I will use the esp8266.

93450101 commented 6 years ago

@ArduCAM hello . I want to collect image data and rebuild image by data i recived ,.can you help me???????????????

KlydeLencioco commented 6 years ago

@UCTRONICS do your shield with micro sd slot works perfectly even with the atmega328p chip?

UCTRONICS commented 6 years ago

@KlydeLencioco Yes, our Shield V2 board is fully compatible with UNO board. For the SD card, we used the pin 9 as the CS of the SD card and share the hardware SPI with the camera.

KlydeLencioco commented 6 years ago

@UCTRONICS where can I place my order?

ArduCAM commented 6 years ago

Our micro SD card adapter is well designed to work with ATMEGA328p, you can find it from: http://www.uctronics.com/arducam-mini-multi-camera-adapter-board-for-arduino-raspberry-pi.html

KlydeLencioco commented 6 years ago

does it need an external power supply?

ArduCAM commented 6 years ago

If running one camera you don't need external power supply, If you want to use 4 cameras you might need extra micro-usb cable to the phone charger.

KlydeLencioco commented 6 years ago

@ArduCAM will that shield also works if I have an esp8266 module?

pkvader commented 6 years ago

capture

pkvader commented 6 years ago

capture1 capture2

pkvader commented 6 years ago

@KlydeLencioco