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

Parents
  • 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

Reply
  • 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

Children
  • 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

  • I am unable to create a timer setting for  button press which detects that 5 seconds when done the device will start advertising. in example u shared in that 5 seconds thing is not there. pls assist at earliest

  • Hello,

    Ridhi said:
    I am unable to create a timer setting for  button press which detects that 5 seconds when done the device will start advertising. in example u shared in that 5 seconds thing is not there.

    Yes, the example here only shows the powerdown and wake-on-button-press GPIOTE PORT event, you will have to add this along with the app_timer to your BLE example if not already present. Keep in mind that I recommended this approach when I thought you just wanted to blink some LEDs - not knowing that you wanted to do advertising following the 5 second press. In this case I would instead recommend that you begin with one of the BLE examples, and then merge this functionality into it.

    I see from your other ticket that you are using the bsp module instead of the app_timer and app_buttons, which means you likely already are working out of an SDK example. Which example is this?
    If you wish to use the bsp module you can change the BSP_LONG_PUSH_TIMEOUT_MS in bsp_config to 5000 ms, and then use the bsp_event_to_button_action_assign function to assign an event to the button's long push, and then have your bsp_event_handler in main.c begin advertising when it receives this event.
    Try this, and let me know if you are able to start advertising following a 5 second button press.
    Keep in mind that all 'long button presses' then will be 5 seconds long.

    Best regards,
    Karl

Related