Voir une ArduCAM via le Bluetooth sur une MEGA

Bonjour,

Débutant dans le code, je n'arrive pas à trouver de solution à mon problème qui est le suivant :

Visualiser en streaming le flux vidéo d'une ArduCAM 2 MP Plus OV2640 présent sur une Mega avec un module Bluetooth HC05.

Ceux-ci pour guider mon robot.

J'ai déjà testé le code donné par ArduCAM sur une UNO et utilisé leur app host pour visualiser le flux, mais là sur la mega les pin sont utilisé par le shield.

Je me suis donc branché sur les pins suivantes :

  • SCK 52
  • MISO 50
  • MOSI 51
  • SS/CS 53
  • SCL 21
  • SDA 20

Et je suis donc bloqué, ne sachant pas trop comment faire ...

arduCam.h

host app

Quel shield ? Décris bien tout ton matériel, ainsi que les pins utilisées par chaque périphérique STP.

Je ne connais pas l'ArduCAM, mais il semble pouvoir être utilisé en SPI ou bien en I2C. Le module BT doit utiliser une liaison série (Serial0 1 ou 2), donc tu peux utiliser I2C ou SPI. Si tu n'as rien sur le SPI, tu peux y brancher ta caméra : ce seront les pins 50 à 53, sinon prend l'I2C (20 (SDA), 21 (SCL)).
Note que les pins SPI sont aussi disponibles sur le connecteur ICSP : il doit être accessible malgré le shield.

SPI et I2C sont des bus, donc tu peux connecter plusieurs devices sur un même bus. Dans le cas du SPI, les fils SCK, MISO et MOSI sont communs à chaque device, et chacun a un SS/CS différent. Donc, si tu as un autre périphérique sur le SPI, il suffit qu'il utilise un autre SS/CS que celui que tu donneras à ta caméra.

Utilisation du SPI :
image

Voir aussi ici pour des explications en anglais sur l'utilisation du SPI sur Méga avec plusieurs périphériques (le cas échéant).

Un exemple de réalisation ArduCAM + Bluetooth :

C'est pas tout à fait une arduino Mega c'est une Keyestuduio Plus mais ça reste la même chose qu'une arduino Mega :

image

J'ai un shield motor HW-130, utilisé pour 4 DC motors, occupants les pins suivantes :

Vin
Gnd
Gnd
5V
3.3V
Reset

0
1

3
4
5
6
7
8

11
12

Gnd
Aref

Mon modules bluetooth HC-05 est branché sur les PIns suivantes :

A14
A15
Gnd coté 53
5V coté 22

C'est ça ?

Si oui, tu as accès aux pins du bus SPI soit sur l'ICSP (au milieu) soit sur les pins 50 à 53, ainsi qu'à l'I2C. Selon cette page :

  • SPI communication interface:D53 stands for SS, D51 is MOSI, D50 is MISO, D52 equals to SCK
  • IIC communication interface:D20 represents SDA, D21 is SCL

Il faut juste en choisir un seul des deux.

La page explique tout (installation de l'IDE, type de carte à choisir, etc).

Oui c'est ce shield là .

Et pour les pins c'est ce que j'ai noté lors de mon premier message.

Pas vraiment : tu as dit

Là tu utilises à la fois le SPI et l'I2C. Moi, je te dis d'en choisir un seul...

Qu'elle est le meilleur choix avec mon projet ? je suis à 115 200 Bauds aussi

Là j'essaye de communiquer avec la CAM via le port usb sur la mega mais je n'y arrive pas ...

Au temps pour moi, il semble que l'ArduCAM a besoin des deux bus. Tous les exemples que je trouve utilisent ce genre de branchement :

Arducam CS MOSI MISO SCK GND VCC SDA SCL
MEGA2560 7 MOSI MISO SCK GND 5V SDA SCL

Donc, désolé... retour à la case départ. Quand tu dis :

Qu'est ce qui se passe (ou ne se passe pas) ?

Oui c'est ce que j'allais te dire :stuck_out_tongue:

Là j'essaye de copier les données en passant par le Bluetooth

Sois plus précis. Tu discutes avec quoi ? Un smartphone ? Quelle appli BT sur lui ? Es-tu sûr qu'il est bien connecté à ta carte ?
Quelles données ? Les images ?
Quel code utilises-tu ?

Alors dans un premier temps j'ai envoyé le programme fait pas ArduCAM dans mon mega via l'IDE arduino via le port USB, j'ai ensuite ouvert l'app host, et j'ai pu communiquer et visualiser le flux sur l'app host

Et donc là j'essaye de copier le flux transmis vers le port Serial en le copiant via le port bleutooth

  
         HC05.write(Serial.read());
                HC05.write(Serial1.read());
                       HC05.write(Serial2.read());
                              HC05.write(Serial3.read());
  
        HC05.write(Serial.println());
                HC05.write(Serial1.println());
                       HC05.write(Serial2.println());
                              HC05.write(Serial3.println());
                              
         HC05.write(Wire.read());
         HC05.write(Wire.println());
          
         HC05.write(temp);
         HC05.write(length);
         HC05.write(start_capture);
         HC05.write(is_header);
         HC05.write(mode);

Un bout de code n'est pas suffisant...
Quel est le code arducam sont tu parles? Il est disponible quelque part?

// ArduCAM Mini demo (C)2017 Lee
// Web: http://www.ArduCAM.com
// This program is a demo of how to use most of the functions
// of the library with ArduCAM Mini camera, and can run on any Arduino platform.
// This demo was made for ArduCAM_Mini_5MP_Plus.
// It needs to be used in combination with PC software.
// It can test OV2640 functions
// This program requires the ArduCAM V4.0.0 (or later) library and ArduCAM_Mini_5MP_Plus
// and use Arduino IDE 1.6.8 compiler or above
#include <Wire.h>
#include <ArduCAM.h>
#include <SPI.h>
#include "memorysaver.h"
//This demo can only work on OV2640_MINI_2MP platform.
#if !(defined OV2640_MINI_2MP)
  #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 = 53;
bool is_header = false;
int mode = 0;
uint8_t start_capture = 0;
#if defined (OV2640_MINI_2MP)
  ArduCAM myCAM( OV2640, 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(57600);
#else
  Wire.begin();
  Serial.begin(115200);
#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;
    } 
  }
#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);
#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:
      myCAM.OV2640_set_JPEG_size(OV2640_160x120);delay(1000);
      Serial.println(F("ACK CMD switch to OV2640_160x120 END"));
     temp = 0xff;
    break;
    case 1:
      myCAM.OV2640_set_JPEG_size(OV2640_176x144);delay(1000);
      Serial.println(F("ACK CMD switch to OV2640_176x144 END"));
    temp = 0xff;
    break;
    case 2: 
      myCAM.OV2640_set_JPEG_size(OV2640_320x240);delay(1000);
      Serial.println(F("ACK CMD switch to OV2640_320x240 END"));
    temp = 0xff;
    break;
    case 3:
    myCAM.OV2640_set_JPEG_size(OV2640_352x288);delay(1000);
    Serial.println(F("ACK CMD switch to OV2640_352x288 END"));
   temp = 0xff;
    break;
    case 4:
      myCAM.OV2640_set_JPEG_size(OV2640_640x480);delay(1000);
      Serial.println(F("ACK CMD switch to OV2640_640x480 END"));
    temp = 0xff;
    break;
    case 5:
    myCAM.OV2640_set_JPEG_size(OV2640_800x600);delay(1000);
    Serial.println(F("ACK CMD switch to OV2640_800x600 END"));
    temp = 0xff;
    break;
    case 6:
     myCAM.OV2640_set_JPEG_size(OV2640_1024x768);delay(1000);
     Serial.println(F("ACK CMD switch to OV2640_1024x768 END"));
    temp = 0xff;
    break;
    case 7:
    myCAM.OV2640_set_JPEG_size(OV2640_1280x1024);delay(1000);
    Serial.println(F("ACK CMD switch to OV2640_1280x1024 END"));
    temp = 0xff;
    break;
    case 8:
    myCAM.OV2640_set_JPEG_size(OV2640_1600x1200);delay(1000);
    Serial.println(F("ACK CMD switch to OV2640_1600x1200 END"));
     temp = 0xff;
    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"));
    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;
    case 0x40:
    myCAM.OV2640_set_Light_Mode(Auto);temp = 0xff;
    Serial.println(F("ACK CMD Set to Auto END"));break;
     case 0x41:
    myCAM.OV2640_set_Light_Mode(Sunny);temp = 0xff;
    Serial.println(F("ACK CMD Set to Sunny END"));break;
     case 0x42:
    myCAM.OV2640_set_Light_Mode(Cloudy);temp = 0xff;
    Serial.println(F("ACK CMD Set to Cloudy END"));break;
     case 0x43:
    myCAM.OV2640_set_Light_Mode(Office);temp = 0xff;
    Serial.println(F("ACK CMD Set to Office END"));break;
   case 0x44:
    myCAM.OV2640_set_Light_Mode(Home);   temp = 0xff;
   Serial.println(F("ACK CMD Set to Home END"));break;
   case 0x50:
    myCAM.OV2640_set_Color_Saturation(Saturation2); temp = 0xff;
     Serial.println(F("ACK CMD Set to Saturation+2 END"));break;
   case 0x51:
     myCAM.OV2640_set_Color_Saturation(Saturation1); temp = 0xff;
     Serial.println(F("ACK CMD Set to Saturation+1 END"));break;
   case 0x52:
    myCAM.OV2640_set_Color_Saturation(Saturation0); temp = 0xff;
     Serial.println(F("ACK CMD Set to Saturation+0 END"));break;
    case 0x53:
    myCAM. OV2640_set_Color_Saturation(Saturation_1); temp = 0xff;
     Serial.println(F("ACK CMD Set to Saturation-1 END"));break;
    case 0x54:
     myCAM.OV2640_set_Color_Saturation(Saturation_2); temp = 0xff;
     Serial.println(F("ACK CMD Set to Saturation-2 END"));break; 
   case 0x60:
    myCAM.OV2640_set_Brightness(Brightness2); temp = 0xff;
     Serial.println(F("ACK CMD Set to Brightness+2 END"));break;
   case 0x61:
     myCAM.OV2640_set_Brightness(Brightness1); temp = 0xff;
     Serial.println(F("ACK CMD Set to Brightness+1 END"));break;
   case 0x62:
    myCAM.OV2640_set_Brightness(Brightness0); temp = 0xff;
     Serial.println(F("ACK CMD Set to Brightness+0 END"));break;
    case 0x63:
    myCAM. OV2640_set_Brightness(Brightness_1); temp = 0xff;
     Serial.println(F("ACK CMD Set to Brightness-1 END"));break;
    case 0x64:
     myCAM.OV2640_set_Brightness(Brightness_2); temp = 0xff;
     Serial.println(F("ACK CMD Set to Brightness-2 END"));break; 
    case 0x70:
      myCAM.OV2640_set_Contrast(Contrast2);temp = 0xff;
     Serial.println(F("ACK CMD Set to Contrast+2 END"));break; 
    case 0x71:
      myCAM.OV2640_set_Contrast(Contrast1);temp = 0xff;
     Serial.println(F("ACK CMD Set to Contrast+1 END"));break;
     case 0x72:
      myCAM.OV2640_set_Contrast(Contrast0);temp = 0xff;
     Serial.println(F("ACK CMD Set to Contrast+0 END"));break;
    case 0x73:
      myCAM.OV2640_set_Contrast(Contrast_1);temp = 0xff;
     Serial.println(F("ACK CMD Set to Contrast-1 END"));break;
   case 0x74:
      myCAM.OV2640_set_Contrast(Contrast_2);temp = 0xff;
     Serial.println(F("ACK CMD Set to Contrast-2 END"));break;
   case 0x80:
    myCAM.OV2640_set_Special_effects(Antique);temp = 0xff;
    Serial.println(F("ACK CMD Set to Antique END"));break;
   case 0x81:
    myCAM.OV2640_set_Special_effects(Bluish);temp = 0xff;
    Serial.println(F("ACK CMD Set to Bluish END"));break;
   case 0x82:
    myCAM.OV2640_set_Special_effects(Greenish);temp = 0xff;
    Serial.println(F("ACK CMD Set to Greenish END"));break;  
   case 0x83:
    myCAM.OV2640_set_Special_effects(Reddish);temp = 0xff;
    Serial.println(F("ACK CMD Set to Reddish END"));break;  
   case 0x84:
    myCAM.OV2640_set_Special_effects(BW);temp = 0xff;
    Serial.println(F("ACK CMD Set to BW END"));break; 
  case 0x85:
    myCAM.OV2640_set_Special_effects(Negative);temp = 0xff;
    Serial.println(F("ACK CMD Set to Negative END"));break; 
  case 0x86:
    myCAM.OV2640_set_Special_effects(BWnegative);temp = 0xff;
    Serial.println(F("ACK CMD Set to BWnegative END"));break;   
   case 0x87:
    myCAM.OV2640_set_Special_effects(Normal);temp = 0xff;
    Serial.println(F("ACK CMD Set to Normal END"));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;
    }
    switch (temp)
    {
       case 0x40:
    myCAM.OV2640_set_Light_Mode(Auto);temp = 0xff;
    Serial.println(F("ACK CMD Set to Auto END"));break;
     case 0x41:
    myCAM.OV2640_set_Light_Mode(Sunny);temp = 0xff;
    Serial.println(F("ACK CMD Set to Sunny END"));break;
     case 0x42:
    myCAM.OV2640_set_Light_Mode(Cloudy);temp = 0xff;
    Serial.println(F("ACK CMD Set to Cloudy END"));break;
     case 0x43:
    myCAM.OV2640_set_Light_Mode(Office);temp = 0xff;
    Serial.println(F("ACK CMD Set to Office END"));break;
   case 0x44:
    myCAM.OV2640_set_Light_Mode(Home);   temp = 0xff;
   Serial.println(F("ACK CMD Set to Home END"));break;
   case 0x50:
    myCAM.OV2640_set_Color_Saturation(Saturation2); temp = 0xff;
     Serial.println(F("ACK CMD Set to Saturation+2 END"));break;
   case 0x51:
     myCAM.OV2640_set_Color_Saturation(Saturation1); temp = 0xff;
     Serial.println(F("ACK CMD Set to Saturation+1 END"));break;
   case 0x52:
    myCAM.OV2640_set_Color_Saturation(Saturation0); temp = 0xff;
     Serial.println(F("ACK CMD Set to Saturation+0 END"));break;
    case 0x53:
    myCAM. OV2640_set_Color_Saturation(Saturation_1); temp = 0xff;
     Serial.println(F("ACK CMD Set to Saturation-1 END"));break;
    case 0x54:
     myCAM.OV2640_set_Color_Saturation(Saturation_2); temp = 0xff;
     Serial.println(F("ACK CMD Set to Saturation-2 END"));break; 
   case 0x60:
    myCAM.OV2640_set_Brightness(Brightness2); temp = 0xff;
     Serial.println(F("ACK CMD Set to Brightness+2 END"));break;
   case 0x61:
     myCAM.OV2640_set_Brightness(Brightness1); temp = 0xff;
     Serial.println(F("ACK CMD Set to Brightness+1 END"));break;
   case 0x62:
    myCAM.OV2640_set_Brightness(Brightness0); temp = 0xff;
     Serial.println(F("ACK CMD Set to Brightness+0 END"));break;
    case 0x63:
    myCAM. OV2640_set_Brightness(Brightness_1); temp = 0xff;
     Serial.println(F("ACK CMD Set to Brightness-1 END"));break;
    case 0x64:
     myCAM.OV2640_set_Brightness(Brightness_2); temp = 0xff;
     Serial.println(F("ACK CMD Set to Brightness-2 END"));break; 
    case 0x70:
      myCAM.OV2640_set_Contrast(Contrast2);temp = 0xff;
     Serial.println(F("ACK CMD Set to Contrast+2 END"));break; 
    case 0x71:
      myCAM.OV2640_set_Contrast(Contrast1);temp = 0xff;
     Serial.println(F("ACK CMD Set to Contrast+1 END"));break;
     case 0x72:
      myCAM.OV2640_set_Contrast(Contrast0);temp = 0xff;
     Serial.println(F("ACK CMD Set to Contrast+0 END"));break;
    case 0x73:
      myCAM.OV2640_set_Contrast(Contrast_1);temp = 0xff;
     Serial.println(F("ACK CMD Set to Contrast-1 END"));break;
   case 0x74:
      myCAM.OV2640_set_Contrast(Contrast_2);temp = 0xff;
     Serial.println(F("ACK CMD Set to Contrast-2 END"));break;
   case 0x80:
    myCAM.OV2640_set_Special_effects(Antique);temp = 0xff;
    Serial.println(F("ACK CMD Set to Antique END"));break;
   case 0x81:
    myCAM.OV2640_set_Special_effects(Bluish);temp = 0xff;
    Serial.println(F("ACK CMD Set to Bluish END"));break;
   case 0x82:
    myCAM.OV2640_set_Special_effects(Greenish);temp = 0xff;
    Serial.println(F("ACK CMD Set to Greenish END"));break;  
   case 0x83:
    myCAM.OV2640_set_Special_effects(Reddish);temp = 0xff;
    Serial.println(F("ACK CMD Set to Reddish END"));break;  
   case 0x84:
    myCAM.OV2640_set_Special_effects(BW);temp = 0xff;
    Serial.println(F("ACK CMD Set to BW END"));break; 
  case 0x85:
    myCAM.OV2640_set_Special_effects(Negative);temp = 0xff;
    Serial.println(F("ACK CMD Set to Negative END"));break; 
  case 0x86:
    myCAM.OV2640_set_Special_effects(BWnegative);temp = 0xff;
    Serial.println(F("ACK CMD Set to BWnegative END"));break;   
   case 0x87:
    myCAM.OV2640_set_Special_effects(Normal);temp = 0xff;
    Serial.println(F("ACK CMD Set to Normal 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]));
    }
    //for old version, enable it else disable
   // 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;
}

Et le HC05 c'est juste le module de configuration de mes pins pour mon modules bluetooth

Le HC05 est connecté comment ? Sur le port Serial ?

non sur les pin A14 et A15

SoftwareSerial HC05(A14, A15); // TX ; RX Bluetooth HC-05

Je ne vois pas cette ligne dans ton code ...???

Du coup j'ai trouvé comment faire :

// ArduCAM Mini demo (C)2018 Lee
// Web: http://www.ArduCAM.com
// This program is a demo of how to use most of the functions
// of the library with ArduCAM Mini camera, and can run on any Arduino platform.
// This demo was made for ArduCAM_Mini_2MP.
// It needs to be used in combination with PC software.
//It supports Bluetooth module
// It can take photo continuously as video streaming.
//
// The demo sketch will do the following tasks:
// 1. Set the camera to JPEG output mode.
// 2. Read data from HC05 port and deal with it
// 3. If receive 0x00-0x08,the resolution will be changed.
// 4. If receive 0x10,camera will capture a JPEG photo and buffer the image to FIFO.Then write datas to HC05 port.
// 5. If receive 0x20,camera will capture JPEG photo and write datas continuously.Stop when receive 0x21.
// 6. If receive 0x30,camera will capture a BMP  photo and buffer the image to FIFO.Then write datas to HC05 port.
// 7. If receive 0x11 ,set camera to JPEG output mode.
// 8. If receive 0x31 ,set camera to BMP  output mode.
// This program requires the ArduCAM V4.0.0 (or later) library and ArduCAM_Mini_2MP
// and use Arduino IDE 1.6.8 compiler or above
#include <Wire.h>
#include <ArduCAM.h>
#include <SPI.h>
#include "memorysaver.h"
#include <SoftwareSerial.h>
SoftwareSerial HC05(A14, A15); // TX ; RX Bluetooth HC-05

//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 = 53;
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();
  HC05.begin(115200);
#else
  Wire.begin();
  HC05.begin(115200);
#endif
HC05.println(F("ACK CMD ArduCAM Start! END"));
// set the CS as an output:
pinMode(CS, OUTPUT);
digitalWrite(CS, HIGH);
// initialize SPI:
//SPI.setClockDivider(SPI_CLOCK_DIV64);
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){
    HC05.println(F("ACK CMD SPI interface Error! END"));
    delay(1000);continue;
  }else{
    HC05.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 ))){
      HC05.println(F("ACK CMD Can't find OV2640 module! END"));
      delay(1000);continue;
    }
    else{
      HC05.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)){
      HC05.println(F("ACK CMD Can't find OV3640 module! END"));
      delay(1000);continue; 
    }else{
      HC05.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)){
      HC05.println(F("ACK CMD Can't find OV5642 module! END"));
      delay(1000);continue;
    }
    else{
      HC05.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 (HC05.available())
{
  temp = HC05.read();
  switch (temp)
  {
    case 0:
    #if defined (OV2640_MINI_2MP)
      myCAM.OV2640_set_JPEG_size(OV2640_160x120);delay(1000);
      HC05.println(F("ACK CMD switch to OV2640_160x120 END"));
    #elif defined (OV3640_MINI_3MP)
      myCAM.OV3640_set_JPEG_size(OV3640_176x144);delay(1000);
      HC05.println(F("ACK CMD switch to OV2640_160x120 END"));
    #else
      myCAM.OV5642_set_JPEG_size(OV5642_320x240);delay(1000);
      HC05.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);
      HC05.println(F("ACK CMD switch to OV2640_176x144 END"));
    #elif defined (OV3640_MINI_3MP)
      myCAM.OV3640_set_JPEG_size(OV3640_320x240);delay(1000);
      HC05.println(F("ACK CMD switch to OV3640_320x240 END"));
    #else
      myCAM.OV5642_set_JPEG_size(OV5642_640x480);delay(1000);
      HC05.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);
      HC05.println(F("ACK CMD switch to OV2640_320x240 END"));
     #elif defined (OV3640_MINI_3MP)
      myCAM.OV3640_set_JPEG_size(OV3640_352x288);delay(1000);
      HC05.println(F("ACK CMD switch to OV3640_352x288 END"));
    #else
      myCAM.OV5642_set_JPEG_size(OV5642_1024x768);delay(1000);
      HC05.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);
      HC05.println(F("ACK CMD switch to OV2640_352x288 END"));
    #elif defined (OV3640_MINI_3MP)
      myCAM.OV3640_set_JPEG_size(OV3640_640x480);delay(1000);
      HC05.println(F("ACK CMD switch to OV3640_640x480 END"));
    #else
      myCAM.OV5642_set_JPEG_size(OV5642_1280x960);delay(1000);
      HC05.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);
      HC05.println(F("ACK CMD switch to OV2640_640x480 END"));
   #elif defined (OV3640_MINI_3MP)
      myCAM.OV3640_set_JPEG_size(OV3640_800x600);delay(1000);
      HC05.println(F("ACK CMD switch to OV3640_800x600 END"));
    #else
      myCAM.OV5642_set_JPEG_size(OV5642_1600x1200);delay(1000);
      HC05.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);
      HC05.println(F("ACK CMD switch to OV2640_800x600 END"));
    #elif defined (OV3640_MINI_3MP)
      myCAM.OV3640_set_JPEG_size(OV3640_1024x768);delay(1000);
      HC05.println(F("ACK CMD switch to OV3640_1024x768 END"));
    #else
      myCAM.OV5642_set_JPEG_size(OV5642_2048x1536);delay(1000);
      HC05.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);
      HC05.println(F("ACK CMD switch to OV2640_1024x768 END"));
   #elif defined (OV3640_MINI_3MP)
      myCAM.OV3640_set_JPEG_size(OV3640_1280x960);delay(1000);
      HC05.println(F("ACK CMD switch to OV3640_1280x960 END"));
    #else
      myCAM.OV5642_set_JPEG_size(OV5642_2592x1944);delay(1000);
      HC05.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);
    HC05.println(F("ACK CMD switch to OV2640_1280x1024 END"));
   #else
      myCAM.OV3640_set_JPEG_size(OV3640_1600x1200);delay(1000);
      HC05.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);
     HC05.println(F("ACK CMD switch to OV2640_1600x1200 END"));
   #else
     myCAM.OV3640_set_JPEG_size(OV3640_2048x1536);delay(1000);
     HC05.println(F("ACK CMD switch to OV3640_2048x1536 END"));
   #endif
    break;
    case 0x10:
    mode = 1;
    temp = 0xff;
    start_capture = 1;
    HC05.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;
    HC05.println(F("ACK CMD CAM start video streaming. END"));
    break;
    case 0x30:
    mode = 3;
    temp = 0xff;
    start_capture = 3;
    HC05.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))
  {
    HC05.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 = HC05.read();
    if (temp == 0x21)
    {
      start_capture = 0;
      mode = 0;
      HC05.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)
        {
          HC05.write(temp);
        }
        else if ((temp == 0xD8) & (temp_last == 0xFF))
        {
          is_header = true;
          HC05.println(F("ACK IMG END"));
          HC05.write(temp_last);
          HC05.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))
  {
    HC05.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 ) 
    {
      HC05.println(F("ACK CMD Over size. END"));
      myCAM.clear_fifo_flag();
      return;
    }
    if (length == 0 ) //0 kb
    {
      HC05.println(F("ACK CMD Size is 0. END"));
      myCAM.clear_fifo_flag();
      return;
    }
    myCAM.CS_LOW();
    myCAM.set_fifo_burst();//Set fifo burst mode
    
    HC05.write(0xFF);
    HC05.write(0xAA);
    for (temp = 0; temp < BMPIMAGEOFFSET; temp++)
    {
      HC05.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);;
        HC05.write(VL);
        delayMicroseconds(12);
        HC05.write(VH);
        delayMicroseconds(12);
      }
    }
    HC05.write(0xBB);
    HC05.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();
  HC05.println(length, DEC);
  if (length >= MAX_FIFO_SIZE) //512 kb
  {
    HC05.println(F("ACK CMD Over size. END"));
    return 0;
  }
  if (length == 0 ) //0 kb
  {
    HC05.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)
    {
      HC05.write(temp);
    }
    else if ((temp == 0xD8) & (temp_last == 0xFF))
    {
      is_header = true;
      HC05.println(F("ACK IMG END"));
      HC05.write(temp_last);
      HC05.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;
}

Mais j'ai un problème avec la vidéo ... qui superpose des images

image

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.