Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

Student Blinky Project Help

Hello,

As part of my Senior Project for graduation I am working using the Blinky example projects to learn about BLE implementation. As part of the project I need to add in functionality that will allow a second button to light up a second LED. I could use some guidance on this. I don't need the code written for me or anything, I just need help figuring out where to add in the extra characteristic and what other things I might need to modify. Any help would be appreciated! I am using SEGGER Embedded Studio, SDK 17, and the Blinky Central and Peripheral Examples. Thank you.



Parents
  • Hello,

    to learn about BLE implementation.

    Please do not hesitate to ask if you should have any questions about BLE development or implementations, we're happy to help you!

    As part of the project I need to add in functionality that will allow a second button to light up a second LED. I could use some guidance on this. I don't need the code written for me or anything, I just need help figuring out where to add in the extra characteristic and what other things I might need to modify.

    I assume you have already taken a look at the ble_blinky examples from the SDK since you mention them, where you can see exactly how you could implement the functionality you describe - it can however be hard to understand how they work just by looking at the code, without knowing the process that the code is implementing.
    In essence, the central example functions by initiating a connection to a advertising peripheral that fits its device name filter, which is "Nordic_Blinky" in this case, and then enabling CCCD for the specific lbs service's characteristic.
    Enabling CCCD means that you enable notifications, which translates to 'send me a message whenever the value of this characteristic changes'.
    Thus, the peripheral is able to alert the central device about a button press through this characteristic, so that it may update its LED status. Since the central is the 'master' in the communication between the devices it is able to update the peripheral device on any of its own LED status changes whenever it would like.

    I highly recommend reading through the beginner's guide to advertising, and the following services and characteristics parts of the tutorial series, to better understand how the communication is structured and implemented.
    Understanding the BLE blinky code will be much easier after you have read through these tutorials.
    Please do not hesitate to ask if you should have any questions!

    Best regards,
    Karl

  • Hi Karl,

    Thanks for your reply. I am still struggling with this a little bit. I am trying to add a second button characteristic and a second LED characteristic to the LBS service.

     

     // Add Button characteristic.
        memset(&add_char_params, 0, sizeof(add_char_params));
        add_char_params.uuid              = LBS_UUID_BUTTON_CHAR;
        add_char_params.uuid_type         = p_lbs->uuid_type;
        add_char_params.init_len          = sizeof(uint8_t);
        add_char_params.max_len           = sizeof(uint8_t);
        add_char_params.char_props.read   = 1;
        add_char_params.char_props.notify = 1;
    
        add_char_params.read_access       = SEC_OPEN;
        add_char_params.cccd_write_access = SEC_OPEN;
    
        err_code = characteristic_add(p_lbs->service_handle,
                                      &add_char_params,
                                      &p_lbs->button_char_handles);
        if (err_code != NRF_SUCCESS)
        {
            return err_code;
        }
    
        // Add Button2 characteristic.
        memset(&add_char_params, 0, sizeof(add_char_params));
        add_char_params.uuid              = LBS_UUID_BUTTON2_CHAR;
        add_char_params.uuid_type         = p_lbs->uuid_type;
        add_char_params.init_len          = sizeof(uint8_t);
        add_char_params.max_len           = sizeof(uint8_t);
        add_char_params.char_props.read   = 1;
        add_char_params.char_props.notify = 1;
    
        add_char_params.read_access       = SEC_OPEN;
        add_char_params.cccd_write_access = SEC_OPEN;
    
        err_code = characteristic_add(p_lbs->service_handle,
                                      &add_char_params,
                                      &p_lbs->button_char_handles);
        if (err_code != NRF_SUCCESS)
        {
            return err_code;
        }
    
        // Add LED characteristic.
        memset(&add_char_params, 0, sizeof(add_char_params));
        add_char_params.uuid             = LBS_UUID_LED_CHAR;
        add_char_params.uuid_type        = p_lbs->uuid_type;
        add_char_params.init_len         = sizeof(uint8_t);
        add_char_params.max_len          = sizeof(uint8_t);
        add_char_params.char_props.read  = 1;
        add_char_params.char_props.write = 1;
    
        add_char_params.read_access  = SEC_OPEN;
        add_char_params.write_access = SEC_OPEN;
    
        return characteristic_add(p_lbs->service_handle, &add_char_params, &p_lbs->led_char_handles);
    
        // Add LED2 characteristic.
        memset(&add_char_params, 0, sizeof(add_char_params));
        add_char_params.uuid             = LBS_UUID_LED2_CHAR;
        add_char_params.uuid_type        = p_lbs->uuid_type;
        add_char_params.init_len         = sizeof(uint8_t);
        add_char_params.max_len          = sizeof(uint8_t);
        add_char_params.char_props.read  = 1;
        add_char_params.char_props.write = 1;
    
        add_char_params.read_access  = SEC_OPEN;
        add_char_params.write_access = SEC_OPEN;
    
        return characteristic_add(p_lbs->service_handle, &add_char_params, &p_lbs->led_char_handles);

    LED2 and BUTTON2 are my new characteristics, but I guess I'm not certain that I understand if this will work or not. Further, this is the current handler for the LED writes:

    static void led_write_handler(uint16_t conn_handle, ble_lbs_t * p_lbs, uint8_t led_state)
    {
        if (led_state)
        {
            bsp_board_led_on(LEDBUTTON_LED);
            NRF_LOG_INFO("Received LED ON!");
        }
        else
        {
            bsp_board_led_off(LEDBUTTON_LED);
            NRF_LOG_INFO("Received LED OFF!");
        }
    }

    I notice that this will never turn on my LEDBUTTON2_LED which I have defined along with LED_BUTTON2_BUTTON.

    I guess I just don't know where to go form here.

    Thanks!

    -Paul

  • Hello again, Paul

    Briefly looking through your code it seems to me that your second characteristic is never actually added, since the function will return immediately after having added the first LED characteristic - thus never making it to the LED2 characteristic.

    Please fix this, and see if it resolves your issue.
    If it does not, please elaborate further on your issue, the behavior you are seeing and how it differs from what you would have expected.

    Best regards,
    Karl

  • Karl,

    That was definitely the issue and my project now works exactly as I intended it to. Thank you so much for your help! You've been great!

    -Paul

  • That's great, Paul!
    No problem at all, I am happy to help! :)
    I am glad to hear that it now works as intended.

    Please do not hesitate to open another ticket if you should encounter any other issues or questions in the future.

    Good luck with your development!

    Best regards,
    Karl

Reply Children
No Data
Related