-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MakeCode issue with MakeCode sonar extension #439
Comments
This is a C++ version of MakeCode code, except I separated CODAL and DAL pulseIn so I could choose either. The pins (13, 14) are selected at the top of The forever loop includes calls to reset both pins to digital inputs with pull down, immediately after receiving the pulse, and before the recommended 60ms pause between readings, which seems to give very good results. Without resetting the pins, most values after the first are low and variable. Example hex files: sonar-v2.zip
|
Even without the resetPin calls in the forever loop above, CODAL currently resets the echo pin and creates a new PulseIn for each call to getPulseUs (see why below). I modified getPulseUs to avoid the reset. I'm not sure if it helped, but it was not nearly as good as "manually" resetting the pins before the pause between readings. I don't know why it's different. Could it be better for the sensor? Details of why the reset occurs... There's a call to getDigitalValue to ensure the pin is in digital input mode. But since MakeCode v5, CODAL v0.2.40 the test at the top of getDigitalValue has been changed to check for a locked peripheral obj. The PulseIn is an obj but it's not locked, so the call disconnects the PulseIn and resets the interrupt behaviour, which is noticed on the next line in getPulseUs. Here's the change at line 335 Note that the code at line 338 has gone, although the comment about fast switching remains. |
So fast input/output switching support has been lost (for one wire sensors, or sonar sensors that use a single pin?) |
Issue:
Extension:
MakeCode pulseIn:
CODAL getPulseUs:
first step would be to write the SR04 code in C++ and see if we can replicate the issue where only 0-10cm is measured.
The text was updated successfully, but these errors were encountered: