How to get image from Arducam SPI OV5642 camera module

Published by Margarito Lehmann on

Home Forums Arducam SPI Cameras How to get image from Arducam SPI OV5642 camera module

Viewing 19 reply threads
  • Author
    Posts
    • #22992
      Margarito Lehmann
      Participant

      Bonjour,

      Je me permets de vous contacter suite à l’achat de deux Arducams OV5642.

      Après plusieurs tentatives infructueuses, je n’arrive malheureusement pas à obtenir de visuel.

      J’ai réalisé le montage ci-dessous avec le code en pièce jointe.

      Vous trouverez également ci-dessous l’écran d’Arducam_Host après téléversement du code.

      Sauriez-vous d’où peut provenir le problème ?

      Arducam 5MP SPI camera

       

    • #23035
      bin
      Keymaster

      Hello,

      Don’t worry and I will try my best to help you. Please attach me the demo you are using. I will help you check it in detail.

       

    • #23053
      Dams
      Participant

      Hi everybody,

      Thx to rescue me in my problem 🙂

      I used the demo code below.

      I have to add every times theses librairies in  the code (OV5642_MINI_5MP ; OV5642_CAM ; “OV5642_regs.h”). Otherwise, I have an error message.

      Then, the application said me “Spi is ok” and he detected my cam. But I have no images or vision which launches (even if I push “Capture”).

      My camera is new and my Arduino (Uno and Mega, I tried both) works with others projets.

      I’m a front of a wall :).

      Damien

      The code:

      #include <Wire.h>
      #include <ArduCAM.h>
      #include <SPI.h>
      #include “memorysaver.h”
      #define OV5642_MINI_5MP
      #define OV5642_CAM
      #include “OV5642_regs.h”

      //This demo can only work on OV2640_MINI_2MP or OV5642_MINI_5MP or OV5642_MINI_5MP_BIT_ROTATION_FIXED platform.
      #if !(defined OV5642_MINI_5MP || defined OV5642_MINI_5MP_BIT_ROTATION_FIXED || defined OV2640_MINI_2MP || defined OV3640_MINI_3MP)
      #error Please select the hardware platform and camera module in the ../libraries/ArduCAM/memorysaver.h file
      #endif
      #define BMPIMAGEOFFSET 66
      const char bmp_header[BMPIMAGEOFFSET] PROGMEM =
      {
      0x42, 0x4D, 0x36, 0x58, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x28, 0x00,
      0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x03, 0x00,
      0x00, 0x00, 0x00, 0x58, 0x02, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0x1F, 0x00,
      0x00, 0x00
      };
      // set pin 7 as the slave select for the digital pot:
      const int CS =7;
      bool is_header = false;
      int mode = 0;
      uint8_t start_capture = 0;
      #if defined (OV2640_MINI_2MP)
      ArduCAM myCAM( OV2640, CS );
      #elif defined (OV3640_MINI_3MP)
      ArduCAM myCAM( OV3640, CS );
      #else
      ArduCAM myCAM( OV5642, CS );
      #endif
      uint8_t read_fifo_burst(ArduCAM myCAM);
      void setup() {
      // put your setup code here, to run once:
      uint8_t vid, pid;
      uint8_t temp;
      #if defined(__SAM3X8E__)
      Wire1.begin();
      Serial.begin(115200);
      #else
      Wire.begin();
      Serial.begin(921600);
      #endif
      Serial.println(F(“ACK CMD ArduCAM Start! END”));
      // set the CS as an output:
      pinMode(CS, OUTPUT);
      digitalWrite(CS, HIGH);
      // initialize SPI:
      SPI.begin();
      //Reset the CPLD
      myCAM.write_reg(0x07, 0x80);
      delay(100);
      myCAM.write_reg(0x07, 0x00);
      delay(100);
      while(1){
      //Check if the ArduCAM SPI bus is OK
      myCAM.write_reg(ARDUCHIP_TEST1, 0x55);
      temp = myCAM.read_reg(ARDUCHIP_TEST1);
      if (temp != 0x55){
      Serial.println(F(“ACK CMD SPI interface Error! END”));
      delay(1000);continue;
      }else{
      Serial.println(F(“ACK CMD SPI interface OK. END”));break;
      }
      }

      #if defined (OV2640_MINI_2MP)
      while(1){
      //Check if the camera module type is OV2640
      myCAM.wrSensorReg8_8(0xff, 0x01);
      myCAM.rdSensorReg8_8(OV2640_CHIPID_HIGH, &vid);
      myCAM.rdSensorReg8_8(OV2640_CHIPID_LOW, &pid);
      if ((vid != 0x26 ) && (( pid != 0x41 ) || ( pid != 0x42 ))){
      Serial.println(F(“ACK CMD Can’t find OV2640 module! END”));
      delay(1000);continue;
      }
      else{
      Serial.println(F(“ACK CMD OV2640 detected. END”));break;
      }
      }
      #elif defined (OV3640_MINI_3MP)
      while(1){
      //Check if the camera module type is OV3640
      myCAM.rdSensorReg16_8(OV3640_CHIPID_HIGH, &vid);
      myCAM.rdSensorReg16_8(OV3640_CHIPID_LOW, &pid);
      if ((vid != 0x36) || (pid != 0x4C)){
      Serial.println(F(“ACK CMD Can’t find OV3640 module! END”));
      delay(1000);continue;
      }else{
      Serial.println(F(“ACK CMD OV3640 detected. END”));break;
      }
      }

      #else
      while(1){
      //Check if the camera module type is OV5642
      myCAM.wrSensorReg16_8(0xff, 0x01);
      myCAM.rdSensorReg16_8(OV5642_CHIPID_HIGH, &vid);
      myCAM.rdSensorReg16_8(OV5642_CHIPID_LOW, &pid);
      if((vid != 0x56) || (pid != 0x42)){
      Serial.println(F(“ACK CMD Can’t find OV5642 module! END”));
      delay(1000);continue;
      }
      else{
      Serial.println(F(“ACK CMD OV5642 detected. END”));break;
      }
      }
      #endif
      //Change to JPEG capture mode and initialize the OV5642 module
      myCAM.set_format(JPEG);
      myCAM.InitCAM();
      #if defined (OV2640_MINI_2MP)
      myCAM.OV2640_set_JPEG_size(OV2640_320x240);
      #elif defined (OV3640_MINI_3MP)
      myCAM.OV3640_set_JPEG_size(OV3640_320x240);
      #else
      myCAM.write_reg(ARDUCHIP_TIM, VSYNC_LEVEL_MASK); //VSYNC is active HIGH
      myCAM.OV5642_set_JPEG_size(OV5642_320x240);
      #endif
      delay(1000);
      myCAM.clear_fifo_flag();
      #if !(defined (OV2640_MINI_2MP))
      myCAM.write_reg(ARDUCHIP_FRAMES,0x00);
      #endif
      }
      void loop() {
      // put your main code here, to run repeatedly:
      uint8_t temp = 0xff, temp_last = 0;
      bool is_header = false;
      if (Serial.available())
      {
      temp = Serial.read();
      switch (temp)
      {
      case 0:
      #if defined (OV2640_MINI_2MP)
      myCAM.OV2640_set_JPEG_size(OV2640_160x120);delay(1000);
      Serial.println(F(“ACK CMD switch to OV2640_160x120 END”));
      #elif defined (OV3640_MINI_3MP)
      myCAM.OV3640_set_JPEG_size(OV3640_176x144);delay(1000);
      Serial.println(F(“ACK CMD switch to OV2640_160x120 END”));
      #else
      myCAM.OV5642_set_JPEG_size(OV5642_320x240);delay(1000);
      Serial.println(F(“ACK CMD switch to OV5642_320x240 END”));
      #endif
      temp = 0xff;
      break;
      case 1:
      #if defined (OV2640_MINI_2MP)
      myCAM.OV2640_set_JPEG_size(OV2640_176x144);delay(1000);
      Serial.println(F(“ACK CMD switch to OV2640_176x144 END”));
      #elif defined (OV3640_MINI_3MP)
      myCAM.OV3640_set_JPEG_size(OV3640_320x240);delay(1000);
      Serial.println(F(“ACK CMD switch to OV3640_320x240 END”));
      #else
      myCAM.OV5642_set_JPEG_size(OV5642_640x480);delay(1000);
      Serial.println(F(“ACK CMD switch to OV5642_640x480 END”));
      #endif
      temp = 0xff;
      break;
      case 2:
      #if defined (OV2640_MINI_2MP)
      myCAM.OV2640_set_JPEG_size(OV2640_320x240);delay(1000);
      Serial.println(F(“ACK CMD switch to OV2640_320x240 END”));
      #elif defined (OV3640_MINI_3MP)
      myCAM.OV3640_set_JPEG_size(OV3640_352x288);delay(1000);
      Serial.println(F(“ACK CMD switch to OV3640_352x288 END”));
      #else
      myCAM.OV5642_set_JPEG_size(OV5642_1024x768);delay(1000);
      Serial.println(F(“ACK CMD switch to OV5642_1024x768 END”));
      #endif
      temp = 0xff;
      break;
      case 3:
      temp = 0xff;
      #if defined (OV2640_MINI_2MP)
      myCAM.OV2640_set_JPEG_size(OV2640_352x288);delay(1000);
      Serial.println(F(“ACK CMD switch to OV2640_352x288 END”));
      #elif defined (OV3640_MINI_3MP)
      myCAM.OV3640_set_JPEG_size(OV3640_640x480);delay(1000);
      Serial.println(F(“ACK CMD switch to OV3640_640x480 END”));
      #else
      myCAM.OV5642_set_JPEG_size(OV5642_1280x960);delay(1000);
      Serial.println(F(“ACK CMD switch to OV5642_1280x960 END”));
      #endif
      break;
      case 4:
      temp = 0xff;
      #if defined (OV2640_MINI_2MP)
      myCAM.OV2640_set_JPEG_size(OV2640_640x480);delay(1000);
      Serial.println(F(“ACK CMD switch to OV2640_640x480 END”));
      #elif defined (OV3640_MINI_3MP)
      myCAM.OV3640_set_JPEG_size(OV3640_800x600);delay(1000);
      Serial.println(F(“ACK CMD switch to OV3640_800x600 END”));
      #else
      myCAM.OV5642_set_JPEG_size(OV5642_1600x1200);delay(1000);
      Serial.println(F(“ACK CMD switch to OV5642_1600x1200 END”));
      #endif
      break;
      case 5:
      temp = 0xff;
      #if defined (OV2640_MINI_2MP)
      myCAM.OV2640_set_JPEG_size(OV2640_800x600);delay(1000);
      Serial.println(F(“ACK CMD switch to OV2640_800x600 END”));
      #elif defined (OV3640_MINI_3MP)
      myCAM.OV3640_set_JPEG_size(OV3640_1024x768);delay(1000);
      Serial.println(F(“ACK CMD switch to OV3640_1024x768 END”));
      #else
      myCAM.OV5642_set_JPEG_size(OV5642_2048x1536);delay(1000);
      Serial.println(F(“ACK CMD switch to OV5642_2048x1536 END”));
      #endif
      break;
      case 6:
      temp = 0xff;
      #if defined (OV2640_MINI_2MP)
      myCAM.OV2640_set_JPEG_size(OV2640_1024x768);delay(1000);
      Serial.println(F(“ACK CMD switch to OV2640_1024x768 END”));
      #elif defined (OV3640_MINI_3MP)
      myCAM.OV3640_set_JPEG_size(OV3640_1280x960);delay(1000);
      Serial.println(F(“ACK CMD switch to OV3640_1280x960 END”));
      #else
      myCAM.OV5642_set_JPEG_size(OV5642_2592x1944);delay(1000);
      Serial.println(F(“ACK CMD switch to OV5642_2592x1944 END”));
      #endif
      break;
      case 7:
      temp = 0xff;
      #if defined (OV2640_MINI_2MP)
      myCAM.OV2640_set_JPEG_size(OV2640_1280x1024);delay(1000);
      Serial.println(F(“ACK CMD switch to OV2640_1280x1024 END”));
      #else
      myCAM.OV3640_set_JPEG_size(OV3640_1600x1200);delay(1000);
      Serial.println(F(“ACK CMD switch to OV3640_1600x1200 END”));
      #endif
      break;
      case 8:
      temp = 0xff;
      #if defined (OV2640_MINI_2MP)
      myCAM.OV2640_set_JPEG_size(OV2640_1600x1200);delay(1000);
      Serial.println(F(“ACK CMD switch to OV2640_1600x1200 END”));
      #else
      myCAM.OV3640_set_JPEG_size(OV3640_2048x1536);delay(1000);
      Serial.println(F(“ACK CMD switch to OV3640_2048x1536 END”));
      #endif
      break;
      case 0x10:
      mode = 1;
      temp = 0xff;
      start_capture = 1;
      Serial.println(F(“ACK CMD CAM start single shoot. END”));
      break;
      case 0x11:
      temp = 0xff;
      myCAM.set_format(JPEG);
      myCAM.InitCAM();
      #if !(defined (OV2640_MINI_2MP))
      myCAM.set_bit(ARDUCHIP_TIM, VSYNC_LEVEL_MASK);
      #endif
      break;
      case 0x20:
      mode = 2;
      temp = 0xff;
      start_capture = 2;
      Serial.println(F(“ACK CMD CAM start video streaming. END”)); Serial.println(F(“ACK IMG END”));
      break;
      case 0x30:
      mode = 3;
      temp = 0xff;
      start_capture = 3;
      Serial.println(F(“ACK CMD CAM start single shoot. END”));
      break;
      case 0x31:
      temp = 0xff;
      myCAM.set_format(BMP);
      myCAM.InitCAM();
      #if !(defined (OV2640_MINI_2MP))
      myCAM.clear_bit(ARDUCHIP_TIM, VSYNC_LEVEL_MASK);
      #endif
      myCAM.wrSensorReg16_8(0x3818, 0x81);
      myCAM.wrSensorReg16_8(0x3621, 0xA7);
      break;
      default:
      break;
      }
      }
      if (mode == 1)
      {
      if (start_capture == 1)
      {
      myCAM.flush_fifo();
      myCAM.clear_fifo_flag();
      //Start capture
      myCAM.start_capture();
      start_capture = 0;
      }
      if (myCAM.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK))
      {
      Serial.println(F(“ACK CMD CAM Capture Done. END”));
      delay(50);
      read_fifo_burst(myCAM);
      //Clear the capture done flag
      myCAM.clear_fifo_flag();
      }
      }
      else if (mode == 2)
      {
      while (1)
      {
      temp = Serial.read();
      if (temp == 0x21)
      {
      start_capture = 0;
      mode = 0;
      Serial.println(F(“ACK CMD CAM stop video streaming. END”));
      break;
      }
      if (start_capture == 2)
      {
      myCAM.flush_fifo();
      myCAM.clear_fifo_flag();
      //Start capture
      myCAM.start_capture();
      start_capture = 0;
      }
      if (myCAM.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK))
      {
      uint32_t length = 0;
      length = myCAM.read_fifo_length();
      if ((length >= MAX_FIFO_SIZE) | (length == 0))
      {
      myCAM.clear_fifo_flag();
      start_capture = 2;
      continue;
      }
      myCAM.CS_LOW();
      myCAM.set_fifo_burst();//Set fifo burst mode
      temp = SPI.transfer(0x00);
      length –;
      while ( length– )
      {
      temp_last = temp;
      temp = SPI.transfer(0x00);
      if (is_header == true)
      {
      Serial.write(temp);
      }
      else if ((temp == 0xD8) & (temp_last == 0xFF))
      {
      is_header = true;
      Serial.println(F(“ACK IMG END”));
      Serial.write(temp_last);
      Serial.write(temp);
      }
      if ( (temp == 0xD9) && (temp_last == 0xFF) ) //If find the end ,break while,
      break;
      delayMicroseconds(15);
      }
      myCAM.CS_HIGH();
      myCAM.clear_fifo_flag();
      start_capture = 2;
      is_header = false;
      }
      }
      }
      else if (mode == 3)
      {
      if (start_capture == 3)
      {
      //Flush the FIFO
      myCAM.flush_fifo();
      myCAM.clear_fifo_flag();
      //Start capture
      myCAM.start_capture();
      start_capture = 0;
      }
      if (myCAM.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK))
      {
      Serial.println(F(“ACK CMD CAM Capture Done. END”));
      delay(50);
      uint8_t temp, temp_last;
      uint32_t length = 0;
      length = myCAM.read_fifo_length();
      if (length >= MAX_FIFO_SIZE )
      {
      Serial.println(F(“ACK CMD Over size. END”));
      myCAM.clear_fifo_flag();
      return;
      }
      if (length == 0 ) //0 kb
      {
      Serial.println(F(“ACK CMD Size is 0. END”));
      myCAM.clear_fifo_flag();
      return;
      }
      myCAM.CS_LOW();
      myCAM.set_fifo_burst();//Set fifo burst mode

      Serial.write(0xFF);
      Serial.write(0xAA);
      for (temp = 0; temp < BMPIMAGEOFFSET; temp++)
      {
      Serial.write(pgm_read_byte(&bmp_header[temp]));
      }
      SPI.transfer(0x00);
      char VH, VL;
      int i = 0, j = 0;
      for (i = 0; i < 240; i++)
      {
      for (j = 0; j < 320; j++)
      {
      VH = SPI.transfer(0x00);;
      VL = SPI.transfer(0x00);;
      Serial.write(VL);
      delayMicroseconds(12);
      Serial.write(VH);
      delayMicroseconds(12);
      }
      }
      Serial.write(0xBB);
      Serial.write(0xCC);
      myCAM.CS_HIGH();
      //Clear the capture done flag
      myCAM.clear_fifo_flag();
      }
      }
      }
      uint8_t read_fifo_burst(ArduCAM myCAM)
      {
      uint8_t temp = 0, temp_last = 0;
      uint32_t length = 0;
      length = myCAM.read_fifo_length();
      Serial.println(length, DEC);
      if (length >= MAX_FIFO_SIZE) //512 kb
      {
      Serial.println(F(“ACK CMD Over size. END”));
      return 0;
      }
      if (length == 0 ) //0 kb
      {
      Serial.println(F(“ACK CMD Size is 0. END”));
      return 0;
      }
      myCAM.CS_LOW();
      myCAM.set_fifo_burst();//Set fifo burst mode
      temp = SPI.transfer(0x00);
      length –;
      while ( length– )
      {
      temp_last = temp;
      temp = SPI.transfer(0x00);
      if (is_header == true)
      {
      Serial.write(temp);
      }
      else if ((temp == 0xD8) & (temp_last == 0xFF))
      {
      is_header = true;
      Serial.println(F(“ACK IMG END”));
      Serial.write(temp_last);
      Serial.write(temp);
      }
      if ( (temp == 0xD9) && (temp_last == 0xFF) ) //If find the end ,break while,
      break;
      delayMicroseconds(15);
      }
      myCAM.CS_HIGH();
      is_header = false;
      return 1;

       

    • #23069
      Arducam jyh
      Moderator

      Hi,

      Please test with our unmodified demo first, select the correct camera in memorysaver. h, and do not add the macro definition in the demo code.

    • #23159
      Dams
      Participant

      hi,

    • #23160
      Dams
      Participant

      Thx for your answer. I tried what you advised. The error message is on this line:
      #if !(defined OV5642_MINI_5MP || defined OV5642_MINI_5MP_BIT_ROTATION_FIXED || defined OV2640_MINI_2MP || defined OV3640_MINI_3MP)
      #error Please select the hardware platform and camera module in the ../libraries/ArduCAM/memorysaver.h file
      #endif

      Although it seems that it doesn’t find the library(Arducam), it’s included.
      I try to download it again but the problem persists.

    • #23154
      Dams
      Participant

      Hi,

      I did what you adviced and I got this error message:

      <b></b><i></i><u></u><span style=”text-decoration: line-through;”></span>

      It’s the same error message I had on all demos. It seems that it doesn’t find my  librairy (Arducam), however it’s defined.

      I tried to download it again but the problem persists.

    • #23155
      Dams
      Participant

      Hi,

      I did what you advices. I had this error message.

      <b></b><i></i><u></u><span style=”text-decoration: line-through;”></span>

      I had this message on all my tests with Arducam. Although it seems it doesn’t find my librairy (Arducam), it’s installed.

      I tried to download it again but the problem persists.

       

       

    • #23158
      Dams
      Participant

      Hi,

      Thx for your answer. I tried what you advised.

      The error message is , at the beginning, on this line:

      I have this message with all demos. It seems that the software doesn’t find my library but it’s included. I tried to download it again  but the problem persists.

    • #23172
      Arducam jyh
      Moderator

      Hi,

      If you have selected the correct board and turned on the corresponding camera in memorysaver. h, you still have the above error, then it maybe the library was placed in the wrong path, please make sure ArduCAM is under the installation path of Arduino, similar to: D:\Program Files (x86)\Arduino\libraries

      This is my file path.

       

    • #23201
      Dams
      Participant

      Hi,

      My Arducam library is under the installation path of Arduino:

      <b></b><i></i><u></u><span style=”text-decoration: line-through;”></span>

       

       

       

    • #23292
      Arducam jyh
      Moderator

      @Dams

      Hi,

      Now you have confirmed the library path is right, have you chosen the right board?Which board did you choose? I suggest you follow this video in detail.

    • #23469
      Dams
      Participant

      Hi,

      I checked up my Arduino IDE and I used the same board than the video (Arduino UNO/ Com4)
      I compared with my device manager and COM4 is the right port.

      I tried to do the same thing than the video but without success.
      I used 2 demos: “Mini_5MP_OV5642_Plus_Functions” and “Mini_5MP_Plus_OV5642_RAW”.
      In both cases, the program didn’t find the library:

       
      At the beginning in “OV5642_Plus_Functions”, the “if library is defined” was in comment (//) and the error message was on this line :”myCAM.rdSensorReg16_8(OV5642_CHIPID_HIGH, &vid)”. I think it’s the same problem and the program doesn’t find the library.
      By the past, I already tried to install Arducam library again, without success.

    • #23484
      Arducam jyh
      Moderator

      Hello,

      At this point, I think you can only completely remove your Arduino software, then re-install it, and operate it according to our video again.If it still can’t find the library, please let me help you with the remote software.

    • #23508
      Dams
      Participant

      Hi,

      I removed my Arduino software and reninstalled it again. I followed the video but I always got the same problem…
      How do you want to do?

    • #23510
      bin
      Keymaster

      Hi,

      This demo is used for 5mp plus, so you should open the memorysaver.h file which is under the Arducam path and enable the Arducam_mini_5mp_plus

       

    • #23515
      Dams
      Participant

      Hi bin,

      As you can see on the picture, my hardware platform is the right one.

      I tried to select/unselect my camera module but It isn’t the problem.

      I checked up my Arduino IDE, it’s good.

      I unistalled and installed the Arduino and Arducam Package again, no results 🙁

       

       

       

       

       

       

       

       

       

       

       

       

       

    • #23540
      Arducam jyh
      Moderator

      @Dams

      Can you use TeamViewer to let us help you remotely?

    • #23554
      Dams
      Participant

      Yes, I can.
      How do you want to do?

    • #23593
      Arducam jyh
      Moderator

      Hi,

      Our working hours are from 8.30 am to 5.30 PM From Monday to Friday, Beijing time. You can choose a time to turn on your computer and send TeamViewer’s account and password to our email([email protected]). We will help you remotely.

       

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