Closed PhilAtKitronik closed 3 years ago
I think the need for an altered time factor in V1 DAL is related to https://github.com/lancaster-university/microbit-dal/issues/451. The drift is triggered because pins.pulseIn reads the time in a tight loop.
We need a event based pulse computation problaby baked in CODAL.
From: Martin Williams notifications@github.com Sent: Thursday, November 5, 2020 8:41:22 PM To: microsoft/pxt-microbit pxt-microbit@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Subject: Re: [microsoft/pxt-microbit] Ultrasonic sensors reading differently between V1 and V2 hardware (#3599)
I think the need for an altered time factor in V1 DAL is related to lancaster-university/microbit-dal#451https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Flancaster-university%2Fmicrobit-dal%2Fissues%2F451&data=04%7C01%7Cjhalleux%40microsoft.com%7C40dc464ac95a4efd622b08d881c2c646%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637402020836471351%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=EDJ7y4GDvfWqsfIEMJXN6dmkwF7zH7zm5VBEzuDoI10%3D&reserved=0. The drift is triggered because pins.pulseIn reads the time in a tight loop.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmicrosoft%2Fpxt-microbit%2Fissues%2F3599%23issuecomment-722600707&data=04%7C01%7Cjhalleux%40microsoft.com%7C40dc464ac95a4efd622b08d881c2c646%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637402020836476343%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=1d83opUvkfAQpT%2BBq0wmE7rQVEou8W4m%2BitVxd50XwU%3D&reserved=0, or unsubscribehttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAA73QKKRIATSXM34PSGQJA3SOL5WFANCNFSM4TLSS5WA&data=04%7C01%7Cjhalleux%40microsoft.com%7C40dc464ac95a4efd622b08d881c2c646%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637402020836481333%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=JKmwAbGoaZ%2B%2BcqVFE2%2B7U1GNJzyP099C%2F8jc3Lob56c%3D&reserved=0.
fixed
@PhilAtKitronik please validate.
I have just tested the code on a V1 microbit and V2 microbit. V1 still requires the value in the formula to be 39, V2 requires the formula to have 58. There does not seem to be any chance unless I have not received the latest update when coding on the beta editor.
With our current code V2 still will read a distance greater than it measures, at 15cm a V2 microbit reads 23cm.
The code for each time is
basic.forever(function () { basic.showNumber(Kitronik_Move_Motor.measure()) basic.pause(500) })
Is there anyway to determine between hardware within the code? That way I can check and put the formula for both in.
This pulsein change seems to have broken single pin ultrasonics. See https://github.com/microsoft/pxt-microbit/issues/3731#issue-746688781
CODAL v0.2.24 has now been released to https://makecode.microbit.org/stable, can you check here to see if this still reproduces for your accessory @PhilAtKitronik?
Fixed
While testing the Kitronik MOVE Motor ultrasonic measuring block, it has been noticed that there has been a change from V1 hardware to V2.
For the V1 hardware, to make the ultrasonic sensor read the correct distance, the formula had to be changed. Typically it is read pulsein then math.idiv of the pulse. The datasheet for the HC-SR04 say this divide should be by 58. However with the V1 micro:bits this gave an incorrect reading, thus the value had to be changed to 39 to get the correct reading.
Now with V2, this code in our block does not work as the near correct value is 58. When testing with 58 in the math.idiv, at 5cm gives reading of 4cm, 10cm gives reading 9cm and at 20cm gives reading of 18cm.
Here is a screenshot of the block code to make the ultrasonics work on the V1 micro:bit
This is the code created (in beta editor) to get the ultrasonic readings to measure within 1cm. The code has been copied out from the block and the correct pins added in the required place, so that its possible to adjust the value in the math.idiv calculation. Also the remove of the enum for selection between reading being converted to cm or inches (which has the same issue with number 98 on V1 and 148 on V2)
The difference presuming is the measurement of pins.pulseIn which is different between the two version.