I am trying to use the Radio Shack camera.pde sketch to take a picture and store to an SD card on an Arduino Uno R3 with an Arduino Ethernet shield and a Radio Shack Camera Shield. I kept getting a zero file size and I wanted to get some feedback on what was going on in the program so I moved the camera rx and tx to pins 2 and 3 and used myserial instead of serial so I could print some outputs on the arduino's serial monitor. My program keeps getting stuck in the while loop below. I think it is because frame_length is such a big number (3133198144) compared to vc_frame_address. The first couple of lines of the serial output are:
Capturing Photo
Capturing Photo2
Capturing Photo3
Capturing Photo4
Capturing Photo5
Capturing Photo6
56
3133198144
112
3133198144
and the relevant part of the code is below. Any help would be greatly appreciated. The entire sketch is also attached. Thanks again.
void capture_photo(){
Serial.begin (9600);
Serial.println("Capturing Photo");
// Check to see if the file exists:
// if exists,delete the file:
if(sd.exists("temp.jpg")) sd.remove("temp.jpg");
// open a new empty file for write at end like the Native SD library
if (!myFile.open("temp.jpg", O_RDWR | O_CREAT | O_AT_END)) {
sd.errorHalt("opening temp.jpg for write failed");
}
// close the file:
myFile.close();
Serial.println("Capturing Photo2");
VC0706_compression_ratio(63);
delay(100);
Serial.println("Capturing Photo3");
VC0706_frame_control(3);
delay(10);
Serial.println("Capturing Photo4");
VC0706_frame_control(0);
delay(10);
rx_ready=false;
rx_counter=0;
Serial.println("Capturing Photo5");
mySerial.end(); // clear all rx buffer
delay(5);
mySerial.begin(115200);
Serial.println("Capturing Photo6");
//get frame buffer length
VC0706_get_framebuffer_length(0);
delay(10);
buffer_read();
//while(1){};
// store frame buffer length for coming reading
frame_length=(VC0706_rx_buffer[5]<<8)+VC0706_rx_buffer[6];
frame_length=frame_length<<16;
frame_length=frame_length+(0x0ff00&(VC0706_rx_buffer[7]<<8))+VC0706_rx_buffer[8];
vc_frame_address =READ_DATA_BLOCK_NO;
myFile.open("temp.jpg", O_RDWR);
while(vc_frame_address<frame_length){
Serial.println(vc_frame_address);
Serial.println(frame_length);
VC0706_read_frame_buffer(vc_frame_address-READ_DATA_BLOCK_NO, READ_DATA_BLOCK_NO);
delay(9);
//get the data with length=READ_DATA_BLOCK_NObytes
rx_ready=false;
rx_counter=0;
buffer_read();
// write data to temp.jpg
myFile.write(VC0706_rx_buffer+5,READ_DATA_BLOCK_NO);
//read next READ_DATA_BLOCK_NO bytes from frame buffer
vc_frame_address=vc_frame_address+READ_DATA_BLOCK_NO;
}
// get the last data
vc_frame_address=vc_frame_address-READ_DATA_BLOCK_NO;
last_data_length=frame_length-vc_frame_address;
VC0706_read_frame_buffer(vc_frame_address,last_data_length);
delay(9);
//get the data
rx_ready=false;
rx_counter=0;
buffer_read();
myFile.write(VC0706_rx_buffer+5,last_data_length);
myFile.close();
Serial.println("Picture Stored");
Serial.end();
}
PicEveryxMinutesmyserial.ino.ino (21.8 KB)