Recherche bug sur un ino

Bonjour,
Merci pour ce forum d'entreaide autour de l'arduino,
Je suis amateur débutant, je suis sur un projet d'automatisation de fermeture de porte poulailler avec: mini pro 5v, shield tb6612fng, ds3231, batterie 12v, panneau solaire, gestionnaire batterie/panneau,

j'ai un programme de base pour tester, simple qui est fonctionnel, pas de probleme, et j'utilise apres le programme general, avec toute les fonctions, mais ce dernier n'est pas fonctionnel et je n'arrive pas a trouver pourquoi, c'est comme s'il n'arrivait plus a sortir de la mise en veille.

pour l'historique, avant j'utilisais un nano+bts7960, mais par soucis d'autonomie j'ai remplacé des composants.
voici le programme test fonctionnel:

int pinAIN1 = 5; //Direction
int pinAIN2 = 6; //Direction
int pinPWMA = 7; //Speed
int pinSTBY = 9;
const int IP4=3; // sensor door closed  

//Constants to help remember the parameters
static boolean turnCW = 0;  //for motorDrive function
static boolean turnCCW = 1; //for motorDrive function
static boolean motor1 = 0;  //for motorDrive, motorStop, motorBrake functions

void setup()
{
//Set the PIN Modes
  pinMode(pinPWMA, OUTPUT);
  pinMode(pinAIN1, OUTPUT);
  pinMode(pinAIN2, OUTPUT);
  pinMode(pinSTBY, OUTPUT);
  pinMode(IP4,INPUT_PULLUP); // set pin in INPUT  
}

void loop()
{
  digitalWrite(pinSTBY, HIGH);
  motorDrive(motor1, turnCW, 100);
   delay(1000);
 motorStop(motor1);
   
   
 
    //sensor
  for(int n = 0 ; n < 550; n+=1)    //550x100=55000=55s
  {
   if (digitalRead(IP4)==1) // sensor not detect the door attention pullup c'est inversé
  {  motorDrive(motor1, turnCCW, 100);
    delay(100);
  }
  else
  {  
     motorStop(motor1);
    break;
    }
    }
    digitalWrite(pinSTBY, LOW);
    delay(2000);
    }



void motorDrive(boolean motorNumber, boolean motorDirection, int motorSpeed)
{
  /*
  This Drives a specified motor, in a specific direction, at a specified speed:
    - motorNumber: motor1 or motor2 ---> Motor 1 or Motor 2
    - motorDirection: turnCW or turnCCW ---> clockwise or counter-clockwise
    - motorSpeed: 0 to 255 ---> 0 = stop / 255 = fast
  */

  boolean pinIn1;  //Relates to AIN1 or BIN1 (depending on the motor number specified)

 
//Specify the Direction to turn the motor
  //Clockwise: AIN1/BIN1 = HIGH and AIN2/BIN2 = LOW
  //Counter-Clockwise: AIN1/BIN1 = LOW and AIN2/BIN2 = HIGH
  if (motorDirection == turnCW)
    pinIn1 = HIGH;
  else
    pinIn1 = LOW;

//Select the motor to turn, and set the direction and the speed
 
    digitalWrite(pinAIN1, pinIn1);
    digitalWrite(pinAIN2, !pinIn1);  //This is the opposite of the AIN1
    analogWrite(pinPWMA, motorSpeed);
  
   
 

//Finally , make sure STBY is disabled - pull it HIGH
  digitalWrite(pinSTBY, HIGH);

}

void motorBrake(boolean motorNumber)
{
/*
This "Short Brake"s the specified motor, by setting speed to zero
*/

      analogWrite(pinPWMA, 0);
 
   
}


void motorStop(boolean motorNumber)
{
  /*
  This stops the specified motor by setting both IN pins to LOW
  */
 
    digitalWrite(pinAIN1, LOW);
    digitalWrite(pinAIN2, LOW);
  
  
}


void motorsStandby()
{
  /*
  This puts the motors into Standby Mode
  */
  digitalWrite(pinSTBY, LOW);
}

et le principale qui n'est pas fonctionnel:

//THP0
 
 #include <Wire.h>  
 #include <RTClibExtended.h>  
 #include <avr/interrupt.h>  
 #include <avr/power.h>  
 #include <avr/sleep.h>  
 #include <avr/io.h>   
  
 const int IP1=2; // DIGITAL INPUT + Interruption  
 const int IP4=3; // sensor door closed  
 int flagInit=0;  
 int flag=0; // sécurité interruption

 int annee, mois, jour, numJourSemaine, numJourMois;
 int heure;
 int minut;
 int sec;
 String jour_sem_str, date_str, date_str_old;
 
 int mois_hiver = 11;
 int mois_ete = 5; // 1 a 12, 4 pour avril

 boolean saison = true, saison_old, mode_horaire; //initialise 3 variables dont saison et affectée à true , les autre simplement déclarées

 ////////////////////////// JANV  FEV   Mars  Avr  Mai  Jun  Juil  Aout  Sept  Oct   Nov  Dec  
 int LeveSoleilHeure[24]=  { 8,8,  7,7,  6,6,  6,6,  5,5,  5,5,  5,5,  6,6,  6,7,  7,8,  7,7,  8,8  };  
 int LeveSoleilMinute[24]= {20,10, 49,24, 58,27, 54,24, 58,38, 26,25, 34,49, 10,31, 54,15,  37,00, 25,48, 07,19  };  
 int CoucheSoleilHeure[24]= {17,17, 17,18, 18,19, 20,20, 21,21, 21,21, 21,21, 21,20, 20,19,  19,18, 17,17, 16,16  };  
 int CoucheSoleilMinute[24]={9,30, 56,21, 41,4, 28,51, 13,33, 49,56, 53,40, 17,50, 18,46,  15,45, 19,1, 52,55  };  
 
int pinAIN1 = 5; //Direction
int pinAIN2 = 6; //Direction
int pinPWMA = 7; //Speed
int pinSTBY = 9;

//Constants to help remember the parameters
static boolean turnCW = 0;  //for motorDrive function
static boolean turnCCW = 1; //for motorDrive function
static boolean motor1 = 0;  //for motorDrive, motorStop, motorBrake functions
 
 RTC_DS3231 RTC;   //we are using the DS3231 RTC  
 
 void setup()   
 {  
  //------------------------------  
  //RTC init  
  //------------------------------  
  //Set SQW pin to OFF (in my case it was set by default to 1Hz)  
  //The output of the DS3231 INT pin is connected to this pin  
  //It must be connected to arduino D2 pin for wake-up  
  RTC.writeSqwPinMode(DS3231_OFF);  
  pinMode(IP1,INPUT_PULLUP); // set pin in INPUT  
  pinMode(IP4,INPUT_PULLUP);
  pinMode(pinPWMA, OUTPUT);
  pinMode(pinAIN1, OUTPUT);
  pinMode(pinAIN2, OUTPUT);
  pinMode(pinSTBY, OUTPUT);
  
  }
 
 void loop() {  
   //When exiting the sleep mode we clear the alarm  
   //Initialize communication with the clock  
   Wire.begin();  
   RTC.begin();
      //clear any pending alarms  
   RTC.armAlarm(1, false);  
   RTC.clearAlarm(1);  
   RTC.alarmInterrupt(1, false);  
   RTC.armAlarm(2, false);  
   RTC.clearAlarm(2);  
   RTC.alarmInterrupt(2, false);  
   DateTime t=RTC.now();  
     //Automation heure étéhiver
   etehiver(); 
   int Index=(t.month()-1)*2;     
   if( t.day()>15)  
    Index++;  
   if(canOpen(t,Index))  
   {  
   forward();  
    RTC.setAlarm(ALM1_MATCH_HOURS,CoucheSoleilMinute[Index], CoucheSoleilHeure[Index],0);   
   }  
   else  
   {  
     backward();  
    RTC.setAlarm(ALM1_MATCH_HOURS,LeveSoleilMinute[Index], LeveSoleilHeure[Index],0);   
   }  
   flagInit=1;  
   RTC.alarmInterrupt(1, true);
  // Met en veille l'arduino  
  sleepNow();  
 }
 
 // functional algo  
 boolean canOpen(DateTime t,int index)  
 {  
   if (  
   ((t.hour()== LeveSoleilHeure[index] && t.minute()>= LeveSoleilMinute[index]) || t.hour()> LeveSoleilHeure[index])  
   &&   
   (t.hour()< CoucheSoleilHeure[index] || (t.hour()== CoucheSoleilHeure[index] && t.minute()< CoucheSoleilMinute[index]))  
   )  
   return true;  
   else   
   return false;  
 }  
 
 void backward()  //descend
 {
  //sensor
  for(int n = 0 ; n < 550; n+=1)    //550x100=55000=55s
  {
   if (digitalRead(IP4)==1) // sensor not detect the door attention pullup c'est inversé
  {  motorDrive(motor1, turnCCW, 100);
    delay(100);
  }
  else
  {  
     motorStop(motor1);
    break;
    }
    }
    digitalWrite(pinSTBY, LOW);
	}

 void forward()  //monte
 {  
    digitalWrite(pinSTBY, HIGH);
  motorDrive(motor1, turnCW, 100);
   delay(1000);
 motorStop(motor1);
 digitalWrite(pinSTBY, LOW);
 }   
 
 // PARTIE MISE EN VEILLE DU proccesseur  
 void sleepNow(void)  
 {  
   flag=0;  
   attachInterrupt(0, pinInterrupt,FALLING);// CHANGE); FALLING  
   delay(1000); // important laisse le temps de mettre en place l'interruption  
   //  
   // Choose our preferred sleep mode:  
   set_sleep_mode(SLEEP_MODE_PWR_DOWN);  
   //  
   // Set sleep enable (SE) bit:  
   sleep_enable();  
   //  
   // Put the device to sleep:  
   sleep_mode();  
   //  
   // Upon waking up, sketch continues from this point.  
   sleep_disable();  
   // SORTI DE LA VEILLE    
   flag=1;  
 }  
   
 void pinInterrupt(void)  
 {  
  if (flag>0)  
   detachInterrupt(0);  
 }  

 void etehiver()  // CHANGEMENT HEURE ETE/HIVER
   {
  DateTime t=RTC.now();
  annee = t.year();
  mois = t.month();
  jour = t.day();
  numJourSemaine = t.dayOfTheWeek();
  jour_sem_str = "";
  heure = t.hour();
  minut = t.minute();
  sec = t.second();
  date_str = jour_sem_str + jour + "/" + mois + "/" + String(annee).substring(2) + " " + heure + ":" + minut +" " + return_saison();

   if(numJourSemaine == 7 & mois == 3 & jour <=7 & heure >= 3 & mode_horaire == false)
  {
    RTC.adjust(DateTime(annee, mois, jour, heure + 1, minut,sec));
    mode_horaire = true;
  }
  if(numJourSemaine == 7 & mois == 10 & jour >=23 & heure >= 3 & mode_horaire == true)
  {
    RTC.adjust(DateTime(annee, mois, jour, heure - 1, minut,sec));
    mode_horaire = false;
  }

 // CALCUL DE PERIODE ETE/HIVER
  if(mois_ete <= mois & mois < mois_hiver){
    saison = true;
  }
  else
  {
    saison = false;
  }
  if(saison == true & saison_old != saison){
    saison_old = saison;
  }
  else
  {
    saison_old = saison;
  }
}

String return_saison()
{
  if(saison == true){
    return "ete";
  }
  else
  {
    return "hiver";
  }
} 

void motorDrive(boolean motorNumber, boolean motorDirection, int motorSpeed)
{
  /*
  This Drives a specified motor, in a specific direction, at a specified speed:
    - motorNumber: motor1 or motor2 ---> Motor 1 or Motor 2
    - motorDirection: turnCW or turnCCW ---> clockwise or counter-clockwise
    - motorSpeed: 0 to 255 ---> 0 = stop / 255 = fast
  */

  boolean pinIn1;  //Relates to AIN1 or BIN1 (depending on the motor number specified)

 
//Specify the Direction to turn the motor
  //Clockwise: AIN1/BIN1 = HIGH and AIN2/BIN2 = LOW
  //Counter-Clockwise: AIN1/BIN1 = LOW and AIN2/BIN2 = HIGH
  if (motorDirection == turnCW)
    pinIn1 = HIGH;
  else
    pinIn1 = LOW;

//Select the motor to turn, and set the direction and the speed
 
    digitalWrite(pinAIN1, pinIn1);
    digitalWrite(pinAIN2, !pinIn1);  //This is the opposite of the AIN1
    analogWrite(pinPWMA, motorSpeed);
  
   
 

//Finally , make sure STBY is disabled - pull it HIGH
  digitalWrite(pinSTBY, HIGH);

}

void motorBrake(boolean motorNumber)
{
/*
This "Short Brake"s the specified motor, by setting speed to zero
*/

      analogWrite(pinPWMA, 0);
 
   
}


void motorStop(boolean motorNumber)
{
  /*
  This stops the specified motor by setting both IN pins to LOW
  */
 
    digitalWrite(pinAIN1, LOW);
    digitalWrite(pinAIN2, LOW);
  
  
}

pouvez vous m'aider pour trouver le bug?

slts

je suis encore en mode experience, donc le cycle et de 1 seconde pour tourner le moteur , le bug, c'est qu'au lancement, il ouvre bien la porte mais ne fait rien d'autre

:warning:
Post mis dans la mauvaise section, on parle anglais dans les forums généraux. déplacé vers le forum francophone.

Merci de prendre en compte les recommandations listées dans Les bonnes pratiques du Forum Francophone

Salut
Il est assez surprenant de voir un logiciel dépourvu de toutes traces de DEBUG.
Connais-tu le moniteur série ?

Salut Henri,
Je suis novice, j'ai regardé ce moniteur serie, je le connais vite fait, dans le sens ou je l'utilise pour controler que mon horloge est a l'heure, comme Serial.println(t.hour());.
Je vais donc inserer cette fonction juste avant la mise en veille pour controler l'etat de INT0, des heures des alarmes, de flag et flagInit.
C'est dans ce sens que tu voulais m'aiguiller?
Bonne journée

Oui c'est ça, partout où c'est nécessaire.

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