<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>MCX MicrocontrollersのトピックHow to Interface HC-SR04 Ultrasonic Sensor with NXP i.MX93 Board Using GPIO and Timer Input Capture?</title>
    <link>https://community.nxp.com/t5/MCX-Microcontrollers/How-to-Interface-HC-SR04-Ultrasonic-Sensor-with-NXP-i-MX93-Board/m-p/2130115#M3506</link>
    <description>&lt;P&gt;I am working on a project involving distance measurement using the &lt;STRONG&gt;HC-SR04 Ultrasonic Sensor&lt;/STRONG&gt; and the &lt;STRONG&gt;i.MX93 EVK (Evaluation Kit)&lt;/STRONG&gt;. I would like to understand the proper method to interface the sensor with the board.&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;&lt;STRONG&gt;Requirements&lt;/STRONG&gt;:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;Trigger the &lt;STRONG&gt;TRIG&lt;/STRONG&gt; pin with a 10 µs high pulse.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Measure the &lt;STRONG&gt;ECHO&lt;/STRONG&gt; pin pulse width using &lt;STRONG&gt;GPIO + Timer Input Capture&lt;/STRONG&gt; (or interruptCalculate the distance in centimeters based on the pulse width.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;HR /&gt;&lt;P&gt;&lt;STRONG&gt;Questions&lt;/STRONG&gt;:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;What GPIO or TPM/EPIT resources on the i.MX93 should I use for:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;Outputting the TRIG pulse?&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Capturing the ECHO signal (input capture or edge-triggered interrupt)?&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;How can I configure the GPIO pins for TRIG and ECHO using &lt;STRONG&gt;GPIO driver or IOMUX settings&lt;/STRONG&gt;?&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;What is the recommended way to generate a 10 µs pulse on TRIG using i.MX93? Should I use a delay loop or a timer?&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;How can I use &lt;STRONG&gt;GPT&lt;/STRONG&gt; (General Purpose Timer) or any available &lt;STRONG&gt;TPM/EPIT timer&lt;/STRONG&gt; to:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;Detect rising and falling edges on ECHO?&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Measure the time between them (pulse width)?&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Do I need to handle timer overflow manually or is there a built-in overflow counter?&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Could you provide a sample initialization and ISR code snippet for:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;TRIG pin setup and pulse generation.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;ECHO pin edge detection and duration capture?&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;What is the recommended system clock configuration for precise timing (1 µs resolution)?&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Thank you in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;LI-PRODUCT title="i.MX93EVK" id="i.MX93EVK"&gt;&lt;/LI-PRODUCT&gt;&amp;nbsp;&lt;LI-PRODUCT title="TPMC-PEXPERT" id="TPMC-PEXPERT"&gt;&lt;/LI-PRODUCT&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 08 Jul 2025 11:23:45 GMT</pubDate>
    <dc:creator>Manjunathb</dc:creator>
    <dc:date>2025-07-08T11:23:45Z</dc:date>
    <item>
      <title>How to Interface HC-SR04 Ultrasonic Sensor with NXP i.MX93 Board Using GPIO and Timer Input Capture?</title>
      <link>https://community.nxp.com/t5/MCX-Microcontrollers/How-to-Interface-HC-SR04-Ultrasonic-Sensor-with-NXP-i-MX93-Board/m-p/2130115#M3506</link>
      <description>&lt;P&gt;I am working on a project involving distance measurement using the &lt;STRONG&gt;HC-SR04 Ultrasonic Sensor&lt;/STRONG&gt; and the &lt;STRONG&gt;i.MX93 EVK (Evaluation Kit)&lt;/STRONG&gt;. I would like to understand the proper method to interface the sensor with the board.&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;&lt;STRONG&gt;Requirements&lt;/STRONG&gt;:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;Trigger the &lt;STRONG&gt;TRIG&lt;/STRONG&gt; pin with a 10 µs high pulse.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Measure the &lt;STRONG&gt;ECHO&lt;/STRONG&gt; pin pulse width using &lt;STRONG&gt;GPIO + Timer Input Capture&lt;/STRONG&gt; (or interruptCalculate the distance in centimeters based on the pulse width.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;HR /&gt;&lt;P&gt;&lt;STRONG&gt;Questions&lt;/STRONG&gt;:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;What GPIO or TPM/EPIT resources on the i.MX93 should I use for:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;Outputting the TRIG pulse?&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Capturing the ECHO signal (input capture or edge-triggered interrupt)?&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;How can I configure the GPIO pins for TRIG and ECHO using &lt;STRONG&gt;GPIO driver or IOMUX settings&lt;/STRONG&gt;?&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;What is the recommended way to generate a 10 µs pulse on TRIG using i.MX93? Should I use a delay loop or a timer?&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;How can I use &lt;STRONG&gt;GPT&lt;/STRONG&gt; (General Purpose Timer) or any available &lt;STRONG&gt;TPM/EPIT timer&lt;/STRONG&gt; to:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;Detect rising and falling edges on ECHO?&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Measure the time between them (pulse width)?&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Do I need to handle timer overflow manually or is there a built-in overflow counter?&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Could you provide a sample initialization and ISR code snippet for:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;TRIG pin setup and pulse generation.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;ECHO pin edge detection and duration capture?&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;What is the recommended system clock configuration for precise timing (1 µs resolution)?&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Thank you in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;LI-PRODUCT title="i.MX93EVK" id="i.MX93EVK"&gt;&lt;/LI-PRODUCT&gt;&amp;nbsp;&lt;LI-PRODUCT title="TPMC-PEXPERT" id="TPMC-PEXPERT"&gt;&lt;/LI-PRODUCT&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jul 2025 11:23:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCX-Microcontrollers/How-to-Interface-HC-SR04-Ultrasonic-Sensor-with-NXP-i-MX93-Board/m-p/2130115#M3506</guid>
      <dc:creator>Manjunathb</dc:creator>
      <dc:date>2025-07-08T11:23:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to Interface HC-SR04 Ultrasonic Sensor with NXP i.MX93 Board Using GPIO and Timer Input Capt</title>
      <link>https://community.nxp.com/t5/MCX-Microcontrollers/How-to-Interface-HC-SR04-Ultrasonic-Sensor-with-NXP-i-MX93-Board/m-p/2130997#M3511</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="HwtZe"&gt;&lt;SPAN class="jCAhz ChMk0b"&gt;&lt;SPAN class="ryNqvb"&gt;To integrate the HC-SR04 ultrasonic sensor with an iMX9, you need to connect the sensor pins to the iMX9's GPIO pins.&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;SPAN class="jCAhz ChMk0b"&gt;&lt;SPAN class="ryNqvb"&gt;The HC-SR04 has four pins: VCC (5V), GND, TRIG, and ECHO.&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;SPAN class="jCAhz ChMk0b"&gt;&lt;SPAN class="ryNqvb"&gt;You'll need to connect VCC to the iMX9's 5V power supply, GND to ground, TRIG to a GPIO pin that we'll configure as an output, and ECHO to another GPIO pin that we'll configure as an input.&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;SPAN class="jCAhz ChMk0b"&gt;&lt;SPAN class="ryNqvb"&gt;Then, using code, you'll generate a pulse on the TRIG pin and measure the time it takes to receive a pulse on the ECHO pin to calculate the distance.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="jCAhz ChMk0b"&gt;&lt;SPAN class="ryNqvb"&gt; Connecting the HC-SR04 to the iMX9: VCC: Connect it to the iMX9's 5V power supply.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="jCAhz ChMk0b"&gt;&lt;SPAN class="ryNqvb"&gt; GND: Connect it to the iMX9's ground.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="jCAhz ChMk0b"&gt;&lt;SPAN class="ryNqvb"&gt; TRIG: Connect it to a GPIO pin on the iMX9 that will be configured as an output.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="jCAhz ChMk0b"&gt;&lt;SPAN class="ryNqvb"&gt; ECHO: Connect it to a GPIO pin on the iMX9 that will be configured as an input.&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="HwtZe"&gt;&lt;SPAN class="jCAhz ChMk0b"&gt;&lt;SPAN class="ryNqvb"&gt;Example code (pseudo-code): C &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;#define TRIG_PIN 2 // Ejemplo, pin GPIO 2&lt;BR /&gt;#define ECHO_PIN 3 // Ejemplo, pin GPIO 3&lt;/P&gt;
&lt;P&gt;// Función para calcular la distancia&lt;BR /&gt;int distancia() {&lt;BR /&gt;// 1. Generar pulso de disparo (10 us)&lt;BR /&gt;digitalWrite(TRIG_PIN, LOW);&lt;BR /&gt;delayMicroseconds(2);&lt;BR /&gt;digitalWrite(TRIG_PIN, HIGH);&lt;BR /&gt;delayMicroseconds(10);&lt;BR /&gt;digitalWrite(TRIG_PIN, LOW);&lt;/P&gt;
&lt;P&gt;// 2. Medir el tiempo del pulso de eco&lt;BR /&gt;long duration = pulseIn(ECHO_PIN, HIGH);&lt;/P&gt;
&lt;P&gt;// 3. Calcular la distancia (velocidad del sonido: 343 m/s o 0.0343 cm/us)&lt;BR /&gt;int distance = duration * 0.0343 / 2;&lt;BR /&gt;return distance;&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;void setup() {&lt;BR /&gt;pinMode(TRIG_PIN, OUTPUT);&lt;BR /&gt;pinMode(ECHO_PIN, INPUT);&lt;BR /&gt;Serial.begin(115200); // Iniciar comunicación serial&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;void loop() {&lt;BR /&gt;int dist = distancia();&lt;BR /&gt;Serial.print("Distancia: ");&lt;BR /&gt;Serial.print(dist);&lt;BR /&gt;Serial.println(" cm");&lt;BR /&gt;delay(100); // Retardo de 100ms&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="HwtZe"&gt;&lt;SPAN class="jCAhz"&gt;&lt;SPAN class="ryNqvb"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="jCAhz"&gt;&lt;SPAN class="ryNqvb"&gt;TRIG_PIN and ECHO_PIN define the iMX9 GPIO pins connected to the sensor.&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;SPAN class="jCAhz"&gt;&lt;SPAN class="ryNqvb"&gt;The distance() function calculates the distance: First, it generates a short pulse (10 ms) on the TRIG pin to start the measurement.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="jCAhz"&gt;&lt;SPAN class="ryNqvb"&gt; Then, it uses the pulseIn() function to measure the pulse duration on the ECHO pin (the time it takes for the echo to return).&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="HwtZe"&gt;&lt;SPAN class="jCAhz"&gt;&lt;SPAN class="ryNqvb"&gt; Finally, it calculates the distance using the speed of sound.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="jCAhz"&gt;&lt;SPAN class="ryNqvb"&gt; setup() initializes the pins as output and input, and begins serial communication.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="jCAhz"&gt;&lt;SPAN class="ryNqvb"&gt; loop() calls the distance() function, prints the result to the serial console, and waits 100 ms before repeating the process.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="jCAhz"&gt;&lt;SPAN class="ryNqvb"&gt; Considerations: Voltage: The HC-SR04 operates at 5 V, while some iMX9 pins may be 3.3 V. You may need a logic level converter or a voltage regulator to ensure compatibility.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="jCAhz"&gt;&lt;SPAN class="ryNqvb"&gt; Libraries: On platforms like Arduino, there are libraries that simplify interaction with the HC-SR04.&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;SPAN class="jCAhz"&gt;&lt;SPAN class="ryNqvb"&gt;If you're using an operating system like Linux on the iMX9, you may need to create your own functions or search for iMX9-specific libraries.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="jCAhz"&gt;&lt;SPAN class="ryNqvb"&gt; Accuracy: The accuracy of the HC-SR04 may vary depending on environmental conditions (temperature, humidity) and the surface of the object.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="jCAhz"&gt;&lt;SPAN class="ryNqvb"&gt; Interference: Avoid interference from other nearby ultrasonic devices.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="HwtZe"&gt;&lt;SPAN class="jCAhz"&gt;&lt;SPAN class="ryNqvb"&gt;Regards&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jul 2025 14:49:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCX-Microcontrollers/How-to-Interface-HC-SR04-Ultrasonic-Sensor-with-NXP-i-MX93-Board/m-p/2130997#M3511</guid>
      <dc:creator>Bio_TICFSL</dc:creator>
      <dc:date>2025-07-09T14:49:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to Interface HC-SR04 Ultrasonic Sensor with NXP i.MX93 Board Using GPIO and Timer Input Capt</title>
      <link>https://community.nxp.com/t5/MCX-Microcontrollers/How-to-Interface-HC-SR04-Ultrasonic-Sensor-with-NXP-i-MX93-Board/m-p/2131618#M3516</link>
      <description>Thank you for your reply!</description>
      <pubDate>Thu, 10 Jul 2025 09:52:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCX-Microcontrollers/How-to-Interface-HC-SR04-Ultrasonic-Sensor-with-NXP-i-MX93-Board/m-p/2131618#M3516</guid>
      <dc:creator>Manjunathb</dc:creator>
      <dc:date>2025-07-10T09:52:06Z</dc:date>
    </item>
  </channel>
</rss>

