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

BLE accelerometer

Greetings,

I'm using nRF52 DK to transfer LIS3DH accelerometer data in Bluetooth. I successfully managed to establish an I2C connection with my sensor, I get my XYZ values. Now I want to send the data in Bluetooth, I'm a bit confused about what to do next. Is there any example program in SDK that will help me? or if you can suggest to me some tutorial that would be helpful too. I'm a beginner, so any advice or suggestions are welcome. Thank you.

Parents
  • Hi,

    It is possible to send the values as a string using Nordic UART Service (NUS). There is an example available in the SDK: UART/Serial Port Emulation over BLE

    If you want to create your own custom service for sending accelerometer data, please have a look at the BLE tutorials. These should be most useful:

    Best regards,
    Jørgen

  • Thank you for your information. I fixed the driver issue. As per your advice, I'm trying to use app_ble_uart to send my TWI sensor data. Can I just use the NUS function to send the data or should I program the ble services and events to function properly? Because I called the function ble_nus_data_send into my sensor read and it didn't work.

    void twim_handler(nrfx_twim_evt_t const * p_event, void * p_context)
    {

    static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
    static uint8_t index = 0;
    uint32_t err_code;

    switch (p_event->type)
    {
    case NRFX_TWIM_EVT_DONE:
    UNUSED_VARIABLE(MPU6050_ReadAcc( &data_array[index]));
    index++;

    if ((data_array[index - 1] == '\n') ||
    (data_array[index - 1] == '\r') ||
    (index >= m_ble_nus_max_data_len))
    {
    if (index > 1)
    {
    NRF_LOG_DEBUG("Ready to send data over BLE NUS");
    NRF_LOG_HEXDUMP_DEBUG(data_array, index);

    do
    {
    uint16_t length = (uint16_t)index;
    err_code = ble_nus_data_send(&m_nus, data_array, &length, m_conn_handle);
    if ((err_code != NRF_ERROR_INVALID_STATE) &&
    (err_code != NRF_ERROR_RESOURCES) &&
    (err_code != NRF_ERROR_NOT_FOUND))
    {
    APP_ERROR_CHECK(err_code);
    }
    } while (err_code == NRF_ERROR_RESOURCES);
    }

    index = 0;
    }
    break;

    m_xfer_done = true;
    break;
    default:
    break;
    }
    }

Reply
  • Thank you for your information. I fixed the driver issue. As per your advice, I'm trying to use app_ble_uart to send my TWI sensor data. Can I just use the NUS function to send the data or should I program the ble services and events to function properly? Because I called the function ble_nus_data_send into my sensor read and it didn't work.

    void twim_handler(nrfx_twim_evt_t const * p_event, void * p_context)
    {

    static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
    static uint8_t index = 0;
    uint32_t err_code;

    switch (p_event->type)
    {
    case NRFX_TWIM_EVT_DONE:
    UNUSED_VARIABLE(MPU6050_ReadAcc( &data_array[index]));
    index++;

    if ((data_array[index - 1] == '\n') ||
    (data_array[index - 1] == '\r') ||
    (index >= m_ble_nus_max_data_len))
    {
    if (index > 1)
    {
    NRF_LOG_DEBUG("Ready to send data over BLE NUS");
    NRF_LOG_HEXDUMP_DEBUG(data_array, index);

    do
    {
    uint16_t length = (uint16_t)index;
    err_code = ble_nus_data_send(&m_nus, data_array, &length, m_conn_handle);
    if ((err_code != NRF_ERROR_INVALID_STATE) &&
    (err_code != NRF_ERROR_RESOURCES) &&
    (err_code != NRF_ERROR_NOT_FOUND))
    {
    APP_ERROR_CHECK(err_code);
    }
    } while (err_code == NRF_ERROR_RESOURCES);
    }

    index = 0;
    }
    break;

    m_xfer_done = true;
    break;
    default:
    break;
    }
    }

Children
No Data
Related