Example code

I have been forced to upgrade to the nRF54L15 from the nRF52840 DK.  The example code in the SDK  for the nRF52840 the 'ble-peripheral' had example code for 'ble_app_uart' which was perfect for me.  All I need to do is receive a string of characters from a smart phone, and then do what I need to do with it. 

In the 'ble_app_uart' example there is a routine called 'nus_data_handler'  which had an array called 'ble_data[]'  which received the string of data from the phone.

I have just installed the SDK for the nRF52840 Development Kit and I can not find anything comparable with the 'ble_app_uart' for nRF52840.

It must be in there somewhere, but I have looked, but can not find it.  I am hoping that you can point me in the right direction.

Cheers,

Brian Fleming

  • I am thinking now that 'bluetooth le uart services' might be where I should be looking, specifically, the routine 'bt_receive_cb' . Any assistance would be appreciated.

  • static void bt_receive_cb (struct bt_conn *conn, const uint8_t *const data, uint16_t len)
    memcpy(tx->data, &data[pos], tx->len);  I think data[] holds the characters received from the central.
  • Hi

    If you're new to the nRF Connect SDK I would strongly recommend checking out the DevAcademy course on nRF Connect SDK fundamentals: https://academy.nordicsemi.com/courses/nrf-connect-sdk-fundamentals/.

    And to answer your question, we do have an equivalent of the BLE NUS example in the nRF Connect SDK as well. It is found under Samples/Bluetooth/peripheral_uart here: https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/samples/bluetooth/peripheral_uart/README.html This already implements the NUS service and should work out of the box on the nRF54L15.

    Best regards,

    Simon

  • Hello. could you take a look at the attached notepad file.  

    I have documented as well as I can about my inability to compile due to a Python error.

    Cheers,

    Brian Fleming

    My problem is that I can not compile (Build) a program like I could with Kiel because it says there is a problem with missing Python.

    I have selected the peripheral_uart from the SDK as it seems that

    static void bt_receive_cb (struct bt_conn *conn, const uint8_t *const data, uint16_t len)

    has the functionality the I require.

    I open the peripheral_uart in the VS Code development environment and without any changes to the code if I click the Build button to compile I receive the following in OUTPUT

    [main] Building folder: c:/ncs/v3.1.1/nrf/samples/bluetooth/peripheral_uart/build

    [main] Configuring project: peripheral_uart

    [proc] Executing command: C:\ncs\toolchains\c1a76fddb2\opt\bin\cmake.exe -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE --no-warn-unused-cli -S C:/ncs/v3.1.1/nrf/samples/bluetooth/peripheral_uart -B c:/ncs/v3.1.1/nrf/samples/bluetooth/peripheral_uart/build

    [cmake] Not searching for unused variables given on the command line.

    [cmake] Loading Zephyr default modules (Zephyr base (cached)).

    [cmake] -- Application: C:/ncs/v3.1.1/nrf/samples/bluetooth/peripheral_uart

    [cmake] -- CMake version: 3.21.0

    [cmake] CMake Error at C:/ncs/toolchains/c1a76fddb2/opt/share/cmake-3.21/Modules/FindPackageHandleStandardArgs.cmake:230 (message):

    [cmake] Could NOT find Python3 (missing: Python3_EXECUTABLE Interpreter) (Required

    [cmake] is at least version "3.10")

    [cmake] Call Stack (most recent call first):

    [cmake] C:/ncs/toolchains/c1a76fddb2/opt/share/cmake-3.21/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)

    [cmake] C:/ncs/toolchains/c1a76fddb2/opt/share/cmake-3.21/Modules/FindPython/Support.cmake:3165 (find_package_handle_standard_args)

    [cmake] C:/ncs/toolchains/c1a76fddb2/opt/share/cmake-3.21/Modules/FindPython3.cmake:485 (include)

    [cmake] C:/ncs/v3.1.1/zephyr/cmake/modules/python.cmake:41 (find_package)

    [cmake] C:/ncs/v3.1.1/zephyr/cmake/modules/zephyr_default.cmake:131 (include)

    [cmake] C:/ncs/v3.1.1/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)

    [cmake] C:/ncs/v3.1.1/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:97 (include_boilerplate)

    [cmake] CMakeLists.txt:8 (find_package)

    [cmake]

    [cmake]

    [cmake] -- Configuring incomplete, errors occurred!

    [proc] The command: C:\ncs\toolchains\c1a76fddb2\opt\bin\cmake.exe -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE --no-warn-unused-cli -S C:/ncs/v3.1.1/nrf/samples/bluetooth/peripheral_uart -B c:/ncs/v3.1.1/nrf/samples/bluetooth/peripheral_uart/build exited with code: 1

    And the following in PROBLEMS

    CMake Error at C:/ncs/toolchains/c1a76fddb2/opt/share/cmake-3.21/Modules/FindPackageHandleStandardArgs.cmake:230 (message):Could NOT find Python3 (missing: Python3_EXECUTABLE Interpreter) (Required

    is at least version "3.10")

    Obviously, it is not finding Python which is installed on my machine. The where and version are returning the following values.

    C:\>where python

    C:\Users\Brian\AppData\Local\Microsoft\WindowsApps\python.exe

    C:\>python --version

    Python 3.13.9

    C:\>

    Here are all the Python executables

    C:\>where pyth*.exe

    C:\Users\Brian\AppData\Local\Microsoft\WindowsApps\python.exe

    C:\Users\Brian\AppData\Local\Microsoft\WindowsApps\python3.13.exe

    C:\Users\Brian\AppData\Local\Microsoft\WindowsApps\python3.exe

    C:\Users\Brian\AppData\Local\Microsoft\WindowsApps\pythonw.exe

    C:\Users\Brian\AppData\Local\Microsoft\WindowsApps\pythonw3.13.exe

    C:\Users\Brian\AppData\Local\Microsoft\WindowsApps\pythonw3.exe

    C:\>

    In the VS Code environment if I click the Gear (Manage) and select the Settings options and search for pyth I find a field which I enter as per below.

    C:\Users\Brian\AppData\Local\Microsoft\WindowsApps\pythonw3.13.exe

    In the VS Code environment in the Extensions the nRF Connect for VS Code and the nRF Connect for VS Code Extension Pack are both installed.

    I have watched the nRF Connect for VS Code, part 1: Installation video in the internet and it does not say anything about configuring Python.

  • Hi

    I assume you had Python already installed when installing the nRF Connect SDK and VS Code extension, correct? 

    On Windows, this usually fails when another Python on your PATH interferes, or when the toolchain’s Python is not visible. Nordic recommends ensuring that the toolchain’s Python is the one CMake picks up.[Build fail CLI][VS Code Python env]

    The first thing to try is that if you haven't, close all VS Code tabs in order to refresh/update all instances of it on your computer, then reopen it again. Next make sure you open the SDK folder so you have the workspace/environment set up correctly. I usually open up the folder of NCS I'm using (C:\ncs\v3.2.0). Then, go to the nRF Connect VS Code extension tab and "Manage SDKs" and "Manage Toolchains" to make sure you have the correct SDK and toolchains try building the project you want. Please let me know if you still see the same error messages.

    Best regards,

    Simon

Related