🔬

Ultrasonic Echo Pulse-Width Distance Measurement

Interface the XRP’s ultrasonic rangefinder with the Red Pitaya to capture the Trigger and Echo pulses on a dual-trace oscilloscope. We will empirically measure the time width of the Echo pulse and compare the hardware's elapsed time against the physical ruler distance.

Materials and Setup

  • XRP Robot and 3.3V-compatible Ultrasonic Rangefinder
  • Red Pitaya (configured for LV ±1V inputs)
  • Oscilloscope probes (configured for 10x attenuation)
  • Four male-to-male jumper wires (GPIO 0, 1 and GND x2).

Measurement Configuration

  1. Verify Zero-Power State: Disconnect the XRP from USB-C and set the physical battery switch to OFF. Make all connections while the system is unpowered.
  2. Connect the Probes: Connect Red Pitaya Channel 1 to XRP GPIO 0 (Trigger) and Channel 2 to GPIO 1 (Echo) using jumper wires. Connect both probe ground clips to the same expansion-header GND pin. Ensure that the probe hooks contact the exposed metal conductors.
  3. Connection Summary:
    1. XRP GPIO 0 / Trigger ── Channel 1 probe
    2. XRP GPIO 1 / Echo ── Channel 2 probe
    3. XRP GND ── both probe ground clips
    4. Secure all connections and do not reposition them during the measurement.
  4. Probes: Set both physical probes and the Red Pitaya software attenuation to 10×.
  5. Oscilloscope: Enable Channels 1 and 2, set to 1 V/div, and set the timebase to 2 ms/div.
  6. Trigger: Select Channel 1, rising edge, approximately 1.5 V, and Normal mode.
  7. Enter Safe Testing State: Connect the USB-C cable to the XRP while leaving the battery switch OFF.

Exploration and Analysis

  1. Signal capture: Run the MicroPython script to initiate a continuous sensing loop:
import time from XRPLib.defaults import * print("Continuous rangefinder routine active.") try: while True: # Measure physical distance in centimeters distance = rangefinder.distance() print("Robot reported distance:", distance, "cm") time.sleep(0.1) except KeyboardInterrupt: print("Routine stopped.")
  1. Place a flat, solid target directly in front of the sensor face. Before calculating, perform the following observations:
    1. Verify which signal appears first and which stays HIGH longer.
    2. Observe how the Echo pulse width changes as the target is moved farther away.
  2. Utilize the oscilloscope’s time cursors to measure the exact Echo pulse width (Δt) (\Delta t) for three distinct distances. Compare the calculated distance against physical ruler measurements and the software's reported values.
 
  • Test 1: Near target
    • Visual Target: Short Echo pulse corresponding to the nearest target position.
    • Task: Measure the Echo pulse width, Δt, using the time cursors and calculate the distance.
    Check measured values and waveform:
    • Approximate ruler distance: 10 cm
    • Measured Echo width: 607 μs = 0.607 ms
    • Calculated distance: d ≈ 17.15×0.607 = 10.41 cm
    • XRP-reported distance: 10.58 cm
    • Observed waveform:
    • notion image
 
  • Test 2: Medium target:
    • Visual Target: Short Echo pulse corresponding to the nearest target position.
    • Task: Measure the Echo pulse width, Δt, using the time cursors and calculate the distance.
    Check measured values and waveform:
    • Approximate ruler distance: 50 cm
    • Measured Echo width: 2.92 ms
    • Calculated distance: d ≈ 17.15×2.92 = 50.08 cm
    • XRP-reported distance: 50.55 cm
    • Observed waveform:
    • notion image
 
  • Test 3: Far target:
    • Visual Target: Short Echo pulse corresponding to the nearest target position.
    • Task: Measure the Echo pulse width, Δt, using the time cursors and calculate the distance.
    Check measured values and waveform:
    • Approximate ruler distance: 100 cm
    • Measured Echo width: 8.17 ms
    • Calculated distance: d ≈ 17.15×5.88 = 100.8 cm
    • XRP-reported distance: 100.43 cm
    • Observed waveform:
    • notion image

Conclusion

By measuring the Echo pulse width in the time domain, we directly relate the ultrasonic signal’s round-trip travel time to the target distance. The measured pulse widths agreed well with the ruler measurements at approximately 10.5 cm, 50 cm, and 100 cm. The results also demonstrate that practical measurement range depends on target size, material, alignment, and beam spread.

Shutdown Procedure

  1. Halt Execution: Stop the MicroPython script in XRPCode.
  2. Verify Waveforms: Confirm via the Red Pitaya interface that all active traces on GPIOs have ceased pulsing and flatlined.
  3. Unplug Logic Power: Disconnect the USB-C cable from the XRP Controller.
  4. Isolate Battery: Double-check that the physical battery switch is set to OFF.
  5. Safe Modifications: Only alter, disconnect, or clean up your physical probe connections and jumper wires once the system is in this completely unpowered state.