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

Controlling GPIO via UART on BLE

Hello

I am looking to make a program on nrf52 in which i send various values from nrf UART app on a mobile, and each value controls a LED on a GPIO. For example, sending 1 turns on the LED, 2 turns off, 3 blinks. Can you please provide me of a reference link which can help me in making this program.

Basically on UART BLE program, i want to include something like if the value in UART buffer=1, set gpio pin x= 1.

thanks in advance and for your time and help

Parents
  • For turning LED ON/OFF you can use something like that:

    ...   
      #define LED1 17
      #define LED2 18
    
      int main(void)
      {
    
          nrf_gpio_cfg_output(LED1);
          nrf_gpio_cfg_output(LED2);
    
          while (true)
          {
             nrf_gpio_pin_clear(LED1); //LED ON
             nrf_gpio_pin_set(LED2);    //LED OFF
             nrf_delay_ms(500);
             nrf_gpio_pin_set(LED1);     //LED ON
             nrf_gpio_pin_clear(LED2);   //LED OFF
             nrf_delay_ms(500);
          }
      }
    

    For blinking LED with BLE UART: use example ...\SDK12.2_full\examples\ble_peripheral\ble_app_uart\

    And modify this function:

    static void nus_data_handler(ble_nus_t * p_nus, uint8_t * p_data, uint16_t length)
    {
        #define LED1 17
        for (uint32_t i = 0; i < length; i++)
        {
            if (p_data[i]=='1')
            {
               nrf_gpio_cfg_output(LED1);
               nrf_gpio_pin_clear(LED1);
            }
            if (p_data[i]=='0')
            {
               nrf_gpio_cfg_output(LED1);
               nrf_gpio_pin_set(LED1);
            }
            while (app_uart_put(p_data[i]) != NRF_SUCCESS);
        }
        while (app_uart_put('\r') != NRF_SUCCESS);
        while (app_uart_put('\n') != NRF_SUCCESS);
    }
    

    Then when you send 1 the LED turn ON and when you send 0 the LED turn OFF

  • I've just tested the example in my updated answer, it works, then you can rewrite to have something clean. In Android I use nRF UART 2.0 from nordicsemi.

Reply Children
No Data
Related