Skip to main content
BlogNewsTop News

Tutorial for your Zephyr-based Nordic nRF52840DK development board

By November 11, 2020May 6th, 2021No Comments

Written by Jan Jongboom, Edge Impulse CTO

This tutorial originally ran on the Edge Impulse website. To see more content like this, visit their website.

Impulses can be deployed as a C++ library. This packages all your signal processing blocks, configuration and learning blocks up into a single package. You can include this package in your own application to run the impulse locally. In this tutorial you’ll export an impulse, and build a Zephyr RTOS application for the nRF52840DK development board to classify sensor data.

๐Ÿ“˜Knowledge required

This tutorial assumes that you’re familiar with building applications for the nRF52840DK or other Zephyr RTOS supported board, and have your environment set up to compile applications for this platform. This tutorial was written using nRF Connect SDK v1.3.0 which is based on Zephyr RTOS v2.3.0-rc1.


Make sure you followed the Continuous motion recognition tutorial, and have a trained impulse. Also make sure you’ve installed the following software:

Cloning the base repository

We created an example repository which contains a small application, which takes the raw features as an argument, and prints out the final classification. You can either download the application or import this repository using Git:

git clone

Deploying your impulse

Head over to your Edge Impulse project, and go to Deployment. From here you can create the full library which contains the impulse and all external required libraries. Select C++ library and click Build to create the library.

Download the .zip file and place the contents in the ‘example-standalone-inferencing-zephyr’ folder (which you downloaded above). Your final folder structure should look like this:

 โ”œโ”€โ”€ CMakeLists.txt
 โ”œโ”€โ”€ docs
 โ”œโ”€โ”€ edge-impulse-sdk
 โ”œโ”€โ”€ model-parameters
 โ”œโ”€โ”€ porting
 โ”œโ”€โ”€ prj.conf
 โ”œโ”€โ”€ sample.yaml
 โ”œโ”€โ”€ src
 โ”œโ”€โ”€ tflite-model
 โ””โ”€โ”€ utils

Running the impulse

With the project ready it’s time to verify that the application works. Head back to the studio and click on Live classification. Then load a validation sample, and click on a row under ‘Detailed result’.

Selecting the row with timestamp ‘320’ under ‘Detailed result’

To verify that the local application classifies the same, we need the raw features for this timestamp. To do so click on the ‘Copy to clipboard’ button next to ‘Raw features’. This will copy the raw values from this validation file, before any signal processing or inferencing happened.

Copying the raw features

In the example directory open src/main.cpp and paste the raw features inside the static const float features[] definition, for example:

static const float features[] = {
    3.9500, 2.0900, 17.2600, 3.2400, 0.7600, 17.6000 ...

Then build the application with west:

$ west build -b nrf52840dk_nrf52840

To flash this application you can either run (if you’ve set up the Segger J-LINK tools):

$ west flash

Or find the build/zephyr/zephyr.bin file and drag it to the JLINK USB mass-storage device (like a USB flash drive).

Seeing the output

To see the output of the impulse, connect to the development board over a serial port on baud rate 115,200 and reset the board.

This will run the signal processing pipeline, and then classify the output:

Edge Impulse standalone inferencing (Zephyr)
Running neural network...
Predictions (time: 1 ms.):
idle:   0.015319
snake:  0.000444
updown: 0.006182
wave:   0.978056
Anomaly score (time: 0 ms.): 0.133557
Predictions (DSP: 18 ms., Classification: 1 ms., Anomaly: 0 ms.): 
[0.01532, 0.00044, 0.00618, 0.97806, 0.134]

Which matches the values we just saw in the studio. You now have your impulse running on your Zephyr development board!


Building without the NRF Connect SDK

You can also build the application without the nRF Connect SDK. Navigate to the example-standalone-inferencing-zephyr folder and run:

$ west init
$ west update

And then read the ‘Invalid choice: ‘build” section below.

Invalid choice: ‘build’

If you try to build the application but it throws an ‘invalid choice’ error like:

$ west build -b nrf52840dk_nrf52840
usage: west [-h] [-z ZEPHYR_BASE] [-v] [-V] <command> ...
west: error: argument <command>: invalid choice: 'build' (choose from 'init', 'update', 'list', 'manifest', 'diff', 'status', 'forall', 'help', 'config', 'topdir', 'selfupdate')

You’ll need to set up your environment variables correctly (more info). You can do so by opening a command prompt or terminal window and running:


$ zephyr\zephyr-env.cmd

macOS / Linux

$ source zephyr/
Zephyr Project