🛠 Connecter le Nicla au WiFi via une carte hôte

Arduino Nicla Sense ME · intermediaire · Schéma : IMG-nicla-sense-me-intermediaire-3-niclasense-wifi-via-passerelle.svg — Nicla Sense ME relié par liaison BLE ou câble ESLOV à un MKR WiFi 1010, lui-même relié par un arc WiFi à une borne Internet, nuage et routeur annotés

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

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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials