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

Using GPIO as button

Hello,

I am trying to understand how to use an external button. In the first stage I am trying to replace the functionality of button0 on the DK with a GPIO.

I took the peripheral\BSP example and made the following changes:

1. pca10056.h:

       I replaced the line:

       #define BUTTON_1       11

       with the following line:

       #define BUTTON_1 NRF_GPIO_PIN_MAP(1, 3)

2. main.c:

      Added the lines:

     #define newPin NRF_GPIO_PIN_MAP(1, 3)

     nrf_gpio_cfg_input(newPin, NRF_GPIO_PIN_PULLUP);

I expected that whenever I connect the 5V on the board to pin 1.3, the button press event will fire. But it doesn't.

Any advice?

Parents Reply Children
  • I used the VDD from the board instead of the 5V. It works fine now, thanks for the help

  • I now have a different problem. I can replace one of the existing buttons with my external button but I don't succeed to use it in addition to the existing ones.
    Here are the changes I made.
    In pca10056.h:
    ==============
    modified:
       #define BUTTONS_NUMBER 5
    added:
       #define BUTTON_5       NRF_GPIO_PIN_MAP(1,6)
       #define BUTTONS_LIST { BUTTON_1, BUTTON_2, BUTTON_3, BUTTON_4, BUTTON_5 }
       #define BSP_BUTTON_4   BUTTON_5
    In sdk_config.h:
    ================
    modified:
       #define GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS 5
    In main.c:
    ========
    Added:
       #define newPin NRF_GPIO_PIN_MAP(1, 6)
       inside bsp_evt_handler():
          case BSP_EVENT_KEY_4
       in main():
          nrf_gpio_cfg_input(newPin, NRF_GPIO_PIN_PULLUP);
  • Hi, 

    I tested with the changes he posted in DevZone, it is working fine. I get a BSP_EVENT_KEY_4 event when I connect P1.06 to GND (We tested in this way because we don't have an external button). I did not use nrf_gpio_cfg_input(newPin, NRF_GPIO_PIN_PULLUP); in main. I do not see what good that should do, but he BSP library will configure the buttons correctly. 

    -Amanda H

Related