GithubHelp home page GithubHelp logo

Comments (8)

Koepel avatar Koepel commented on July 24, 2024 1

The Wire.endTransmission() returns an error, and the Wire.requestFrom() returns the number of received bytes and the Wire.available() return how many bytes are available in the buffer. Those can be used to check for error or collision and so on.

The forever while loop will never return when the sensor is disconnected or with a collision. However, there is no need for this intermediary step. Just do it right, that's all. Adafruit is doing it better and better, and in most new code the data is just read after a Wire.requestFrom().

An extra check for something wrong on the I2C bus can be by checking the Wire.requestFrom() return variable or with Wire.available() (just once).

The official Arduino Wire library is sadly blocking internally. When something is wrong, some functions of the Wire library will never return and the sketch will halt. That is where those timeouts are needed (inside the Wire library).

from adafruit_hmc5883_unified.

budryerson avatar budryerson commented on July 24, 2024

The public function "bool begin(void);" always returns TRUE.

The function is apparently meant to detect whether an HMC5883 device is detected, and to trigger the "Ooops, no HMC5883 detected ... Check your wiring!" message in the Adafruit sensor initialization example code if no device is detected. It does no such thing; and the function's code always returns TRUE.

from adafruit_hmc5883_unified.

grossadamm avatar grossadamm commented on July 24, 2024

@budryerson isn't that a separate issue from what @Koepel is talking about?

from adafruit_hmc5883_unified.

budryerson avatar budryerson commented on July 24, 2024

@grossadamm Thank you for your gentle correction. I have resubmitted the comment as a "new issue."

from adafruit_hmc5883_unified.

grossadamm avatar grossadamm commented on July 24, 2024

Made a pull request that will help with those that run into their code hanging due to this disagreement. #4 This allows a timeout for the while loop, since my guess is that this disagreement is at a stalemate.

from adafruit_hmc5883_unified.

Koepel avatar Koepel commented on July 24, 2024

I'm sorry grossadamm, but a timeout is wrong as well. After a Wire.requestFrom() there is no need to wait. Either the return value of Wire.requestFrom() or the return value of Wire.available() can be used to check if the I2C transaction failed, but waiting for something is not needed.
The Wire.requestFrom() waits until the I2C transaction has finished, and waiting for the receive buffer makes no sense.

The Arduino Wire library can not be used in a way that waiting like that is needed.

There are (software) implementations that are not compatible with the Arduino Wire library. The Wire library for the Due started wrong but is now okay. The Wire library for the ESP8266 is not yet fully compatible. But as far as I know all the Wire.requestFrom() functions wait until the I2C transaction has finished.

from adafruit_hmc5883_unified.

grossadamm avatar grossadamm commented on July 24, 2024

What happens when the wire becomes disconnected? Or, more likely, as mentioned in other threads there is a collision between two masters? The existing while loop will never exit. I can assure you that having a while loop that never exits must also be wrong. I personally have run into this situation on a number of occasions and my project can not tolerate a possibility of hanging.

You and the developer(s) seem at odds on if your understanding on the usage of Wire.available() and Wire.requestFrom() is correct. I tend to your side, but perhaps this intermediary step will satisfy parties in my situation until you two come to an agreement.

In the event you consider this pull request unacceptable, please feel free to make a pull request with what you consider the proper solution.

from adafruit_hmc5883_unified.

grossadamm avatar grossadamm commented on July 24, 2024

As I said earlier, I understand and agree with many of your points. But as I also said earlier, I merely want a way to not hang indefinitely. I solved that as far as I can tell. It may not be the correct solution per you, but it seems to work per me.

I appreciate your input, but if in fact you want it done right per you, I suggest you submit a pull request.

from adafruit_hmc5883_unified.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.