Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement
Répondre à la discussion
Page 1 sur 3 12 DernièreDernière
Affichage des résultats 1 à 30 sur 68

Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement



  1. #1
    moduleloi

    Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement


    ------

    Bonjour,etant débutant je bloque sur une partie d'arduino depuis une semaine :/ j'ai tous les composant nécessaire et j'essaye de modifier le programme de ce site http://www.seeedstudio.com/wiki/Grove_-_Serial_Camera pour remplacer le bouton poussoir par un détecteur de mouvement car je veux que quand il détecte une personne la caméra engendre une photo automatiquement et non par boutton poussoir voila le programme , je suis pret à payer tellement je suis démoralisé ,meme un peu d'aide me serais tres important .


    Code:
    //  File SerialCamera.pde for camera.
    //  25/7/2011 by Piggy
    //  Modify by Deray  08/08/2012 
    //  Demo code for using seeeduino or Arduino board to cature jpg format 
    //  picture from seeed serial camera and save it into sd card. Push the 
    //  button to take the a picture .
     
    //  For more details about the product please check http://www.seeedstudio.com/depot/
    
    #include <SD.h>
    
    File myFile;
    #define PIC_BUF_LEN 96        //data length of each read
    
    char cmdRST[] = {
      0x56,0x00,0x26,0x00};        //Reset command
    char cmdCAP[] = {      
      0x56,0x00,0x36,0x01,0x00};  //Take picture command
    char cmdGetLen[] = {
      0x56,0x00,0x34,0x01,0x00};   //Read JPEG file size command
    char cmdGetDat[] = {           //Read JPEG data command
      0x56,0x00,0x32,0x0c,0x00,0x0a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0a}; 
    char cmdConti[] = {           
      0x56,0x00,0x36,0x01,0x02};   //Take next picture command
      
    const int buttonPin = 19;      // the number of the pushbutton pin
    unsigned int picTotalLen = 0;  // picture length
    int picNameNum = 0;
    
    void setup()
    {
      Serial.begin(115200); 
      pinMode(buttonPin,INPUT);    // initialize the pushbutton pin as an input
      Serial.println("Initializing SD card....");
      pinMode(10,OUTPUT);          // CS pin of SD Card Shield
      
      if (!SD.begin(10)) {
        Serial.print("initialzation failed");
        return;
      }
      Serial.println("initialization done.");
      Restart();
    }
    void loop()
    {
      int n = 0;
      while(1){
        Serial.flush();
        Serial.println("Press the button to take a picture");
        while(digitalRead(buttonPin) == LOW);      //wait for buttonPin status to HIGH
        if(digitalRead(buttonPin) == HIGH){
          delay(50);                               //Debounce
          if(digitalRead(buttonPin) == HIGH){
            delay(200);
            if(n == 0)Capture();
            else ContCapture();
            GetData();
           }
          Serial.print("Taking pictures success ,number : ");
          Serial.println(n);
          n ++ ;
          }
        }
    }
    
    
      
    void Restart()
    {
       sendCmd(cmdRST,4);
       delay(1000);
       while(Serial.available() > 0)Serial.write(Serial.read());
       Serial.println("Camera initialization done.");
    }
    void Capture()
    {
      sendCmd(cmdCAP,5);
      delay(50);
      while(Serial.available() > 0){
        Serial.read();
      }
    }
    
    void GetData()
    {
      unsigned int picTotalLen;
      sendCmd(cmdGetLen,5);
      delay(50);
      for(char i = 0; i < 7; i++){
        Serial.read();
      }
      picTotalLen = 0;
      int high = Serial.read();
      picTotalLen |= high ;
      int low  = Serial.read();
      picTotalLen = picTotalLen << 8 ;
      picTotalLen |= low ;                      //get the length of picture 
      
      unsigned int addr = 0;
      cmdGetDat[8] = 0;
      cmdGetDat[9] = 0;
      unsigned int count = picTotalLen / PIC_BUF_LEN;
      char tail = picTotalLen % PIC_BUF_LEN;
      cmdGetDat[13] = PIC_BUF_LEN;              //the length of each read data
      
      char picName[] = "pic00.jpg";
      picName[3] = picNameNum/10 + '0';
      picName[4] = picNameNum%10 + '0';
      
      myFile = SD.open(picName, FILE_WRITE);
      if(!myFile){
        Serial.println("myFile open fail...");
      }
      else{
        for(char i = 0; i < count; i++){      //get and save count*PIC_BUF_LEN data
          sendCmd(cmdGetDat,16);
          delay(10);
          readCamSaveToFile(myFile, PIC_BUF_LEN);
          addr += PIC_BUF_LEN;
          cmdGetDat[8] = addr >> 8;
          cmdGetDat[9] = addr & 0x00FF;
        }
        cmdGetDat[13] = tail;                  //get rest part of the pic data
        sendCmd(cmdGetDat,16);
        delay(10);
        readCamSaveToFile(myFile, tail);      
      }
      myFile.close();
      picNameNum ++;
    }
    void ContCapture()
    {
      sendCmd(cmdConti,5);
      delay(50);
      while(Serial.available() > 0){
        Serial.write(Serial.read());
      }
    
    }
    
    void readCamSaveToFile(File &myFile,int toBeReadLen)
    {
      char readLen = 0;
      for(char i = 0;i < 5;i ++){//read the signal that tells us that it's ready to send data 
        Serial.read();
      }
      while(readLen < toBeReadLen){//read and store the JPG data that starts with 0xFF 0xDB
          myFile.write(Serial.read());
          readLen++;
      }
      for(char i = 0;i < 5;i ++){ //read the signal of sussessful sending
        Serial.read();
      }
    }
    void sendCmd(char cmd[] ,int cmd_len)
    {
      for(char i = 0; i < cmd_len; i++)Serial.print(cmd[i]);  
    }

    -----
    Dernière modification par gienas ; 02/04/2015 à 11h01. Motif: Ajouté les balises code obligatoires pour la lisibilité des programmes

  2. #2
    DAUDET78

    Re : Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement

    Et c'est quoi le détecteur de mouvement ?
    J'aime pas le Grec

  3. #3
    moduleloi

    Re : Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement

    Bonjour,voici le détecteur de mouvement http://www.gotronic.fr/art-detecteur...357p-18975.htm

  4. #4
    moduleloi

    Re : Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement

    Autant supprimé le premier topic "arduino capteur de mouvement+ camera grove les reliées" ,je n'ai qu'un but maitenant c'est de pouvoir modifier le programme

  5. A voir en vidéo sur Futura
  6. #5
    antek

    Re : Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement

    D'après la doc, le capteur sort un niveau 1 lorsque quelqu'un bouge à une distance de 3 m, et sinon 0.
    Les 3 m seraient par défaut et paramétrables.
    Si tu sais gérer un interrupteur tu sais gérer ce capteur.

  7. #6
    jiherve

    Re : Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement

    Bonjour,
    il serait judicieux et agréable pour le lecteur désireux d'aider de placer le code entre deux balises code(#) accessibles en édition avancée, une indentation correcte serait un plus facilitant lecture et compréhension.
    Donc un petit effort et on en reparle.
    JR
    l'électronique c'est pas du vaudou!

  8. #7
    Yoruk

    Re : Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement

    Et mes remarques de l'autre fil restent valables... Tu testes d'abord le détecteur NU, sans rien, pour vérifier son fonctionnement, tu testes l'appareil photo déclenché par un bouton poussoir, pour vérifier si le module marche, et enfin tu assembles les 2.
    La robotique, c'est fantastique !

  9. #8
    moduleloi

    Re : Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement

    Merci pour votre aides

    Antek,oui je sais sa,à part que c'etais parametrable oO,mais le souci c'est que je sais pas ou placé ce détail et aussi quel parti inutile à supprimé

    jiherve:d'accord désolé

    Yorukui j'ai testé les deux marche ,le detecteur + led et le détecteur caméra+ boutton poussoir,le probleme c'est que j'ai besoin d'une sd card shield obligatoirement,donc il n'ya que la deuxieme parti auquel je peux m'inspirer (détecteur caméra boutton poussoir)

  10. #9
    Yoruk

    Re : Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement

    Citation Envoyé par moduleloi Voir le message
    j'ai testé les deux marche ,le detecteur + led et le détecteur caméra+ boutton poussoir,le probleme c'est que j'ai besoin d'une sd card shield obligatoirement,donc il n'ya que la deuxieme parti auquel je peux m'inspirer (détecteur caméra boutton poussoir)
    Rien compris... Tu as réussi à faire une photo et à l'enregistrer sur carte SD ? (déclenchée par un bouton poussoir) ? C'est quoi ta "2eme partie" ?
    La robotique, c'est fantastique !

  11. #10
    antek

    Re : Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement

    Y'a rien à supprimer si ton code était correct au départ.
    Et puis chercher la gestion d'une pin dans un fouilli en arduino . . .

  12. #11
    moduleloi

    Re : Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement

    la deuxieme parti c'est faire la photo et enregistré avec un boutton poussoir.

    antek comment sa ? le programme avec boutton poussioir ?
    Dernière modification par moduleloi ; 02/04/2015 à 10h49.

  13. #12
    Yoruk

    Re : Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement

    Citation Envoyé par Yoruk Voir le message
    Rien compris... Tu as réussi à faire une photo et à l'enregistrer sur carte SD ? (déclenchée par un bouton poussoir) ?
    Oui ou non ?

    Si oui -> tu remplaces le bouton poussoir par le détecteur en t'inspirant du bout de programme le faisant fonctionner
    Si non -> continues à travailler jusqu’à ce que ça marche.
    La robotique, c'est fantastique !

  14. #13
    moduleloi

    Re : Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement

    Oui j'ai réussi,c'est sa le probleme yoruk,j'essaye de m'inspirer du bout de programme,en remplacent le boutton par un detecteur,mais c'est sa auquel je n'arrive pas,je m'inspire mais bon....

  15. #14
    Yoruk

    Re : Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement

    Postes les 2 codes : celui de la photo qui marche avec le bouton poussoir, et celui du détecteur. Entre balises !!
    La robotique, c'est fantastique !

  16. #15
    jiherve

    Re : Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement

    Re
    Merci Gienas
    Maintenant c'est lisible.
    Donc à priori il n'y a rien à modifier dans ce code, s'il fonctionnait avant avec un switch sur "buttonPin" il devrait fonctionner aussi avec un signal logique connecté au même endroit.
    Seul petit bémol comme il y a un bout de code pour le debounce il faut être sur que le capteur maintient son niveau '1' assez longtemps.
    http://www.seeedstudio.com/wiki/imag...-_BISS0001.pdf
    JR
    l'électronique c'est pas du vaudou!

  17. #16
    Yoruk

    Re : Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement

    Et mettre une tempo pour que le bestiau ne fasse pas 50 photos par secondes...

    il faut être sur que le capteur maintient son niveau '1' assez longtemps.
    Ou choper le front montant...
    La robotique, c'est fantastique !

  18. #17
    moduleloi

    Re : Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement

    Jiherve sa veut dire que j'ai juste à déclarer le détecteur de mouvement et remplacer boutton poussoir par détecteur de mouvement ?

    Yoruk voici celui qui marche avec le boutton poussoir + caméra

    Code:
    //  File SerialCamera.pde for camera.
    //  25/7/2011 by Piggy
    //  Modify by Deray  08/08/2012 
    //  Demo code for using seeeduino or Arduino board to cature jpg format 
    //  picture from seeed serial camera and save it into sd card. Push the 
    //  button to take the a picture .
     
    //  For more details about the product please check http://www.seeedstudio.com/depot/
    
    #include <SD.h>
    
    File myFile;
    #define PIC_BUF_LEN 96        //data length of each read
    
    char cmdRST[] = {
      0x56,0x00,0x26,0x00};        //Reset command
    char cmdCAP[] = {      
      0x56,0x00,0x36,0x01,0x00};  //Take picture command
    char cmdGetLen[] = {
      0x56,0x00,0x34,0x01,0x00};   //Read JPEG file size command
    char cmdGetDat[] = {           //Read JPEG data command
      0x56,0x00,0x32,0x0c,0x00,0x0a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0a}; 
    char cmdConti[] = {           
      0x56,0x00,0x36,0x01,0x02};   //Take next picture command
      
    const int buttonPin = 19;      // the number of the pushbutton pin
    unsigned int picTotalLen = 0;  // picture length
    int picNameNum = 0;
    
    void setup()
    {
      Serial.begin(115200); 
      pinMode(buttonPin,INPUT);    // initialize the pushbutton pin as an input
      Serial.println("Initializing SD card....");
      pinMode(10,OUTPUT);          // CS pin of SD Card Shield
      
      if (!SD.begin(10)) {
        Serial.print("initialzation failed");
        return;
      }
      Serial.println("initialization done.");
      Restart();
    }
    void loop()
    {
      int n = 0;
      while(1){
        Serial.flush();
        Serial.println("Press the button to take a picture");
        while(digitalRead(buttonPin) == LOW);      //wait for buttonPin status to HIGH
        if(digitalRead(buttonPin) == HIGH){
          delay(50);                               //Debounce
          if(digitalRead(buttonPin) == HIGH){
            delay(200);
            if(n == 0)Capture();
            else ContCapture();
            GetData();
           }
          Serial.print("Taking pictures success ,number : ");
          Serial.println(n);
          n ++ ;
          }
        }
    }
    
    
      
    void Restart()
    {
       sendCmd(cmdRST,4);
       delay(1000);
       while(Serial.available() > 0)Serial.write(Serial.read());
       Serial.println("Camera initialization done.");
    }
    void Capture()
    {
      sendCmd(cmdCAP,5);
      delay(50);
      while(Serial.available() > 0){
        Serial.read();
      }
    }
    
    void GetData()
    {
      unsigned int picTotalLen;
      sendCmd(cmdGetLen,5);
      delay(50);
      for(char i = 0; i < 7; i++){
        Serial.read();
      }
      picTotalLen = 0;
      int high = Serial.read();
      picTotalLen |= high ;
      int low  = Serial.read();
      picTotalLen = picTotalLen << 8 ;
      picTotalLen |= low ;                      //get the length of picture 
      
      unsigned int addr = 0;
      cmdGetDat[8] = 0;
      cmdGetDat[9] = 0;
      unsigned int count = picTotalLen / PIC_BUF_LEN;
      char tail = picTotalLen % PIC_BUF_LEN;
      cmdGetDat[13] = PIC_BUF_LEN;              //the length of each read data
      
      char picName[] = "pic00.jpg";
      picName[3] = picNameNum/10 + '0';
      picName[4] = picNameNum%10 + '0';
      
      myFile = SD.open(picName, FILE_WRITE);
      if(!myFile){
        Serial.println("myFile open fail...");
      }
      else{
        for(char i = 0; i < count; i++){      //get and save count*PIC_BUF_LEN data
          sendCmd(cmdGetDat,16);
          delay(10);
          readCamSaveToFile(myFile, PIC_BUF_LEN);
          addr += PIC_BUF_LEN;
          cmdGetDat[8] = addr >> 8;
          cmdGetDat[9] = addr & 0x00FF;
        }
        cmdGetDat[13] = tail;                  //get rest part of the pic data
        sendCmd(cmdGetDat,16);
        delay(10);
        readCamSaveToFile(myFile, tail);      
      }
      myFile.close();
      picNameNum ++;
    }
    void ContCapture()
    {
      sendCmd(cmdConti,5);
      delay(50);
      while(Serial.available() > 0){
        Serial.write(Serial.read());
      }
    
    }
    
    void readCamSaveToFile(File &myFile,int toBeReadLen)
    {
      char readLen = 0;
      for(char i = 0;i < 5;i ++){//read the signal that tells us that it's ready to send data 
        Serial.read();
      }
      while(readLen < toBeReadLen){//read and store the JPG data that starts with 0xFF 0xDB
          myFile.write(Serial.read());
          readLen++;
      }
      for(char i = 0;i < 5;i ++){ //read the signal of sussessful sending
        Serial.read();
      }
    }
    void sendCmd(char cmd[] ,int cmd_len)
    {
      for(char i = 0; i < cmd_len; i++)Serial.print(cmd[i]);  
    }
    et voici celui du détecteur + led
    Code:
     #define PIR_MOTION_SENSOR 2//Use pin 2 to receive the signal from the module 
    #define LED	4//the Grove - LED is connected to D4 of Arduino
    
    void setup()
    {
    	pinsInit();
    }
    
    void loop() 
    {
    	if(isPeopleDetected())//if it detects the moving people?
    		turnOnLED();
    	else
    		turnOffLED();
    }
    void pinsInit()
    {
    	pinMode(PIR_MOTION_SENSOR, INPUT);
    	pinMode(LED,OUTPUT);
    }
    void turnOnLED()
    {
    	digitalWrite(LED,HIGH);
    }
    void turnOffLED()
    {
    	digitalWrite(LED,LOW);
    }
    /***************************************************************/
    /*Function: Detect whether anyone moves in it's detecting range*/
    /*Return:-boolean, true is someone detected.*/
    boolean isPeopleDetected()
    {
    	int sensorValue = digitalRead(PIR_MOTION_SENSOR);
    	if(sensorValue == HIGH)//if the sensor value is HIGH?
    	{
    		return true;//yes,return true
    	}
    	else
    	{
    		return false;//no,return false
    	}
    }

  19. #18
    Yoruk

    Re : Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement

    Dans ton premier code, remplace la sub loop par :

    Code:
    void loop()
    {
      int n = 0;
      while(1){
        Serial.flush();
        
        while(isPeopleDetected() == LOW);      //wait for buttonPin status to HIGH
        if(isPeopleDetected() == HIGH){
          delay(50);                               //Debounce
          if(isPeopleDetected() == HIGH){
            delay(200);
            if(n == 0)Capture();
            else ContCapture();
            GetData();
           }
          Serial.print("Taking pictures success ,number : ");
          Serial.println(n);
          n ++ ;
          }
        }
    }
    ajoute dans le setup :

    Code:
    pinMode(PIR_MOTION_SENSOR, INPUT);
    pinMode(LED,OUTPUT);
    ajoute en tête de programme :

    Code:
     #define PIR_MOTION_SENSOR 2//Use pin 2 to receive the signal from the module 
    #define LED	4//the Grove - LED is connected to D4 of Arduino
    et colle quelque part avant le loop:

    Code:
    boolean isPeopleDetected()
    {
    	int sensorValue = digitalRead(PIR_MOTION_SENSOR);
    	if(sensorValue == HIGH)//if the sensor value is HIGH?
    	{
    		return true;//yes,return true
    	}
    	else
    	{
    		return false;//no,return false
    	}
    }
    Non testé... S'il y a des erreurs, donne-les.
    La robotique, c'est fantastique !

  20. #19
    moduleloi

    Re : Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement

    Mercii beaucoup,je pourrais essaye le mardi apres midi je te donnerai des nouvelles

    Sur ce j'ai retiré la led puisque comme j'utilise plus la platine grove mais la sd carte shield sa m'est pas pratique ^^

    Donc en résumé je fais sa ?

    // File SerialCamera.pde for camera.
    // 25/7/2011 by Piggy
    // Modify by Deray 08/08/2012
    // Demo code for using seeeduino or Arduino board to cature jpg format
    // picture from seeed serial camera and save it into sd card. Push the
    // button to take the a picture .

    // For more details about the product please check http://www.seeedstudio.com/depot/

    #include <SD.h>
    #define PIR_MOTION_SENSOR 2//Use pin 2 to receive the signal from the module
    #define LED 4//the Grove - LED is connected to D4 of Arduino
    Code:
    File myFile;
    #define PIC_BUF_LEN 96        //data length of each read
    
    char cmdRST[] = {
      0x56,0x00,0x26,0x00};        //Reset command
    char cmdCAP[] = {      
      0x56,0x00,0x36,0x01,0x00};  //Take picture command
    char cmdGetLen[] = {
      0x56,0x00,0x34,0x01,0x00};   //Read JPEG file size command
    char cmdGetDat[] = {           //Read JPEG data command
      0x56,0x00,0x32,0x0c,0x00,0x0a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0a}; 
    char cmdConti[] = {           
      0x56,0x00,0x36,0x01,0x02};   //Take next picture command
      
    const int buttonPin = 19;      // the number of the pushbutton pin
    unsigned int picTotalLen = 0;  // picture length
    int picNameNum = 0;
    
    void setup()
    {
      Serial.begin(115200); 
     pinMode(PIR_MOTION_SENSOR, INPUT);;    // initialize the pushbutton pin as an input
      Serial.println("Initializing SD card....");
     pinMode(LED,OUTPUT);        // CS pin of SD Card Shield
      
      if (!SD.begin(10)) {
        Serial.print("initialzation failed");
        return;
      }
      Serial.println("initialization done.");
      Restart();
    }
    boolean isPeopleDetected()
    {
    	int sensorValue = digitalRead(PIR_MOTION_SENSOR);
    	if(sensorValue == HIGH)//if the sensor value is HIGH?
    	{
    		return true;//yes,return true
    	}
    	else
    	{
    		return false;//no,return false
    	}
    }
    void loop()
    {
      int n = 0;
      while(1){
        Serial.flush();
        
        while(isPeopleDetected() == LOW);      //wait for buttonPin status to HIGH
        if(isPeopleDetected() == HIGH){
          delay(50);                               //Debounce
          if(isPeopleDetected() == HIGH){
            delay(200);
            if(n == 0)Capture();
            else ContCapture();
            GetData();
           }
          Serial.print("Taking pictures success ,number : ");
          Serial.println(n);
          n ++ ;
          }
        }
    }
    
      
    void Restart()
    {
       sendCmd(cmdRST,4);
       delay(1000);
       while(Serial.available() > 0)Serial.write(Serial.read());
       Serial.println("Camera initialization done.");
    }
    void Capture()
    {
      sendCmd(cmdCAP,5);
      delay(50);
      while(Serial.available() > 0){
        Serial.read();
      }
    }
    
    void GetData()
    {
      unsigned int picTotalLen;
      sendCmd(cmdGetLen,5);
      delay(50);
      for(char i = 0; i < 7; i++){
        Serial.read();
      }
      picTotalLen = 0;
      int high = Serial.read();
      picTotalLen |= high ;
      int low  = Serial.read();
      picTotalLen = picTotalLen << 8 ;
      picTotalLen |= low ;                      //get the length of picture 
      
      unsigned int addr = 0;
      cmdGetDat[8] = 0;
      cmdGetDat[9] = 0;
      unsigned int count = picTotalLen / PIC_BUF_LEN;
      char tail = picTotalLen % PIC_BUF_LEN;
      cmdGetDat[13] = PIC_BUF_LEN;              //the length of each read data
      
      char picName[] = "pic00.jpg";
      picName[3] = picNameNum/10 + '0';
      picName[4] = picNameNum%10 + '0';
      
      myFile = SD.open(picName, FILE_WRITE);
      if(!myFile){
        Serial.println("myFile open fail...");
      }
      else{
        for(char i = 0; i < count; i++){      //get and save count*PIC_BUF_LEN data
          sendCmd(cmdGetDat,16);
          delay(10);
          readCamSaveToFile(myFile, PIC_BUF_LEN);
          addr += PIC_BUF_LEN;
          cmdGetDat[8] = addr >> 8;
          cmdGetDat[9] = addr & 0x00FF;
        }
        cmdGetDat[13] = tail;                  //get rest part of the pic data
        sendCmd(cmdGetDat,16);
        delay(10);
        readCamSaveToFile(myFile, tail);      
      }
      myFile.close();
      picNameNum ++;
    }
    void ContCapture()
    {
      sendCmd(cmdConti,5);
      delay(50);
      while(Serial.available() > 0){
        Serial.write(Serial.read());
      }
    
    }
    
    void readCamSaveToFile(File &myFile,int toBeReadLen)
    {
      char readLen = 0;
      for(char i = 0;i < 5;i ++){//read the signal that tells us that it's ready to send data 
        Serial.read();
      }
      while(readLen < toBeReadLen){//read and store the JPG data that starts with 0xFF 0xDB
          myFile.write(Serial.read());
          readLen++;
      }
      for(char i = 0;i < 5;i ++){ //read the signal of sussessful sending
        Serial.read();
      }
    }
    void sendCmd(char cmd[] ,int cmd_len)
    {
      for(char i = 0; i < cmd_len; i++)Serial.print(cmd[i]);  
    }

  21. #20
    Yoruk

    Re : Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement

    De loin, ça à l'air bon...
    La robotique, c'est fantastique !

  22. #21
    moduleloi

    Re : Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement

    Merci alors,mais la parti led ne m'intéresse pas ,quel parti je devrai enlever ^^ ?

  23. #22
    Yoruk

    Re : Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement

    Tu devrais être capable d'identifier les lignes concernées dans le programme, non...?
    La robotique, c'est fantastique !

  24. #23
    moduleloi

    Re : Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement

    Oui ,mais bon enlever la parti où la led est concerné peut avoir des conséquence sur le programme et ne pas fonctionner ,c'est pour sa que je te demande ^^

  25. #24
    Yoruk

    Re : Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement

    Citation Envoyé par moduleloi Voir le message
    mais bon enlever la parti où la led est concerné peut avoir des conséquence sur le programme et ne pas fonctionner
    Si tu supprimes les bonnes lignes, aucune conséquence sur le reste...
    La robotique, c'est fantastique !

  26. #25
    moduleloi

    Re : Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement

    Ah d'accord,je savais pas ,quand je posé la question je voulais juste une confirmation ,Bon à mardi alors ^^

  27. #26
    moduleloi

    Re : Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement

    Voila en faite j'ai trouvé un programme plus adapté pour ma caméra

    voici un meilleur programme pour faire fonctionner mon programme avec un boutton poussoir

    // File SerialCamera_DemoCode_CJ-OV528.ino
    // 8/8/2013 Jack Shao
    // Demo code for using seeeduino or Arduino board to cature jpg format
    // picture from seeed serial camera and save it into sd card. Push the
    // button to take the a picture .
    // For more details about the product please check http://www.seeedstudio.com/depot/
    #include <arduino.h>
    #include <SD.h>
    #include <SoftwareSerial.h>
    #define PIC_PKT_LEN 128 //data length of each read, dont set this too big because ram is limited
    #define PIC_FMT_VGA 7
    #define PIC_FMT_CIF 5
    #define PIC_FMT_OCIF 3
    #define CAM_ADDR 0
    #define CAM_SERIAL softSerial
    #define PIC_FMT PIC_FMT_VGA
    File myFile;
    SoftwareSerial softSerial(2, 3); //rx,tx (11-13 is used by sd shield)
    const byte cameraAddr = (CAM_ADDR << 5); // addr
    const int buttonPin = A5; // the number of the pushbutton pin
    unsigned long picTotalLen = 0; // picture length
    int picNameNum = 0;
    /****************************** ****************************** *********/
    void setup()
    {
    Serial.begin(115200);
    CAM_SERIAL.begin(9600); //cant be faster than 9600, maybe difference with diff board.
    pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input
    //Serial.println("Initializing SD card....");
    pinMode(4,OUTPUT); // CS pin of SD Card Shield
    if (!SD.begin(4)) {
    //Serial.print("sd init failed");
    return;
    }
    //Serial.println("sd init done.");
    initialize();
    }
    /****************************** ****************************** *********/
    void loop()
    {
    int n = 0;
    while(1){
    //Serial.println("\r\nPress the button to take a picture");
    while (digitalRead(buttonPin) == LOW); //wait for buttonPin status to HIGH
    //Serial.println("taking");
    if(digitalRead(buttonPin) == HIGH){
    delay(20); //Debounce
    if (digitalRead(buttonPin) == HIGH)
    {
    delay(200);
    if (n == 0) preCapture();
    Capture();
    //Serial.print("Saving picture...");
    GetData();
    }
    //Serial.print("\r\nDone ,number : ");
    //Serial.println(n);
    n++ ;
    }
    }
    }
    /****************************** ****************************** *********/
    void clearRxBuf()
    {
    while (CAM_SERIAL.available())
    {
    CAM_SERIAL.read();
    }
    }
    /****************************** ****************************** *********/
    void sendCmd(char cmd[], int cmd_len)
    {
    for (char i = 0; i < cmd_len; i++) CAM_SERIAL.write(cmd[i]);
    }
    /****************************** ****************************** *********/
    int readBytes(char *dest, int len, unsigned int timeout)
    {
    int read_len = 0;
    unsigned long t = millis();
    while (read_len < len)
    {
    while (CAM_SERIAL.available()<1)
    {
    if ((millis() - t) > timeout)
    {
    return read_len;
    }
    }
    *(dest+read_len) = CAM_SERIAL.read();
    Serial.write(*(dest+read_len)) ;
    read_len++;
    }
    return read_len;
    }
    /****************************** ****************************** *********/
    void initialize()
    {
    char cmd[] = {0xaa,0x0d|cameraAddr,0x00,0x0 0,0x00,0x00} ;
    unsigned char resp[6];
    Serial.print("initializing camera...");
    while (1)
    {
    sendCmd(cmd,6);
    if (readBytes((char *)resp, 6,1000) != 6)
    {
    Serial.print(".");
    continue;
    }
    if (resp[0] == 0xaa && resp[1] == (0x0e | cameraAddr) && resp[2] == 0x0d && resp[4] == 0 && resp[5] == 0)
    {
    if (readBytes((char *)resp, 6, 500) != 6) continue;
    if (resp[0] == 0xaa && resp[1] == (0x0d | cameraAddr) && resp[2] == 0 && resp[3] == 0 && resp[4] == 0 && resp[5] == 0) break;
    }
    }
    cmd[1] = 0x0e | cameraAddr;
    cmd[2] = 0x0d;
    sendCmd(cmd, 6);
    //Serial.println("\nCamera initialization done.");
    }
    /****************************** ****************************** *********/
    void preCapture()
    {
    char cmd[] = { 0xaa, 0x01 | cameraAddr, 0x00, 0x07, 0x00, PIC_FMT };
    unsigned char resp[6];
    while (1)
    {
    clearRxBuf();
    sendCmd(cmd, 6);
    if (readBytes((char *)resp, 6, 100) != 6) continue;
    if (resp[0] == 0xaa && resp[1] == (0x0e | cameraAddr) && resp[2] == 0x01 && resp[4] == 0 && resp[5] == 0) break;
    }
    }
    void Capture()
    {
    char cmd[] = { 0xaa, 0x06 | cameraAddr, 0x08, PIC_PKT_LEN & 0xff, (PIC_PKT_LEN>>8) & 0xff ,0};
    unsigned char resp[6];
    while (1)
    {
    clearRxBuf();
    sendCmd(cmd, 6);
    if (readBytes((char *)resp, 6, 100) != 6) continue;
    if (resp[0] == 0xaa && resp[1] == (0x0e | cameraAddr) && resp[2] == 0x06 && resp[4] == 0 && resp[5] == 0) break;
    }
    cmd[1] = 0x05 | cameraAddr;
    cmd[2] = 0;
    cmd[3] = 0;
    cmd[4] = 0;
    cmd[5] = 0;
    while (1)
    {
    clearRxBuf();
    sendCmd(cmd, 6);
    if (readBytes((char *)resp, 6, 100) != 6) continue;
    if (resp[0] == 0xaa && resp[1] == (0x0e | cameraAddr) && resp[2] == 0x05 && resp[4] == 0 && resp[5] == 0) break;
    }
    cmd[1] = 0x04 | cameraAddr;
    cmd[2] = 0x1;
    while (1)
    {
    clearRxBuf();
    sendCmd(cmd, 6);
    if (readBytes((char *)resp, 6, 100) != 6) continue;
    if (resp[0] == 0xaa && resp[1] == (0x0e | cameraAddr) && resp[2] == 0x04 && resp[4] == 0 && resp[5] == 0)
    {
    if (readBytes((char *)resp, 6, 1000) != 6)
    {
    continue;
    }
    if (resp[0] == 0xaa && resp[1] == (0x0a | cameraAddr) && resp[2] == 0x01)
    {
    picTotalLen = (resp[3]) | (resp[4] << 8) | (resp[5] << 16);
    //Serial.print("picTotalLen:");
    //Serial.println(picTotalLen);
    break;
    }
    }
    }
    }
    /****************************** ****************************** *********/
    void GetData()
    {
    unsigned int pktCnt = (picTotalLen) / (PIC_PKT_LEN - 6);
    if ((picTotalLen % (PIC_PKT_LEN-6)) != 0) pktCnt += 1;
    char cmd[] = { 0xaa, 0x0e | cameraAddr, 0x00, 0x00, 0x00, 0x00 };
    unsigned char pkt[PIC_PKT_LEN];
    char picName[] = "pic00.jpg";
    picName[3] = picNameNum/10 + '0';
    picName[4] = picNameNum%10 + '0';
    if (SD.exists(picName))
    {
    SD.remove(picName);
    }
    myFile = SD.open(picName, FILE_WRITE);
    if(!myFile){
    //Serial.println("myFile open fail...");
    }
    else{
    for (unsigned int i = 0; i < pktCnt; i++)
    {
    cmd[4] = i & 0xff;
    cmd[5] = (i >> 8) & 0xff;
    int retry_cnt = 0;
    retry:
    delay(10);
    clearRxBuf();
    sendCmd(cmd, 6);
    uint16_t cnt = readBytes((char *)pkt, PIC_PKT_LEN, 200);
    unsigned char sum = 0;
    for (int y = 0; y < cnt - 2; y++)
    {
    sum += pkt[y];
    }
    if (sum != pkt[cnt-2])
    {
    if (++retry_cnt < 100) goto retry;
    else break;
    }
    myFile.write((const uint8_t *)&pkt[4], cnt-6);
    //if (cnt != PIC_PKT_LEN) break;
    }
    cmd[4] = 0xf0;
    cmd[5] = 0xf0;
    sendCmd(cmd, 6);
    }
    myFile.close();
    picNameNum ++;
    }[/CODE]

    Bon j'ai testé ce programme il marche avec boutton poussoir,mais maintenant j'ai essayé de modifier le programme pour le faire fonctionné avec un capteur de mouvement comme tu me la dit yoruk mais y'a trop d'erreur,avec ce nouveau programme tu n'aurais pas d'autre solution ?

  28. #27
    moduleloi

    Re : Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement

    Voila j'ai modifier le programme vous le trouver bon pour le faire fonctionner avec capteur de mouvement?

    // File SerialCamera_DemoCode_CJ-OV528.ino
    // 8/8/2013 Jack Shao
    // Demo code for using seeeduino or Arduino board to cature jpg format
    // picture from seeed serial camera and save it into sd card. Push the
    // button to take the a picture .
    // For more details about the product please check http://www.seeedstudio.com/depot/
    Code:
    #include <arduino.h>
    #include <SD.h>
    #include <SoftwareSerial.h>
    #define PIC_PKT_LEN 128 //data length of each read, dont set this too big because ram is limited
    #define PIC_FMT_VGA 7
    #define PIC_FMT_CIF 5
    #define PIC_FMT_OCIF 3
    #define CAM_ADDR 0
    #define CAM_SERIAL softSerial
    #define PIC_FMT PIC_FMT_VGA
    
    File myFile;
    SoftwareSerial softSerial(2, 3); //rx,tx (11-13 is used by sd shield)
    const byte cameraAddr = (CAM_ADDR << 5); // addr
    const int PIR_MOTION_SENSOR = A5; // the number of the pushbutton pin
    unsigned long picTotalLen = 0; // picture length
    int picNameNum = 0;
    /*********************************************************************/
    void setup()
    {
    Serial.begin(115200);
    CAM_SERIAL.begin(9600); //cant be faster than 9600, maybe difference with diff board.
    pinMode(PIR_MOTION_SENSOR, INPUT); // initialize the pushbutton pin as an input
    //Serial.println("Initializing SD card....");
    pinMode(4,OUTPUT); // CS pin of SD Card Shield
    if (!SD.begin(4)) {
    //Serial.print("sd init failed");
    return;
    }
    //Serial.println("sd init done.");
    initialize();
    }
    
    void loop()
    {
    int n = 0;
    while(1){
    //Serial.println("\r\nPress the button to take a picture");
    while (digitalRead(PIR_MOTION_SENSOR) == LOW); //wait for buttonPin status to HIGH
    //Serial.println("taking");
    if(digitalRead(PIR_MOTION_SENSOR) == HIGH){
    delay(20); //Debounce
    if (digitalRead(PIR_MOTION_SENSOR) == HIGH)
    {
    delay(200);
    if (n == 0) preCapture();
    Capture();
    //Serial.print("Saving picture...");
    GetData();
    }
    //Serial.print("\r\nDone ,number : ");
    //Serial.println(n);
    n++ ;
    }
    }
    }
    /*********************************************************************/
    void clearRxBuf()
    {
    while (CAM_SERIAL.available())
    {
    CAM_SERIAL.read();
    }
    }
    /*********************************************************************/
    void sendCmd(char cmd[], int cmd_len)
    {
    for (char i = 0; i < cmd_len; i++) CAM_SERIAL.write(cmd[i]);
    }
    /*********************************************************************/
    int readBytes(char *dest, int len, unsigned int timeout)
    {
    int read_len = 0;
    unsigned long t = millis();
    while (read_len < len)
    {
    while (CAM_SERIAL.available()<1)
    {
    if ((millis() - t) > timeout)
    {
    return read_len;
    }
    }
    *(dest+read_len) = CAM_SERIAL.read();
    Serial.write(*(dest+read_len));
    read_len++;
    }
    return read_len;
    }
    /*********************************************************************/
    void initialize()
    {
    char cmd[] = {0xaa,0x0d|cameraAddr,0x00,0x00,0x00,0x00} ;
    unsigned char resp[6];
    Serial.print("initializing camera...");
    while (1)
    {
    sendCmd(cmd,6);
    if (readBytes((char *)resp, 6,1000) != 6)
    {
    Serial.print(".");
    continue;
    }
    if (resp[0] == 0xaa && resp[1] == (0x0e | cameraAddr) && resp[2] == 0x0d && resp[4] == 0 && resp[5] == 0)
    {
    if (readBytes((char *)resp, 6, 500) != 6) continue;
    if (resp[0] == 0xaa && resp[1] == (0x0d | cameraAddr) && resp[2] == 0 && resp[3] == 0 && resp[4] == 0 && resp[5] == 0) break;
    }
    }
    cmd[1] = 0x0e | cameraAddr;
    cmd[2] = 0x0d;
    sendCmd(cmd, 6);
    //Serial.println("\nCamera initialization done.");
    }
    /*********************************************************************/
    void preCapture()
    {
    char cmd[] = { 0xaa, 0x01 | cameraAddr, 0x00, 0x07, 0x00, PIC_FMT };
    unsigned char resp[6];
    while (1)
    {
    clearRxBuf();
    sendCmd(cmd, 6);
    if (readBytes((char *)resp, 6, 100) != 6) continue;
    if (resp[0] == 0xaa && resp[1] == (0x0e | cameraAddr) && resp[2] == 0x01 && resp[4] == 0 && resp[5] == 0) break;
    }
    }
    void Capture()
    {
    char cmd[] = { 0xaa, 0x06 | cameraAddr, 0x08, PIC_PKT_LEN & 0xff, (PIC_PKT_LEN>>8) & 0xff ,0};
    unsigned char resp[6];
    while (1)
    {
    clearRxBuf();
    sendCmd(cmd, 6);
    if (readBytes((char *)resp, 6, 100) != 6) continue;
    if (resp[0] == 0xaa && resp[1] == (0x0e | cameraAddr) && resp[2] == 0x06 && resp[4] == 0 && resp[5] == 0) break;
    }
    cmd[1] = 0x05 | cameraAddr;
    cmd[2] = 0;
    cmd[3] = 0;
    cmd[4] = 0;
    cmd[5] = 0;
    while (1)
    {
    clearRxBuf();
    sendCmd(cmd, 6);
    if (readBytes((char *)resp, 6, 100) != 6) continue;
    if (resp[0] == 0xaa && resp[1] == (0x0e | cameraAddr) && resp[2] == 0x05 && resp[4] == 0 && resp[5] == 0) break;
    }
    cmd[1] = 0x04 | cameraAddr;
    cmd[2] = 0x1;
    while (1)
    {
    clearRxBuf();
    sendCmd(cmd, 6);
    if (readBytes((char *)resp, 6, 100) != 6) continue;
    if (resp[0] == 0xaa && resp[1] == (0x0e | cameraAddr) && resp[2] == 0x04 && resp[4] == 0 && resp[5] == 0)
    {
    if (readBytes((char *)resp, 6, 1000) != 6)
    {
    continue;
    }
    if (resp[0] == 0xaa && resp[1] == (0x0a | cameraAddr) && resp[2] == 0x01)
    {
    picTotalLen = (resp[3]) | (resp[4] << 8) | (resp[5] << 16);
    //Serial.print("picTotalLen:");
    //Serial.println(picTotalLen);
    break;
    }
    }
    }
    }
    /*********************************************************************/
    void GetData()
    {
    unsigned int pktCnt = (picTotalLen) / (PIC_PKT_LEN - 6);
    if ((picTotalLen % (PIC_PKT_LEN-6)) != 0) pktCnt += 1;
    char cmd[] = { 0xaa, 0x0e | cameraAddr, 0x00, 0x00, 0x00, 0x00 };
    unsigned char pkt[PIC_PKT_LEN];
    char picName[] = "pic00.jpg";
    picName[3] = picNameNum/10 + '0';
    picName[4] = picNameNum%10 + '0';
    if (SD.exists(picName))
    {
    SD.remove(picName);
    }
    myFile = SD.open(picName, FILE_WRITE);
    if(!myFile){
    //Serial.println("myFile open fail...");
    }
    else{
    for (unsigned int i = 0; i < pktCnt; i++)
    {
    cmd[4] = i & 0xff;
    cmd[5] = (i >> 8) & 0xff;
    int retry_cnt = 0;
    retry:
    delay(10);
    clearRxBuf();
    sendCmd(cmd, 6);
    uint16_t cnt = readBytes((char *)pkt, PIC_PKT_LEN, 200);
    unsigned char sum = 0;
    for (int y = 0; y < cnt - 2; y++)
    {
    sum += pkt[y];
    }
    if (sum != pkt[cnt-2])
    {
    if (++retry_cnt < 100) goto retry;
    else break;
    }
    myFile.write((const uint8_t *)&pkt[4], cnt-6);
    //if (cnt != PIC_PKT_LEN) break;
    }
    cmd[4] = 0xf0;
    cmd[5] = 0xf0;
    sendCmd(cmd, 6);
    }
    myFile.close();
    picNameNum ++;
    }

  29. #28
    Yoruk

    Re : Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement

    Tu nous fait quoi là ? il donne quoi le programme que je t'ai donné ? Pourquoi changer ?
    La robotique, c'est fantastique !

  30. #29
    moduleloi

    Re : Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement

    Le programme que tu m'a donné est faux car le programme avec boutton poussoir que je t'avais passé était faux en faite,je m'etais trompé de programme et mon poste à 14h10 est le vrai programme qui fonctionne avec boutton poussoir,la j'ai essayé de modifier le programme pour qu'il fonctionne avec le détecteur de mouvement ,mais j'ai du oublier des choses pour que sa fonctionne ,tu ne vois pas ce que je devrai modifier de plus pour qu'il marche (mon poste à 14h23

  31. #30
    Yoruk

    Re : Modifier le programme en remplacent le bouton poussir par un detecteur de mouvement

    Tu m'as dit que le premier programme était bon....

    Analyse ce que j'ai fait pour assembler les 2 programmes et fait la même modif sur les nouveaux ! Ou alors, prends mon programme assemblé et fait-le fonctionner avec le "nouveau programme du bouton poussoir".
    La robotique, c'est fantastique !

Page 1 sur 3 12 DernièreDernière

Discussions similaires

  1. aide pour modifier un programme du pic
    Par yassinema1992 dans le forum Électronique
    Réponses: 8
    Dernier message: 03/02/2013, 18h55
  2. Probléme pour modifier un programme
    Par invitea883d7b1 dans le forum Électronique
    Réponses: 5
    Dernier message: 27/04/2011, 10h49
  3. modifier un detecteur de mouvement et de bruit
    Par alf0016 dans le forum Électronique
    Réponses: 3
    Dernier message: 15/01/2010, 17h22
  4. Modifier Un Programme de Pic
    Par invitef894bf53 dans le forum Électronique
    Réponses: 2
    Dernier message: 15/06/2009, 08h36
  5. Lumiere avec detecteur IR auto et bouton de forcage
    Par cybertop dans le forum Électronique
    Réponses: 3
    Dernier message: 01/11/2007, 17h39
Découvrez nos comparatifs produits sur l'informatique et les technologies.