Hardware to connect camera to a button to take a picture and store in an SD card

I am a Year 10 student and I'm trying to do a project outside of school for my silver CREST award.

Anyway, for one aspect of the project, I have to code a camera that is button activated and when that button is pressed it takes a photo and then stores it in an SD card in JPEG format.

I've done all the software for the camera and the SD card but I got stuck connecting the button to the camera through code and then connecting that to the SD card through code. Furthermore, I tried to build the camera and button and SD together but I can't work out how to do it.

Can anyone help me with the process I need to do in order to connect the software for the SD card and Camera and add a button and/or how to build the hardware for the camera, SD card, and button?

I'm using an Arduino Mega 2560 board with an OV2640 camera.

Any help would be greatly appreciated!

What kind of an award do we get?

Paul

Erinyoung:
I've done all the software for the camera and the SD card

Please post it, in code tags.

#include <ArduCAM.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include "memorysaver.h"

//This demo can only work on OV2640_MINI_2MP or ARDUCAM_SHIELD_V2 platform.
#if !(defined (OV2640_MINI_2MP)||(defined (ARDUCAM_SHIELD_V2) && defined (OV2640_CAM)))
#error Please select the hardware platform and camera module in the ../libraries/ArduCAM/memorysaver.h file
#endif
// set GPIO16 as the slave select :
const int CS = 16;
//Version 1,set GPIO1 as the slave select :
const int SD_CS = 1;
ArduCAM myCAM(OV2640, CS);

void myCAMSaveToSDFile(){
char str[8];
byte buf[256];
static int i = 0;
static int k = 0;
static int n = 0;
uint8_t temp, temp_last;
File file;
//Flush the FIFO
myCAM.flush_fifo();
//Clear the capture done flag
myCAM.clear_fifo_flag();
//Start capture
myCAM.start_capture();
Serial.println("star 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
file = SD.open(str, O_WRITE | O_CREAT | O_TRUNC);
if(! file){
Serial.println("open file faild");
return;
}
i = 0;
myCAM.CS_LOW();
myCAM.set_fifo_burst();
#if !(defined (ARDUCAM_SHIELD_V2) && defined (OV2640_CAM))
SPI.transfer(0xFF);
#endif
//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();
file.write(buf ,256);
i = 0;
buf[i++] = temp;
myCAM.CS_LOW();
myCAM.set_fifo_burst();
}
delay(0);
}

//Write the remain bytes in the buffer
if(i > 0){
myCAM.CS_HIGH();
file.write(buf,i);
}
//Close the file
file.close();
Serial.println("CAM Save Done!");
}

void setup(){
uint8_t vid, pid;
uint8_t temp;
Wire.begin();
Serial.begin(115200);
Serial.println("ArduCAM Start!");

//set the CS as an output:
pinMode(CS,OUTPUT);

//initialize SPI:
SPI.begin();
SPI.setFrequency(4000000); //4MHZ

delay(1000);
//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("SPI1 interface Error!");
while(1);
}

//Initialize SD Card
if(!SD.begin(SD_CS)){
Serial.println("SD Card Error");
}
else
Serial.println("SD Card detected!");

//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("Can't find OV2640 module!");
else
Serial.println("OV2640 detected.");
myCAM.set_format(JPEG);
myCAM.InitCAM();
}

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

This is my camera code, it puts the picture into the SD card I just don't know how to do the hardware aspect