Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. [SOLVED] NRF24 can not sleep

[SOLVED] NRF24 can not sleep

Scheduled Pinned Locked Moved Development
10 Posts 3 Posters 2.8k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pavel Polititsky
    wrote on last edited by Yveaux
    #1

    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
    
    mfalkviddM 1 Reply Last reply
    0
    • P Pavel Polititsky

      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
      
      mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Pavel Polititsky
        wrote on last edited by
        #3

        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

        mfalkviddM 1 Reply Last reply
        0
        • P Pavel Polititsky

          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

          mfalkviddM Offline
          mfalkviddM Offline
          mfalkvidd
          Mod
          wrote on last edited by
          #4

          @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.

          P 1 Reply Last reply
          0
          • mfalkviddM mfalkvidd

            @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.

            P Offline
            P Offline
            Pavel Polititsky
            wrote on last edited by Pavel Polititsky
            #5

            @mfalkvidd it's possible... :smirk:
            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.

            mfalkviddM 1 Reply Last reply
            0
            • P Pavel Polititsky

              @mfalkvidd it's possible... :smirk:
              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.

              mfalkviddM Offline
              mfalkviddM Offline
              mfalkvidd
              Mod
              wrote on last edited by
              #6

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

              P maghacM 2 Replies Last reply
              0
              • mfalkviddM mfalkvidd

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

                P Offline
                P Offline
                Pavel Polititsky
                wrote on last edited by
                #7

                @mfalkvidd :astonished: Another module just fu...g works. Great thx!

                1 Reply Last reply
                1
                • mfalkviddM mfalkvidd

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

                  maghacM Offline
                  maghacM Offline
                  maghac
                  wrote on last edited by
                  #8

                  @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.

                  mfalkviddM P 2 Replies Last reply
                  0
                  • maghacM maghac

                    @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.

                    mfalkviddM Offline
                    mfalkviddM Offline
                    mfalkvidd
                    Mod
                    wrote on last edited by
                    #9

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

                    1 Reply Last reply
                    1
                    • maghacM maghac

                      @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.

                      P Offline
                      P Offline
                      Pavel Polititsky
                      wrote on last edited by
                      #10

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

                      1 Reply Last reply
                      1

                      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                      With your input, this post could be even better 💗

                      Register Login
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      11

                      Online

                      12.0k

                      Users

                      11.2k

                      Topics

                      113.4k

                      Posts


                      Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • MySensors
                      • OpenHardware.io
                      • Categories
                      • Recent
                      • Tags
                      • Popular