Bonjour à tous,

Je fais (une nouvelle fois) appel à votre aide car j'ai constaté chez moi un problème entre une carte MKRFOX1200 et un relai (3.3V) lors de scénarios bien précis.

Lorsque je veux mettre à jour le sketch, directement pendant l'upload du fichier, le relai se met en ON/OFF des centaines de fois par seconde cad en fonction du clignotement de la led intégrée lors du transfert série.

Le scénario se reproduit durant le fonctionnement dès que la carte transmet sur le backend SigFox.

Il y a un visiblement problème au niveau de la liaison série sur ce type de carte lors d'utilisation de relais.

Y a t-il qqch à faire au niveau du code ?

Merci pour votre aide.

Voici mon script basique:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
 
#include <SigFox.h>
#include "uFire_SHT20.h"
uFire_SHT20 sht20;
#define DEBUG 1                                  // need to be declared for serial reading with use of MKRFOX1200
const int fanRelayPin = 6;                       // Initialized a pin for window relay module
 
enum : byte {temp, airHumidity};                 //used for sensor returning data
 
unsigned long prevSHT20Time = 0;                 // For interval calculation
const long SHT20Interval = 60000;                // Read sensor every minutes
 
String incomingData;                                 // String for reading SigFox data
int fanRunningTemp = 30;                         // Default value in degree for running fan
 
/**
 * Functions regarding window management
 */
    void fanOn(){
        if (DEBUG){
        Serial1.println(F("Fan is running"));
        }
       digitalWrite(fanRelayPin,LOW);
 
 
    }
 
    void fanStop(){
        if (DEBUG){
        Serial1.println(F("Fan stop"));
        }
        digitalWrite(fanRelayPin,HIGH);
 
 
    }
 
 
 
  void fanAction(){
 
              if ( millis() - prevSHT20Time >= SHT20Interval) {
 
                  if (sht20Check(temp) > fanRunningTemp ) fanOn();
                  else fanStop();
 
                  prevSHT20Time = millis(); 
             }
 
 
 
  }
 
/**
 * Functions reading SHT20 sensor
 */
 
  float sht20Check(int param) {
       if(param == temp) { 
          if (DEBUG){
            Serial1.print("Temp :");
            Serial1.println(sht20.temperature());
          }
            return sht20.temperature();              // Read Temperature
       }
       else return sht20.humidity(); 
  }
 
void reboot() {
  NVIC_SystemReset();
  while (1);
}
 
void sendAndReadData(){
 
  if (!SigFox.begin()) {
    //something is really wrong, try rebooting
    reboot();
  }
  delay(100);
  SigFox.debug();
 
  // define sigfox payload data structure
   struct data{
     float temp;
     float hum;
     int lit;
   };
 
   struct data reading;
   reading.temp = sht20Check(temp);
   reading.hum = sht20Check(airHumidity);
   reading.lit = 50;
 
  SigFox.beginPacket();
  SigFox.write((const char*)&reading, sizeof(reading));
 
  int ret = SigFox.endPacket(true);  // send buffer to SIGFOX network and wait for a response
 
  if (ret > 0) {
    if (DEBUG){
    Serial1.println("No transmission");
    }
  } else {
    if (DEBUG){
    Serial1.println("Transmission ok");
    }
  }
 
 
  if (SigFox.parsePacket()) {
    if (DEBUG){
    Serial1.println("Response from server:");
    }
    while (SigFox.available()) {
      //Serial1.print("0x");
      //Serial1.println(SigFox.read(), HEX);
      //incomingData = String(SigFox.read(),DEC);
      char buf = SigFox.read();
      if (DEBUG){
      Serial1.print(buf);
      }
      incomingData += buf;
 
    }
  } else {
    if (DEBUG){
    Serial1.println("Could not get any response from the server");
    Serial1.println("Check the SigFox coverage in your area");
    Serial1.println("If you are indoor, check the 20dB coverage or move near a window");
    }
  }
 
 
  SigFox.end();
 
}
 
 
 
void setup() {
  if (DEBUG){
    Serial1.begin(9600);
    while (!Serial) {};
  }
  Wire.begin();
  sht20.begin();
  pinMode(fanRelayPin, OUTPUT);  
 
  //fan relay initialisation
  delay(1000);
  digitalWrite(fanRelayPin,HIGH);
 
  //SigFox test
  sendAndReadData(); // put here just to test at initialisation
 
}
 
void loop() {
  fanAction(); 
 
}
Nom : relayboard.png
Affichages : 175
Taille : 201,6 Ko