Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CANT FIND OV2640 module #592

Open
SHUNTER56 opened this issue Jul 27, 2024 · 0 comments
Open

CANT FIND OV2640 module #592

SHUNTER56 opened this issue Jul 27, 2024 · 0 comments

Comments

@SHUNTER56
Copy link

Hi All

currently making a circuit to save images to SD card, previously i bought an arducam and my code worked perfectly (however it kept saving over old files on SD card but thats beside the point) then one day it stopped working, and it wouldnt find the arducam. i thought it was a problem with the arducam so i took it and tried lots of code and still cant find it. im using SPI and ive followed every single tutorial.

does this happen often? its connected to arduino pro mini, all lines are the same as arduino e.g CS on 7 etc. it worked for a couple of weeks then suddenly stopped.

code is below

Thanks

#include <ArduCAM.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <LoRa.h>

int LED = 6; //test LED for comms diagnostics
int val = 0; //diagnostic integer for incoming LoRa.
int h = 12; //time when turned on (hours)
int m = 0; //time when turned on (minutes)
int s = 0; //time when turned on (seconds)
int flag = 0;
int TIME = 0;
const int hs = 0;
const int ms = 1;
int state1 = 0;
int state2 = 0;

String inString = ""; // string to hold input

#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 8 // SD card chip select pin (needs to be unique and not used by any other device)
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

String command;
void myCAMSaveToSDFile(){
char str[8] = "SAT.S.H"; //name of output file
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("Starting Capture"));
while(!myCAM.get_bit(ARDUCHIP_TRIG , CAP_DONE_MASK));
Serial.println(F("Capture Complete."));
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 failed"));
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 confirmed."));
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(){

pinMode(LED,OUTPUT);
uint8_t vid, pid;
uint8_t temp;

Wire.begin();
Serial.begin(9600);
Serial.println(F("ArduCAM Start!")); //set the CS as an output:
pinMode(SPI_CS,OUTPUT);
digitalWrite(SPI_CS, HIGH);
pinMode(SD_CS,OUTPUT);
digitalWrite(SD_CS, HIGH);
// initialize SPI:
SPI.begin();

//Reset the CPLD
myCAM.write_reg(0x07, 0x80);
delay(100);
myCAM.write_reg(0x07, 0x00);
delay(100);

while (!Serial);
Serial.println("LoRa Device Connected Successfully");
if (!LoRa.begin(433E6)) { // or 915E6
Serial.println("Starting LoRa failed!");
while (1);
}

while(1){
//Check if the ArduCAM SPI bus is OK
myCAM.write_reg(ARDUCHIP_TEST1, 0x50);
temp = myCAM.read_reg(ARDUCHIP_TEST1);

if (temp != 0x50){ //is it 0x30?
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 successfully."));

#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 successfully"));break;
}
}

#endif
myCAM.set_format(JPEG);
myCAM.InitCAM();
#if defined (OV2640_MINI_2MP)
myCAM.OV2640_set_JPEG_size(OV2640_1600x1200); //picture quality here
#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);
Serial.println("Type Command (Take) to take a photo");

   digitalWrite(LED, HIGH);
   delay(2000);
   digitalWrite(LED,LOW);

}
void loop(){

cameracommand();
}

void cameracommand(){
int packetSize = LoRa.parsePacket();
if (packetSize) {
// read packet
while (LoRa.available())
{
//Serial.println((char)LoRa.read());
// }
int inChar = LoRa.read();
inString += (char)inChar;
val = inString.toInt();
Serial.println(val);
}
inString = "";
//delay(100);
if (val == 1){
myCAMSaveToSDFile();
//Serial.println("image taken");

   digitalWrite(LED, HIGH);
    delay(1000);
   digitalWrite(LED,LOW);    
}    

}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant