Open kimlabtoy opened 1 year ago
Could you create a share link to the exact program that reproduces this using the button?
Just pinging myself here to track this in case there's a deeper CODAL cause. The 030 would indicate a memory fault on the heap...
I don't see anything in pxt-sonar that feels likely to induce an error but will see if I can get a minimal repro, feels more likely it could be stemming from one of the packages handling the display or potentially some edge case in codal. for ref pxt-codal is just https://github.com/microsoft/pxt-sonar/blob/master/main.ts; so relevant code basically just comes out to
pins.setPull(trig, PinPullMode.PullNone);
pins.digitalWritePin(trig, 0);
control.waitMicros(2);
pins.digitalWritePin(trig, 1);
control.waitMicros(10);
pins.digitalWritePin(trig, 0);
// read pulse
const d = pins.pulseIn(echo, PulseValue.High, maxCmDistance * 58);
switch (unit) {
case PingUnit.Centimeters /** 1 **/: return Math.idiv(d, 58);
case PingUnit.Inches /** 2 **/: return Math.idiv(d, 148);
default: return d ;
}
I found that sonar program can work well in v5.1.40, but doesn't work in v6.0.1~v6.0.17. (V2 board) In v6.0.17 sonar (use SR04) can only detect <10cm, but no error code. In v6.0.16 show error code 030 in a few second.
@jwunderl I use another program that remove oled12864, but it looks like a same situation. https://makecode.microbit.org/S93364-44504-66711-82927
@JohnVidler @carlosperate this one may be important to address.
Variable 'Centimeters' in pxt-sonar is duplicated in maqueen.ts version 1.7.2 Hence duplicate error....
Just my 2 cents in trying to get it working.
Thanks @horssenp
@carlosperate @jaustin this one is good to address for this release.
We'll see if we can fit it in the next CODAL tag, but will depend on external factors as we don't have a dedicated codal person at the moment.
I tried V1 and V2 in MakeCode v5 and live (6.0.28) measuring a distance of about 92cm with the sonar sensor on a :MOVE MOTOR.
Eventually, I noticed that every test started with a single high reading that was in fact correct, followed by varying lower readings.
The lower readings seem to be fixed by adding a digital read of the trigger pin after the ping pulse in, with a pause before the next reading.
I modified the example from https://github.com/microsoft/pxt-microbit/issues/5327#issuecomment-1650376757 to set the trigger pin back to digital input. I changed the pins to 13/14 for the buggy sensor. https://makecode.microbit.org/_ELdeFJHz88fs Note this has OLED and sensors extensions plus an old version of sonar, but it works for me with the reset of the trigger pin
Here's a fresh new project https://makecode.microbit.org/_JziM4K2wyRHj
And a :MOVE MOTOR one. https://makecode.microbit.org/_9k5WjWP1zdwb
@carlosperate does this needs to be tracked for this release?
For the post-release hotfix, yes.
I run my program use V1 in v6.0.15 build, its work well, and run the same program use V2 in v6.0.15 build, it can only detect <10cm and quickly show error 030. Run this program use V2 in v6.0.16 build will show error 914.