Skip to content

No need to wait after Wire.requestFrom(). #6

Open
@Koepel

Description

@Koepel

In the file "SparkFun_Photon_Weather_Shield_Particle_Library/firmware/SparkFun_Photon_Weather_Shield_Library.cpp", in the function "makeMeasurment()", there waiting with a delay and a timeout. That can be removed.
Explanation: Common-mistakes#1

The Wire.endTransmission() is not checked for an error, so I seen no reason to check for the number of received bytes. However, to keep that functionality of the code, it can be replaced by checking Wire.available() just once.

This:

  Wire.requestFrom(ADDRESS,nBytes);
  //Wait for data
  int counter = 0;
  while (Wire.available() < nBytes){
    delay(1);
    counter ++;
    if (counter >100){
      // Timeout: Sensor did not return any data
      return 100;
    }
  }

could be replaced by this:

  Wire.requestFrom(ADDRESS,nBytes);
  if(Wire.available() != nBytes){
    return 100;
  }

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