Arduino Nicla Sense ME as a MKR Shield

Learn how to set up and use the Nicla Sense ME as a MKR Shield

Overview

The Arduino Nicla Sense ME mounted on top of the MKR WiFi 1010
The Arduino Nicla Sense ME mounted on top of the MKR WiFi 1010

The form factor of the Nicla Sense allows the board to be used as a MKR shield. In this tutorial we will walk you through converting the Nicla Sense Board into a shield to extend some of the functionalities of the MKR boards using the I2C communications and explain how this communication functions through an example sketch.

Goals.

  • How to solder the headers on the Nicla Sense ME.
  • To establish an I2C communication between the MKRWiFi 1010 and the Nicla Sense

Required Hardware and Software

The following sketches can be found inside the Arduino_BHY2 and Arduino_BHY2Host libraries, available at the library manager, you will need to add the changes shown in this tutorial

Instructions

1. The Setup

We will need the latest version of the mbed_portenta core to be able to install the needed drivers of the Nicla Sense ME (minimum v2.5.2). Install the Arduino_BHY2 and Arduino_BHY2Host libraries from the library manager.

To convert the Nicla Sense ME into a Shield, you will have to solder 2 rows of headers one side has 9 pins and the other 8 pins, the long side of the headers needs to be on the battery connectors side.

Once the headers are soldered and the board plugged on top of the MKR, it will be possible to see the Nicla Sense ME LED and the Reset button, also to confirm the correct position you can see a white silk outline in the GND pin of the Nicla Sense ME, it needs to be aligned with the MKR GND pin. Have a look to at video to figure out the correct orientation of the board.

Assembly of the Nicla Sense ME in top of the MKR WiFi 1010

This set-up works with the ESLOV cable as well.Also keep in mind female headers or raw cables can be used as well, make sure the connections of the pinout match with the MKR pinout (3V3, GND, SCL and SDA).

2. Structure of the Communication

The host (MKR WiFi 1010), will communicate through the BHY2Host library with the Nicla Sense ME (both devices communicate over I2C)

3. Host Communication of the MKR WiFi 1010

To make the host communicate with the Nicla Sense ME which is mounted as a shield you can modify one of the existing examples. Open the sketch under Examples -> Arduino_BHY2Host -> Accelerometer and modify the

setup
function.

Add the following parameters to

BHY2Host.begin()
:
BHY2Host.begin(false, NICLA_AS_SHIELD);
The first parameter defines if the data should be passed through the Serial connection. This allows to control the Nicla Sense ME from a PC when connected through a host board. You can use the
arduino-bhy
tool to control the Nicla Sense ME from either the PC command line or from a web page.

Full sketch:

1#include "Arduino.h"
2#include "Arduino_BHY2Host.h"
3
4SensorXYZ accel(SENSOR_ID_ACC);
5
6void setup()
7{
8 // debug port
9 Serial.begin(115200);
10 while(!Serial);
11
12 BHY2Host.begin(false, NICLA_AS_SHIELD);
13
14 accel.begin();
15}
16
17void loop()
18{
19 static auto printTime = millis();
20 BHY2Host.update();
21
22 if (millis() - printTime >= 1000) {
23 printTime = millis();
24 Serial.println(String("Acceleration values: ") + accel.toString());
25 }
26}

4. Program of the Nicla Sense ME

Program the Nicla Sense ME with the App.ino sketch from the BHY2 library. You can find it under Examples -> Arduino_BHY2 -> App . Modify it as follows:

Navigate to the

setup
function and add two parameters to
BHY2.begin()

1BHY2.begin(NICLA_I2C, NICLA_AS_SHIELD);

You may use

NICLA_I2C
,
NICLA_BLE
,
NICLA_BLE_AND_I2C
as the first parameter, and as the second one
NICLA_VIA_ESLOV
or
NICLA_AS_SHIELD
. Remember to use the corresponding settings on the HOST board.

These settings will internally adjust the communication parameters so it can communicate through the headers.

We suggest to unplug the Nicla Sense ME from the host Arduino board while connecting the USB to the computer.

Full sketch:

1#include "Arduino.h"
2#include "Arduino_BHY2.h"
3
4// Set DEBUG to true in order to enable debug print
5#define DEBUG false
6
7void setup(){
8#if DEBUG
9 Serial.begin(115200);
10 BHY2.debug(Serial);
11#endif
12
13 BHY2.begin(NICLA_I2C, NICLA_AS_SHIELD);
14}
15
16void loop(){
17 // Update and then sleep
18 BHY2.update(100);
19}

Conclusion

This tutorial shows how easy is to access the Nicla Sense ME sensors data and pins if it is plugged as a shield. The BHY2 Library encapsulates the I2C communication and therefore reduces the complexity of your sketch.

Troubleshooting

Make sure you have the latest version of both libraries Arduino_BHY2 and Arduino_BHY2Host installed.

If you don't see any output on the Serial monitor, make sure you have set the correct baud rate. In this example sketch we use 115200.

Make sure the pins are soldered on the correct side and the Nicla Sense ME is mounted with the correct orientation on the host board.

Next Steps

Using the Cloud dashboard to select which sensor you want to use and initialize, so you have all the control from there.