This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

BLE blinky using NRF Connect SDK

Hi 

 I need to Send one character from mobile. based on the character I need to glow the LEDs which is placed on DK. How can I achieve this is there any sample available for reference?

Thanks & Regards

Navin

Parents
  • Hi Navin,

    I recommend you use the ble/peripheral_uart sample, and merge it with this UART topic from Nordics Academy where you can toggle the lights with input from a terminal.
    Check these samples out one by one first before you merge them and see they work. Then move on to integrating the functions from the Academy-sample into the peripheral sample.

    Let me know if this is of any help!

    Kind regards,
    Andreas

  • Hi andreas,

    I have already checked those sample. Actually, i don't know where the data is received in that from ble. If I understand that i can do it other things.

    Thanks & Regards,

    Navin

  • Hi Navin,

    Mr.NCK said:
    I have already checked those sample.

    Thats good.

    Mr.NCK said:
    Actually, i don't know where the data is received in that from ble.

    I am not sure if I understand what you mean by this, so I am going to answer the two things I think you might be meaning. Please correct me if I have misunderstood.

    1) Did you mean that you built, flashed and tried the "Testing" steps in the sample and did not see any data? 

    2) Did you mean that you don't see where in the code the ble data is sent? If so, the received part of the code can be seen at line 451 in function "static void bt_receive_cb(...)"  the sample, which uses Nordic UART Service (NUS), where you can see more details on how to receive the data in nus.c.

    Let me know if this helped clarify things for you or if I misunderstood what you did not understand.

    Kind regards,
    Andreas

  • HI andreas,

     Point 2 was right, I have check the below mentioned lines

    static void bt_receive_cb(struct bt_conn *conn, const uint8_t *const data,
    uint16_t len)
    {
    int err;
    char addr[BT_ADDR_LE_STR_LEN] = {0};

    bt_addr_le_to_str(bt_conn_get_dst(conn), addr, ARRAY_SIZE(addr));

    LOG_INF("Received data from: %s", log_strdup(addr));

    for (uint16_t pos = 0; pos != len;) {
    struct uart_data_t *tx = k_malloc(sizeof(*tx));

    if (!tx) {
    LOG_WRN("Not able to allocate UART send data buffer");
    return;
    }

    /* Keep the last byte of TX buffer for potential LF char. */
    size_t tx_data_size = sizeof(tx->data) - 1;

    if ((len - pos) > tx_data_size) {
    tx->len = tx_data_size;
    } else {
    tx->len = (len - pos);
    }

    memcpy(tx->data, &data[pos], tx->len);

    pos += tx->len;

    /* Append the LF character when the CR character triggered
    * transmission from the peer.
    */
    if ((pos == len) && (data[len - 1] == '\r')) {
    tx->data[tx->len] = '\n';
    tx->len++;
    }

    err = uart_tx(uart, tx->data, tx->len, SYS_FOREVER_MS);
    if (err) {
    k_fifo_put(&fifo_uart_tx_data, tx);

    }

    }
    }

    In the above lines, where can I check the received values? Kindly explain the flow.

    Thanks & Regards

    Navin

  • Hi,

    The function that sends the bytes through UART is uart_tx(..). You can check the values by performing the steps in the testing part of the documentation for the sample aswell as reading up on how tx and rx in UART works in this thorough guide

    Kind regards 

    Andreas

  • Hi Andreas,

     Thank you, Now I can able to control the device but I can't able to control the gpio in that sample. Kindly, Let me know how can I achieve this.

    Thanks

    Navin

  • Hi Navin,

    Mr.NCK said:
    Let me know how can I achieve this.

    This lesson contains what you need to learn how to use the GPIO interface. Use this with the peripheral_uart sample and the UART topic I linked in the previous reply.

    What you want to do is to in steps
    1) Implement the functionality that allows you to send a something over bluetooth/UART (peripheral_uart and central_uart are great for this)
    2) Use what is sent over Bluetooth/UART as arguments in a callback function to trigger what leds are supposed to be triggered. (Academy UART and GPIO  topics). Take a closer look at this function from the UART exercise to see how you can implement this.

    static void uart_cb(const struct device *dev, struct uart_event *evt, void *user_data)
    {
        switch (evt->type) {
        case UART_RX_RDY:
            if((evt->data.rx.len) == 1){
                if(evt->data.rx.buf[evt->data.rx.offset] == '1')
                gpio_pin_toggle(leds,PIN0);
            else if (evt->data.rx.buf[evt->data.rx.offset] == '2')
                gpio_pin_toggle(leds,PIN1);
            else if (evt->data.rx.buf[evt->data.rx.offset] == '3')
                gpio_pin_toggle(leds,PIN2);
            break;
        }
        case UART_RX_DISABLED:
            uart_rx_enable(dev ,rx_buf,sizeof rx_buf,RECEIVE_TIMEOUT);
            break;
        default:
            break;
        }
    }

    This function reads the input and toggles the lights corresponding to the input char. Do the same, but only with button presses instead according to 3)

    3) Investigate reading buttons and controlling LEDS to see how you can 

    4) Change 2) to send button presses instead of sending a user written char to trigger the light, i.e merge 2) with 3) 

    I hope this helps!

    Kind regards,
    Andreas

Reply
  • Hi Navin,

    Mr.NCK said:
    Let me know how can I achieve this.

    This lesson contains what you need to learn how to use the GPIO interface. Use this with the peripheral_uart sample and the UART topic I linked in the previous reply.

    What you want to do is to in steps
    1) Implement the functionality that allows you to send a something over bluetooth/UART (peripheral_uart and central_uart are great for this)
    2) Use what is sent over Bluetooth/UART as arguments in a callback function to trigger what leds are supposed to be triggered. (Academy UART and GPIO  topics). Take a closer look at this function from the UART exercise to see how you can implement this.

    static void uart_cb(const struct device *dev, struct uart_event *evt, void *user_data)
    {
        switch (evt->type) {
        case UART_RX_RDY:
            if((evt->data.rx.len) == 1){
                if(evt->data.rx.buf[evt->data.rx.offset] == '1')
                gpio_pin_toggle(leds,PIN0);
            else if (evt->data.rx.buf[evt->data.rx.offset] == '2')
                gpio_pin_toggle(leds,PIN1);
            else if (evt->data.rx.buf[evt->data.rx.offset] == '3')
                gpio_pin_toggle(leds,PIN2);
            break;
        }
        case UART_RX_DISABLED:
            uart_rx_enable(dev ,rx_buf,sizeof rx_buf,RECEIVE_TIMEOUT);
            break;
        default:
            break;
        }
    }

    This function reads the input and toggles the lights corresponding to the input char. Do the same, but only with button presses instead according to 3)

    3) Investigate reading buttons and controlling LEDS to see how you can 

    4) Change 2) to send button presses instead of sending a user written char to trigger the light, i.e merge 2) with 3) 

    I hope this helps!

    Kind regards,
    Andreas

Children
No Data
Related