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. What is the good wait() time ?

What is the good wait() time ?

Scheduled Pinned Locked Moved Development
waitwait push-button
15 Posts 6 Posters 1.3k Views 5 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.
  • scalzS Offline
    scalzS Offline
    scalz
    Hardware Contributor
    wrote on last edited by scalz
    #6

    when it's for presentation, it's not really a big deal to add such wait time. note for a a coincell batt powered node it would be better to use sleep..

    But in others application with some "critical" timing in user tasks, you could get some troubles like missing state changes, slower polling etc. as it doesn't make your sketch asynchronous..

    For longterm, I think it's not ideal to use such hack when getting comm issues. and also makes nodes slower (and perhaps jamming's easier too ?).

    1 Reply Last reply
    0
    • T tommies

      Hello,

      i have a node with 3 push-button in loop().
      without wait() , i don't receive messages from gateway.
      With wait(50) i receive message (but not all).
      with wait(500) i receive nothing.
      Is it normal ? I thought that wait() was for spending time for receive message. larger time should be larger time for receiving messages ?
      what is the ideal waiting time ?
      THnaks

      YveauxY Offline
      YveauxY Offline
      Yveaux
      Mod
      wrote on last edited by
      #7

      @tommies You could give message queueing a try:

      • Connect the nRF24 IRQ pin to pin 2 on your Arduino
      • add #define MY_RF24_IRQ_PIN (2)
      • add #define MY_RX_MESSAGE_BUFFER_FEATURE
      • add #define MY_RX_MESSAGE_BUFFER_SIZE (10)
      • that last value may be lower (e.g. 5) when running out of memory

      This will listen to the interrupt from the nRF24 when a message comes in and immediately pause the running code to retrieve the message.
      Then your code continues and any messages stored will be processed outside the loop() function automatically.
      The wait() call(s) can be removed from your code.
      It might interfere with your NeoPixel update though, but there's only one way to find out ;-)

      Refer to e.g. https://forum.mysensors.org/topic/7190/irq-pin-for-nrf24l01 for a discussion on message queueing.

      http://yveaux.blogspot.nl

      T 1 Reply Last reply
      1
      • alowhumA Offline
        alowhumA Offline
        alowhum
        Plugin Developer
        wrote on last edited by
        #8

        @scalz I add the wait to make sure the radio has enough power without having to resort to adding a capacitor.

        mfalkviddM scalzS 2 Replies Last reply
        0
        • alowhumA alowhum

          @scalz I add the wait to make sure the radio has enough power without having to resort to adding a capacitor.

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

          @alowhum I don't think any wait time will ensure sufficient power in a reliable way. The nrf is too sensitive to power fluctuations to be used without a capacitor.

          1 Reply Last reply
          1
          • T Offline
            T Offline
            tommies
            wrote on last edited by
            #10

            @yveaux
            interesting... i must take a look to this option.
            Thanks. :-)

            1 Reply Last reply
            0
            • alowhumA alowhum

              @scalz I add the wait to make sure the radio has enough power without having to resort to adding a capacitor.

              scalzS Offline
              scalzS Offline
              scalz
              Hardware Contributor
              wrote on last edited by scalz
              #11

              @alowhum said in What is the good wait() time ?:

              @scalz I add the wait to make sure the radio has enough power without having to resort to adding a capacitor.

              I already got it. But it seems you have a "design flaw", it's treating symptoms instead of root.. So it's not a great tip.
              For very simple case like a temperature sensor, it might seem handy and work, but not for all usercases, like I said, you add latency to your nodes.

              I prefer Yveaux advice. And if it's not enough:

              • hardware flaws
              • library bug..

              I also agree with mfalkvidd. If you don't want to tweak/solder stuff on any hw, then you might get troubles, or poor range when using different power supplies sources (noisy, etc) and wait() will be ineffective.

              1 Reply Last reply
              1
              • YveauxY Yveaux

                @tommies You could give message queueing a try:

                • Connect the nRF24 IRQ pin to pin 2 on your Arduino
                • add #define MY_RF24_IRQ_PIN (2)
                • add #define MY_RX_MESSAGE_BUFFER_FEATURE
                • add #define MY_RX_MESSAGE_BUFFER_SIZE (10)
                • that last value may be lower (e.g. 5) when running out of memory

                This will listen to the interrupt from the nRF24 when a message comes in and immediately pause the running code to retrieve the message.
                Then your code continues and any messages stored will be processed outside the loop() function automatically.
                The wait() call(s) can be removed from your code.
                It might interfere with your NeoPixel update though, but there's only one way to find out ;-)

                Refer to e.g. https://forum.mysensors.org/topic/7190/irq-pin-for-nrf24l01 for a discussion on message queueing.

                T Offline
                T Offline
                tommies
                wrote on last edited by
                #12

                @yveaux Did it. wired Pin 2, removed wait() in my loop... works like a Harry Potter enchantment.
                now i need to find another PCB board with IRQ pin connected !!
                damned !
                Thanks
                now i must change my gateay

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  tommies
                  wrote on last edited by
                  #13

                  I already use PIN2 and/or PIN3 as wake up interrupt to wake up node in sleeping sensors.
                  Is there any way to use interrupt in non sleeping node ?
                  By the way, it would avoid to use loop fonction to detect push button change state.

                  YveauxY 1 Reply Last reply
                  0
                  • T tommies

                    I already use PIN2 and/or PIN3 as wake up interrupt to wake up node in sleeping sensors.
                    Is there any way to use interrupt in non sleeping node ?
                    By the way, it would avoid to use loop fonction to detect push button change state.

                    YveauxY Offline
                    YveauxY Offline
                    Yveaux
                    Mod
                    wrote on last edited by
                    #14

                    @tommies MySensors is using regular Arduino attachInterrupt/detachInterrupt to handle the nRF24 interrupts, so any other pin compatible with the Arduino interrupt system should work.

                    http://yveaux.blogspot.nl

                    1 Reply Last reply
                    0
                    • alowhumA Offline
                      alowhumA Offline
                      alowhum
                      Plugin Developer
                      wrote on last edited by
                      #15

                      @scalz Interesting. But in reality I do see that adding a delay results in fewer NACK issues. What could that be?

                      I also always place my radios in the Nano Wireless Board, which solves pretty much all the issues with power and wiring I had before.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      23

                      Online

                      11.7k

                      Users

                      11.2k

                      Topics

                      113.1k

                      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