Custom MatterPPM sensor class

Hello, can someone help me to create a PPM class for the Arduino nano matter?
At the moment i am working arround using the Tempsensor class for sending the PPM
Like 100 ppm is showing me 1 Grad Celsius.

/*
   Matter temperature sensor example

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

   The example creates a Matter temperature sensor device and publishes the current CPU temperature 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
   - Seeed Studio XIAO MG24 (Sense)

   Author: Tamas Jozsi (Silicon Labs)
 */
#include <Matter.h>
#include <MatterTemperature.h>
#include <SparkFun_SGP40_Arduino_Library.h>

SGP40 sgp40_sensor;

MatterTemperature matter_temp_sensor;

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

  pinMode(BTN_BUILTIN, INPUT_PULLUP);
  pinMode(LEDR, OUTPUT);
  digitalWrite(LEDR, HIGH);

  matter_temp_sensor.begin();

  Serial.println("Matter temperature 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);
    decommission_handler();
  }

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

  Serial.println("Waiting for Matter device discovery...");
  while (!matter_temp_sensor.is_online()) {
    delay(200);
    decommission_handler();
  }
  Serial.println("Matter device is now online");


  // Initialize I2C
  Wire.begin();

  // Initialize sensor
  Serial.println("SGP40 sensor initializing...");
  if (!sgp40_sensor.begin()) {
    Serial.println("SGP40 not detected");
    Serial.println("Check connections and press the reset button to reinitialize");
    while (1) ; // freezing
  }
  Serial.println("SGP40 sensor initialize done");
}

void loop()
{
  decommission_handler();

  int current_voc = sgp40_sensor.getVOCindex();
  matter_temp_sensor.set_measured_value_raw(current_voc);

  Serial.printf("Current CPU VOC: %.02f C\n", current_voc);

  delay(2000);
}
void decommission_handler() {
  if (digitalRead(BTN_BUILTIN) == LOW) {  //Push button pressed
    // measures time pressed
    int startTime = millis();
    while (digitalRead(BTN_BUILTIN) == LOW) {
      //delay(50);

      int elapsedTime = (millis() - startTime) / 1000.0;

      if (elapsedTime > 10) {
        Serial.printf("Decommissioning!\n");
        for (int i = 0; i < 10; i++) {
          digitalWrite(LEDR, !(digitalRead(LEDR)));
          delay(100);
        };

        if (!Matter.isDeviceCommissioned()) {
          Serial.println("Decommission done!");
          digitalWrite(LEDR, LOW);
        } else {
          Serial.println("Matter device is commissioned-> Starting Decommission process");
          nvm3_eraseAll(nvm3_defaultHandle);  // Decomission command
          digitalWrite(LED_BUILTIN, LOW);
          Serial.println("Decommission done!");
        }
        break;
      }
    }
  }
}

Thanks

If ChatGPT created, only CharGPT can fix. Good luck.

no this code is working, i have createt by my self.
I asked chatgpt to help how to send real PPM on my home assistant but i dont know where to register the PPM class

I am not OOP trained so I will say bye.

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