Problème Arduino mkr 1000 et lib ArduinoLowPower.h

Bonjour à tous,

Je suis en train de commencer à travailler sur l'Arduino mkr 1000 mais j'ai un petit problème avec la librairie ArduinoLowPower.h

Quand je mets le mkr en sommeil, il ne se reveille jamais. J'utilise simplement la commande LowPower.sleep(500);

auriez vous une idée du problème ? J'ai trouvé certain qui disent de mettre "LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, dummy, CHANGE);" mais moi je n'ai rien à lui faire faire, quand il doit se reveiller.

Voici mon code

Merci de votre aide

#include <WiFi101.h>
#include <ArduinoLowPower.h>

#define SECRET_SSID "franky"
#define SECRET_PASS "xxxxxxxxx"

///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID;        // your network SSID (name)
char pass[] = SECRET_PASS;    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;            // your network key Index number (needed only for WEP)

byte mac[6];
char macChar[6];
int wifiStatut = 0;
unsigned long CouranteTime;

int status = WL_IDLE_STATUS;
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
char server[] = "iot.henpier.fr";    // name address for Google (using DNS)

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
WiFiClient client;

void setup() {
  // put your setup code here, to run once:
//Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

// check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }

  // attempt to connect to WiFi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
    
    if(status == WL_CONNECTED){
        Serial.println("Connected to wifi");
      printWiFiStatus();
      wifiStatut = 1;
    }
    
    if(status != WL_CONNECTED){
        Serial.println("wifi Not Connected");
        wifiStatut = 0;
        break;
    } 
  }
    LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, dummy, CHANGE);
}

void loop() {
  // put your main code here, to run repeatedly:

CouranteTime = millis();
Serial.print("CouranteTime : ");
Serial.println(CouranteTime);

WiFi.macAddress(mac);

LowPower.sleep(500);
}

void printWiFiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  WiFi.macAddress(mac);
  Serial.print("MAC address: ");
  Serial.print(mac[5], HEX);
  Serial.print(mac[4], HEX);
  Serial.print(mac[3], HEX);
  Serial.print(mac[2], HEX);
  Serial.print(mac[1], HEX);
  Serial.print(mac[0], HEX);
  Serial.println("");

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

void dummy() {
  // This function will be called once on device wakeup
  // You can do some little operations here (like changing variables which will be used in the loop)
  // Remember to avoid calling delay() and long running functions since this functions executes in interrupt context
  volatile int aaa=0;
}

Voici un bon tuto sur les moyens de mettre un Arduino en sommeil.

Pour ton problème, il faut peut-être utiliser :

LowPower.deepSleep(5000);

J'ai mis 5000 car 500 me semble trop court pour voir quelque chose

Tu devrais tester le sleep seul, avec un sketch dédié, qui ferait par exemple allumer une LED un moment, puis l'éteindre avant de mettre le processeur en sommeil, et rallumer la LED lorsque le proc se réveille.

Quand tu auras compris comment ça fonctionne, tu ajoutes le reste de ton programme.

Le tuto de Nick est pour les Atmega328P (uno et similaire). Le MKR1000 est basée sur un SAMD21 Cortex M0 - pas la même chose

Effectivement j’ai lu qu’implémenter l’ISR suffisait à faire fonctionner le réveil - Avez vous essayé avec le code que vous postez, ça donne quoi?

Et si vous utilisez ce code, est-ce que ça fonctionne ?
Essayez avec ou sans commenter la ligne LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, dummy, CHANGE);

oups !

:slight_smile: :slight_smile:

Salut à tous,

Merci encore pour votre retour.

J’ai essayé maintenant avec juste la librairie et un serail.print avec un sleep de 5000ms, le premier print marche et ensuite plus rien et l’arduino est bien en sommeil, car obligé de la rebooter, pour lui reflasher du code...

Merci de votre aide

Et avec le code pointé en #2 ?

Bonsoir à tous,

Je viens de faire plusieurs tests. Voici les résultats.

Quand je fais que flasher le led, et je mets en mode sleep 5s, ça marche bien, la led clignote.

Quand je fais la même choses, avec un serial.print, le led clignote bien, mais après le sleep, plus d'affichage avec serial.print.

Est-ce normal? Avez vous un idée?

Merci

Vous faites le print dans l’ISR ?
Vous lui donnez le temps de s’imprimer ? (Avant de dormir)

Postez le code de test

J-M-L:
Vous faites le print dans l’ISR ?
Vous lui donnez le temps de s’imprimer ? (Avant de dormir)

Postez le code de test

voici mon code :

/*
  TimedWakeup
  This sketch demonstrates the usage of Internal Interrupts to wakeup a chip in sleep mode.
  Sleep modes allow a significant drop in the power usage of a board while it does nothing waiting for an event to happen. Battery powered application can take advantage of these modes to enhance battery life significantly.
  In this sketch, the internal RTC will wake up the processor every 2 seconds.
  Please note that, if the processor is sleeping, a new sketch can't be uploaded. To overcome this, manually reset the board (usually with a single or double tap to the RESET button)
  This example code is in the public domain.
*/

#include "ArduinoLowPower.h"

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  // Uncomment this function if you wish to attach function dummy when RTC wakes up the chip
  // LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, dummy, CHANGE);

  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial1.println("Start program");
  delay(5000);
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  // Triggers a 2000 ms sleep (the device will be woken up only by the registered wakeup sources and by internal RTC)
  // The power consumption of the chip will drop consistently
  Serial.println("sleep");
  LowPower.sleep(2000);
  Serial.println("wake");
}

void dummy() {
  // This function will be called once on device wakeup
  // You can do some little operations here (like changing variables which will be used in the loop)
  // Remember to avoid calling delay() and long running functions since this functions executes in interrupt context
}

T’en si vous décommentez le

LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, dummy, CHANGE);

Et rajoutez la fonction dummy?

J-M-L:
T’en si vous décommentez le

LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, dummy, CHANGE);

Et rajoutez la fonction dummy?

Non la même :confused:

Normalement, cette fonction permet de faire une interruption, lorsque l'arduino est réveillé. Donc pour moi, elle n'est pas utile dans mon cas.

J-M-L:
Vous faites le print dans l’ISR ?
Vous lui donnez le temps de s’imprimer ? (Avant de dormir)

Peut-être faut-il ajouter un delay(200); avant LowPower.sleep(2000); ?

Je pense que le delay(500) avant le premier print ne sert à rien.

Bon j'ai essayé beaucoup de chose, mais ça ne donne rien, le port serial ne remonte pas après un sleep.

Voici mon code testé, je vous mets que le loop :

void loop() {

  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.println("Start program");
  delay(5000);
  
  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  // Triggers a 2000 ms sleep (the device will be woken up only by the registered wakeup sources and by internal RTC)
  // The power consumption of the chip will drop consistently
  Serial.println("sleep");
  delay(500);
  Serial.flush();
  Serial.end();
  delay(500);
  LowPower.sleep(2000);
  delay(500);
  //Serial.println("wake");
}