Add argument to specify triggerwidth, accomodating slower-response sensors
Hi Tim,
Working on ESPEasy, where a user requested the trigger-width for these distance sensors to be configurable, so I implemented that in the local copy of NewPing
used by ESPEasy.
This being OSS, it seems most appropriate to have this improvement also in the main NewPing code.
Unfortunately I’m not allowed to create a PR here (yet?), so I could contribute my changes, based on v1.9.6.
Kind regards,
Ton
Comments (15)
-
repo owner -
repo owner - marked as trivial
-
reporter Finally got back to this and created the PR. Being more used to the Github flow, Bitbucket feels a bit clunky.
The reasoning for this proposed change is that some users are using compatible hardware, but that seems to be more timing critical, so they requested for the trigger-width to be configurable, which I implemented locally, and, trying to be nice, I prefer to share any improvements with the original library, for others to also be able to use that when needed
Tried to link the PR to automatically close this issue once you decide to merge, but not sure if that actually works like it does with Github, and the UI didn’t give any clues, other than to link a Jira issue, which obviously I didn’t create.
-
repo owner I looked at your PR. Adding a new parameter to the NewPing constructor would be a breaking change for anyone currently not using the new parameter.
Instead, why not just define a value in
NewPing.h
like this:#define TRIGGER_WIDTH 10
Then replace the trigger delay with:
delayMicroseconds(TRIGGER_WIDTH);
This wouldn’t break any existing code, wouldn’t increase the code size, and the user could change TRIGGER_WIDTH if they had an out of spec sensor which required longer than 10uS to trigger the sensor. This would also be consistent with other values which users can set like
MAX_SENSOR_DELAY
andPING_MEDIAN_DELAY
. -
reporter The constructor has a default value of 10 for that argument, making it optional. That is a main point in my coding, be backward compatible.
ESPEasy is a project that doesn’t need compilation for an end-user (the 'Easy' part of the name…), so it has configuration settings, including this trigger-width setting. That still defaults to 10 microseconds, also for backward compatibility.
-
repo owner Since I’ve never heard of a sensor requiring more than 10uS till this issue was opened, I feel it’s a very rare edge case situation. If someone has an out of spec sensor like that, why not just change
TRIGGER_WIDTH
to 15 or whatever? Seems like accommodating for an extreme edge case to me. -
reporter - edited description
-
reporter The original requester seems to use a SR04M, similar to shown in this link
Probably this hardware has enough similarity with a HC-SR04 to mostly work, but requires a different timing to work reliably.
-
repo owner I found documentation for that sensor which shows it should be 10uS to trigger. I also found people using the NewPing library successfully with that sensor. However, I did find someone who needed to set the trigger time to 11uS (unrelated to NewPing). So it seems there could be some which need a bit longer in rare situations.
Do you happen to know what value this individual needed to set for the trigger width? Was it just 11uS?
-
reporter Do you happen to know what value this individual needed to set for the trigger width? Was it just 11uS?
They requested to be able to extend to 20 uSec, but as I’m not familiar with this type of hardware I expected for the worst, and allow for up to 50.
Can reduce to range 10..20 uSec.
-
repo owner I don’t think it needs more than 11 uS
-
Hi,
I have also come across this issue with HC-SR04 purchased from Duinotech ( Jaycar )
the only way to make these work is by setting it to 15 seconds -
repo owner 15 SECONDS? I hope you mean 15 uSec.
-
yeah totally 15 uSec.
-
repo owner - changed status to resolved
V1.9.7 resolves this issue by setting the TRIGGER_WIDTH to 12uS and allowing the user to change this value if their sensors are drastically out of spec.
- Log in to comment
What sensor needs more than an a
10uS
trigger notch? Also, you don't create a pull request in this repo. That's not how repos work. You Fork, create your own branch, then create a pull request from your fork/branch to this repo. I'm sure there's a tutorial somewhere that walks you through how to create a pull request into someone else's repo.