The Arduino Nano 33 BLE Sense Sensor Library You Have Been Waiting For

Quick Links

UPDATE 21/03/2023

Nano33BLESensor has a new release with version 1.1.0 now available. It solves some issues related to MbedOS and dependency version issues.

The Arduino Nano 33 BLE Sense was released in July 2019 and was a real step up for Arduino! Using the Arm Cortex-M4F based nRF52840, the Nano 33 BLE’s arrival made the days of Atmel based 8-bit microcontrollers seem numbered. With the proliferation of dirt cheap Arduino clones this was probably the result of Arduino seeing the writing on the wall that keeping it simple was probably not going to bring in the dough anymore. In the end the sheer amounts of fairly useless Arduino projects seem a bit dull these days, and with more complex offerings such as the Nano 33 series, a new era of seriously cool projects may be on the horizon.

Previously in The Hacky Super Loop Arduino Nano 33 BLE Sense Example You Have Been Waiting For I attempted to address the lack of meaningful working examples for this board. The interfaces for each sensor are not always ideal, and no concrete examples are widely available that enable uses to utilise Mbed OS to gather sensor values.

The ability to use Mbed OS with Arduino is a real step up for Arduino. Finally, a reasonably performant and relatively deterministic way of arranging our more complex Arduino projects! In attempt to simplify the collection of sensor data and at the same time utilise the power of Mbed OS, Nano33BLESensor was born.

The Nano33BLESensor Library

Nano33BLESensor leverages Mbed OS to automatically place sensor measurements in a ring buffer that can be integrated into programs in a simple manner. This means Nano33BLESensor takes care of placing measurements in to the buffer “in the background”, and your program can retrieve them from the buffer at a later time when your program has time. It can be found on GitHub here. It can also be found using Arduino’s Library Manager, and available when searched for when using the Arduino IDE. Simple examples also exist to help get people started.

Nano33BLESensor Features

  • Class implementation with common interface for the following sensor measurements
    • 3-axis Accelerometer
    • 3-axis Gyroscope
    • 3-axis Magnetic
    • RMS Microphone
    • Barometric Pressure
    • Temperature (with humidity)
    • Proximity
    • RGBC Colour
    • Gesture
  • Mbed OS usage, allowing easy integration with programs.
  • Ring buffer usage, allowing the softening of time constraints in regard to the reading sensor measurements.
  • Excellent examples for all sensors designed for BLE and Serial Plotter that help you to get started.

In the end, the result of this is:

  • Super simple initialisation of on board sensors.
  • No code required beyond initialisation for collection of sensor data.
  • Super simple usage of sensor data.
  • Common interface among different sensors.
  • Using Mbed OS effectively makes the reading of sensor measurements happen “in the background”, and keeps it out of the main program loop.

Nano33BLESensor Examples

The Nano33BLESensor Library comes with a series of powerful examples that include sensor measurement data output using both Serial and Bluetooth. It is possible to view this data at the same time using Arduino’s Serial Plotter and a Bluetooth packet analysis tool such as Bluetooth LE Explorer. Some of the examples available on the GitHub repository are as follows:

Below are the results of a few of those examples.

Accelerometer Example

Gyroscope Example

Entire IMU Sensor Example

In order to view the data in a visually acceptable way, Bluetooth LE Explorer must be configured in a specific way. The below animation shows this setup.

How Nano33BLESensor Simplifies Sensor Usage

Here are a couple of examples of how Nano33BLESensor simplifies the collection of sensor data with the Nano 33 BLE Sense. For the full API, you can checkout the GitHub repository.

Initialising the on board accelerometer, reading data, and printing it.

Arduino_LSM9DS1

#include <Arduino_LSM9DS1.h>

float accelerometerX, accelerometerY, accelerometerZ;
void setup()
{
  IMU.begin()
}

void loop()
{
  if(IMU.accelerationAvailable())
  {
    IMU.readAcceleration(accelerometerX, accelerometerY, accelerometerZ);
    Serial.printf("%f,%f,%f\r\n", accelerometerX, accelerometerY, accelerometerZ);
  }
}

Nano33BLESensor

#include "Nano33BLEAccelerometer.h"

Nano33BLEAccelerometerData accelerometerData;
void setup()
{
  Accelerometer.begin()
}

void loop()
{ 
  if(Accelerometer.pop(accelerometerData))
  {
     Serial.printf("%f,%f,%f\r\n", accelerometerData.x, accelerometerData.y, accelerometerData.z);
  }
}

Initialising the on board colour sensor, reading data, and printing it.

Arduino_APDS9960

#include <Arduino_APDS9960.h>

int colourR, colourG, colourB, colourC;
void setup()
{
  APDS.setGestureSensitivity(50);
  APDS.begin();
  APDS.setLEDBoost(0);
}
void loop()
{
  if (APDS.colorAvailable())
  {
    APDS.readColor(colourR, colourG, colourB, colourC);
    Serial.printf("%d,%d,%d,%d\r\n", colourR, colourG, colourB, colourC);
  }
  delay(1000);
}

Nano33BLESensor

#include "Nano33BLEColour.h"

Nano33BLEColourData colourData;
void setup()
{
  Colour.begin()
}

void loop()
{ 
  if(Colour.pop(colourData))
  {
    Serial.printf( "%d,%d,%d,%d\r\n", colourData.r, colourData.g, colourData.b, colourData.c);
  }
}

Initialising the on board temperature sensor, reading data, and printing it

Arduino_HTS221

#include <Arduino_HTS221.h>

float temperature, humidity;
void setup()
{
  HTS.begin();
}
void loop()
{
  temperature = HTS.readTemperature();
  humidity = HTS.readHumidity();
  Serial.printf("%f, %f\r\n", temperature, humidity);
  delay(1000);
}

Arduino33BLESensor

#include "Nano33BLETemperature.h"

Nano33BLETemperatureData temperatureData;
void setup()
{
  Temperature.begin()
}

void loop()
{ 
  if(Temperature.pop(temperatureData))
  {
    Serial.printf("%f,%f\r\n", temperatureData.temperatureCelsius, temperatureData.humidity);
  }
}

Conclusion

Nano33BLESensor enables some interesting possibilities with the Nano 33 BLE. It simplifies the usage of onboard sensors by using a common interface, and leverages Mbed OS to allow the softening of time constraints in regard to the reading sensor measurements. It is hoped that this library will be useful to someone down the track!

15 thoughts on “The Arduino Nano 33 BLE Sense Sensor Library You Have Been Waiting For

  1. Pingback: The Hacky Super Loop Arduino Nano 33 BLE Sense Example You Have Been Waiting For | DaleGia

  2. Alex Jonsson

    Dear Dale, thanks for making this tutorial and sharing it with the rest of us.
    Have you had the chance to look at the long-range features of this ble chip, and
    how to address the coded phy 125 MHz mode that would ultimately result in really long-range
    applications? I’ve surfed around quite a bit, but find only questions, and pretty much no answers
    on how to achieve the true range potential of the Nordic nRF52840

    best

    Alex

    Reply
    1. dale-blog Post author

      Hi Alex,

      Unfortunately I haven’t had a look at the long range capabilities of the nRF52840 and Nano 33 BLE. I’d say for the time being if you really need the long range functionality you are better off using a different board that has better supported long range capability such as the ESP32. The Nano 33 BLE Sense is such a cool board because of everything that is packed into it, but support for it is really lacking at the moment perhaps due to the added complexity that makes it so cool in the first place. Hopefully this changes over time.

  3. bzkim

    Thank you for the powerful program. Very cool. Will the example code you upload run and receive code examples from other nano 33 ble boards?

    Reply
    1. dale-blog Post author

      Hi Alex,

      One way might be to create an application that works with Arduino Science Journal. I haven’t had a chance to look if this is possible but I think it would be a pretty good use of this library.

      Other than that you would have to create your own program using a charting library. From the top of my head, chrome has bluetooth support, and there are some great charting libraries these days with Javascript such as Chart.js. Provided you don’t require a super fast chart refresh rate this would probably be the easiest solution.

      Thanks
      Dale

  4. Jose

    Hi, Dale.
    Many thanks, vert nice work.
    I have some problems to test “Nano33BLESensorExample_microphoneRMS,ino” when compile to send to board, I have a error, “Nano33BLEMicrophoneRMS.cpp:105: undefined reference to `arm_rms_q15′”, but I don´t know why, I have te las version of “Mbed OS”.

    Could you help me, please.

    Thanks in advance.

    Best regards.

    Reply
  5. Jose

    Hi again Dale.
    I have my system as you mention on Issue 6, but, I can´t compile the file.
    I have Aduino IDE 1.8.13 ver.
    I have again same error “\Arduino\libraries\Nano33BLESensor-master\src/Nano33BLEMicrophoneRMS.cpp:105: undefined reference to `arm_rms_q15′
    collect2.exe: error: ld returned 1 exit status”

    And In my Arduino´s directories, I have The correct file “boards.txt” with the correct sentence.
    C:\Users\j****\AppData\Local\Arduino15\packages\arduino\hardware\mbed\1.3.2
    “nano33ble.compiler.mbed=”{build.variant.path}/libs/libmbed.a” “{build.variant.path}/libs/libcc_310_core.a” “{build.variant.path}/libs/libcc_310_ext.a” “{build.variant.path}/libs/libcc_310_trng.a””

    Many thanks in advance

    Best regards

    Reply
  6. Jose

    Hi Dale, sorry I after doing the recomendations, copy the library file in the directory, compile again, and now I have this error:
    “arm-none-eabi-g++: error: C:\Users\****\AppData\Local\Arduino15\packages\arduino\hardware\mbed\1.3.2\variants\ARDUINO_NANO33BLE /libs/libarm_cortexM4l_math.a: No such file or directory
    exit status 1”

    Many thanks in advance.

    Best regards.

    Reply
  7. Jose

    Hi Dale, sorry, it is working now, very well.
    There was a mistake in the path oh the new library.

    Many thanks.

    Best regards

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.