Arduino che non torna a "dormire".

Buongiorno a tutti, ho ripreso dopo anni a smanettare con i microcontroller e ad essere sincero sto facendo un po' fatica. :slight_smile:

Ho preso 2 talk2 whispernode.
Vorrei utilizzarli per creare dei sensori che comunicano tra di loro via radio a seguito di un evento particolare. Tra un evento e l'altro, per risparmiare batteria, metterli in sleepmode con la libreria lowpower.

Qual'è il problema? Il whispernode "parte" correttamente, va in sleep, si riattiva a seguito dell'evento (un sensore reed che lo manda in high) ma poi alla fine non torna a dormire... che cosa sbaglio nel codice?

Ps: Capisco che non torna in sleep tramite multimetro, non lascio led o altro acceso...

#include <SPI.h>
#include <RH_RF69.h>
#include "LowPower.h"

// Singleton instance of the radio driver
RH_RF69 rf69;
//RH_RF69 rf69(15, 16); // For RF69 on PJRC breakout board with Teensy 3.1

 //int buttonA = 4;
 const int wakeUpPin = 3;
 bool msg_inviato = false;



void setup() 
{
  Serial.begin(9600);
  if (!rf69.init())
    Serial.println("init failed");
  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
  // No encryption
  if (!rf69.setFrequency(915.0))
    Serial.println("setFrequency failed");

  // If you are using a high power RF69, you *must* set a Tx power in the
  // range 14 to 20 like this:
  rf69.setTxPower(16);

  // The encryption key has to be the same as the one in the server
  uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
  rf69.setEncryptionKey(key);

 
  
  pinMode(6, OUTPUT);
  pinMode(9, OUTPUT);
  //pinMode(buttonA, INPUT);
  pinMode(wakeUpPin, INPUT);
}



void loop()
{

    // Allow wake up pin to trigger interrupt on low.
    //attachInterrupt(1, wakeUp, CHANGE);
    attachInterrupt(1, wakeUp, CHANGE);
    
    // Enter power down state with ADC and BOD module disabled.
    // Wake up when wake up pin is low.
    LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF); 
    
    // Disable external pin interrupt on wake up pin.
    detachInterrupt(1);

    Send_Msg();

}

void wakeUp(){

  //Serial.println("Rilevato movimento al millis: ");
  // Just a handler for the pin interrupt.
  //state = !state;

  Serial.println("WakeUP void");

  }

void Send_Msg() {

if (digitalRead(wakeUpPin) == HIGH) {
      Serial.println("Sending to rf69_server");
      // Send a message to rf69_server
      uint8_t data[] = "Hello World!";
      rf69.send(data, sizeof(data));
      
      rf69.waitPacketSent();
      // Now wait for a reply
      uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
      uint8_t len = sizeof(buf);
    
      if (rf69.waitAvailableTimeout(1000))
      { 
        // Should be a reply message for us now   
        if (rf69.recv(buf, &len))
        {
          Serial.print("got reply: ");
          Serial.println((char*)buf);
          digitalWrite(9, LOW);    // turn the LED off by making the voltage LOW
          digitalWrite(6, HIGH);   // turn the LED on (HIGH is the voltage level)
          delay(250);              // wait for a second
          digitalWrite(6, LOW);    // turn the LED off by making the voltage LOW
          msg_inviato = true;
        }
        else
        {
          Serial.println("recv failed");
          digitalWrite(6, LOW);    // turn the LED off by making the voltage LOW
          
          digitalWrite(9, HIGH);   // turn the LED on (HIGH is the voltage level)
          delay(125);              // wait for a second
          digitalWrite(9, LOW);    // turn the LED off by making the voltage LOW
          delay(125);              // wait for a second
    
          digitalWrite(9, HIGH);   // turn the LED on (HIGH is the voltage level)
          delay(125);              // wait for a second
          digitalWrite(9, LOW);    // turn the LED off by making the voltage LOW
          //delay(125);              // wait for a second
          msg_inviato = false;
         }
      }
      else
      {
        Serial.println("No reply, is rf69_server running?");
        digitalWrite(6, LOW);    // turn the LED off by making the voltage LOW
        digitalWrite(9, HIGH);   // turn the LED on (HIGH is the voltage level)
        msg_inviato = false;
        delay(125);
                
      }

      if (msg_inviato==true) return true;
            
      //delay(3000);
    }
  
}

cosa sono i "talk2 whispernode"?

https://bitbucket.org/talk2/whisper-node-avr

Chiariamo un fatto. Quella scheda non é un Arduino.

Ha un ATmega328 come un Arduino UNO.
Non sono riuscita a scaricare lo schema elettrico e percui non so dirti niente su cosa é diverso rispetto ad un Arduino UNO.

Ciao Uwe

Fai finta che sia un arduino, cosa sbaglio secondo te?

La Tua é una scheda che non é compatibile al 100% con Arduino UNO perché ha del hardware differente/in piú. Cerca di scoprire quali sono le differenze e dopo se le differenze danno problemi con il sleep.
Ciao Uwe