mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
128 lines
3.0 KiB
Plaintext
128 lines
3.0 KiB
Plaintext
|
|
Try this (not tested)
|
|
[code]
|
|
//#include <UTFT.h>
|
|
#include <SD.h>
|
|
#include <Wire.h>
|
|
#include <ArduCAM.h>
|
|
#include <avr/pgmspace.h>
|
|
|
|
#define SD_CS 9
|
|
|
|
|
|
//UTFT(byte model, int RS, int WR, int RD, int CS)
|
|
//UTFT myGLCD(ITDB32S,A2,A1,A0,10); // Remember to change the model parameter to suit your display module!
|
|
//ArduCAM(byte model,int RS, int WR, int RD, int REG_CS, int FIFO_CS)
|
|
ArduCAM myCAM(OV2640,A2,A1,A0,A3,10); // Remember to change the model parameter to suit your canera module!
|
|
|
|
void setup()
|
|
{
|
|
Serial.begin(115200); // <<<<<<<<<<<<<<<<<<<<<<<
|
|
Serial.println("Start arducam test");
|
|
|
|
//Initialize I2C Bus
|
|
Wire.begin();
|
|
//Switch to FIFO Mode
|
|
myCAM.write_reg(ARDUCHIP_TIM, MODE_MASK);
|
|
//Set sensor to JPEG mode. Note don't all the camera modules support JPEG mode
|
|
myCAM.OV2640_set_format(JPEG);
|
|
//Initialize Camera Module
|
|
myCAM.InitCAM();
|
|
myCAM.OV2640_set_JPEG_size(OV2640_320x240);
|
|
|
|
Serial.println("SD.begin");
|
|
//Initialize SD Card
|
|
if (!SD.begin(SD_CS))
|
|
{
|
|
Serial.println("SD card failed");
|
|
//while (1); //If failed, stop here
|
|
}
|
|
Serial.println("SD card success");
|
|
Serial.println("End setup");
|
|
}
|
|
|
|
void loop()
|
|
{
|
|
Serial.print(millis());
|
|
Serial.println("\tstart loop");
|
|
|
|
char str[8];
|
|
File outFile;
|
|
static int k = 0;
|
|
uint8_t temp,temp_last;
|
|
uint8_t start_capture = 0;
|
|
|
|
Serial.print(millis());
|
|
Serial.println("\tWait trigger from shutter buttom");
|
|
|
|
//Wait trigger from shutter buttom
|
|
if(myCAM.read_reg(ARDUCHIP_TRIG) & SHUTTER_MASK)
|
|
{
|
|
//Wait until buttom released
|
|
while(myCAM.read_reg(ARDUCHIP_TRIG) & SHUTTER_MASK);
|
|
start_capture = 1;
|
|
}
|
|
|
|
|
|
Serial.print(millis());
|
|
Serial.println("\tStart capture I");
|
|
//Start capture when detect a valid shutter press
|
|
if(start_capture)
|
|
{
|
|
//Flush the FIFO
|
|
myCAM.flush_fifo();
|
|
//Start capture
|
|
myCAM.start_capture();
|
|
}
|
|
|
|
if(myCAM.read_reg(ARDUCHIP_TRIG) & CAP_DONE_MASK)
|
|
{
|
|
//Construct a file name
|
|
k = k + 1;
|
|
itoa(k, str, 10);
|
|
strcat(str,".jpg");
|
|
//Open the new file
|
|
outFile = SD.open(str,FILE_WRITE);
|
|
if (! outFile)
|
|
{
|
|
Serial.print(millis());
|
|
Serial.println("\tfailure outfile");
|
|
return;
|
|
}
|
|
|
|
Serial.print(millis());
|
|
Serial.println("\toutfile succes");
|
|
|
|
//Enable FIFO
|
|
myCAM.enable_fifo();
|
|
|
|
uint32_t bytecounter = 0;
|
|
//Read the first dummy byte from FIFO
|
|
temp = myCAM.read_fifo();
|
|
|
|
//Read JPEG data from FIFO
|
|
while( (temp != 0xD9) | (temp_last != 0xFF) )
|
|
{
|
|
bytecounter++;
|
|
if (bytecounter % 32 == 0) Serial.print('.');
|
|
if (bytecounter % 1024 == 0) Serial.println;
|
|
temp_last = temp;
|
|
temp = myCAM.read_fifo();
|
|
//Write image data to file
|
|
outFile.write(temp);
|
|
}
|
|
Serial.println();
|
|
|
|
//Disable FIFO when all the image data is saved to the file
|
|
myCAM.disable_fifo();
|
|
//Close the file
|
|
outFile.close();
|
|
|
|
//Clear the capture done flag
|
|
myCAM.clear_fifo_flag();
|
|
//Clear the start capture flag
|
|
start_capture = 0;
|
|
}
|
|
}
|
|
|
|
[/code] |