Skip to content
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

Update/standardize I2C functionailty #9

Open
santaimpersonator opened this issue Feb 29, 2024 · 0 comments
Open

Update/standardize I2C functionailty #9

santaimpersonator opened this issue Feb 29, 2024 · 0 comments

Comments

@santaimpersonator
Copy link

santaimpersonator commented Feb 29, 2024

Issue

The latest release of the Si7021 Arduino library (v2.0.0) causes an issue when utilized with this library, due to the differences in how the Wire library is implemented in them. Therefore, special care must be taken in how the libraries are linked and intialized (see sparkfun/Weather_Shield#36 (comment)).

Both of these libraries, are utilized in the example code from the Arduino Weather Shield Hookup Guide V12.

Test Conditions:

Request

Update this library with the same I2C standardization as the Si7021 Arduino library. Thereby, limiting the specific requirements only to:

  • The Wire library being linked after both of the sensor libraries
  • I2C bus being intialized before the sensors in the setup() loop

Additionally, update the hookup guide accordingly.

Workaround:

The current fix, requires specific order for how the libraries are linked and their initialization in the setup() loop. If they aren't to the exact specifications mentioned in sparkfun/Weather_Shield#36 (comment), it either results in a compilation issue, the code hangs on a sensor initialization, or the sensor readings are returned improperly (i.e. -20000degF).

#include "SparkFun_Si7021_Breakout_Library.h"  //Humidity sensor - http://librarymanager/All#SparkFun_Si7021
#include <Wire.h>               //I2C needed for sensors
#include "SparkFunMPL3115A2.h"  //Pressure sensor - //http://librarymanager/All#SparkFun_MPL3115A2

MPL3115A2 myPressure;  //Create an instance of the pressure sensor
SI7021 myHumidity;     //Create an instance of the humidity sensor

//Hardware pin definitions
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
const byte STAT_BLUE = 7;
const byte STAT_GREEN = 8;

//Global Variables
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
long lastSecond;  //The millis counter to see when a second rolls by

void setup() {
  Serial.begin(115200);
  Serial.println("Weather Shield Example");

  pinMode(STAT_BLUE, OUTPUT);   //Status LED Blue
  pinMode(STAT_GREEN, OUTPUT);  //Status LED Green

  //Configure the humidity sensor
  Wire.begin();

  while (myHumidity.begin() == false) {
    Serial.println("Sensor not found. Please check wiring. Freezing...");
    while (true)
      ;
  }
  myHumidity.setResolution(0);  // RH 12-bit, Temp 14-bit (Default)
  myHumidity.heaterOff();       // Turn internal heater off
  // myHumidity.setHeaterCurrent(0b0000); // Set heater to min 3.09mA (Default)


  //Configure the pressure sensor
  myPressure.begin();               // Get sensor online
  myPressure.setModeBarometer();    // Measure pressure in Pascals from 20 to 110 kPa
  myPressure.setOversampleRate(7);  // Set Oversample to the recommended 128
  myPressure.enableEventFlags();    // Enable all three pressure and temp event flags

  lastSecond = millis();

  Serial.println("Weather Shield online!");
}

void loop() {
  //Print readings every second
  if (millis() - lastSecond >= 1000) {
    digitalWrite(STAT_BLUE, HIGH);  //Blink stat LED

    lastSecond += 1000;

    //Check Humidity Sensor
    float humidity = myHumidity.getRH();
    Serial.print("Humidity = ");
    Serial.print(humidity, 1);
    Serial.print("%,");

    //Check tempf from humidity sensor
    float temp_h = myHumidity.getTemperatureF();
    Serial.print(" temp_h = ");
    Serial.print(temp_h, 2);
    Serial.print("F,");

    //Check Pressure Sensor
    float pressure = myPressure.readPressure();
    Serial.print(" Pressure = ");
    Serial.print(pressure);
    Serial.print("Pa,");

    //Check tempf from pressure sensor
    float tempf = myPressure.readTempF();
    Serial.print(" temp_p = ");
    Serial.print(tempf, 2);
    Serial.print("F");

    Serial.println();

    digitalWrite(STAT_BLUE, LOW);  //Turn off stat LED
  }

  delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant