ultrasonic - Driver for ultrasonic range meters HC-SR04, HY-SRF05

group ultrasonic

ESP-IDF driver for ultrasonic range meters, e.g.

HC-SR04, HY-SRF05 and so on

Ported from esp-open-rtos

Copyright (C) 2016, 2018 Ruslan V. Uss unclerus@gmail.com

BSD Licensed as described in the file LICENSE

Defines

ESP_ERR_ULTRASONIC_PING
ESP_ERR_ULTRASONIC_PING_TIMEOUT
ESP_ERR_ULTRASONIC_ECHO_TIMEOUT

Functions

esp_err_t ultrasonic_init(const ultrasonic_sensor_t *dev)

Init ranging module.

Parameters

dev – Pointer to the device descriptor

Returns

ESP_OK on success

esp_err_t ultrasonic_measure_raw(const ultrasonic_sensor_t *dev, uint32_t max_time_us, uint32_t *time_us)

Measure time between ping and echo.

Parameters
  • dev – Pointer to the device descriptor

  • max_time_us – Maximal time to wait for echo

  • [out] time_us – Time, us

Returns

ESP_OK on success, otherwise:

esp_err_t ultrasonic_measure(const ultrasonic_sensor_t *dev, float max_distance, float *distance)

Measure distance in meters.

Parameters
  • dev – Pointer to the device descriptor

  • max_distance – Maximal distance to measure, meters

  • [out] distance – Distance in meters

Returns

ESP_OK on success, otherwise:

esp_err_t ultrasonic_measure_cm(const ultrasonic_sensor_t *dev, uint32_t max_distance, uint32_t *distance)

Measure distance in centimeters.

Parameters
  • dev – Pointer to the device descriptor

  • max_distance – Maximal distance to measure, centimeters

  • [out] distance – Distance in centimeters

Returns

ESP_OK on success, otherwise:

struct ultrasonic_sensor_t
#include <ultrasonic.h>

Device descriptor.