ArduCAM / Arduino

This is ArduCAM library for Arduino boards
MIT License
472 stars 348 forks source link

Stuck at "Start Capture" in ArduCAM_Mini_5MP_TimeElapse2SD #74

Closed NetForces closed 8 years ago

NetForces commented 8 years ago

Just got a 5MP Mini RevB and I'm trying to at least get a picture on an SD card using a Arduino UNO.

When the Arduino starts I get:

ArduCAM Start!
OV5642 detected
SD Card detected!
Start Capture

But it stays there. never reach the Capture Done!.

Any clue ?

NetForces commented 7 years ago

Copy or attach the content of your memorysaver.h file here.

diegoto commented 7 years ago

Ifndef MEMORYSAVER

Definir MEMORYSAVER

// Sólo cuando se utiliza frambuesa, habilitarla // RASPBERRY_PI #define

// Hay dos pasos es necesario modificar en este archivo antes de la compilación normales // Sólo plataforma de la serie ArduCAM Escudo necesita seleccionar módulo de la cámara, ArduCAM Mini-plataforma de la serie no lo hace

// Paso 1: seleccionar la plataforma de hardware, sólo uno a la vez

//# Definir OV2640_MINI_2MP // #define OV3640_MINI_3MP

define OV5642_MINI_5MP

// #define OV5642_MINI_5MP_BIT_ROTATION_FIXED // OV5642_MINI_5MP_PLUS #define // OV5640_MINI_5MP_PLUS #define

// #define ARDUCAM_SHIELD_REVC
// ARDUCAM_SHIELD_V2 #define

// Paso 2: Seleccione uno de los módulo de la cámara, sólo uno a la vez

Si (definida (ARDUCAM_SHIELD_REVC) || definido (ARDUCAM_SHIELD_V2))

// OV7660_CAM #define
// OV7725_CAM #define
// OV7670_CAM #define
// OV7675_CAM #define

// OV2640_CAM #define // OV3640_CAM #define OV5642_CAM #define // OV5640_CAM #define

// MT9D111A_CAM #define
// MT9D111B_CAM #define
// MT9M112_CAM #define
// MT9V111_CAM #define  
// MT9M001_CAM #define  
// MT9T112_CAM #define
// MT9D112_CAM #define

endif

Endif // MEMORYSAVER

NetForces commented 7 years ago

Did you run the code in a translator ?

Definir is not something valid and all pre-processor keywords in C should start with #

NetForces commented 7 years ago

@ArduCAM Please use tags when you make a release !

diegoto commented 7 years ago

Okay, I'm going to modify it and tell me, if it's okay with you

diegoto commented 7 years ago

Ifndef MEMORYSAVER

Define MEMORYSAVER

// Sólo cuando se utiliza frambuesa, habilitarla // RASPBERRY_PI #define

// Hay dos pasos es necesario modificar en este archivo antes de la compilación normales // Sólo plataforma de la serie ArduCAM Escudo necesita seleccionar módulo de la cámara, ArduCAM Mini-plataforma de la serie no lo hace//

// Paso 1: seleccionar la plataforma de hardware, sólo uno a la vez

//# Define OV2640_MINI_2MP // #define OV3640_MINI_3MP

define OV5642_MINI_5MP

// #define OV5642_MINI_5MP_BIT_ROTATION_FIXED // #defineOV5642_MINI_5MP_PLUS #define // #defineOV5640_MINI_5MP_PLUS #define

// #define ARDUCAM_SHIELD_REVC
// #define ARDUCAM_SHIELD_V2

// Paso 2: Seleccione uno de los módulo de la cámara, sólo uno a la vez

Si (definida (ARDUCAM_SHIELD_REVC) || definido (ARDUCAM_SHIELD_V2))

//#define OV7660_CAM //#define OV7725_CAM

// #define OV7670_CAM // #define OV7675_CAM // #define OV2640_CAM #define // #define OV3640_CAM

define OV5642_CAM

// #define OV5640_CAM
// #define MT9D111A_CAM // #define MT9D111B_CAM // #define MT9M112_CAM // #define MT9V111_CAM
// #define MT9M001_CAM // #define MT9T112_CAM // #define MT9D112_CAM

endif

Endif // MEMORYSAVER

diegoto commented 7 years ago

now?

NetForces commented 7 years ago

No... It should be like:

#ifndef _MEMORYSAVER_
#define _MEMORYSAVER_

//Only when using raspberry,enable it
//#define RASPBERRY_PI

//There are two steps you need to modify in this file before normal compilation
//Only ArduCAM Shield series platform need to select camera module, ArduCAM-Mini series platform doesn't

//Step 1: select the hardware platform, only one at a time
//#define OV2640_MINI_2MP
//#define OV3640_MINI_3MP
#define OV5642_MINI_5MP
//#define OV5642_MINI_5MP_BIT_ROTATION_FIXED
//#define OV5642_MINI_5MP_PLUS
//#define OV5640_MINI_5MP_PLUS

//#define ARDUCAM_SHIELD_REVC   
//#define ARDUCAM_SHIELD_V2

//Step 2: Select one of the camera module, only one at a time
#if (defined(ARDUCAM_SHIELD_REVC) || defined(ARDUCAM_SHIELD_V2))
    //#define OV7660_CAM
    //#define OV7725_CAM
    //#define OV7670_CAM
    //#define OV7675_CAM
  //#define OV2640_CAM
//  #define OV3640_CAM
    #define OV5642_CAM
    //#define OV5640_CAM 

    //#define MT9D111A_CAM
    //#define MT9D111B_CAM
    //#define MT9M112_CAM
    //#define MT9V111_CAM   
    //#define MT9M001_CAM   
    //#define MT9T112_CAM
    //#define MT9D112_CAM
#endif 

#endif  //_MEMORYSAVER_
NetForces commented 7 years ago

Or you can just remove everything that is commented-out that is useless:

#ifndef _MEMORYSAVER_
#define _MEMORYSAVER_

//There are two steps you need to modify in this file before normal compilation
//Only ArduCAM Shield series platform need to select camera module, ArduCAM-Mini series platform doesn't

//Step 1: select the hardware platform, only one at a time
#define OV5642_MINI_5MP

//Step 2: Select one of the camera module, only one at a time
#if (defined(ARDUCAM_SHIELD_REVC) || defined(ARDUCAM_SHIELD_V2))
    #define OV5642_CAM
#endif 

#endif  //_MEMORYSAVER_
diegoto commented 7 years ago

ok, i am going to see it, thank you

diegoto commented 7 years ago

I already did, now I return to the problem of before, thanks in advance for everything you are doing for me``

diegoto commented 7 years ago

Arduino:1.8.1 (Windows 8.1), Tarjeta:"Arduino/Genuino Uno"

C:\Users\Diego-PC\Desktop\myCAM\myCAM.ino: In function 'void loop()':

myCAM:116: error: 'class ArduCAM' has no member named 'get_bit'

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

             ^

myCAM:133: error: 'class ArduCAM' has no member named 'CS_LOW'

myCAM.CS_LOW();

     ^

myCAM:134: error: 'class ArduCAM' has no member named 'set_fifo_burst'

myCAM.set_fifo_burst();

     ^

myCAM:148: error: 'class ArduCAM' has no member named 'CS_HIGH'

   myCAM.CS_HIGH();

         ^

myCAM:152: error: 'class ArduCAM' has no member named 'CS_LOW'

   myCAM.CS_LOW();

         ^

myCAM:153: error: 'class ArduCAM' has no member named 'set_fifo_burst'

   myCAM.set_fifo_burst();

         ^

myCAM:159: error: 'class ArduCAM' has no member named 'CS_HIGH'

 myCAM.CS_HIGH();

       ^

exit status 1 'class ArduCAM' has no member named 'get_bit'

Este reporte podría tener más información con "Mostrar salida detallada durante la compilación" opción habilitada en Archivo -> Preferencias. ``

NetForces commented 7 years ago

If you want send me your sketch at courchea at net - forces dot com

diegoto commented 7 years ago

My sketch is yours that you have uploaded on the web

diegoto commented 7 years ago

// ArduCAM demo (C)2015 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 OV5642 5MP sensor. // It will run the ArduCAM Mini 5MP as a real 5MP digital camera, provide 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.OV5642_set_JPEG_size() function. // This program requires the ArduCAM V3.4.0 (or later) library and ArduCAM Mini 5MP shield // and use Arduino IDE 1.5.2 compiler or above

include

include

include

include

include

include "memorysaver.h"

if defined(arm)

include

endif

define SD_CS 8

// set pin 10 as the slave select for SPI: const int SPI_CS = 10;

ArduCAM myCAM(OV5642, SPI_CS); boolean isShowFlag = true;

void setup() { uint8_t vid, pid; uint8_t temp;

if defined(SAM3X8E)

Wire1.begin();

else

Wire.begin();

endif

Serial.begin(115200); Serial.println("ArduCAM Start!"); // set the SPI_CS as an output: pinMode(SPI_CS, OUTPUT);

// initialize SPI: SPI.begin(); //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("SPI interface Error!"); while (1); }

//Check if the camera module type is OV5642 myCAM.rdSensorReg16_8(OV5642_CHIPID_HIGH, &vid); myCAM.rdSensorReg16_8(OV5642_CHIPID_LOW, &pid); if ((vid != 0x56) || (pid != 0x42)) Serial.println("Can't find OV5642 module!"); else Serial.println("OV5642 detected");

myCAM.set_format(JPEG); myCAM.InitCAM(); myCAM.write_reg(ARDUCHIP_TIM, VSYNC_LEVEL_MASK); //VSYNC is active HIGH //myCAM.OV5642_set_JPEG_size(OV5642_320x240); // myCAM.OV5642_set_JPEG_size(OV5642_640x480); // myCAM.OV5642_set_JPEG_size(OV5642_1280x720); // myCAM.OV5642_set_JPEG_size(OV5642_1920x1080); // myCAM.OV5642_set_JPEG_size(OV5642_2048x1563); // myCAM.OV5642_set_JPEG_size(OV5642_2592x1944); //Initialize SD Card if (!SD.begin(SD_CS)) { while (1); //If failed, stop here Serial.println("SD Card Error"); } else Serial.println("SD Card detected!"); }

void loop() { char str[8]; File outFile; byte buf[256]; static int i = 0; static int k = 0; static int n = 0; uint8_t temp, temp_last; uint8_t start_capture = 0; int total_time = 0;

start_capture = 1; delay(5000);

if (start_capture) { //Flush the FIFO myCAM.flush_fifo(); //Clear the capture done flag myCAM.clear_fifo_flag(); //Start capture myCAM.start_capture(); Serial.println("Start Capture"); }

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

Serial.println("Capture Done!"); //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("open file failed"); return; } total_time = millis();

i = 0; myCAM.CS_LOW(); myCAM.set_fifo_burst(); temp = SPI.transfer(0x00);

//Read JPEG data from FIFO while ( (temp != 0xD9) | (temp_last != 0xFF) ) { temp_last = temp; temp = SPI.transfer(0x00);; //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(); } } //Write the remain bytes in the buffer if (i > 0) { myCAM.CS_HIGH(); outFile.write(buf, i); } //Close the file outFile.close(); total_time = millis() - total_time; Serial.print("Total time used:"); Serial.print(total_time, DEC); Serial.println(" millisecond"); //Clear the capture done flag myCAM.clear_fifo_flag(); //Clear the start capture flag start_capture = 0;

}``

diegoto commented 7 years ago

A question ... even if I do not have the SD connected to my arduino, the camera should work fine, right?``

NetForces commented 7 years ago

I have the feeling that you never coded in C right ?

If you look at the code there is:

if (!SD.begin(SD_CS))
{
while (1); //If failed, stop here
Serial.println("SD Card Error");
}
else
Serial.println("SD Card detected!");
}

So if there is no card detected it will stop there.

diegoto commented 7 years ago

If I worked but very little, I regret my behavior, but I decided to do a job of degree and I need to activate the camera and save the photo in the sd, I do not know if during these days you could help me NetForces, I would be very grateful for it``

NetForces commented 7 years ago

write to me via e-mail please.

diegoto commented 7 years ago

This is the SD I have

http://www.dx.com/es/p/spi-microsd-card-adapter-v0-9b-for-arduino-works-with-official-arduino-board-246784?tc=EUR&gclid=Cj0KEQjwoqvIBRD6ls6og8qB77YBEiQAcqqHe1WdoZfTYNFFzNfWjcos2SiAO7d8OdgOCUvIg6gO3hwaAsqm8P8HAQ#.WQuPRVXyi00

diegoto commented 7 years ago

What is your NetForce mailing address?``

diegoto commented 7 years ago

What is your NetForce mailing addresss?

Diego Torres Herrador

El 4 may 2017, a las 22:32, NetForces notifications@github.com escribió:

write to me via e-mail please.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

NetForces commented 7 years ago

courchea at net - forces dot com

diegoto commented 7 years ago

I'm sorry, but I wrote to the email address that you've passed me and it gives me error. Is the correct e-mail address the one you've given me?``

diegoto commented 7 years ago

this is my email

diego.torresherrador@gmail.com

diegoto commented 7 years ago

Write me but you care and save your address

mnotgod96 commented 5 years ago

@NetForces Hi, I am facing the same problem with my ov2640 module (getting corrupted JPG file on my SD card). Did you find a solution to that?

UCTRONICS commented 5 years ago

@NetForces You can try to print the image data to the serial port. To check the jpeg header "FFD8" and the then end "FFD9"

mnotgod96 commented 5 years ago

@UCTRONICS Do you mean I should hexdump my JPG files and see if they start with FFD8 and end with FFD9?

mnotgod96 commented 5 years ago

Here is the header and ending of my JPG file, it seems that it starts with D8FF instead of FFD8 (it ends with FFD9 though). Does that mean I am losing the first byte of my JPG data for some reasons? 1 2

mnotgod96 commented 5 years ago

@UCTRONICS Thank you for your help! After inserting FF at the beginning of the file by myself, I can open the image with no problem. However, I am still wondering what caused this issue.

UCTRONICS commented 5 years ago

@mnotgod96 Yes, I found you have lost the first FF. Please attach me your code and I will help you optimize it.

mnotgod96 commented 5 years ago

Here is my code. I am sharing the I2C bus with my LCD and sharing the SPI bus with the micro SD breakout.

`#include

include

include

include

include

include

include "memorysaver.h"

if defined(arm)

include

endif

define SD_CS 10

const int SPI_CS = 9;

ArduCAM myCAM(OV2640, SPI_CS); UTFT myGLCD(SPI_CS); LiquidCrystal_I2C lcd(0x27,16,2);

int count = 0;

void setupCamera() { uint8_t vid,pid; uint8_t temp;

if defined(SAM3X8E)

Wire1.begin();

else

Wire.begin();

endif

lcd.clear(); lcd.setCursor(0,0); lcd.print("I2C-SPI test");

// set the SPI_CS as an output: pinMode(SPI_CS, 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; } }

//Check if the camera module type is OV2640 while(1){ myCAM.wrSensorReg8_8(0xff, 0x01); myCAM.rdSensorReg8_8(OV2640_CHIPID_HIGH, &vid); myCAM.rdSensorReg8_8(OV2640_CHIPID_LOW, &pid); lcd.setCursor(0,1); if ((vid != 0x26) || (pid != 0x42)) { lcd.print("Can't find 2640!"); delay(1000); continue; } else { lcd.print("2640 detected "); break; } } delay(500); //Let 2640 card info be displayed myCAM.set_format(JPEG); myCAM.InitCAM(); myCAM.OV2640_set_JPEG_size(OV2640_640x480);

//Initialize SD Card lcd.setCursor(0,1); while (!SD.begin(SD_CS)) { lcd.print("SD Card Error "); delay(1000); } lcd.print("SD Card found! "); delay(500); //Let SD card info be displayed }

void takePicture() { char str[8]; File outFile; byte buf[256]; static int i = 0; static int k = 0; static int n = 0; uint8_t temp, temp_last; uint8_t start_capture = 0; int total_time = 0;

start_capture = 1;

if (start_capture) { //Flush the FIFO myCAM.flush_fifo(); //Clear the capture done flag myCAM.clear_fifo_flag(); //Start capture myCAM.start_capture(); lcd.setCursor(0,1); lcd.print("Start Capture "); }

while (!myCAM.get_bit(ARDUCHIP_TRIG , CAP_DONE_MASK)); lcd.setCursor(0,1); lcd.print("End Capture ");

//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) { lcd.setCursor(0,1); lcd.print("Open file failed"); return; } total_time = millis(); i = 0; myCAM.CS_LOW(); myCAM.set_fifo_burst(); temp = SPI.transfer(0x00);

//Read JPEG data from FIFO while ( (temp != 0xD9) | (temp_last != 0xFF)) { temp_last = temp; temp = SPI.transfer(0x00);

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

} //Write the remain bytes in the buffer if (i > 0) { myCAM.CS_HIGH(); outFile.write(buf, i); } //Close the file outFile.close(); //Clear the capture done flag myCAM.clear_fifo_flag(); //Clear the start capture flag start_capture = 0; }

void setup() { lcd.init(); lcd.backlight(); setupCamera(); }

void loop() { count = count + 1; lcd.clear(); lcd.print("Picture " + String(count)); takePicture(); delay(10000); }`

UCTRONICS commented 5 years ago

@mnotgod96 `#include

include

include

include

include

include

include "memorysaver.h"

if defined(arm)

include

endif

define SD_CS 10

const int SPI_CS = 9;

ArduCAM myCAM(OV2640, SPI_CS); UTFT myGLCD(SPI_CS); LiquidCrystal_I2C lcd(0x27,16,2);

int count = 0;

void setupCamera() { uint8_t vid,pid; uint8_t temp;

if defined(SAM3X8E)

Wire1.begin();

else

Wire.begin();

endif

lcd.clear(); lcd.setCursor(0,0); lcd.print("I2C-SPI test");

// set the SPI_CS as an output: pinMode(SPI_CS, 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; } }

//Check if the camera module type is OV2640 while(1){ myCAM.wrSensorReg8_8(0xff, 0x01); myCAM.rdSensorReg8_8(OV2640_CHIPID_HIGH, &vid); myCAM.rdSensorReg8_8(OV2640_CHIPID_LOW, &pid); lcd.setCursor(0,1); if ((vid != 0x26) || (pid != 0x42)) { lcd.print("Can't find 2640!"); delay(1000); continue; } else { lcd.print("2640 detected "); break; } } delay(500); //Let 2640 card info be displayed myCAM.set_format(JPEG); myCAM.InitCAM(); myCAM.OV2640_set_JPEG_size(OV2640_640x480);

//Initialize SD Card lcd.setCursor(0,1); while (!SD.begin(SD_CS)) { lcd.print("SD Card Error "); delay(1000); } lcd.print("SD Card found! "); delay(500); //Let SD card info be displayed }

void takePicture() { char str[8]; File outFile; byte buf[256]; static int i = 0; static int k = 0; static int n = 0; uint8_t temp, temp_last; uint8_t start_capture = 0; int total_time = 0;

start_capture = 1;

if (start_capture) { //Flush the FIFO myCAM.flush_fifo(); //Clear the capture done flag myCAM.clear_fifo_flag(); //Start capture myCAM.start_capture(); lcd.setCursor(0,1); lcd.print("Start Capture "); }

while (!myCAM.get_bit(ARDUCHIP_TRIG , CAP_DONE_MASK)); lcd.setCursor(0,1); lcd.print("End Capture ");

//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) { lcd.setCursor(0,1); lcd.print("Open file failed"); return; } total_time = millis(); i = 0; myCAM.CS_LOW(); myCAM.set_fifo_burst(); //temp = SPI.transfer(0x00);

//Read JPEG data from FIFO while ( (temp != 0xD9) | (temp_last != 0xFF)) { temp_last = temp; temp = SPI.transfer(0x00);

//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(); } } //Write the remain bytes in the buffer if (i > 0) { myCAM.CS_HIGH(); outFile.write(buf, i); } //Close the file outFile.close(); //Clear the capture done flag myCAM.clear_fifo_flag(); //Clear the start capture flag start_capture = 0; }

void setup() { lcd.init(); lcd.backlight(); setupCamera(); }

void loop() { count = count + 1; lcd.clear(); lcd.print("Picture " + String(count)); takePicture(); delay(10000); }`

UCTRONICS commented 5 years ago

@mnotgod96 It is due to the code. The camera you are using is the new version, you don't need to lose the first byte. For our old version, the first byte is 00, so in the code, we lose the first code.