Skip to content

No need to wait after Wire.requestFrom() and it should not be followed by Wire.endTransmission(). #257

@Koepel

Description

@Koepel

The Wire library is used in the wrong way in the files:

  • SwarmBaseCode-ROS/arduino/libraries/IMU/LPS.cpp
  • SwarmBaseCode-ROS/arduino/libraries/IMU/L3G.cpp
  • SwarmBaseCode-ROS/arduino/libraries/IMU/LSM303.cpp
  • SwarmBaseCode-ROS/arduino/libraries/lsm303-arduino/LSM303.cpp
  • SwarmBaseCode-ROS/arduino/libraries/ros_lib/examples/Temperature/Temperature.pde

Explanation: Common-mistakes, number 1 and 2.

After a Wire.requestFrom() there should be no Wire.endTransmission().
After a Wire.requestFrom(), all the waiting may be removed, for example while (Wire.available() < 3); or delay(10);.
The waiting with millis() may also be removed. There is not timeout after a Wire.requestFrom(), so the variable did_timeout makes no sense.

It is possible to check if the data was received:

  Wire.requestFrom(address, (byte)6);
  if(Wire.available() != 6)
  {
    i2c_sensor_error = true;   // a variable name that I made up
    return;
  }

That will detect if the sensor was connected or not, but the return value of Wire.endTransmission() could also be used for that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions