Use Ultrasonic module on DEBIX - Part 1

2024.5.27by debix.io

Example Device: DEBIX Model A + I/O Board

Overview

lThe model of Ultrasonic Distance Measuring Module is HC-SR04.

lApply a 10us high level signal to the Trig end, and the Echo end will receive a response level that is proportional to the measurement distance.

lThe distance calculation formula is: distance (m) = high level time * speed of sound (340m/s)/2.


Hardware installation

lUltrasonic module's VCC terminal is connected to J2 Pin2 of DEBIX I/O board

lUltrasonic module's Trig terminal is connected to J2 Pin33 of DEBIX I/O board

lUltrasonic module's Echo terminal is connected to J2 Pin31 of DEBIX I/O board

lUltrasonic module's GND terminal is connected to J2 Pin39 of DEBIX I/O board

Modify the device tree imx8mp-evk.dts

1. Add the GPIO to be used under iomuxc node:

pinctrl_HC_SR04: SR04group{

fsl,pins = <

MX8MP_IOMUXC_SPDIF_RX__GPIO5_IO04 0x40000

MX8MP_IOMUXC_SPDIF_TX__GPIO5_IO03 0x40000

>;

};

2. Add the ultrasonic module node under the root node:

hc_sr04: hc_sr04 {

compatible = "HC_SR04";

pinctrl-0 = <&pinctrl_HC_SR04>;

trig-gpios = <&gpio5 03 GPIO_ACTIVE_LOW>;

echo-gpios = <&gpio5 04 GPIO_ACTIVE_LOW>;

};


3. Add outside the root node:

&hc_sr04 {

status = "okay";

};

4. Compile and replace the device tree file

lCompile the device tree in the source directory: make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- dtbs

lCopy the compiled new device tree file arch/arm64/boot/dts/freescale/imx8mp-evk.dtb to the /boot directory of DEBIX and restart DEBIX.


5. Check whether dts contains the modified device tree node.

lRun the command ls /sys/firmware/devicetree/base/hc_sr04/


Run the command cat /sys/firmware/devicetree/base/hc_sr04/compatible