This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

ble button function

When i intially burn the code on dk, my dk should be in system off mode ie all functionality should be off. Then i want to press a button for 5 seconds with which the device blinks an led pattern. and if uptil  not 5 seconds button not pressed then nothing occurs and device remains in sleep mode

  • Hello,

    Then i want to press a button for 5 seconds with which the device blinks an led pattern. and if uptil  not 5 seconds button not pressed then nothing occurs and device remains in sleep mode

    Unfortunately there is no way to delay the wakeup by 5 seconds before waking up. If you configure the device to wake on an external event through the GPIOTE PORT event, or similar, it will start the full wakeup immediately when this happens. So, if you want to see that the button is still pressed after 5 seconds you will have to add a check for this that runs as the first thing upon wakeup from SYSTEM_OFF.
    Alternatively, you will need some external circuitry that delays the wakeup signal with 5 seconds, if it is crucial that the device does not wake up for the first 5 seconds.

    You can see SYSTEM_OFF sleep mode demonstrated in most of the ble_peripheral examples in the SDK, such as the Nordic UART peripheral example's sleep_mode_enter function. The bsp_btn_ble module is also used to extract the startup event, i.e seeing which button is still pressed upon startup. You could do the same and have a timer start upon startup, to see if the button is held for 5 seconds. If it is not, the device may return to sleep.

    Best regards,
    Karl

  • yes Karl u are getting exactly the way i want.

    i have seen the Nordic UART peripheral example's sleep_mode_enter function. Can u pls assist me in a code whereby i can check this:

    initially the device is in sleep mode as when the code is flashed. Then i press a button for 5 secs to see some led pattern or advertising should start and in case if button is not held for 5 secs then it should still remain in sleep mode and if beyond 5 seconds it should nt register anything

  • You can make use of the extracted startup event to start a timer that is either stopped upon release of the button before 5 seconds have passed - putting the device back to sleep - or that starts advertising and normal function if button is pressed for the entire 5 second period.
    The simplest way to do this I guess would be to have the 5 second expiration toggle a boolean to indicate that the button has been released too soon and the device should go back to sleep, or example.

    Please note what I said in my previous comment that there is no way to delay the wakeup by 5 seconds - the device will wake fully when you first press the button - but you may implement logic that differentiate whether the button is pressed for 5 seconds upon startup or not.
    The device will be fully awake and ready to do whatever processing in the 5 second period in which it is waiting to see if the button press lasts for 5 seconds. I would suggest having the device go into SYSTEM_ON sleep for this duration if nothing else is to be done. SYSTEM_ON sleep is demonstrated in the idle_state_handler function of the Nordic UART peripheral example.

    Best regards,
    Karl

  • can u give me a reference code so that i can start pls

  • You can take a look at these minimal powerdown examples in this repository. The examples are made for a very old SDK version, but the general approach will be the same as for the GPIOTE peripheral in the newer SDK versions.

    Start by going through the example and understanding the approach, and then continue with adding an app_timer that starts counting to 5 s upon wakeup and that could be interrupted by releasing the button, as written in my previous comment.

    Let me know if you encounter any issues, or have any questions to this!

    Best regards,
    Karl

Related