2.2.0-rc.1 sleep not working as expected...



  • Hi,

    I have a pro mini with 1MHz bootloader (running at 3.3v to test).
    I am using the door sensor from the 'build' page, with the addition of a sleep function as it will be battery powered.
    Here is the code...

    // 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_HIGH   //Options are: RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH or RF24_PA_MAX
    //#define MY_RADIO_RFM69
    //#define MY_NODE_ID 1
    #include <SPI.h>
    #include <MySensors.h>
    #include <Bounce2.h>
    unsigned long SLEEP_TIME = 0; // Sleep time between reports (in milliseconds)
    #define CHILD_ID 3
    #define BUTTON_PIN  3  // Arduino Digital I/O pin for button/reed switch
    
    Bounce debouncer = Bounce(); 
    int oldValue=-1;
    
    // Change to V_LIGHT if you use S_LIGHT in presentation below
    MyMessage msg(CHILD_ID,V_TRIPPED);
    
    void setup()  
    {  
      // Setup the button
      pinMode(BUTTON_PIN,INPUT);
      // Activate internal pull-up
      digitalWrite(BUTTON_PIN,HIGH);
    
      // After setting up the button, setup debouncer
      debouncer.attach(BUTTON_PIN);
      debouncer.interval(5);
      Serial.begin(4800);
    }
    
    void presentation() {
      sendSketchInfo("Door Sensor", "1.0");
      // 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.
      present(CHILD_ID, S_DOOR);  
    }
    
    
    //  Check if digital input has changed and send in new value
    void loop() 
    {
      debouncer.update();
      // Get the update value
      int value = debouncer.read();
    
      if (value != oldValue) {
         // Send in the new value
         send(msg.set(value==HIGH ? 1 : 0));
         oldValue = value;
         Serial.print("Value change  ");
         Serial.println(value);
      }
        // Sleep until interrupt comes in on motion sensor. Send update every two minute.
     // sleep(digitalPinToInterrupt(BUTTON_PIN), CHANGE, SLEEP_TIME);
    }
    

    With this setup it will only work with sleep commented out (ie no sleep function). As soon as I remove the comment from sleep it fails to send on pin change.

    I invite anyone to test this out for themselves and tell me if it works or not for you.

    Thanks for any help....



  • Not sure, but your problem may be related to the use of debounce() and sleep().
    As on PINs 2+3 there is already some sort of debouncing from mcu side, you may just use the same code as in the motion sensor example without further debouncing.



  • @rejoe2

    Thanks for the reply.

    That is bizzare. I would expect the two sketches to be the same as it is basically the same thing (a button press).

    I modified the motion to report as a door, here is the 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.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - Henrik Ekblad
     *
     * DESCRIPTION
     * Motion Sensor example using HC-SR501
     * http://www.mysensors.org/build/motion
     *
     */
    
    // Enable debug prints
    // #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    #define MY_RF24_PA_LEVEL RF24_PA_HIGH  //Options are: RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH or RF24_PA_MAX
    
    //#define MY_RADIO_NRF5_ESB
    //#define MY_RADIO_RFM69
    //#define MY_RADIO_RFM95
    
    #include <MySensors.h>
    
    uint32_t SLEEP_TIME = 0; // Sleep time between reports (in milliseconds)
    #define DIGITAL_INPUT_SENSOR 3   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
    #define CHILD_ID 1   // Id of the sensor child
    
    // Initialize motion message
    MyMessage msg(CHILD_ID, V_TRIPPED);
    
    void setup()
    {
        pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
    }
    
    void presentation()
    {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Door Sensor", "2.0");
    
        // Register all sensors to gw (they will be created as child devices)
        present(CHILD_ID, S_DOOR);
    }
    
    void loop()
    {
        // Read digital motion value
        bool tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
    
        Serial.println(tripped);
        send(msg.set(tripped?"1":"0"));  // Send tripped value to gw
    
        // Sleep until interrupt comes in on motion sensor. Send update every two minute.
        sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
    }
    

    I will try and get more time to test this out again. Maybe tomorrow. I wonder if having the nrf24l01+ irq pin attached to the pro mini has some effect? Again will test out when I can.



  • I have used that same debouncer library but not in a battery powered node. I'm not sure I fully understand how the debouncer library and the sleep in interrupt mode may play together, but I'd bet the problem is there...

    You may want to ask the author on the official questions thread here.



  • @manutremo

    Thanks for the input - I did get further with this, but have different issues now. I will get back if I find a solution. I hope to get time this weekend to have a good look into my code and see what the issue might be. Failing this I will post how far I get and ask for more input from the friendly helpful people on here. :)



  • @skywatch said in 2.2.0-rc.1 sleep not working as expected...:

    I wonder if having the nrf24l01+ irq pin attached to the pro mini has some effect? Again will test out when I can.

    The irq@nRF is not used yet within MySensors. Afik this is planned for version 3.0 (don't have any link wrt this at the moment).





  • @skywatch Thx for clarification.
    Seems this is a very recent development (I only knew this to be planed for V3, so things are ahead of theit time..). Nevertheless, most users will not yet have activated the MY_RX_MESSAGE_BUFFER_FEATURE.


  • Mod

    @rejoe2 it is a feature currently mainly useful for gateways. Furthermore, only avr is supported, as far as I know.
    It has been in for over a year iirr.


Log in to reply
 

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.