Arduino Nano 33 BLE Sense

Building & Flashing Arduino Firmware

Arduino firmware in this guide is flashed using the Arduino built-in flashing tools. For building the firmware, we have chosen to use PlatformIO as the main interface for building firmware for Arduino boards. It allows the user ease of access to change and add build flags, as well as allowing for multiple build environments.

PlatformIO can be installed into your favorite editor, many IDE’s, or be run from the command line. All screenshots here are taken from Visual Studio Code, PlatformIO’s recommended editor.

These instructions apply to both data capture and Knowledge Pack code bases.

Data Collection Firmware code

Data collection firmware code can be found here.

This code implements a working example of the Simple Streaming Interface.

Note

Data Collection Firmware is required to record data with Data Capture Lab. Data collection is disabled when running a Knowledge Pack.

Knowledge Pack/Recognition Firmware Code

Knowledge Pack Firmware can be found here.

Once you have installed PlatformIO and cloned the repository, the PlatformIO home page should be shown in an editor. If not, open the folder of the repository in your editor.

The PlatformIO Home page. Open an existing project with the cloned repository

PlatformIO should also show in your sidebar (for VS Code users):

The PlatformIO icon in the side bar.

Click that icon to bring up the PlatformIO commands. Here, you can select which environment you’re building for (there is currently only one in the project).

PlatformIO Environment build

From here, PlatformIO should pull down all the libraries and packages needed to build. The first build will take the longest because of this.

Once the firmware builds, ensure your Nano 33 is plugged in to a USB port on your computer, and then click upload.

PlatformIO Environment upload

PlatformIO should automatically detect the proper COM port (Windows) or /dev/ port (Linux) and upload.

Using TensorFlow Lite for Microcontrollers in a Knowledge Pack

When running a model built using TensorFlow Lite, another environment is provided in the Knowledge Pack code base. The environment env:nano33ble_with_tensorflow will automatically link this in with the same code base.

Changing IMU Frequency

For Arduino boards, the Data Capture Lab does not actively configure the device, the configuration is set at compile-time.

To change the frequency the board checks for new samples from the IMU, open include/sensor_config.h.

Look for #define ACCEL_GYRO_DEFAULT_ODR the default value for both is ACCEL_GYRO_ODR_119HZ, but can be changed.

Enabling Audio

To enable audio for recognition or capture, open include/sensor_config.h and search for #define ENABLE_AUDIO. Change this value to a 1 to enable audio.

Note: At this time we are supporting IMU or Audio independently, but not both at the same time. Enabling Audio will disable the IMU.

Adding Sensors

The Nano33 BLE Sense has more sensors than just the IMU and Audio.

The data capture code provided here is meant to be an example for the following:

  • Adding Sensors in the order intended to be run in a model

  • Creating the JSON configuration message so that the Data Capture Lab knows what data is coming in

  • Sending sensor data out in the same order specified by the configuration message.

Adding another sensor from the board takes the following:

  1. Adding the appropriate library to platformio.ini in the lib_deps section.

  2. Adding a setup_sensor() function to main.cpp (or elsewhere). This setup function will add the sensor column names to the configuration message. The highest sample rate will be used when sending data out, regardless of if the sensor has an update.

  3. Adding an update_sensor() function to main.cpp (or elsewhere). This function will add the sensors in the same order as the configuration message specifies.

Seeing Added Sensors to Data Capture Lab

The Nano33 is a default device plugin in the Data Capture Lab. However, this is only with IMU and Audio sensors. If you wish to add other sensors, you will need to use the nano33_custom.ssf file provided in the GitHub repository, and add the sensors you are using.

This lays out what sensors are available to the DCL, and also lets our servers know what is being used.

For more on the device import and custom sensors, see Adding Custom Device Firmware.