🛠 Connecter le Nicla au WiFi via une carte hôte
Objectives
Provide network access to the Nicla Sense ME despite the complete absence of an onboard WiFi radio. Before any wiring, keep in mind: the board has neither an ESP32-N4 nor any kind of WiFi chip — the official manual is categorical, "The Nicla Sense ME does not have built-in Wi-Fi" — and the path documented by Arduino is a host board (MKR WiFi 1010 or Portenta C33) acting as a gateway, either via BLE, via an ESLOV cable, or via MKR-shield connectors using I²C. The Arduino_BHY2Host library bridges the gap: the Nicla remains the autonomous sensor node, while the host retrieves the data and provides its own connectivity.
Hardware
- Arduino Nicla Sense ME board (ABX00050) loaded with the "App" sketch from the Arduino_BHY2 library (peripheral mode)
- Host board: MKR WiFi 1010 (core ≥ 2.5.2 for shield mode) or Portenta C33
- Arduino_BHY2Host library on the host; ESLOV cable or simple BLE proximity for the link
- >
Complete Code
// A televerser sur la CARTE HOTE (MKR WiFi 1010), pas sur le Nicla
#include "Arduino.h"
#include "Arduino_BHY2Host.h"
#include <WiFi101.h>
Sensor tempSensor(SENSOR_ID_TEMP);
const char* ssid = "MON_WIFI";
const char* pass = "MON_MOT_DE_PASSE";
void setup {
Serial.begin(115200);
while (!Serial);
// 2e argument : NICLA_VIA_BLE, NICLA_VIA_ESLOV ou NICLA_AS_SHIELD
BHY2Host.begin(false, NICLA_VIA_BLE);
tempSensor.begin;
while (WiFi.begin(ssid, pass) != WL_CONNECTED) {
Serial.println("Connexion WiFi en cours...");
delay(2000);
}
Serial.println("Passerelle connectee");
}
void loop {
static auto printTime = millis;
BHY2Host.update; // pompe les donnees recues du Nicla
if (millis - printTime >= 5000) {
printTime = millis;
Serial.println(String("Temperature (via Nicla) : ") + String(tempSensor.value, 2));
}
}
Expected Verification
The Nicla flashed in "App" mode is detected by the host; the host console displays the Nicla's BME688 temperature every 5 seconds, and WiFi is established (IP address can be displayed with WiFi.localIP). Once this gateway is validated, any network library on the host (HTTP, MQTT, Arduino Cloud) can utilize the Nicla's data — see the advanced MQTT tutorial.
Common Errors
- Forgetting to flash the "App" sketch onto the Nicla before launching BHY2Host: the host then sees no peripheral.
- Confusing transport constants:
NICLA_VIA_BLE,NICLA_VIA_ESLOV, andNICLA_AS_SHIELDcorrespond to three different connections; choosing the wrong one results in a silent timeout. - ESLOV hook: if no ESLOV activity occurs within the first minute, the LDO shuts off and the ESLOV dies (low-power design); bypass this with
BHY2.setLDOTimeout(milliseconds)on the Nicla side. - Intermittent host suspensions on I²C (known bug in the reset pin control of the BHY2Host stack): prefer BLE to start, then test ESLOV.
Other tutorials for this board
Code examples for this board
led_rgb.inoArduinoimu_bhi260.inoArduinorotation_fusion.inoArduinopression_bmp390.inoArduinonose_electronique.inoArduinoboussole_bmm150.inoArduino