-
Notifications
You must be signed in to change notification settings - Fork 14
Description
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:
- Hardware: RedBoard Plus + Weather Shield (v12)
- Arduino IDE: v2.3.2
- Arduino Libraries:
- Code:
Weather_Shield_Basic_V12.ino
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);
}