nRF52840 Dongle - Library - Multiple Delays Without Blocking Code Execution

Is there any pre-existing library similar to the Arduino avdweb_VirtualDelay library available for the Nordic Semiconductor nRF52840 Dongle?

I do see the procedure on how to make a library over here, but I'm looking for one that pre-exists if possible.

  • Hi,

    I am not familiar with the Arduino VirtualDelay library from before, but looking at how it works I cannot say I have seen something similar before. Is it a reason you want to use this and not other approaches?

    If you are using the nRF Connect SDK, that consists of Zephyr RTOS, where you would typically solve this by other means, for instance using work queues with delayable work, or using separate threads with k_sleep or similar (though blocking in only blocks the thread were it is used, and not other threads).

  • Well, I'm new to RTOS so I really don't know what options I should be approaching with or best practices.  I was wondering maybe if this should be handled with multiple threads so that even if the thread is sleeping it doesn't block any other tasks.  If you have any suggestions on what options I should be approaching I'm open ears.

    So in my case I'm needing to read data from a sensor every X minutes and then transmit the accumulated data so far very Y minutes.  A button will be also involved where the sensor data will be collected immediately and then transmitted immediately which will then reset the cycle for collection and transmission.  With a sleeping thread the button will not be detected to be pressed.

  • Hi,

    I see. You are right that a sleeping thread doe snot block other threads. So it very often makes sense to use multiple threads (particularily when using blocking API calls but you want other work to be done while waiting for teh call to return, or similar). If you are new to these concepts I recomend you go through the nRF Connect SDK Fundamentals and Intermediate courses on DevAcademy.

    Frivolous4121 said:
    With a sleeping thread the button will not be detected to be pressed.

    For the button you probably want to use a GPIO interrupt instead of polling, so sleeping or not should not matter I assume? You can see an example of using pin interrupt in the basic button sample.

  • Thanks, I'll take the time to go through the DevAcademy content as I seem to have the wrong paradigm approach to development which seems to conflict with what is needed on RTOS systems.

    Side note: I also discovered Nordic Semiconductor AI and have found it overwhelmingly helpful with figuring out fine details that I can't find answers to as well as examples to help me grasp what approach I should be taking.

Related