Reading pulse from HC-SR04 sensor

titi_prog
Posts: 1
Joined: Wed May 16, 2018 8:17 pm

Reading pulse from HC-SR04 sensor

Postby titi_prog » Wed May 16, 2018 8:20 pm

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)

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Need a little help!

Postby kolban » Thu May 17, 2018 2:25 pm

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".
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Reading pulse from HC-SR04 sensor

Postby ESP_Angus » Fri May 18, 2018 2:06 am

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

Deouss
Posts: 425
Joined: Tue Mar 20, 2018 11:36 am

Re: Reading pulse from HC-SR04 sensor

Postby Deouss » Fri May 18, 2018 12:25 pm

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 ;)

Deouss
Posts: 425
Joined: Tue Mar 20, 2018 11:36 am

Re: Reading pulse from HC-SR04 sensor

Postby Deouss » Mon May 21, 2018 11:17 am


Who is online

Users browsing this forum: Bing [Bot] and 86 guests