I'm thinking of a project using the Nicla as a remote sensor and the Nano 33 IoT as the control MCU. The Nicla pin spacing is designed to be able to use it directly as a shield on MKR format boards, but since I want the sensor to be remote (a few feet or more) - I'd rather use a Nano 33 IoT as I have a few of those available.
I've tried using the Nicla over BLE using WebBLE: Nicla Sense - Minor issue with BLE WebServer. And I also tried using it with the Portenta H7 using the BHY2Host library with NICLA_VIA_BLE set.
However, when I tried to use the Nano 33 IoT it didn't work - compiled and uploaded fine, but just returned zero values.
It turns out that the only two boards that the BHY2Host library supports via BLE are the Portenta H7 and the MKR WiFi 1010. Not sure why that is - I've posted the question on the Arduino forum. Seems weird because the MKR WiFi 1010 and the Nano 33 IoT use the same radio module and SamD21 MCUs.
If you look in the Arduino_BHY2Host.h file you can see where the supported boards are defined:
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_SAMD_MKRWIFI1010)
#define __BHY2_HOST_BLE_SUPPORTED__
#include "BLEHandler.h"
#endif
I considered just allowing all boards to be supported since I'm not going to distribute this modified library and can use it at my own risk. For now, I just added the Nano 33 IoT by changing the first line:
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT)
I was then able to modify the Standalone example to receive the sensor values on the Nano 33 IoT via BLE (the Nicla is running the App program).
arduino_nano33iot_nicla_sense.ino
#include "Arduino.h" #include "Arduino_BHY2Host.h" SensorXYZ accel(SENSOR_ID_ACC); SensorXYZ gyro(SENSOR_ID_GYRO); Sensor temp(SENSOR_ID_TEMP); Sensor gas(SENSOR_ID_GAS); SensorQuaternion rotation(SENSOR_ID_RV); int lastCheck = 0; #define DEBUG true void setup(){ Serial.begin(115200); while(!Serial); #if DEBUG BHY2Host.debug(Serial); #endif Serial.println("Configuring Nicla..."); while(!BHY2Host.begin(false, NICLA_VIA_BLE)) {} Serial.println("NICLA device found!"); accel.begin(); gyro.begin(); temp.begin(); gas.begin(); rotation.begin(); } void loop(){ static auto lastCheck= millis(); BHY2Host.update(); // Check sensor values every 5 seconds if (millis() - lastCheck >= 5000) { lastCheck = millis(); Serial.println(String("acceleration: ") + accel.toString()); Serial.println(String("gyroscope: ") + gyro.toString()); Serial.println(String("temperature: ") + String(temp.value(),3)); Serial.println(String("gas: ") + String(gas.value(),3)); Serial.println(String("rotation: ") + rotation.toString()); } }
Here is the Serial Monitor output:
10:03:51.224 -> Configuring Nicla... 10:03:51.224 -> NICLA_VIA_BLE selected 10:03:51.224 -> Starting BLE...OK! 10:03:52.686 -> Nicla peripheral found! 10:03:52.766 -> Successfully connected to peripheral. 10:03:53.165 -> Sensor service discovered. 10:03:53.165 -> configCharacteristic found 10:03:53.165 -> Subscribed to dataCharacteristic 10:03:53.165 -> NICLA device found! 10:03:53.165 -> Config packet: 4, 0, 0, 7A, 44, 0, 0, 0, 0, 10:03:53.200 -> Config packet: D, 0, 0, 7A, 44, 0, 0, 0, 0, 10:03:53.234 -> Config packet: 80, 0, 0, 7A, 44, 0, 0, 0, 0, 10:03:53.270 -> Config packet: 83, 0, 0, 7A, 44, 0, 0, 0, 0, 10:03:53.313 -> Config packet: 22, 0, 0, 7A, 44, 0, 0, 0, 0, 10:03:58.323 -> 10:03:58.323 -> acceleration: XYZ values - X: -2527 Y: 286 Z: 3225 10:03:58.323 -> gyroscope: XYZ values - X: -2 Y: 0 Z: -3 10:03:58.323 -> temperature: 26.710 10:03:58.323 -> gas: 17183.000 10:03:58.323 -> rotation: Quaternion values - X: 0.045 Y: 0.325 Z: -0.022 W: 0.944 Accuracy: 3.142 10:04:03.356 -> 10:04:03.356 -> acceleration: XYZ values - X: -2523 Y: 279 Z: 3208 10:04:03.356 -> gyroscope: XYZ values - X: -3 Y: -1 Z: -2 10:04:03.356 -> temperature: 26.710 10:04:03.356 -> gas: 17183.000 10:04:03.356 -> rotation: Quaternion values - X: 0.045 Y: 0.325 Z: -0.022 W: 0.944 Accuracy: 3.142 10:04:08.334 -> 10:04:08.334 -> acceleration: XYZ values - X: -2550 Y: 279 Z: 3225 10:04:08.334 -> gyroscope: XYZ values - X: 0 Y: 7 Z: -5 10:04:08.334 -> temperature: 26.710 10:04:08.334 -> gas: 17127.000 10:04:08.334 -> rotation: Quaternion values - X: 0.046 Y: 0.325 Z: -0.022 W: 0.944 Accuracy: 3.142 10:04:13.329 -> 10:04:13.329 -> acceleration: XYZ values - X: -2522 Y: 295 Z: 3202 10:04:13.329 -> gyroscope: XYZ values - X: 3 Y: 4 Z: 4 10:04:13.329 -> temperature: 26.700 10:04:13.329 -> gas: 17155.000 10:04:13.329 -> rotation: Quaternion values - X: 0.046 Y: 0.325 Z: -0.022 W: 0.944 Accuracy: 3.142 10:04:18.348 -> 10:04:18.348 -> acceleration: XYZ values - X: -2524 Y: 290 Z: 3245 10:04:18.348 -> gyroscope: XYZ values - X: -3 Y: 0 Z: -3 10:04:18.348 -> temperature: 26.700 10:04:18.348 -> gas: 17016.000 10:04:18.348 -> rotation: Quaternion values - X: 0.046 Y: 0.325 Z: -0.022 W: 0.944 Accuracy: 3.142 10:04:23.339 -> 10:04:23.339 -> acceleration: XYZ values - X: -2528 Y: 295 Z: 3225 10:04:23.339 -> gyroscope: XYZ values - X: 0 Y: 0 Z: 2 10:04:23.339 -> temperature: 26.700 10:04:23.339 -> gas: 17016.000 10:04:23.339 -> rotation: Quaternion values - X: 0.046 Y: 0.325 Z: -0.022 W: 0.944 Accuracy: 3.142 10:04:28.343 -> 10:04:28.343 -> acceleration: XYZ values - X: -2528 Y: 293 Z: 3235 10:04:28.343 -> gyroscope: XYZ values - X: -5 Y: -4 Z: -3 10:04:28.343 -> temperature: 26.700 10:04:28.343 -> gas: 17141.000 10:04:28.343 -> rotation: Quaternion values - X: 0.046 Y: 0.325 Z: -0.022 W: 0.944 Accuracy: 3.142 10:04:33.342 -> 10:04:33.342 -> acceleration: XYZ values - X: -2529 Y: 293 Z: 3222 10:04:33.342 -> gyroscope: XYZ values - X: 0 Y: -1 Z: 0 10:04:33.342 -> temperature: 26.700 10:04:33.342 -> gas: 17141.000 10:04:33.342 -> rotation: Quaternion values - X: 0.046 Y: 0.325 Z: -0.022 W: 0.944 Accuracy: 3.142 10:04:38.350 -> 10:04:38.350 -> acceleration: XYZ values - X: -2547 Y: 294 Z: 3231 10:04:38.350 -> gyroscope: XYZ values - X: -2 Y: -1 Z: -3 10:04:38.350 -> temperature: 26.700 10:04:38.350 -> gas: 17127.000 10:04:38.350 -> rotation: Quaternion values - X: 0.046 Y: 0.325 Z: -0.022 W: 0.944 Accuracy: 3.142
So, I guess it works - time will tell...