-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No need to wait after Wire.requestFrom(). #3
Comments
Thank you Koepel for saying. I see you have mentioned this before back in 2016. |
There is not a single Wire-compatible library or faster processor, where the Wire.requestFrom() returns before everything is received. That is not possible. Nothing appears later. Not a single byte on earth did ever appear later for as long as the Wire library exists. I don't know why the change failed, perhaps a timing issue. When the sensor is disconnected, your timeout prevents that the sketch halts. This issue is therefor not a real "bug", it is about code that is not needed. |
It would be good to have this script working without the timeout. https://www.roboticboat.uk/Teensy/Teensy40/BNO080b.html |
So are you saying the online Arduino help documentation is wrong? https://www.arduino.cc/en/Reference/WireRead |
Yes, it's wrong. When the I2C device is not connected at all, then Wire.available() returns zero. It is inherit to the I2C protocol that when a Master reads a number of bytes from a Slave, then the Slave can do nothing to send less or more bytes. Therefor that comment is at least misleading. That is why my advice for Wire.requestFrom() is: "It is therefor better to first check for errors and if there are no errors, then read all the bytes". You might try to see what happens when you search with this: https://www.google.com/search?q=site%3Agithub.com+%22no+need+to+wait%22. |
I have made an issue for the documentation: arduino/reference-en#893 |
Koepel some scripts that gave the idea of waiting are here. https://www.robot-electronics.co.uk/htm/arduino_examples.htm#CMPS12/11%20I2C The CMPSs should be fine - so I'm updating the code. But the BNO080 still has issues. Does the I2C wire library allow time stretching? |
I know there are many bad examples. The Arduino Wire library supports clock pulse stretching, otherwise an Arduino board as a I2C Slave would not work. The code should work in the first place and it is not a real bug. You can keep it as it is and add comment to the header. Thank you for testing and notifying that is not longer worked. That means this issue is the same as this one at Sparkfun: sparkfun/SparkFun_BNO080_Arduino_Library#3 |
Library updated. |
Hi, I noticed that you wait with a timeout after a Wire.requestFrom(). It is in five files.
However, there is no such thing as waiting for data, with or without a timeout. That is a myth.
Explanation: Common-mistakes#1
If you want to return -1 when the I2C devices was not found (or if there was a I2C bus problem), then you can do this:
Written in a shorter and nice way:
Or in a short and ugly way:
The text was updated successfully, but these errors were encountered: