Ultrasonic icon indicating copy to clipboard operation
Ultrasonic copied to clipboard

An update is needed for example code of this library in PlatformIO extension of VS Code

Open mianqi2016 opened this issue 5 years ago • 4 comments

I used your library today in VS Code, I verified the code on Arduino UNO board,

the IDE said: 'class Ultrasonic' has no member named 'read'

by the intellisense function, I knew it was "distanceRead()" rather than "read()", so maybe there need an update in your example code in PlatformIO extension for VS Code.

mianqi2016 avatar Jul 31 '20 07:07 mianqi2016

And, when I used it, it shown negative value sometimes, like "-277 cm", what did it mean ?

mianqi2016 avatar Jul 31 '20 13:07 mianqi2016

Hi @mianqi2016!

The "distanceRead ()" method has been replaced by "read ()". It should continue to work, but will issue a warning during compilation.

From what I saw in the example on Platformio.org, the available example is correct, just like the ones available here on GitHub.

Unfortunately, I am not responsible for updating the library within the PlatformIO platform, I believe they automatically take the code released here on GitHub. I checked the source code available there and it, like the examples, is the same as what is here on GitHub. Anyway, I can do some tests if you give me more details about your development environment and what Arduino Board you are using.

As for the negative reading value, this would not be possible due to the implementation of the library, since the value returned by the read method is unsigned int. So, I imagine two possible problems:

  1. An incorrect conversion of data types;
  2. Some problem with the circuit, especially with the wires connecting the trigger and the echo.

If you can share the code snippet where the value is read and displayed on the console, I can help.

In any case, thank you very much for using the library and for sharing your doubts. I hope I can help you.

ErickSimoes avatar Aug 20 '20 20:08 ErickSimoes

Sometimes, it showed negative value, expecialy when I put a barrier nearer than 3cm, is it normal?


发件人: Erick Sim?es [email protected] 发送时间: 2020年8月20日 20:14 收件人: ErickSimoes/Ultrasonic [email protected] 抄送: Mian Qi [email protected]; Mention [email protected] 主题: Re: [ErickSimoes/Ultrasonic] An update is needed for example code of this library in PlatformIO extension of VS Code (#52)

Hi @mianqi2016https://github.com/mianqi2016!

The "distanceRead ()" method has been replaced by "read ()". It should continue to work, but will issue a warning during compilation.

From what I saw in the example on Platformio.orghttps://platformio.org/lib/show/1507/Ultrasonic/examples, the available example is correct, just like the ones available here on GitHub.

Unfortunately, I am not responsible for updating the library within the PlatformIO platform, I believe they automatically take the code released here on GitHub. I checked the source code available there and it, like the examples, is the same as what is here on GitHub. Anyway, I can do some tests if you give me more details about your development environment and what Arduino Board you are using.

As for the negative reading value, this would not be possible due to the implementation of the library, since the value returned by the read method is unsigned int. So, I imagine two possible problems:

  1. An incorrect conversion of data types;
  2. Some problem with the circuit, especially with the wires connecting the trigger and the echo.

If you can share the code snippet where the value is read and displayed on the console, I can help.

In any case, thank you very much for using the library and for sharing your doubts. I hope I can help you.

― You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/ErickSimoes/Ultrasonic/issues/52#issuecomment-677880363, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AFPCOAX6GATVQGR6NN4BIZLSBV73TANCNFSM4PPU4UVQ.

mianqi2016 avatar Aug 24 '20 10:08 mianqi2016

Due to the nature of the sensor, it does not work well with measurements below 4 cm, due to the path the wave has to take to get to an obstacle and back.

In the latest update, the readout has a default time out value, which prevents it from returning a negative value.

ErickSimoes avatar Oct 13 '21 12:10 ErickSimoes