Can't detect Interrupt on Arduino Mini Pro or can't wake MySensor ?



  • Hi everybody,

    I spent several time trying to detect interrupt on arduino mini pro 3.3v 8mhz with Atmega328 with button but without success. I tryed to downgrade compiler in 1.6.9 but it doesn't work neither.
    If i remove sleep function it's working, but i need sleep because it a battery node for the mailbox...

    Each time i press the button, i can read that in the log in the serial monitor :

    2369 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    2375 MCO:SLP:TPD
    2377 MCO:SLP:WUP=0
    2379 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    2383 MCO:SLP:TPD
    2385 MCO:SLP:WUP=0
    2387 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    2394 MCO:SLP:TPD
    

    But nothing else.

    Could someone helping me ?

    Thx,
    Ghislain

    This is my code :

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * DESCRIPTION
     *
     * Simple binary switch example 
     * Connect button or door/window reed switch between 
     * digitial I/O pin 3 (BUTTON_PIN below) and GND.
     * http://www.mysensors.org/build/binary
     */
    
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    #define MY_RF24_PA_LEVEL RF24_PA_LOW
    #define MY_NODE_ID 8
    
    
    #include <SPI.h>
    #include <MySensors.h>
    #include <Bounce2.h>
    #include <Vcc.h>
    
    
    #define CHILD_ID_MAIL 0
    #define CHILD_ID_MAIL2 1
    #define CHILD_ID_VOLT 2                  // Child id for battery reading
    
    #define BUTTON_PIN 2  // Arduino Digital I/O pin for button/reed switch
    #define BUTTON2_PIN 3  // Arduino Digital I/O pin for button/reed switch
    #define SLEEP_TIME 1 * 60 * 1000UL
    
    
    // Variables' declaration
    const static uint32_t COUNTER = 60;  // en secondes
    unsigned long sendTime = 0; 
    unsigned long time = 0;
    Bounce debouncer = Bounce(); 
    Bounce debouncer2 = Bounce(); 
    int oldValueC1=-1;
    int oldValueC2=-1;
    boolean gwSend = true;
    
    const float VccMin   = 3;           // Minimum expected Vcc level, in Volts.
    const float VccMax   = 4;           // Maximum expected Vcc level, in Volts.
    const float VccCorrection = 1.0/1.0;  // Measured Vcc by multimeter divided by reported Vcc
    float batteryV = 0;
    int batteryPcnt = 0;
    Vcc vcc(VccCorrection);
    
    
    // Change to V_LIGHT if you use S_LIGHT in presentation below
    MyMessage msgMail(CHILD_ID_MAIL,V_TRIPPED);
    MyMessage msgMail2(CHILD_ID_MAIL2,V_TRIPPED);
    MyMessage msgVolt(CHILD_ID_VOLT, V_VOLTAGE);
    
    void setup()  
    {  
      // Setup the button
      pinMode(DIGITAL_INPUT_SENSOR, INPUT_PULLUP);
      pinMode(BUTTON2_PIN, INPUT_PULLUP);
      // Activate internal pull-up
      //digitalWrite(BUTTON_PIN,HIGH);
      //digitalWrite(BUTTON2_PIN,HIGH);
    
      // After setting up the button, setup debouncer
      debouncer.attach(DIGITAL_INPUT_SENSOR);
      debouncer2.attach(BUTTON2_PIN);
      debouncer.interval(5);
      debouncer2.interval(5);
    
        #ifdef MY_DEBUG
          Serial.begin(115200);
        #endif    
      
      batteryV  = vcc.Read_Volts();
      batteryPcnt = vcc.Read_Perc(VccMin, VccMax);
    
    }
    
    void presentation() {
      // Register binary input sensor to gw (they will be created as child devices)
      // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. 
      // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
      sendSketchInfo("BAL", "1.0");
      present(CHILD_ID_MAIL, S_DOOR);
      present(CHILD_ID_MAIL2, S_DOOR); 
      present(CHILD_ID_VOLT, S_MULTIMETER);
    }
    
    
    //  Check if digital input has changed and send in new value
    void loop() 
    {
      debouncer.update();
      debouncer2.update();
      
      // Get the update value
    uint8_t  value1 = debouncer.read();
    uint8_t  value2 = debouncer2.read();
      
     
      if (value1 != oldValueC1) {
         // Send in the new value
          gwSend = true;
    
         #ifdef MY_DEBUG
            Serial.println(value1);
         #endif   
         
         oldValueC1 = value1;
      }
    
        if (value2 != oldValueC2) {
         // Send in the new value
          gwSend = true;
    
         #ifdef MY_DEBUG
            Serial.println(value2);
         #endif   
         
         oldValueC2 = value2;
      }
    
     // **** Re-send value every X minutes **** 
        time = millis()/1000;
        
    //    if(time - sendTime >= COUNTER) {
    //    
    //    batteryV  = vcc.Read_Volts();
    //    batteryPcnt = vcc.Read_Perc(VccMin, VccMax);
    //   
    //
    //     #ifdef MY_DEBUG
    //        delay(2000);
    //        Serial.println(batteryPcnt);
    //     #endif    
    //     
    //    gwSend = true;
    //    sendTime = time;
    //    }
    
       if (gwSend == true) {
        
         send(msgMail.set(value1==LOW ? 1 : 0));
         send(msgMail2.set(value2==LOW ? 1 : 0));
         send(msgVolt.set(batteryV, 2));
         sendBatteryLevel(batteryPcnt);
         gwSend = false;
       }
      else {
      }
    
    sleep(0, CHANGE, SLEEP_TIME);
    
    } ```


  • @ghislain Am I missing something? I don't see anything having to do with an interrupt, just 2 debouncers. An interrupt would use attachInterrupt() and call an ISR (Interrupt Service Routine) which is a separate function in your sketch that would get called when the button gets pressed. On the Pro Mini boards, only pins 2 and 3 can be tied to interrupts, which is the two pins you are using. What did you want the interrupt to do?


  • Hardware Contributor

    @ghislain your node is waking up. To understand the log, select the "Build" menu item on this website, and chose "Log Parser" in the left column, then you can paste the log and get some full text descriptions of what is happening.

    Do not use debouncer if you are using sleep, instead at the beginning of the loop() method (so it will be called just after the sleep() ends) use a wait(value in ms) command that is long enough to allow the bouncing of the button to finish. Then you can just read the value of the input.

    You also have a problem with your sleep function, you are setting only interrupt 0 (the one that triggers the wake up in your log) but interrupt 1 is not set so the second button will not work.

    @dbemowsk said in Can't detect Interrupt on Arduino Mini Pro or can't wake MySensor ?:

    @ghislain Am I missing something? I don't see anything having to do with an interrupt, just 2 debouncers.

    It's called by the sleep function of MySensors that he calls at the end of his script.



  • Thank you both for your answer.

    To resume what i want to do, i want to watch when mail is arrived in my outdoor mailbox, i will do that with 2 "door sensor".

    @Nca78 if i well understood that you say, interrupt was catched and wake up arduino but value1 (the status of the "door sensor") wasn't updated and so my code doesn't do anything and it fall asleep again. Is that correct ?

    I know, i just have one interrupt else i'm using 2, but it was for test with one firstly.

    I will try to do in another way as you say.

    thanks



  • This is my change and it is working, thank you for your help.

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * DESCRIPTION
     *
     * Simple binary switch example 
     * Connect button or door/window reed switch between 
     * digitial I/O pin 3 (BUTTON_PIN below) and GND.
     * http://www.mysensors.org/build/binary
     */
    
    
    // Enable debug prints to serial monitor
    //#define MY_DEBUG 
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    #define MY_RF24_PA_LEVEL RF24_PA_LOW
    #define MY_NODE_ID 8
    
    
    #include <SPI.h>
    #include <MySensors.h>
    #include <Vcc.h>
    
    
    #define CHILD_ID_MAIL 0
    #define CHILD_ID_MAIL2 1
    #define CHILD_ID_VOLT 2                  // Child id for battery reading
    
    #define BUTTON_PIN 2  // Arduino Digital I/O pin for button/reed switch
    #define BUTTON2_PIN 3  // Arduino Digital I/O pin for button/reed switch
    #define SLEEP_TIME 1 * 60 * 1000UL
    
    
    
    int oldValueC1=-1;
    int oldValueC2=-1;
    boolean gwSend = true;
    
    const float VccMin   = 3;           // Minimum expected Vcc level, in Volts.
    const float VccMax   = 4;           // Maximum expected Vcc level, in Volts.
    const float VccCorrection = 1.0/1.0;  // Measured Vcc by multimeter divided by reported Vcc
    float batteryV = 0;
    int batteryPcnt = 0;
    Vcc vcc(VccCorrection);
    
    
    // Change to V_LIGHT if you use S_LIGHT in presentation below
    MyMessage msgMail(CHILD_ID_MAIL,V_TRIPPED);
    MyMessage msgMail2(CHILD_ID_MAIL2,V_TRIPPED);
    MyMessage msgVolt(CHILD_ID_VOLT, V_VOLTAGE);
    
    void setup()  
    {  
      // Setup the button
      pinMode(BUTTON_PIN, INPUT);
      pinMode(BUTTON2_PIN, INPUT);
      // Activate internal pull-up
      digitalWrite(BUTTON_PIN,HIGH);
      digitalWrite(BUTTON2_PIN,HIGH);
    
    
        #ifdef MY_DEBUG
          Serial.begin(115200);
        #endif    
      
     }
    
    void presentation() {
      // Register binary input sensor to gw (they will be created as child devices)
      // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. 
      // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
      sendSketchInfo("BAL", "1.0");
      present(CHILD_ID_MAIL, S_DOOR);
      present(CHILD_ID_MAIL2, S_DOOR); 
      present(CHILD_ID_VOLT, S_MULTIMETER);
    }
    
    
    //  Check if digital input has changed and send in new value
    void loop() 
    {
      wait(100);
      // Get the update value
    uint8_t  volet = digitalRead(BUTTON_PIN);
    uint8_t  porte = digitalRead(BUTTON2_PIN);
      
      #ifdef MY_DEBUG
            Serial.println(volet);
            Serial.println(porte);
         #endif   
     
      if (volet != oldValueC1) {
         // Send in the new value
          gwSend = true;
    
         #ifdef MY_DEBUG
            Serial.println(volet);
         #endif   
         
         oldValueC1 = volet;
      }
    
        if (porte != oldValueC2) {
         // Send in the new value
          gwSend = true;
    
         #ifdef MY_DEBUG
            Serial.println(porte);
         #endif   
         
         oldValueC2 = porte;
      }  
        
        batteryV  = vcc.Read_Volts();
        batteryPcnt = vcc.Read_Perc(VccMin, VccMax);
        send(msgVolt.set(batteryV, 2));
        sendBatteryLevel(batteryPcnt);
    
         #ifdef MY_DEBUG
            //delay(2000);
            Serial.println(batteryPcnt);
         #endif    
         
       
    
       if (gwSend == true) {
        
         send(msgMail.set(volet==LOW ? 1 : 0));
         send(msgMail2.set(porte==LOW ? 1 : 0));
         send(msgVolt.set(batteryV, 2));
         sendBatteryLevel(batteryPcnt);
         gwSend = false;
       }
      else {
      }
    
    sleep(0, FALLING, 1, FALLING, SLEEP_TIME);
    } 
    

Log in to reply
 

Suggested Topics

51
Online

11.4k
Users

11.1k
Topics

112.7k
Posts