2 Prerequisites and Devicetree Setup

The Zephyr project provides official installation and setup instructions online. This document assumes that Zephyr is installed and running, and that the Python virtual environment is currently running. This walkthrough uses the SAM L21 Xplained Pro Evaluation Kit (ATSAML21-XPRO-B) connected to the MTCH9010 Evaluation Kit (EV24U22A). Other boards (including those from other MCU vendors) are also compatible but may have differences in the UART/GPIO setup.

Note: The source code for this application note is included in the Zephyr project as the MTCH9010 Liquid Leak Detector Testbench, located in the samples/sensor/mtch9010 folder.

Ensure that a non-console UART instance is instantiated in Devicetree, with a baud rate of 38400 (no parity, 1 stop bit, 8-bit character length). This UART instance must not be the same as the serial terminal output. Then, inside the UART node, define the MTCH9010 sensor as shown in the snippet below from conductive.overlay.

/*
 * Copyright (c) 2025 Microchip Technology Inc.
 *
 * SPDX-License-Identifier: Apache-2.0
 */
#include <zephyr/dt-bindings/sensor/mtch9010.h>

&sercom1 {
	status = "okay";
	compatible = "atmel,sam0-uart";
	current-speed = <38400>;
	rxpo = <3>;
	txpo = <1>;

	pinctrl-0 = <&sercom1_default>;
	pinctrl-names = "default";

	my9010: mtch9010 {
		compatible = "microchip,mtch9010";

		uart-config-enable;
		operating-mode = "MTCH9010_CONDUCTIVE";
		extended-output-enable;
		extended-output-format = "MTCH9010_OUTPUT_FORMAT_BOTH";
		detect-value = <100>;

		wake-gpios = <&portb 14 GPIO_ACTIVE_LOW>;
		output-gpios = <&portb 15 GPIO_ACTIVE_HIGH>;
		heartbeat-gpios = <&porta 20 GPIO_ACTIVE_HIGH>;
	};
};

The node my9010 is the label assigned to the MTCH9010 in this case. Then, specify the device driver to use is microchip,mtch9010. Enabling this node is not necessary, as newly created nodes are enabled by default. The next segment of settings defines the desired MTCH9010 configuration that Zephyr will use.

First, set uart-config-enable to specify that Zephyr should configure this device over UART (as opposed to using GPIO or not configuring it at all). Then, operating-mode specifies whether the conductive (MTCH9010_CONDUCTIVE) or capacitive (MTCH9010_CAPACITIVE) detection mode will be used. If a sleep-period is set, the MTCH9010 will report data every specified number of seconds (1, 2, 4, … 256), as opposed to reporting on demand.

Then, set the flag extended-output-enable to customize the contents of the UART message. The message can contain the change from the last reading (MTCH9010_OUTPUT_FORMAT_DELTA), the current value (MTCH9010_OUTPUT_FORMAT_CURRENT), both the change and current values (MTCH9010_OUTPUT_FORMAT_BOTH), or a data stream for MPLAB® Data Visualizer (decoding is not supported in Zephyr; included for completeness).

The final two configuration parameters are the reference-value and the detect-value. The reference value is the baseline value of the sensor. If left undefined, then the sensor value at start-up time will be used. KConfig can be used to configure averaging at start-up, instead of using just a single sample point. The detect-value is the detection threshold at which the MTCH9010 will indicate that a liquid has leaked. This value requires tuning for each application, but a value of 100 for capacitive and conductive modes will detect a finger placed on the sensor.

Tip: The MTCH9010 Evaluation Kit (EV24U22A) can be directly connected to a computer to measure and experiment with sensor values using the built-in USB bridge. For additional information, refer to the MTCH9010 Evaluation Kit User Guide (DS50003876).

The last three components of the Devicetree configuration are the GPIO lines to wake (trigger) the device, the heartbeat output, and the state of the detect GPIO from the MTCH9010. Wake is only used when sleep-period is not set. If sleep-period is set, wake signals will be ignored by the MTCH9010. The heartbeat output from the MTCH9010 is an optional signal that allows the driver to ensure the device is connected. Finally, the output GPIO indicates the detect status (liquid detected/not detected). If a GPIO is not allocated, the driver will attempt to determine in software whether the sensor is tripped.

Warning: Software output calculation is not supported when using the MTCH9010_OUTPUT_FORMAT_DELTA format.

For additional information about the MTCH9010 driver, including settings not used in this tutorial, refer to the documentation page on the Zephyr website.