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

nrf51822 ble read the data send from smartphone

Hi all,

I am new to nRF51822,now I want to used a simple ble application to send a data,and nRF51822 ble device read this data to control RC servo motor ,for example app send value 1 then RC servo motor clockwise and send value 2 then RC servo motor counterclockwise,but i don't know how to read the data on nRF51822,can someone tell me how to do or provide sample code to me ?

Thanks in advance Peter.

  • Welcome, Peter

    BLE introduces a new way of communicating. The smartphone will act as a Central, while the board will act as a Peripheral. The peripheral has to have a service with characteristics which can then be accessed from the central. In the smartphone, you have to:

    • Discover your peripheral and its services
    • Find its characteristics
    • Write a value to a characteristic

    The peripheral then will be notified when the write occurs, so you can take further actions.

    You can find many examples on the SDK files.

    Regards,

  • Are you using the nRF51822 Evaluation Kit?

    I would recommend to start with the ble_app_uart example in the SDK. It has a corresponding android app which you can download the source code for here.

    In the UART example, in main.c there is a nus_data_handler function which you can modify to handle incoming data from the mobile app.

    You can then modify the mobile app so it has a button that sends the text "right", and in the handler function above you can check if p_data = "right" and then call a function which turns the motor to the right (you would have to write this function yourself, though. Try searching for PWM here on devzone, and you will find a lot of good answers)

Related