Seeduino XIAO SAMD21 High state pins at startup

Hello,

I am currently working on a subject with a Seeduino XIAO SAMD21 and (x 4) 6V 2-Position 3-Way Air Valves. My system is currently powered by the usb Plug of my computer of the XIAO.

My problem is the following, I am running a program which use the valve one by one and works well. However, at the startup,all the vanes turns on for a few second as if all pins were set in high state mode by default. Despite the fact that I write them all to LOW in OUTPUT mode in the setup().

PS : Sorry my code is in frensh :slight_smile:

Could somoene help me with that ?

#include <Arduino.h>

// 4 Pins Enable
#define PIN_ENABLE_ELECTRO_1  1
#define PIN_VENTILO 4
#define PIN_ENABLE_ELECTRO_2  2
#define PIN_ENABLE_ELECTRO_3  3
#define PIN_ENABLE_ELECTRO_4  9
#define PIN_COMMUNICATION_LORA 5
#define PIN_LED_TEST 7



const uint16_t delai_ouverture_electrovanne = 5000;
const uint16_t delai_attente = 1;
//Variables
int counter=0;
const double_t seuil_altitude[] = {0,1000,1500,}; // Définit les 4 différents seuils d'altitudes pour déclencher les expériences
const int electro_vannes[] = {PIN_ENABLE_ELECTRO_1, PIN_ENABLE_ELECTRO_2, PIN_ENABLE_ELECTRO_3, PIN_ENABLE_ELECTRO_4}; // Définit les PINS des 4 électrovannes (pour y avoir accès via un indice) 
  
// 1 Pins Inputdefine 
#define PIN_ELECTROVANNE_MUTUAL_INPUT 10

// put function declarations here:
void lock_electro(uint8_t vanne_1,u_int16_t c_delay){
  /*Active une électroVanne (vanne_1) pendant un délai (c_delay)
  *params:
  *uint8_t : vanne_1 : Pin de la vanne Ă  activer
  *int16_t : c_delay : Delai d'activation de l'electrovanne
  */
    digitalWrite(vanne_1,HIGH);
    digitalWrite(PIN_LED_TEST,HIGH);
    digitalWrite(PIN_VENTILO,HIGH);
    digitalWrite(PIN_ELECTROVANNE_MUTUAL_INPUT,HIGH);

    delay(c_delay);
    digitalWrite(vanne_1,LOW);
    digitalWrite(PIN_LED_TEST,LOW);
    digitalWrite(PIN_VENTILO,LOW);
    digitalWrite(PIN_ELECTROVANNE_MUTUAL_INPUT,LOW);

}

/* int select_eletro(double_t altitude, const double_t seuil_altitude[]){
  int selected_index = 0;
  for(int i=0;i<4;i++){
    if (seuil_altitude[i] < altitude) {
      selected_index = i;
    }
  }
  return selected_index;
} */

void setup() {
  // Définition des PIN Electrovanne Enable en mode OUTPUT
  pinMode(PIN_ENABLE_ELECTRO_1,OUTPUT);
  pinMode(PIN_ENABLE_ELECTRO_2,OUTPUT);
  pinMode(PIN_ENABLE_ELECTRO_3,OUTPUT);
  pinMode(PIN_ENABLE_ELECTRO_4,OUTPUT);
  // Définition du Pin Ventilo 
  pinMode(PIN_VENTILO,OUTPUT);
  // Définition des pins Electrovanne commun
  pinMode(PIN_ELECTROVANNE_MUTUAL_INPUT,OUTPUT);
  pinMode(PIN_LED_TEST,OUTPUT);
  // Activation par défaut des Pins
  pinMode(PIN_COMMUNICATION_LORA,INPUT);
  digitalWrite(PIN_ENABLE_ELECTRO_1,LOW);
  digitalWrite(PIN_ENABLE_ELECTRO_2,LOW);
  digitalWrite(PIN_ENABLE_ELECTRO_3,LOW);
  digitalWrite(PIN_ENABLE_ELECTRO_4,LOW);
  digitalWrite(PIN_ELECTROVANNE_MUTUAL_INPUT,LOW);

}



void loop() {
  while(digitalRead(PIN_COMMUNICATION_LORA)!=HIGH){
    delay(delai_attente);
  }
  counter+=1;
  if (counter==0){return;}
  else if(counter>0 && counter <5){
    lock_electro(electro_vannes[counter-1],delai_ouverture_electrovanne);
  }
  delay(1000);
}


Your topic has been moved. Please do not post in "Uncategorized"; see the sticky topics in Uncategorized - Arduino Forum

During a reset and starting of the processor all pins are in high impedance state (input). You will have to externally pull the problematic pins down with a resistor (based on your description).

1 Like

Why not use the French forum, or use English comments?

void setup() {
  //while(!Serial);
  ss.begin(GPSBaud);
  pinMode(XIAO_PIN,OUTPUT);
  Serial.begin(9600);
  initialitationCapteur();
  digitalWrite(XIAO_PIN,LOW); <<<< call first  before pinMode
Wire.begin();

I have my answer, I need to plug some pull-down resistor on each enable pin. That was answered on another subject on the forum

As said in post #2 :wink:

Please mark your topic as solved by clicking the checkbox under the most useful reply.

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