Try to implement LED Blinky on Matter Template Example code.

I want to modify the example code which is provided by Matter SDK and there are several examples are there are Light bulb example code, Light Switch example code and Template code as well. Now I just right now simply wants to understand the code and modify it.


But it very complex to understand the code so can you please provide or explain the basic flow of Template like how it works. 

And also, I want to modify that code want to do some practical's like blink an LED but i did not know exactly where in that code I have to Change.

Please your help will be appreciated. 

Parents
  • Hi,

    I recommend taking a look at Adding clusters to Matter application. The part about using the ZAP tool to add clusters and attributes is not relevant for your question, but section 3 and 4 where you modify and add code are.
    The main takeaway is that you have events (in AppEvent) which are added to a queue when they happen. When an event is first in the queue and should be handled, the corresponding handler will be called. For example, you have the ButtonEvent which is added to the app event queue when a button is pressed. When it is time for this event to be handled, the function ButtonEventHandler() is called, where you can add code for what you want to happen when a specific button is pressed.

    And also, I want to modify that code want to do some practical's like blink an LED but i did not know exactly where in that code I have to Change.

    This depends on when you want the LED to blink. If you want it to blink regularly you could create use a timer similar to sFunctionTimer, and then toggle the LED in the callback.

    Best regards,
    Marte

  • Okay first of all I will take understanding of Adding clusters to Matter application and in that particular section 3 and 4.

    I am also wanting to know from you that Can you please give me some reference to get more knowledge about ZAP tool because I want to perform DHT11 Temperature sensor on Matter Light Switch Example code so in that case is there any use of ZAP tool?

  • Hi,

    Yes, you can use the ZAP tool to add devices on endpoints and clusters, so you can use this to add a temperature sensor device. This is what is done in step 2 in the guide I linked to in my previous reply, so I recommend going through that. You can also find some information in our documentation under Matter tools - ZAP tool, and in the official ZCL Advanced Platform documentation.

    Best regards,
    Marte

  • Okay thanks for it.

    Now Basically I want to implement DHT11 Temperature Sensor on Matter Light Switch Example code and for that as you mentioned I followed above steps of ZAP tool as well. But In that I have one doubt that when we select our device in ZAP tool and I want DHT11 Temperature Sensor and in that DHT11 Sensor is not mentioned so now which Sensor I choose from there.

    As you also see above image there are different Sensors like HA Temperature Sensor and all but there is not option of DHT11 Sensor.

Reply
  • Okay thanks for it.

    Now Basically I want to implement DHT11 Temperature Sensor on Matter Light Switch Example code and for that as you mentioned I followed above steps of ZAP tool as well. But In that I have one doubt that when we select our device in ZAP tool and I want DHT11 Temperature Sensor and in that DHT11 Sensor is not mentioned so now which Sensor I choose from there.

    As you also see above image there are different Sensors like HA Temperature Sensor and all but there is not option of DHT11 Sensor.

Children
  • Hi,

    Device type is not related to the physical sensor. You should select "Matter Temperature Sensor".

    Best regards,
    Marte

  • Yes Marte that work is done.

    Now I can add new clusters as you said Matter Temperature Sensor I selected and Generate their files as well. 

    When I open callback-stub.cpp file I can See the clusters of Temperature Sensor.

    But Now I have an doubt that How can I add My PIR Sensor with the Temperature Cluster which I created.

    Also Can You me some reference about once I created the cluster of Temperature Sensor and after that at which place in code I have to modify for Implement PIR Sensor on Matter SDK.

  • Hi,

    You should test the sensor standalone before integrating it with Matter, to ensure that the sensor is working correctly and that you are able to get data from it. 
    I recommend starting with DHT: Aosong DHT Digital-output Humidity and Temperature Sensor. This is using DHT22 by default, but if you do not have the dht22 property in the overlay file, then it will use DHT11 instead.

    You will have to create an overlay file for your board (nrf52840dk_nrf52840.overlay) similar to the nrf52dk_nrf52832.overlay that is already in the sample, just with DHT11. Your overlay file should look similar to this:

    / {
    	dht11 {
    		compatible = "aosong,dht";
    		status = "okay";
    		dio-gpios = <&gpio0 11 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
    	};
    };

    Best regards,
    Marte

  • Yes Marte, We done above implementation of DHT Sensor.

    We got the temperature and humidity as an Output of DHT11 Sensors that we have for it.

    Now I want to ask that how Can I Integrate it with Matter?

  • Hi,

    I recommend taking a look at the Thingy53 Matter weather station application. This is using the temperature and humidity sensor on the Thingy53 to update the temperature and humidity measurements, so it should be similar to what you are doing.

    Most of the relevant code can be found in app_task.cpp.

    The function UpdateClustersState(), calls sensor_sample_fetch() to fetch new data from the sensor. This is the same as is used in the DHT sample. If fetching sensor data was successful, it calls UpdateTemperatureClusterState() to update the MeasuredValue attribute of the Temperature Measurement cluster. UpdateClustersState() is called regularly using a timer, similar to the SensorTimer in the Adding clusters to Matter application.

    If you have followed the guide and implemented everything there, what you need to do to get the actual measurements is to change SensorMeasureHandler() to be more like the Matter weather station application as explained above. If you only want to have it as a temperature sensor and only update the Temperature Measurement cluster, you can ignore UpdateClustersState() and only add code similar to UpdateTemperatureClusterState() in your SensorMeasureHandler().

    Additionally, you must make sure to add the necessary configurations in prj.conf and nrf52840dk_nrf52840.overlay. For nrf52840dk_nrf52840.overlay you need to add dht11 as in my previous reply. In prj.conf you need to add the following:

    CONFIG_SENSOR=y
    CONFIG_GPIO=y

    Best regards,
    Marte

Related