Arducam-Mini-5MP(OV5642) with arduino MKR 1400 board results in very dark images

Published by katesfb on

Home Forums Arducam SPI Cameras Arducam-Mini-5MP(OV5642) with arduino MKR 1400 board results in very dark images

  • This topic has 8 replies, 4 voices, and was last updated 1 week ago by bin.
Viewing 8 reply threads
  • Author
    Posts
    • #21875
      katesfb
      Participant

      Hi,

      I’m using the Arducam-Mini-5MP(OV5642) with an arduino MKR 1400 board to capture images and then upload them to an FTP server. Every thing works fine except that the uploaded images are very dark. If i capture the images to an SD card the images are fine. Below is the arduino example code for capturing an image that has been altered to capture the image to the file system storage on the modem of the MKR 1400. It also takes quite a long time (several seconds) to write the captured data to the file system storage whereas if i write to an sd card the transfer takes less than a second. Should the code below work OK when capturing an image to the file system on the MKR 1400.

       

      Any help is much appreciated.

       

      void getImage() {
      char str[22];
      File outFile;
      byte buf[256];
      static int i = 0;
      //static int k = 0;
      static int n = 0;
      uint8_t temp, temp_last;
      uint8_t start_capture = 0;
      int total_time = 0;

      memset(dirFile,0,sizeof(dirFile));

      Serial.println(“Set image size”);
      myCAM.clear_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK);
      myCAM.OV5642_set_JPEG_size(OV5642_1280x720);
      myCAM.set_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK);

      delay(250);

      start_capture = 1;
      //delay(10000);

      Serial.println(“\nSetting up capture”);
      Serial.println(“Disable low pwr mode!”);
      myCAM.clear_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK);//disable low power
      delay(250);

      if (start_capture)
      {
      //Flush the FIFO
      myCAM.flush_fifo();
      //Clear the capture done flag
      myCAM.clear_fifo_flag();
      //Start capture
      myCAM.start_capture();
      Serial.println(“Start Capture”);
      }

      while (!myCAM.get_bit(ARDUCHIP_TRIG , CAP_DONE_MASK));

      Serial.println(“Capture Done!”);
      Serial.println(“re-enable low pwr mode”);
      myCAM.set_bit(ARDUCHIP_GPIO,GPIO_PWDN_MASK);
      delay(250);

      i = 0;
      myCAM.CS_LOW();
      myCAM.set_fifo_burst();
      temp = SPI.transfer(0x00);

      //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 modem FS
      myCAM.CS_HIGH();
      FILESYSTEM.write(“temp”, (uint8_t *)buf, 256);
      i = 0;
      buf[i++] = temp;
      myCAM.CS_LOW();
      myCAM.set_fifo_burst();
      }
      }
      //Write the remain bytes in the buffer
      if (i > 0)
      {
      myCAM.CS_HIGH();
      FILESYSTEM.write(“temp”, (uint8_t *)buf, i);

      }

      total_time = millis() – total_time;
      Serial.print(“Total time used:”);
      Serial.print(total_time, DEC);
      Serial.println(” millisecond”);
      //Clear the capture done flag
      myCAM.clear_fifo_flag();
      //Clear the start capture flag
      start_capture = 0;
      }

    • #21886
      Arducam jyh
      Moderator

      Hello,

      I suggest that you upload the same image to the FTP server and SD card, and then compare the data of the two images to see if they are consistent. If the data is inconsistent, you need to check whether there is a problem with the sending or receiving method.

    • #21922
      katesfb
      Participant

      Hi,

      And thanks for the reply, much appreciated.

       

      Yes i think the problem is related to the way i am sending the data, i am currently sending the captured image data directly to the modem file storage (FS) on the MKR 1400 which i dont think is the right way to do it. I should capture to the SD card first (which works and image is fine), then move the SD card image data to the modem FS either by decoding the JPEG data into a bit stream then copying to the modem FS or maybe transferring the image data to a byte array and then to the modem FS but this is where i have a second problem;

       

      I have already put a second question on the forum.

      Essentially i cant do both (write to SD card and upload to FTP server). If initialise the modem on the MKR 1400, the image capture still works but writing to the SD card fails. If i dont initialise the modem i can write to the SD card but obviously cant upload to the FTP server. This is strange behaviour as another project that works exactly the same way recording data from an ultrasonic sensor connected to the UART (not SPI) port works perfectly. It almost feels like some form of SPI conflict is going on.

       

      Any thoughts on this or potential solutions  would be much appreciated.

       

      Cheers.

    • #21934
      Arducam jyh
      Moderator

      Hello,

      If you cannot upload image data to FTP and SD card at the same time due to SPI conflict, you could try to upload the data to FTP and serial port, and then compare the data of the same image.

      This can determine if there is a problem with the method of uploading to FTP server.

    • #22919
      dumisebastian
      Participant

      I have a question for the author: how did you manage to get the camera module working for the MKR1400? I suspect you modified the ArduCAM.h file by adding some code. If so, what did you add?

    • #22997
      katesfb
      Participant

      Hi Ian,

      I did not need to alter the ArduCAM.h file. From the start the arducam example code (arducam_mini_5mp_TimelapsetoSD) worked with the MKR1400 to capture images to the SD card (albeit with a small change to the code and using the old library). The issues i was having were related to trying to transfer  the captured data directly to the modem FS on the MKR1400 instead of transferring to the SD card first which didnt work (see above) and an SPI conflict related to how i was assigning the SPI_CS pin which meant that i couldn’t write to the sd card and write to the modem FS. Those issues have been fixed. I also have the “SPI interface error” issue but currently this only occurs if i attempt to reprogram the board. If i disconnect the USB, reconnect and reprogram everything is fine. I think this is due to incorrect  SPI bus speed maybe.

       

      So currently i can:

      Capture an image to the SD card, copy the created image file from the SD card to the modem FS and then upload the created file on the modem FS to the FTP server. However i still have one last issue where it only does the capture  once, when it goes through the loop for the second time to get another image it gets “stuck” in the image capture bit;

       

      “while (!myCAM.get_bit(ARDUCHIP_TRIG , CAP_DONE_MASK));”

       

      So still a few things to work through to make it work properly but i am getting close.

       

      Cheers.

       

    • #23003
      bin
      Keymaster

      Hello,

      Before getting each image, you should ensure you have cleared FIFO flag and set start capture flag.

       

    • #23205
      dumisebastian
      Participant

      Hi katesfb,

      Could you please provide the “small change to the code” which you made in order to capture to the SD? I have made some changes myself, but I keep getting errors I do not understand.

      Thank you and I apologize for this off-topic inquiry.

    • #23221
      bin
      Keymaster

      Hello,

      Don’t worry and I will try my best to help you.

      As normal, If we want to get one frame, after we init the sensor.

      We generally take the following steps:

      //Flush the FIFO
      myCAM.flush_fifo();
      //Clear the capture done flag
      myCAM.clear_fifo_flag();
      //Start capture
      myCAM.start_capture();
      Serial.println(F(“start Capture”));
      while(!myCAM.get_bit(ARDUCHIP_TRIG , CAP_DONE_MASK));
      Serial.println(F(“Capture Done.”));
      length = myCAM.read_fifo_length();
      Serial.print(F(“The fifo length is :”));
      Serial.println(length, DEC);

       

Viewing 8 reply threads
  • You must be logged in to reply to this topic.