Nano Matter on Alexa with temp and humidity sensors

Hi,

I received an Arduino Nano Matter a couple of days ago and have managed to get it working with a Sparkfun BME280 board providing temperature data, using a modified version of the matter_temp_sensor example. I will say right up front that getting it to connect to Alexa via an Echo 4th Gen serving as a Thread Border Router is tedious and a balky process. Can't blame the Arduino Nano Matter for that; could just be the way the Alexa infrastructure works.

When the matter_temp_sensor example running on the Nano Matter connects to Alexa, it shows two devices: an Arduino hub, and the temperature sensor. Alexa might call them "first device" and "second device" when it initially discovers them, but you can name them something meaningful.

I wanted to use the Arduino Nano Matter + BME280 to report both temperature and humidity through Alexa. Silly me. While the Arduino Nano Matter Silicon Labs examples include matter_humidity_sensor.ino, Alexa has no interface for a humidity sensor per se.

So I thought about what the BME280 can provide. It can report temperature, humidity, dewpoint, and pressure. Well, dewpoint is a temperature. So I modified the matter_temp_sensor.ino example to report two temperatures, thusly:

/*
   Matter temperature and dewpoint sensor example

   The example shows how to create a temperature and dewpoint sensor with the Arduino Matter API.

   The example creates a Matter temperature and dewpoint sensor device and publishes the current
   temperature and dewpoint through it.
   The device has to be commissioned to a Matter hub first.

   Compatible boards:
   - Arduino Nano Matter
   - SparkFun Thing Plus MGM240P
   - xG24 Explorer Kit
   - xG24 Dev Kit

   Author: Tamas Jozsi (Silicon Labs)
   Modified by Chip F. (Just 'Plane Circuits) 16 may 2024 to report temp and DP from a BME280
 */
#include <Matter.h>
#include <MatterTemperature.h>
#include <SparkFunBME280.h>

MatterTemperature matter_temp_sensor1;
MatterTemperature matter_temp_sensor2;

BME280 mySensor;  //Uses default I2C address 0x77

void initBME();

void setup()
{
  Serial.begin(115200);
  Matter.begin();
  matter_temp_sensor1.begin();
  matter_temp_sensor2.begin();

  initBME();

  Serial.println("Matter temperature and dewpoint sensor");

  if (!Matter.isDeviceCommissioned()) {
    Serial.println("Matter device is not commissioned");
    Serial.println("Commission it to your Matter hub with the manual pairing code or QR code");
    Serial.printf("Manual pairing code: %s\n", Matter.getManualPairingCode().c_str());
    Serial.printf("QR code URL: %s\n", Matter.getOnboardingQRCodeUrl().c_str());
  }
  while (!Matter.isDeviceCommissioned()) {
    delay(200);
  }

  Serial.println("Waiting for Thread network...");
  while (!Matter.isDeviceThreadConnected()) {
    delay(200);
  }
  Serial.println("Connected to Thread network");

  Serial.println("Waiting for Matter device discovery...");
  while (!matter_temp_sensor1.is_online() || !matter_temp_sensor2.is_online()) {
    delay(200);
  }
  Serial.println("Matter devices are now online");
}

void loop()
{
  float current_temp1 = mySensor.readTempC();
  float current_temp2 = mySensor.dewPointC();

  matter_temp_sensor1.set_measured_value_celsius(current_temp1);
  matter_temp_sensor2.set_measured_value_celsius(current_temp2);

  Serial.printf("Current temperature: %.02f C\n", current_temp1);
  Serial.printf("Current dewpoint: %.02f C\n", current_temp2);
  Serial.println();

  delay(5000);
}

// Initialize the BME280 sensor
void initBME() {
  Wire.begin();

  mySensor.setI2CAddress(0x77);  //The default for the SparkFun Environmental Combo board is 0x77 (jumper open).
  //If you close the jumper it is 0x76
  //The I2C address must be set before .begin() otherwise the cal values will fail to load.

  if (mySensor.beginI2C() == false) {
    Serial.println("BME280 sensor connect failed");
  } else {
    Serial.println("BME280 sensor initialization appears to have succeeded.");
  }
}

The most urgent problem I'm currently experiencing is that if I move the Nano Matter + BME280 and the Amazon Echo Gen 4 serving as a Thread Border Router from my family room to my garage, the Nano Matter doesn't seem to reliably re-connect to Alexa. When I use the Alexa app on my phone to look at the temperature and dewpoint sensors, Alexa reports that they are connected to Echo Dot devices whose power supplies I unplugged after I moved the Nano Matter. (!!!) Is there a way, using the Silicon Labs-provided software, to detect a faulty Matter connection and re-initialize the connection?

I will also say that compiling simple sketches such as the above for the Arduino Nano Matter using the Arduino IDE is an extremely time-consuming and tedious process. Push the button, go out to lunch kind of tedious. And that's on a Windows 11 machine with 16 GB of RAM and an i7-1195G7 @ 2.90GHz. Makes troubleshooting very time-consuming.

TIA for any constructive comments.

Hi, I just tried your code on a Mac M2 Air and it complied in about 45secs ? I haven't tested uploading just yet, need to wire up the BME280 to my Nano Matter devices

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.