element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Blog Nicla Sense - Nano 33 IoT as BHY2 Host
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: ralphjy
  • Date Created: 9 Apr 2022 5:43 PM Date Created
  • Views 6581 views
  • Likes 9 likes
  • Comments 5 comments
  • bhy2 host
  • bhy controller
  • nano 33 iot
  • nicla sense me
Related
Recommended

Nicla Sense - Nano 33 IoT as BHY2 Host

ralphjy
ralphjy
9 Apr 2022

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...

  • Sign in to reply
  • javagoza
    javagoza over 3 years ago in reply to tyler.berryman

    In addition to updating the WiFinina module firmware of the arduino nano 33 IoT I had to update the bhi firmware of the Nicla sense board.

    For updating the bhi firmware use the BHYFirmwareUpdate.ino sketch under examples

    or from github

    nicla-sense-me-fw/Arduino_BHY2/examples/BHYFirmwareUpdate at main · arduino/nicla-sense-me-fw (github.com)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • ralphjy
    ralphjy over 3 years ago in reply to tyler.berryman

    Please see the this tutorial Simple Remote Air Quality Monitor Project Tutorial by javagoza for a good explanation of using the Nicla over BLE.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • tyler.berryman
    tyler.berryman over 3 years ago

    I have tried using your code to enable communication via BLE between my Arduino  Nano 33 IOT and Nicla Sense ME. It seems like the Nano IOT never connects to the Nicla via BLE. See image of the Serial Monitor below:

    image

    The firmware version of the WiFiNINA module on the Arudino Nano 33 IOT is : 1.4.8. 

    I modified the Arduino_BHY2Host.h file to include the Nano 33 IOT board in the supported boards section as mentioned in your blog post. Did you make any modifications to the App sketch that is used by the Nicla board? Could you share the App sketch that you used on the Nicla board to get the communication to work? 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • javagoza
    javagoza over 3 years ago

    This is great Ralph. I couldn't get it to work on the Arduino Nano 33 IoT via BLE. I have tried again updating the firmware of the WifiNINA module and it already works with the Arduino Nano 33 IoT too.

    As the BLE had never worked for me with the Arduino 33 IoT, I didn't think about updating the firmware. Beginner's mistake.

    Thanks for sharing!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • ralphjy
    ralphjy over 3 years ago

    Just a quick update - I got a response on the Arduino Forum https://forum.arduino.cc/t/bhy2-host-ble-supported/979167 that suggested doing what I did.  I'll also try this with the Nano 33 BLE Sense, but I think javagoza indicated that he might have had to make other changes to make that work.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube