Arducam Mega 5MP SPI camera - config for full resolution

  1. Where did you get the camera module(s)?
    test-sample as part of the Kickstarter Campaign

  2. Model number of the product(s)?
    MEGA-5MP
    MEGA-5MP - Arducam Wiki

  3. What hardware/platform were you working on?
    ESP32

  4. Instructions you have followed. (link/manual/etc.)
    https://www.arducam.com/downloads/arducam_mega_getting_started_guide.pdf
    ESP32 Node — SPICamera documentation

  5. Problems you were having?
    I am directly controlling the camera by script and it works fine for all resolution modes except for the highest. Github–>CAM_IMAGE_MODE

  6. Troubleshooting attempts you’ve made?

I have taken the provided sample code, which broadcasts the image file to a http endpoint and modified it, so that it stores the file on a local ftp server. this is my code, which works perfectly with all lower resolutions:

void sendImageData(String projectID = "default") {
  String deviceID = String(EEPROM.read(0)) + "-" + String(EEPROM.read(1));
  Serial.println("sending Image Data");
  int i = 0;
  char* filename;
  unsigned long currentTime = millis();
  char timestamp[50];
  sprintf(timestamp, "%s_%s_%lu.jpg", deviceID.c_str(), projectID.c_str(), currentTime);
  filename = timestamp;
  Serial.println(filename);
  // read bytes from camera and store in buffer

  ftp.OpenConnection();
  ftp.InitFile(COMMAND_XFER_TYPE_BINARY);
  ftp.AppendFile(filename);
  while (myCAM.getReceivedLength()) {
    imageData = imageDataNext;
    imageDataNext = myCAM.readByte();
    if (headFlag == 1) {
      buffer[i++] = imageDataNext;
      if (i >= bufferSize) {
        Serial.println("writing full buffer");
        ftp.WriteData(buffer, sizeof(buffer));
        i = 0;
      }
    }
    // check for start of image data
    if (imageData == 0xff && imageDataNext == 0xd8) {
      Serial.println("start of image data detected");
      headFlag = 1;
      buffer[i++] = imageData;
      buffer[i++] = imageDataNext;
    }
    // check for end of image data
    if (imageData == 0xff && imageDataNext == 0xd9) {
      headFlag = 0;
      Serial.println("writing END Data");
      ftp.WriteData(buffer, sizeof(buffer));
      i = 0;
      break;
    }
    
  }
  Serial.println("Image Sent");

  ftp.CloseFile();
}

The uncommented line //Serial.print(imageDataNext) will show a constant stream of data. When working with lower resolutions, the serial output looks as expected:

start of image data detected
writing full buffer
writing full buffer
writing full buffer
...
writing full buffer
writing END Data
Image send

the output starts immediately after calling sendImageData(),
Whereas on highest resolution there are two different behaviors, it does not start immediately and

(CASE 1) It does not set the headflag to 1 (does not get start of image) → the received image data is only one buffersize large and mostly empty

writing END Data

(CASE 2) It detects the start of the file multiple times

start of image data detected
writing full buffer
...
writing full buffer
start of image data detected
writing full buffer
...
writing full buffer
writing END Data

I have tried varying the buffersize too, without any effect.

  1. What help do you need?
    I am not sure, what could cause this issue. Could you please point me in some direction, so that I can use the camera to its full potential.

Btw, the 3MP camera is working as expected!