So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By BlackCode
#69088 Hey,

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:

Image

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.

Code: Select allvoid 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
User avatar
By GEEN777
#69414 Hello BlackCode,

first, I can't help you but I'm interested in what you do. If you found a solution or if I could help you in any way, let me know.

My project is to build a low energy consumption webcam, which takes every 10 minutes a picture and post it to a web site.

Best Geert
User avatar
By gdsports
#69473 I cannot help with the ArduCam since I have never used one but there are options for examining what is in SPIFFS and even uploading and downloading files.

1. There is an FTP server for ESP8266.

2. The ESP8266 Arduino package includes an HTTP file browser example named FSBrowser. FSBrowser works on files in SPIFFS.