sparkfun / Weather_Shield

Barometric pressure, temperature, humidity and light sensing weather shield for Arduino.
https://www.sparkfun.com/
Other
69 stars 67 forks source link

New Si7021 library release #36

Open alsim95 opened 7 months ago

alsim95 commented 7 months ago

Hi everyone, I just bought recently a pair of weather shields to build weather stations and I wanted to try them today. I have installed the necessary libraries (Si7021, MPL3115A2 and Weather Meter Kit) but when I try to either simply verify or upload the Weather Shield firmware example, I get a compiling issue which says basically the following :

error: 'Weather' does not name a type error: 'myHumidity' was not declared in this scope

It's depending of the line 26 of the .ino code, which is :

Weather myHumidity;//Create an instance of the humidity sensor

It seems pretty strange as all libraries are properly installed, and I did not change any single line of the code. I also didn't see any trace of that issue anywhere of the web, so I don't really know what to do. Can someone help me with that please ? Thanks and have a nice day !

PaulZC commented 7 months ago

Hi @alsim95 ,

Please check you still have these lines at the start of your code:

#include "SparkFunMPL3115A2.h" //Pressure sensor - Search "SparkFun MPL3115" and install from Library Manager
#include "SparkFun_Si7021_Breakout_Library.h" //Humidity sensor - Search "SparkFun Si7021" and install from Library Manager

Best wishes, Paul

alsim95 commented 7 months ago

Hi @PaulZC thank you for your answer. Indeed, I still have these lines on top of the code. I found some kind of solution actually. The problem seems to be the module "Weather" which is called but doesn't exist in any of these libraries. I tried replacing it with the module named "SI7021" as described in that library and it is compiling now. But after uploading the sketch into the Arduino I don't seem to get any proper values. Here is an example :

Humidity = 0.00%, temp_h = -52.33F, Pressure = -999.00Pa, temp_p = -1766.20F, light_lvl = 0.83V, VinPin = 4.46V

Is there something wront with the board maybe ? It seems to be powered on properly as the blue led on the shield is flashing, and I feel like I soldered the headers correctly.

PaulZC commented 7 months ago

Hi @alsim95 ,

Ah, I am sorry. It looks like the example code has been partially updated, but not fully.

I am looking at the hook-up guide: https://learn.sparkfun.com/tutorials/arduino-weather-shield-hookup-guide-v12#example-firmware---basic

If you install and include the SparkFun_Weather_Meter_Kit_Arduino_Library, all should be well.

#include "SparkFun_Weather_Meter_Kit_Arduino_Library.h"  //Weather meter kit - Search "SparkFun Weather Meter" and install from Library Manager

Please let me know if this fixes your issue.

Best wsihes, Paul

alsim95 commented 7 months ago

I tried using that sketch (Weather_Shield_Basic_V12.ino as found here on Github) and just added the line you mentionned, however it doesn't change anything, I still get that compiling error...

PaulZC commented 7 months ago

OK - thank you. I am sorry. I have let my colleague know about the issue. We will get the example code updated soon.

Best wishes, Paul

alsim95 commented 7 months ago

Thanks ! Also, for your information, when I change the module "Weather" to "SI7021", the first time I compile and upload the sketch, I get the following message :

In file included from c:\Users\alegrand\Documents\Arduino\libraries\SparkFun_MPL3115A2_Altitude_and_Pressure_Sensor_Breakout\src\SparkFunMPL3115A2.cpp:36:0: C:\Users\alegrand\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src/Wire.h: In member function 'float MPL3115A2::readAltitude()': C:\Users\alegrand\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src/Wire.h:68:13: note: candidate 1: uint8_t TwoWire::requestFrom(int, int) uint8_t requestFrom(int, int); ^~~ C:\Users\alegrand\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src/Wire.h:65:13: note: candidate 2: uint8_t TwoWire::requestFrom(uint8_t, uint8_t) uint8_t requestFrom(uint8_t, uint8_t); ^~~ C:\Users\alegrand\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src/Wire.h: In member function 'float MPL3115A2::readPressure()': C:\Users\alegrand\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src/Wire.h:68:13: note: candidate 1: uint8_t TwoWire::requestFrom(int, int) uint8_t requestFrom(int, int); ^~~ C:\Users\alegrand\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src/Wire.h:65:13: note: candidate 2: uint8_t TwoWire::requestFrom(uint8_t, uint8_t) uint8_t requestFrom(uint8_t, uint8_t); ^~~ C:\Users\alegrand\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src/Wire.h: In member function 'float MPL3115A2::readTemp()': C:\Users\alegrand\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src/Wire.h:68:13: note: candidate 1: uint8_t TwoWire::requestFrom(int, int) uint8_t requestFrom(int, int); ^~~ C:\Users\alegrand\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src/Wire.h:65:13: note: candidate 2: uint8_t TwoWire::requestFrom(uint8_t, uint8_t) uint8_t requestFrom(uint8_t, uint8_t); ^~~ C:\Users\alegrand\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src/Wire.h: In member function 'byte MPL3115A2::IIC_Read(byte)': C:\Users\alegrand\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src/Wire.h:68:13: note: candidate 1: uint8_t TwoWire::requestFrom(int, int) uint8_t requestFrom(int, int); ^~~ C:\Users\alegrand\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src/Wire.h:65:13: note: candidate 2: uint8_t TwoWire::requestFrom(uint8_t, uint8_t) uint8_t requestFrom(uint8_t, uint8_t); ^~~

But it doesn't abort the compiling, it is actually working and uploading afterwards. I must admit that my understanding of the variables declarations and types is not perfect but do you think that could explain why I don't get any correct values ?

santaimpersonator commented 6 months ago

So it looks like the Si7021 Arduino library was recently updated: https://github.com/sparkfun/SparkFun_Si7021_Arduino_Library/commits/main/

The example code in the hookup guide and this repo were written for the previous version. Try rolling back the Arduino library to the v1.0.5 release: version

santaimpersonator commented 6 months ago

Due to the new I2C implentation in the latest release of the Si7021 library (v2.0.0), care must be taken in how the all libraries are initialized and linked in the example code.

When linking the libraries, the Wire library must be linked between the Si7021 and MPL3115A2 libraries:

#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

When intializing the sensors in the setup() loop, the I2C port must be initialized before the humidity sensor. Additionally, the pressure sensor can only be initialized after the humidity sensor:

//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

Note: These, are in addition to how the humidity sensor is instantiated (as mentioned previously):

SI7021 myHumidity;     //Create an instance of the humidity sensor

This is how the Weather_Shield_Basic_V12.ino example code would be updated for the current I2C implementations inside of the Si7021 and MPL3115A2 Arduino libraries:

/*
  Weather Shield Example
  By: Nathan Seidle
  SparkFun Electronics
  Date: June 10th, 2016
  License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).

  This example prints the current humidity, air pressure, temperature and light levels.

  The weather shield is capable of a lot. Be sure to checkout the other more advanced examples for creating
  your own weather station.

  Updated by Joel Bartlett
  03/02/2017
  Removed HTU21D code and replaced with Si7021

  Updated by Wes F
  02/29/2024
  Accounted for updated Si7021 library release

*/

#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;

const byte REFERENCE_3V3 = A3;
const byte LIGHT = A1;
const byte BATT = A2;

//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

  pinMode(REFERENCE_3V3, INPUT);
  pinMode(LIGHT, INPUT);

  //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,");

    //Check light sensor
    float light_lvl = get_light_level();
    Serial.print(" light_lvl = ");
    Serial.print(light_lvl);
    Serial.print("V,");

    //Check batt level
    float batt_lvl = get_battery_level();
    Serial.print(" VinPin = ");
    Serial.print(batt_lvl);
    Serial.print("V");

    Serial.println();

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

  delay(100);
}

//Returns the voltage of the light sensor based on the 3.3V rail
//This allows us to ignore what VCC might be (an Arduino plugged into USB has VCC of 4.5 to 5.2V)
float get_light_level() {
  float operatingVoltage = analogRead(REFERENCE_3V3);

  float lightSensor = analogRead(LIGHT);

  operatingVoltage = 3.3 / operatingVoltage;  //The reference voltage is 3.3V

  lightSensor = operatingVoltage * lightSensor;

  return (lightSensor);
}

//Returns the voltage of the raw pin based on the 3.3V rail
//This allows us to ignore what VCC might be (an Arduino plugged into USB has VCC of 4.5 to 5.2V)
//Battery level is connected to the RAW pin on Arduino and is fed through two 5% resistors:
//3.9K on the high side (R1), and 1K on the low side (R2)
float get_battery_level() {
  float operatingVoltage = analogRead(REFERENCE_3V3);

  float rawVoltage = analogRead(BATT);

  operatingVoltage = 3.30 / operatingVoltage;  //The reference voltage is 3.3V

  rawVoltage = operatingVoltage * rawVoltage;  //Convert the 0 to 1023 int to actual voltage on BATT pin

  rawVoltage *= 4.90;  //(3.9k+1k)/1k - multiple BATT voltage by the voltage divider to get actual system voltage

  return (rawVoltage);
}
alsim95 commented 6 months ago

Hi everyone, sorry for coming back to you this late. I had sorted out by myself and the weather shield is woring properly for the moment. However, I am now trying to send the data from the shield (and the meter kit as well) to another Arduino through a nRF24L01 with the Mirf library but I am getting some new issues while compiling. It sounds like some sort of compatibility issue, because as soon as I remove either the Mirf library or the Si7021/MPL3115A2 libraries, then it is compiling properly.

Does any of you have an idea of why this happens ? Is there maybe another library I could use with the nRF24L01 module ? Thanks in advance !