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

Add a supplementary button and led on Blinky android ap

How can I add an extra button and led on Blinky Android app ?

i did that for nrf-ble-blinky example, but I do not know what to do for the Android app

  • Hi

    How much experience do you have with Android app development?

    Have you downloaded the source code for the Android-nRF-Blinky app?

    The existing button is defined in the activity_blinky.xml file. Look for the Switch with ID "led_switch", and make another one with a different ID. You will also need to change the layout constraints to define where on the screen the switch should be placed, otherwise it will be placed on top of the existing switch. 

    Then you should go to BlinkyActivity.java and add some code for responding to input from the switch. Look at how the Switch mLed variable is handled in the code, and do something similar for your new button. 

    Best regards
    Torbjørn

  • Thank you for your answer
    i have good experiences with android studio but i dont know what i should do with NRF52 code. e.g. how can i send and receive a string to android app

  • Hi

    The LBS service is configured by ble_lbs.c, in the function called ble_lbs_init(..)

    Both the button and LED characteristic supports a single byte only, but you can change this by modifying the init_len and max_len fields in the add_char_params struct to a higher value, and making sure the is_var_len field is set to true to allow variably sized updates. 

    Then you should be able to send strings of varying lengths from the nRF52 side to the phone, and vice versa. 

    For reference please have a look at the ble_app_uart example which uses the ble_nus.c service implementation. It is very similar to the blinky service, except it uses variably sized characteristics for TX and RX, rather than single byte characteristics.

    Best regards
    Torbjørn

  • Thanks bro!