HC-SR04 supported in esp32?

323 views
Skip to first unread message

Rosario Pomillo

unread,
Mar 28, 2021, 6:15:16 PM3/28/21
to TasmotaUsers
Hi all,
I shoud be able to answer 'yes' and it is simply reading platform.io and my_user_config.h.
After #define USE_SR04, running platform, and updating custom fw I'm able to read echo distance wit a tasmota on esp8266 (wemos D1) but none happen on an esp-wroom-32.
Anyone had similar experience? ManY other sensors work wery well on the esp-wroom-32: BME280, BH1750, MLX90614 end so on, but SR04 does not collaborate. Any idea?
Thank you in advance.
R

Justin Adie

unread,
Mar 29, 2021, 12:51:04 AM3/29/21
to Rosario Pomillo, TasmotaUsers
I get unstable results in all modes of the SR04 on an esp32.   Some modes work better than others.   I have not been able to tie down why the results are unstable but I have found that even writing my own driver doesn't create solid results.  The same sensor and esp32 with just some sensor code on it works fine though.  

My suspicion is the interrupt handing is to blame.  I've wondered whether I could put the hr04 code onto a separate processor thread and see whether that improves things.  I'd have to dig further into the code to see whether tasmota is using the two cores sensibly.   In the meantime I have only three designs in the works that use an hr04 and  I intend to add a small second processor to handle the echo control if I use tasmota.  



--
You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/sonoffusers/a1cf4539-449c-4147-82a0-86087f60627fn%40googlegroups.com.

Philip Knowles

unread,
Mar 29, 2021, 2:16:25 AM3/29/21
to Rosario Pomillo, Justin Adie, TasmotaUsers
Have you tried the pre-compiled ESP32 sensors bin? If that works you know it's an issue in compiling. If not can raise an issue.

Regards

Phil K


From: 'Justin Adie' via TasmotaUsers <sonof...@googlegroups.com>
Sent: Monday, March 29, 2021 5:50:50 AM
To: Rosario Pomillo <asche...@gmail.com>
Cc: TasmotaUsers <sonof...@googlegroups.com>
Subject: Re: HC-SR04 supported in esp32?
 

aschenez69

unread,
Mar 29, 2021, 5:27:46 AM3/29/21
to TasmotaUsers
Thanks Phil & Justin,
Phil, the pre-compiled ESP32 sensors bin was my first option; the possibility of user (me) mistakes are very low because I made cross-tests between esp8266, esp32, and all other kind of sensors available to me at the moment, with the pre-compiled bin or with custom bin as necessary.

Justin, for sure I'm not able to carry out the kind of tests you made on driver source code, but I presume from symptoms that you are right. Perhaps the trig-echo loop performance is critically dependant on timing factors acting differently on esp32 and esp8266....
R.


Rosario Pomillo

unread,
Mar 29, 2021, 10:35:03 AM3/29/21
to TasmotaUsers

Justin Adie

unread,
Mar 30, 2021, 3:12:15 AM3/30/21
to Rosario Pomillo, TasmotaUsers
Just to flag I have found the non-waterproof (separate emitter/receiver) sensors to perform more reliably than the single emitter/receiver versions.



--
You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.

Laurentp

unread,
Mar 30, 2021, 9:03:55 PM3/30/21
to TasmotaUsers
>> I've wondered whether I could put the hr04 code onto a separate processor thread and see whether that improves things.

There is already an SR04 "variant" with (I guess) it's own uC: https://www.aliexpress.com/item/32907061275.html?spm=a2g0s.9042311.0.0.27425c0fEY0PYe
Some modes rely on serial comm, not "pulse" interface.
Hope this helps. Waterproof sensor as a bonus ;p

Laurent

sfromis

unread,
Mar 31, 2021, 4:49:22 AM3/31/21
to TasmotaUsers
The issue with HC-SR04 on ESP32 Tasmota should be fixed now. Works for me.

Reply all
Reply to author
Forward
0 new messages