avatarDavid Such

Summary

The undefined website provides an in-depth look at the Arduino Nano 33 BLE Sense Rev 2, the Seeed XIAO nRF52840 Sense, and their use in the Reefwing AHRS library for flight controller software.

Abstract

The Arduino Nano 33 BLE family, particularly the Nano 33 BLE Sense Rev 2, is a hardware platform utilized for the Raven Flight Controller Software. This board, along with the Seeed XIAO nRF52840 Sense, is based on the nRF52840 processor and includes various sensors for advanced applications like AHRS, which processes IMU data to provide roll, pitch, and yaw angles. The article discusses the differences between the Nano 33 BLE versions, the sensors they incorporate, and the challenges faced in updating the Reefwing AHRS library to support the new sensors. It also provides insights into the development of new Arduino libraries for the XIAO and the Reefwing LPS22HB and LSM9DS1 libraries, emphasizing the importance of accurate sensor data for flight control systems.

Opinions

  • The author emphasizes the necessity of updating the AHRS library to accommodate the new sensors in the Nano 33 BLE Sense Rev 2 and the XIAO nRF52840 Sense.
  • There is a clear preference for the nRF52840 processor-based boards for their capabilities and the range of sensors they support.
  • The author suggests that the process of identifying the correct board type and version is crucial for the proper functioning of the AHRS library.
  • The development of the Reefwing LPS22HB and LSM9DS1 libraries is seen as a significant improvement, offering features not found in the official Arduino libraries.
  • The article implies that the community's requests, such as support for the XIAO in the AHRS library, are taken seriously and acted upon by the developers.
  • The author values readability and ease of use in library development, as evidenced by the structure and features of the new libraries.
  • There is an appreciation for the Medium platform and its readers, as the author encourages membership and support for their writing.

Arduino Nano 33 BLE Sense Rev 2 and the Seeed nRF52840 Sense

The Nano 33 BLE family of boards is considered part of the Arduino Pro range, targeted at non-hobbyist applications. We are using it as one of the hardware platforms for our Raven Flight Controller Software.

There are now three board configuration options:

  1. Nano 33 BLE — A board with 3.3V logic and a 9 axis inertial sensor (LSM9DS1). As the name suggests, it has a 2.4 GHz Bluetooth® 5 Low Energy (BLE) module from u-blox, and an internal antenna. It uses the nRF52840 chip from Nordic Semiconductors, a 32-bit ARM® Cortex®-M4 CPU running at 64 MHz.
  2. Nano 33 BLE SENSE — The SENSE is identical to the Nano 33 BLE but includes additional sensors: a microphone, a gesture, light and colour sensor (APDS9960), as well as temperature, humidity, and air pressure sensors (LPS22HB).
  3. Nano 33 BLE SENSE Rev 2 — The Rev 2 is the same as the SENSE but with updated sensors. In particular:
- Replacement of IMU from the LSM9DS1 (9 axis) to a combination of two
  IMUs, the BMI270, 6 axis gyro & accelerometer and the BMM150,
  3 axis magnetometer
- Replacement of temperature and humidity sensor from HTS221 to the HS3003
- Replacement of microphone from MP34DT05 to MP34DT06JTR
- Replacement of power supply MPM3610 to MP2322
- Addition of VUSB soldering jumper on the top side of the board
- New test point for USB, SWDIO and SWCLK.
Figure 1. Arduino Nano 33 BLE (credit: Arduino)

The Seeed Studio XIAO nRF52840 Sense

In addition to the Arduino range, a number of other manufacturers have released boards based on the nRF52840 processor. One example is the Seeed XIAO nRF52840 Sense. This inexpensive board includes Bluetooth 5.0, low power consumption, a LSM6DS3TR-C 6-axis IMU and a MSM261D3526H1CPM digital microphone with Pulse Density Modulation (PDM) capabilities. It is small and light! Figure 2 illustrates its size compared to the Nano 33 BLE Sense, which isn’t big either.

The embedded BQ25101 chip supports battery charge management and there are 11 digital I/O that can output PWM and 6 analog pins connect to the ADC. Communication is via UART, I²C, and SPI.

Figure 2. XIAO Sense and the Nano 33 BLE Sense (Rev. 2)

There are two Arduino board libraries available for the XIAO. To use the IMU, you want the one called Seeed nRF52 mbed-enabled Boards. In order to install this library using the Arduino IDE Board Manager, you have to first navigate to File > Preferences, and fill “Additional Boards Manager URLs” with the url below:

de>https://files.seeedstudio.com/arduino/package_seeeduino_boards_index.json

One of the users of our AHRS library requested that we support the XIAO so we have added that in the latest release.

The Reefwing Attitude and Heading Reference System (AHRS)

An Attitude and Heading Reference System (AHRS) takes information from the IMU and processes it to provide reliable roll, pitch and yaw angles (Figure 3).

Figure 3. Attitude and Heading Reference System (AHRS)

We have released an open source AHRS Arduino library (Reefwing AHRS) for the Nano 33 BLE family of boards. Both the Rev 1 SENSE and the Nano 33 BLE used the same IMU so our library would work with both.

The Rev 2 SENSE has made things a bit more complicated as it has replaced the original IMU (LSM9DS1) with two different IMU chips (the BMI270 and BMM150). The XIAO uses another IMU again (the LSM6DS3TR-C).

The LSM9DS1 IMU

The LSM9DS1 is manufactured by STMicroelectronics (now known as ST). It has a 3D digital linear acceleration sensor, a 3D digital angular rate sensor (gyroscope), and a 3D digital magnetic sensor. It includes SPI and I²C (standard 100 kHz and fast mode 400 kHz) serial interfaces but the Arduino Nano 33 BLE uses I2C. Full details of this chip are available in the LSM9DS1 data sheet.

  • accelerometer: 16 bit ADC with ±2g/±4g/±8g/±16g ranges available;
  • gyroscope: 16 bit ADC with ±245/±500/±2000 dps ranges.
  • magnetometer: 16 bit ADC with range of ±4/±8/±12/±16 gauss.

The available IMU Output Data Rates (ODR) are 14.9, 59.5, 119, 238, 476 and 952 Hz.

The LSM6DS3TR-C IMU

The LSM6DS3TR-C is also manufactured by ST, and has very similar specifications to the LSM9DS1, without the magnetometer but with a faster maximum sample rate. However, the XIAO uses I²C so that will probably be the limiting data rate. This IMU has a free-fall detection interrupt which could be useful in flight applications.

The LSM6DS3 can be interfaced to using SPI or I²C. Full details of this chip may be found in the LSM6DS3TR-C data sheet.

  • accelerometer: ±2g/±4g/±8g/±16 g full scale ranges available;
  • gyroscope: ±125/±250/±500/±1000/±2000 dps full scale

The available IMU Output Data Rates (ODR) are 12.5, 26, 52, 104, 208, 416, 833, 1666, 3332, and 6664 Hz.

The BMI270 and BMM150 IMUs

In Rev. 2 of the Nano 33 BLE SENSE, the LSM9DS1 IMU is replaced with the BMI270 and BMM150 IMUs from Bosch. The BMI270 is a 6-axis gyroscope and accelerometer.

  • accelerometer: 16 bit ADC with ±2g/±4g/±8g/±16g ranges available;
  • gyroscope: 16 bit ADC with ±125dps/±250dps/±500dps/±1000dps/±2000dps ranges.

The BMI270 is a 3-axis magnetometer. It has a measurement range of ±1300 µt (on the x-, y- axis) and ±2500µT (z-axis).

Determining the nRF52840 Board Type and Nano 33 BLE Version

We need to update our AHRS library in order for it to be able to handle the new sensors. To know which sensor library to use we have to know which version of the Nano 33 BLE or XIAO is connected.

From an Arduino IDE perspective, there is no difference between the three Nano 33 BLE versions. They all use the same processor and the same Arduino Core, which leverage the MBed OS. Normally, conditional compilation in an Arduino sketch is done something like what is shown in Code Block 1.

Alternatively, each Arduino board variant defines a constant called BOARD_NAME, which you can examine.

The BOARD_NAME of the XIAO is Seeed XIAO nRF52840 Sense, so we can use this to detect that the XIAO is attached. Alternatively, we could check for the IMU on the I²C bus at address 0x6A.

Unfortunately, all three variants of the Nano 33 BLE have the same BOARD_NAME. This is defined in pins_arduino.h. Thus, the only way we can tell these boards apart is to try and communicate with the sensors and see who talks back. We will use the temperature and humidity sensor as this is different on all three Arduino boards.

Nano 33 BLE: None
Nano 33 BLE SENSE Rev 1: HTS221  [I2C Address - 0x5F]
Nano 33 BLE SENSE Rev 2: HS3003  [I2C Address - 0x44]

The temperature and humidity sensors sit on the I²C bus and the different sensors have different addresses, so the simplest approach is to check which addresses are being used.

Figure 4. I²C Scanner Results for the Nano 33 BLE Sense Rev 2

Note that the Nano 33 BLE has two I²C buses and the internal sensors are found on Wire1, not Wire.

Figure 5. I²C Scanner Results for the Nano 33 BLE Sense Rev 1

As shown in Figures 4, 5 and 6, we can clearly identify the Nano 33 BLE variety based on the I²C addresses used. The sensors also have a “who am I” register which we could query to positively ID them but that is not required as only the board mounted sensors are connected to Wire1 and any external sensors will be on Wire, so there is no risk of another device with the same address being on that bus.

Figure 6. I²C Scanner Results for the Nano 33 BLE

Putting all this together, the sketch in Code Block 3 can be used to determine the nRF52840 board attached.

Updating the Reefwing AHRS Library

This turned into quite a big update as the library wasn’t structured to support different IMUs. The upside is adding support for further boards and IMUs should now be easier. Previously everything was driven from the LSM9DS1 class, which was overlayed with various sensor fusion algorithms. We had to introduce a new class, ReefwingAHRS, to detect the board type and then load the appropriate IMU library. In addition, we split out the sensor classes as separate libraries which makes it easier to only incorporate those we need. The new libraries are:

  • Reefwing LPS22HB — Arduino Library for the LPS22HB Pressure Sensor, found in the Nano 33 BLE Sense Revisions 1 and 2.
  • Reefwing LSM9DS1 — Library for the 9-axis IMU found in the Nano 33 BLE.

We didn’t write our own LSM6DS3 Library as the Seeed version has everything we need.

The development of the Reefwing LPS22HB Library is discussed in a separate article. Our LPS22HB library differs from the Arduino LPS22HB library in the following ways:

  • It provides altitude calculations for QNE, QNH and QFE pressure references.
  • It enables Block Data Update (`BDU`) which ensures that the content of the output registers is not updated until the last register is read, avoiding the reading of values related to different samples. This is important if you set the sampling rate (ODR) to anything other than one-shot.
  • It includes 2’s complement conversion for the temperature reading allowing negative values to be returned.

We also put together an article on the Reefwing LSM9DS1 Library, which differs from the official Arduino LSM9DS1 library in the following ways:

  • Where it makes sense, we have emphasized readability over code size. Configuring the IMU requires a lot of register operations, which can be done very concisely, but it then becomes harder to understand what is happening. Configuration will normally only be done once, at the start of the program, so this should not impact loop speed.
  • We include the option to set the LOW_POWER gyro/accelerometer operation mode. You can also put the gyro into SLEEP mode.
  • It is possible to enable/disable accelerometer auto bandwidth and set this manually if required.
  • You can set any of the five FIFO modes (Arduino library includes only continuous and single shot). A method is provided to return the number of samples currently stored in FIFO memory.
  • The Arduino Library allows you to calibrate both the slope and the bias offset. Our library currently only calibrates the bias offset.
  • You can reverse the gyro sign on any axis and change the sensor orientation using reverseGyroSign() and setGyroOrientation().
  • Enable FastODR for the magnetometer and you can use the higher sample rates (155, 300, 560, & 1000 Hz) associated with this. You can also enable temperature compensation for the magnetometer.
  • The magnetometer operating modes (LOW, MEDIUM, HIGH & ULTRA) can be set in addition to the sampling modes (CONTINUOUS, SINGLE, & IDLE).
  • Gyro chip temperature and its availability is provided.
  • Self Test methods are provided for all three sensors. The gyro/accel version should be considered experimental as ST do not document this function. The magnetometer self test feature is well documented.
  • We provide microsecond time stamps for every sensor reading.
  • It is designed to be compatible with the new and improved Reefwing AHRS Library.

If you enjoyed this article and would like to help support my writing, then please subscribe to become a Medium Member. I will get a portion of your subscription fee and you get access to every story on Medium. Alternatively, you can buy me a coffee or subscribe, to get an email whenever I publish a new article.

Arduino
Nano 33 Ble
Nrf52840
Imu
Board Detection
Recommended from ReadMedium