I am working on a new ESP-Project and after a few hours of frustration I decided to post here
to seek some help.
This is my first post here and I am trying to be as precise as possible.
I have connected the ArduCam 2MP Mini to my ESP8266-12F. Nothing special here:
What I am trying to do is simply starting the cam, taking a picture and saving it to the ESP's storage.
All examples I found online were using some local server - however I don't like to do that.
Just take a picture and save it to the esp. (I like to send that picture later to Telegram)
Currently I did throw this together with help from the internet.
When the function is executed tho I get the message that the Data storage is full, which is very unlikely since the picture is really small and my script uses only 30% of the storage..
Also I can't verify if the picture was actually taken and saved since there is nothing like a filebrowser
for the esp.
void myCAMSaveToSPIFFS() {
SPIFFS.begin();
delay(10);
myCAM.set_format(JPEG);
myCAM.InitCAM();
setCamResolution(resolution);
// as file space is used, capturing images will get slower. At a certain point, the images will become distored
// or they will not save at all due to lack of space. To avoid this we set a limit and allow some free space to remain
if ((fileTotalKB - fileUsedKB) < fileSpaceOffset)
{
String maxStr = "====== Maximum Data Storage Reached =========";
Serial.println(maxStr);
HomeBot.sendMessage(HomeBot.message[1][4], EncodeURL("Data storage is full! Failed to take picture!") , "");
errMsg = maxStr;
return;
}
String str;
byte buf[256];
static int i = 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();
while (!myCAM.get_bit(ARDUCHIP_TRIG , CAP_DONE_MASK));
Serial.println("File Capture Done!");
fileCount++;
str = "/pics/" + String(fileCount) + ".jpg";
File f = SPIFFS.open(str, "w");
if (!f) {
Serial.println("prop file open failed");
}
else
{
Serial.println(str);
}
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();
f.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();
f.write(buf, i);
}
//Close the file
f.close();
Serial.println("CAM Save Done!");
}
Also, in case I can figure out how to do the saving, I like to ask
whats the best way to load the saved jpg picture from the storage for further processing?
Regards,,
BlackCode