ErickSimoes / Ultrasonic

Minimalist library for Ultrasonic Module HC-SR04, PING))) and Seeed SEN136B5B to Arduino
MIT License
137 stars 65 forks source link

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

Open mianqi2016 opened 4 years ago

mianqi2016 commented 4 years ago

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 commented 4 years ago

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

ErickSimoes commented 4 years ago

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.

mianqi2016 commented 4 years ago

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


发件人: Erick Sim?es notifications@github.com 发送时间: 2020年8月20日 20:14 收件人: ErickSimoes/Ultrasonic Ultrasonic@noreply.github.com 抄送: Mian Qi mian.qi@outlook.com; Mention mention@noreply.github.com 主题: 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.

ErickSimoes commented 3 years ago

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.