[SOLVED] NRF24 can not sleep



  • Hi
    Several days im trying to build radio button using example for binary switch
    But at final I got the trouble with power consumption by NRF24
    328P was sleeping well and take only ~0.2uA. But NRF24 module still powered up with current ~800uA (sometimes 15mA, by chance) This current was measured on the power pin of NRF
    So, how to force it to sleep?
    Thx

    My code:

    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_NRF5_ESB
    //#define MY_RADIO_RFM69
    //#define MY_RADIO_RFM95
    
    #include <MySensors.h>
    #include <avr/sleep.h>
    
    #define SKETCH_NAME "Binary Sensor"
    #define SKETCH_MAJOR_VER "1"
    #define SKETCH_MINOR_VER "0"
    
    #define PRIMARY_CHILD_ID 3
    #define SECONDARY_CHILD_ID 4
    
    #define PRIMARY_BUTTON_PIN 2   // Arduino Digital I/O pin for button/reed switch
    #define SECONDARY_BUTTON_PIN 3 // Arduino Digital I/O pin for button/reed switch
    
    #if (PRIMARY_BUTTON_PIN < 2 || PRIMARY_BUTTON_PIN > 3)
    #error PRIMARY_BUTTON_PIN must be either 2 or 3 for interrupts to work
    #endif
    #if (SECONDARY_BUTTON_PIN < 2 || SECONDARY_BUTTON_PIN > 3)
    #error SECONDARY_BUTTON_PIN must be either 2 or 3 for interrupts to work
    #endif
    #if (PRIMARY_BUTTON_PIN == SECONDARY_BUTTON_PIN)
    #error PRIMARY_BUTTON_PIN and BUTTON_PIN2 cannot be the same
    #endif
    #if (PRIMARY_CHILD_ID == SECONDARY_CHILD_ID)
    #error PRIMARY_CHILD_ID and SECONDARY_CHILD_ID cannot be the same
    #endif
    
    
    
    // Change to V_LIGHT if you use S_LIGHT in presentation below
    MyMessage msg(PRIMARY_CHILD_ID, V_TRIPPED);
    MyMessage msg2(SECONDARY_CHILD_ID, V_TRIPPED);
    
    void setup()
    {
    	// Setup the buttons
    	pinMode(PRIMARY_BUTTON_PIN, INPUT);
    	pinMode(SECONDARY_BUTTON_PIN, INPUT_PULLUP);
    }
    
    void presentation()
    {
    	sendSketchInfo(SKETCH_NAME, SKETCH_MAJOR_VER "." SKETCH_MINOR_VER);
    	present(PRIMARY_CHILD_ID, S_DOOR);
    	present(SECONDARY_CHILD_ID, S_DOOR);
    }
    
    void wake ()
    {
      // cancel sleep as a precaution
      sleep_disable();
      // precautionary while we do other stuff
      detachInterrupt (0);
    }  // end of wake
    
    // Loop will iterate on changes on the BUTTON_PINs
    void loop()
    {
    	uint8_t value;
    	static uint8_t sentValue=2;
    	static uint8_t sentValue2=2;
    
    	sleep(5);
    
    	value = !digitalRead(PRIMARY_BUTTON_PIN);
    
    	if (value != sentValue) {
    		// Value has changed from last transmission, send the updated value
    		send(msg.set(value==LOW));
    		sentValue = value;
        sleepNow(); // sleep function called here
    	}
      
      sleepNow();
      }
      
    
    void sleepNow() // here we put the arduino to sleep
    {
       ADCSRA = 0;  
      
      set_sleep_mode (SLEEP_MODE_PWR_DOWN);  
      sleep_enable();
    
      noInterrupts ();
     
      attachInterrupt (0, wake, RISING);
      EIFR = bit (INTF0);  // clear flag for interrupt 0
     
      // BODS must be set to one and BODSE must be set to zero within four clock cycles
      MCUCR = bit (BODS) | bit (BODSE);
      // The BODS bit is automatically cleared after three clock cycles
      MCUCR = bit (BODS); 
     
      interrupts ();  // one cycle
      sleep_cpu ();   // one cycle
    
      } // end of loop
    

  • Mod

    @pavel-polititsky Mysensors has a built-in sleep function, that will turn off the nrf24. Use that and throw away all the complicated code 😉



  • It is just result of my experiments, builtin mysensors sleep function works the same. Also 800uA to NRF
    I' ve cheked right now. NRF consuming ~800uA in all examples.
    Its not posible to use battaries power


  • Mod

    @pavel-polititsky there have been a few cases where people have purchased bad nrf24 clones that wouldn't go to sleep properly. Maybe you stumbled on that variant.



  • @mfalkvidd it's possible... 😏
    But in this case I want to know exactly how much consumes original module with any example... Then I will try to replace several modules.


  • Mod

    @pavel-polititsky 900nA (yes nA, not µA)



  • @mfalkvidd 😲 Another module just fu...g works. Great thx!



  • @mfalkvidd How do you measure such low currents? I have the problems with some nodes that are consuming way too much power and I'd like to check them.


  • Mod

    @maghac I don't. But the most accurate way seems to be to get a uCurrent gold.



  • @maghac Im using mastech MY65 and I can measure ~0.1uA minimal current with some error


Log in to reply
 

Suggested Topics

  • 1
  • 10
  • 6
  • 2
  • 1
  • 2

48
Online

11.4k
Users

11.1k
Topics

112.7k
Posts