Page 1 of 1

Reading pulse from HC-SR04 sensor

Posted: Wed May 16, 2018 8:20 pm
by titi_prog
Hello,

So i am developing a driver for the HC-SR04 ultrasonic senosr with esp-idf, and i don't seem to get it working. Do you have any suggestions on what api should i use for reading the pulse ? (i tried doing my own way but dosen't semm to work)

Re: Need a little help!

Posted: Thu May 17, 2018 2:25 pm
by kolban
Howdy,
Did you try googling using "esp32 HC-SR04"? It seems to turn up quite a wealth of hits. Maybe examine some of these and see which APIs these folks used?

Please don't take this badly, but maybe consider a more descriptive names for your posts ... for example "Timing API for use with HC-SR04".

Re: Reading pulse from HC-SR04 sensor

Posted: Fri May 18, 2018 2:06 am
by ESP_Angus
I've renamed the post with a more meaningful name.

The ESP32 RMT peripheral is ideal for reading the gaps between pulse lengths. You can check out the RMT TX/RX example in ESP-IDF:
https://github.com/espressif/esp-idf/tr ... _nec_tx_rx

(In your case you only need the RX.)

The RMT peripheral driver is documented here:
http://esp-idf.readthedocs.io/en/latest ... s/rmt.html

Re: Reading pulse from HC-SR04 sensor

Posted: Fri May 18, 2018 12:25 pm
by Deouss
I was about to program same sensor too to measure water levels during day.
I think it is very simple - you must create pin interrupt triggered on high at the 'echo' pin on the sensor.
You start device by setting 'trigger' pin high - then delay 10us and set it to low, save ticks and after that measure end ticks at the interrupt ;)

Re: Reading pulse from HC-SR04 sensor

Posted: Mon May 21, 2018 11:17 am
by Deouss