SR04 sensor driver serial mode not receiving data

453 views
Skip to first unread message

Ross Ackland

unread,
Sep 20, 2022, 8:08:42 AM9/20/22
to TasmotaUsers
Some  time ago I purchased an HC-SR04 distance sensor which worked perfectly with the SR04 sensor module in Trig/Echo mode. I then switched to the A02YYUW (listed at DFRobot as SKU:SEN0311) which uses a serial UART with 4  byte output (Header,DATA_H,DATA_L,SUM), 9600 baud. The SR04 module supports both Trig/Echo and UART serial devices, but I cant seem to read any data from the A02YYUW when using the SR04 module.

If I connect the sensor Tx output to GPIO3 and the Tasmota module configuration  Generic(18) configured for RX GPIO3 = SerialRx and issue a SerialSend4 command from the console, I can see lots of data coming in the console:

MQT: Water_Tank/tele/RESULT = {"SerialReceived":"06F8FDFF06F8FDFF06F8FDFF06F8F,,,,,8FDFF"}

I get exactly 519 values at roughly 7 sec intervals, which is probably the Rx buffer filling up as SerialSend4 means send as binary and value for SerialDelimiter is 255 (disabled). 

Now, when I set the module configuration so that RX GPIO3 = SR04 Ech/RX the SR04 driver correctly sets the sensor mode to SR04_MODE_SER_RECEIVER,   Mode 2 - Serial receive only. This mode doesn't use the SR04 Tri/TX assignment and the sensor specification says: When "RX" floats or input High level, the sensor outputs processed values, the data is more steady, response time: 100-300ms; when input Low level, the module outputs real-time value, response time: 100ms. 

However, the xsns_22_sr04 driver never sees any input bytes from the sensor. 
I do get a single entry in the console on restart:

RSL: RESULT = {"SerialReceived":"FF06F9FEFF06F7FC,,,,,,FAFF06F3F8FF06F308"}
but after that every attempt by SR4 to read there is no input data. For some reason the serial input buffer is empty, ie, the function call: sonar_serial->available() is always false

I'm using tasmota-sensors firmware version 12.1.1
If anyone can suggest what I'm doing wrong I would be very grateful. 





Philip Knowles

unread,
Sep 20, 2022, 8:40:38 AM9/20/22
to Ross Ackland, TasmotaUsers

It sends 4 bytes starting with FF and ending with a checksum. The middle 2 bytes are the distance. As far as I know there isn’t a UART on the HC-SR04 – it’s a time based measure – but I might be wrong

 

Sent from Mail for Windows

--
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/c716d828-850e-4d46-b9d3-fb59bcff6caen%40googlegroups.com.

 

Ross Ackland

unread,
Sep 20, 2022, 5:37:24 PM9/20/22
to TasmotaUsers
Hi Philip,
You are correct regarding 4 bytes from the A02YYUW and the HC-SR04 being time based only. The Tasmota SR04 driver supports both time based and serial sensors, including two byte and four byte serial versions which is pretty clever! The problem appears to be in the lower level TasmotaSerial driver. I'm guessing something to do with receiving the byte stream in raw binary mode. 
Before digging deeper, I thought I'd try the support forum.
thanks,
Ross

Philip Knowles

unread,
Sep 21, 2022, 12:39:19 AM9/21/22
to Ross Ackland, TasmotaUsers
There's an option somewhere for hex input on serial I seem to remember 


From: sonof...@googlegroups.com <sonof...@googlegroups.com> on behalf of Ross Ackland <ross.a...@gmail.com>
Sent: Tuesday, September 20, 2022 10:37:08 PM
To: TasmotaUsers <sonof...@googlegroups.com>
Subject: Re: SR04 sensor driver serial mode not receiving data
 

Ross Ackland

unread,
Sep 21, 2022, 2:18:29 AM9/21/22
to TasmotaUsers
I solved the problem. I noticed the software serial driver was always being used even though I assigned the GPIO-3 RX pin which is connected to the UART. Looking at the source code for TasmotaSerial driver the constructor checks which GPIO pins are assigned to decide if hardware_fallback is available. To fix this (in xsns_22_sr04.ino) the value of sr04_trig_pin needs to be -1 then it all works fine. Now I have a working A02YYUW sensor. :-)

On Wed, Sep 21, 2022 at 2:39 PM Philip Knowles <knowles...@gmail.com> wrote:
There's an option somewhere for hex input on serial I seem to remember 

Reply all
Reply to author
Forward
0 new messages