Sparkfun Weather Shield issue with new Uno Wifi r2

I recently purchased a Uno wifi r2 from Core with the view of connecting the Sparkfun Weather Shield but have found some issues.
I’m getting the unchanging -ve values from pressure, temp and humidity.
The interrupts for the wind and rain don’t seem to be working.
The only thing that works is the wind direction.
I also get the following compile errors, however if I change line 188 of SparkFun_Si7021_Breakout_Library.cpp from a uint_16 to an int it compiles.

D:\src\Arduino\libraries\SparkFun_Si7021_Humidity_and_Temperature_Sensor\src\SparkFun_Si7021_Breakout_Library.cpp: In member function 'uint16_t Weather::makeMeasurment(uint8_t)':

D:\src\Arduino\libraries\SparkFun_Si7021_Humidity_and_Temperature_Sensor\src\SparkFun_Si7021_Breakout_Library.cpp:200:33: error: call of overloaded 'requestFrom(int, uint16_t&)' is ambiguous

  Wire.requestFrom(ADDRESS,nBytes);
                           ^
In file included from D:\src\Arduino\libraries\SparkFun_Si7021_Humidity_and_Temperature_Sensor\src\SparkFun_Si7021_Breakout_Library.cpp:34:0:
C:\Users\rgunner\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.6\libraries\Wire\src/Wire.h:60:13: note: candidate: virtual uint8_t TwoWire::requestFrom(uint8_t, size_t)
     uint8_t requestFrom(uint8_t, size_t);
             ^~~~~~~~~~~
C:\Users\rgunner\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.6\libraries\Wire\src/Wire.h:62:13: note: candidate: uint8_t TwoWire::requestFrom(int, int)
     uint8_t requestFrom(int, int);

             ^~~~~~~~~~~ 

I read that the crypto chip might share the same address as the Pressure sensor 0x60 but I changed the address of the pressure sensor and it didn’t seem to make any difference.

I checked the Uno wifi rev 2 page on the Arduino site and it said the interrupts were unchanged and available on any digital pin.

Same shield works fine on other Uno wifi (older rev).
Has anyone else experienced this?

Cheers

2 Likes

Hey Mate,

How interesting, are you able to put up the .ino in a post so we can take a look over it for you please? You’re exactly right in that if you’ve got a pigeon-hole collision in the addresses of the sensors that’ll cause the issues you’re seeing, but that’s unlikely to be the case if you’ve forced an address change already. It sounds like it may be an issue with the interrupts and how that’s implemented on the board, there’s been a few bugs with it in the rev 2, but there’s usually workarounds depending on the project.

1 Like

Hi Bryce
Thanks for the reply.

I read the article on Arduino and set interrupts as they suggested but no difference.
Still no windspeed or rain and negative values for temp, pressure and humidity. Also 0 for light and battery. I use a custom class to wrap the wifi & http functions - haven’t supplied code but can - however you can see from the serial output from this ino that the issue is in this ino.

Thanks
Rob


  // attach external interrupt pins to IRQ functions
  attachInterrupt(digitalPinToInterrupt(0), rainIRQ, FALLING);
  attachInterrupt(digitalPinToInterrupt(1), wspeedIRQ, FALLING);

/*

Weather Shield Example

 By: Nathan Seidle

 SparkFun Electronics

 Date: November 16th, 2013

 License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).

 Much of this is based on Mike Grusin's USB Weather Board code: https://www.sparkfun.com/products/10586

 This is a more advanced example of how to utilize every aspect of the weather shield. See the basic

 example if you're just getting started.

 This code reads all the various sensors (wind speed, direction, rain gauge, humidity, pressure, light, battLvl)

 and reports it over the serial comm port. This can be easily routed to a datalogger (such as OpenLog) or

 a wireless transmitter (such as Electric Imp).

 Measurements are reported once a second but windspeed and rain gauge are tied to interrupts that are

 calculated at each report.

  Updated by Joel Bartlett

  03/02/2017

  Removed HTU21D code and replaced with Si7021

 

  Updated By: Robert Gunner

  Date: 04/12/2020 

*/

 

#include <Wire.h> //I2C needed for sensors

#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

#include <WiFiNINA.h>

#include "SparkfunWifi.h"

#include "arduino_secrets.h"

#include "WeatherData.h"

char* ssid = SECRET_SSID;

char* pass = SECRET_PASS;

String serverName = "dionysus";  // server address

uint16_t port = 5000; // port number

WiFiClient wifi;

SparkfunWifi client(wifi, serverName, port, ssid, pass);

MPL3115A2 myPressure; //Create an instance of the pressure sensor

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

//Hardware pin definitions

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

// digital I/O pins

const byte WSPEED = 3;

const byte RAIN = 2;

const byte STAT1 = 7;

const byte STAT2 = 8;

// analog I/O pins

const byte REFERENCE_3V3 = A3;

const byte LIGHT = A1;

const byte BATT = A2;

const byte WDIR = A0;

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

//Global Variables

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

long lastSecond; //The millis counter to see when a second rolls by

byte seconds; //When it hits 60, increase the current minute

byte seconds_2m; //Keeps track of the "wind speed/dir avg" over last 2 minutes array of data

byte minutes; //Keeps track of where we are in various arrays of data

byte minutes_10m; //Keeps track of where we are in wind gust/dir over last 10 minutes array of data

long lastWindCheck = 0;

volatile long lastWindIRQ = 0;

volatile byte windClicks = 0;

//We need to keep track of the following variables:

//Wind speed/dir each update (no storage)

//Wind gust/dir over the day (no storage)

//Wind speed/dir, avg over 2 minutes (store 1 per second)

//Wind gust/dir over last 10 minutes (store 1 per minute)

//Rain over the past hour (store 1 per minute)

//Total rain over date (store one per day)

byte windspdavg[120]; //120 bytes to keep track of 2 minute average

int winddiravg[120]; //120 ints to keep track of 2 minute average

float windgust_10m[10]; //10 floats to keep track of 10 minute max

int windgustdirection_10m[10]; //10 ints to keep track of 10 minute max

volatile float rainHour[60]; //60 floating numbers to keep track of 60 minutes of rain

//These are all the weather values that wunderground expects:

int winddir = 0; // [0-360 instantaneous wind direction]

float windspeedmph = 0; // [mph instantaneous wind speed]

float windgustmph = 0; // [mph current wind gust, using software specific time period]

int windgustdir = 0; // [0-360 using software specific time period]

float windspdmph_avg2m = 0; // [mph 2 minute average wind speed mph]

int winddir_avg2m = 0; // [0-360 2 minute average wind direction]

float windgustmph_10m = 0; // [mph past 10 minutes wind gust mph ]

int windgustdir_10m = 0; // [0-360 past 10 minutes wind gust direction]

float humidity = 0; // [%]

float temperature = 0; // [temperature F]

float rainin = 0; // [rain inches over the past hour)] -- the accumulated rainfall in the past 60 min

volatile float dailyrainin = 0; // [rain inches so far today in local time]

//float baromin = 30.03;// [barom in] - It's hard to calculate baromin locally, do this in the agent

float pressure = 0;

//float dewptf; // [dewpoint F] - It's hard to calculate dewpoint locally, do this in the agent

float batt_lvl = 11.8; //[analog value from 0 to 1023]

float light_lvl = 455; //[analog value from 0 to 1023]

// volatiles are subject to modification by IRQs

volatile unsigned long raintime, rainlast, raininterval, rain;

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

//Interrupt routines (these are called by the hardware interrupts, not by the main code)

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

void rainIRQ()

// Count rain gauge bucket tips as they occur

// Activated by the magnet and reed switch in the rain gauge, attached to input D2

{

  raintime = millis(); // grab current time

  raininterval = raintime - rainlast; // calculate interval between this and last event

    if (raininterval > 10) // ignore switch-bounce glitches less than 10mS after initial edge

  {

    dailyrainin += 0.011; //Each dump is 0.011" of water

    rainHour[minutes] += 0.011; //Increase this minute's amount of rain

    rainlast = raintime; // set up for next event

  }

}

void wspeedIRQ()

// Activated by the magnet in the anemometer (2 ticks per rotation), attached to input D3

{

  if (millis() - lastWindIRQ > 10) // Ignore switch-bounce glitches less than 10ms (142MPH max reading) after the reed switch closes

  {

    lastWindIRQ = millis(); //Grab the current time

    windClicks++; //There is 1.492MPH for each click per second.

  }

}

void setup()

{

  Serial.begin(9600);

  Serial.println("Weather Shield Example");

  pinMode(STAT1, OUTPUT); //Status LED Blue

  pinMode(STAT2, OUTPUT); //Status LED Green

  pinMode(WSPEED, INPUT_PULLUP); // input from wind meters windspeed sensor

  pinMode(RAIN, INPUT_PULLUP); // input from wind meters rain gauge sensor

  pinMode(REFERENCE_3V3, INPUT);

  pinMode(LIGHT, INPUT);

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

  //Configure the humidity sensor

  myHumidity.begin();

  seconds = 0;

  lastSecond = millis();

  // attach external interrupt pins to IRQ functions

  attachInterrupt(digitalPinToInterrupt(0), rainIRQ, FALLING);

  attachInterrupt(digitalPinToInterrupt(1), wspeedIRQ, FALLING);

  // turn on interrupts

  interrupts();

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

}

void loop()

{

  //Keep track of which minute it is

  if(millis() - lastSecond >= 1000)

  {

    digitalWrite(STAT1, HIGH); //Blink stat LED

    lastSecond += 1000;

    //Take a speed and direction reading every second for 2 minute average

    if(++seconds_2m > 119) seconds_2m = 0;

    //Calc the wind speed and direction every second for 120 second to get 2 minute average

    float currentSpeed = get_wind_speed();

    windspeedmph = currentSpeed; //update global variable for windspeed when using the printWeather() function

    //float currentSpeed = random(5); //For testing

    int currentDirection = get_wind_direction();

    windspdavg[seconds_2m] = (int)currentSpeed;

    winddiravg[seconds_2m] = currentDirection;

    //if(seconds_2m % 10 == 0) displayArrays(); //For testing

    //Check to see if this is a gust for the minute

    if(currentSpeed > windgust_10m[minutes_10m])

    {

      windgust_10m[minutes_10m] = currentSpeed;

      windgustdirection_10m[minutes_10m] = currentDirection;

    }

    //Check to see if this is a gust for the day

    if(currentSpeed > windgustmph)

    {

      windgustmph = currentSpeed;

      windgustdir = currentDirection;

    }

    if(++seconds > 59)

    {

      seconds = 0;

      if(++minutes > 59) minutes = 0;

      if(++minutes_10m > 9) minutes_10m = 0;

      rainHour[minutes] = 0; //Zero out this minute's rainfall amount

      windgust_10m[minutes_10m] = 0; //Zero out this minute's gust

    }

    sendWeather();

    digitalWrite(STAT1, LOW); //Turn off stat LED

  }

}

//Calculates each of the variables that wunderground is expecting

void calcWeather()

{

  //Calc winddir

  winddir = get_wind_direction();

  //Calc windspeed

  //windspeedmph = get_wind_speed(); //This is calculated in the main loop on line 196

  //Calc windgustmph

  //Calc windgustdir

  //Report the largest windgust today

  //windgustmph = 0;

  //windgustdir = 0;

  //Calc windspdmph_avg2m

  float temp = 0;

  for(int i = 0 ; i < 120 ; i++)

    temp += windspdavg[i];

  temp /= 120.0;

  windspdmph_avg2m = temp;

  //Calc winddir_avg2m

  temp = 0; //Can't use winddir_avg2m because it's an int

  for(int i = 0 ; i < 120 ; i++)

    temp += winddiravg[i];

  temp /= 120;

  winddir_avg2m = temp;

  //Calc windgustmph_10m

  //Calc windgustdir_10m

  //Find the largest windgust in the last 10 minutes

  windgustmph_10m = 0;

  windgustdir_10m = 0;

  //Step through the 10 minutes  

  for(int i = 0; i < 10 ; i++)

  {

    if(windgust_10m[i] > windgustmph_10m)

    {

      windgustmph_10m = windgust_10m[i];

      windgustdir_10m = windgustdirection_10m[i];

    }

  }

  //Calc humidity

  humidity = myHumidity.getRH();

  //float temp_h = myHumidity.readTemperature();

  //Serial.print(" TempH:");

  //Serial.print(temp_h, 2);

  //Calc temp from pressure sensor

  temperature = myPressure.readTempF();

  //Serial.print(" TempP:");

  //Serial.print(temp, 2);

  //Total rainfall for the day is calculated within the interrupt

  //Calculate amount of rainfall for the last 60 minutes

  rainin = 0;  

  for(int i = 0 ; i < 60 ; i++)

    rainin += rainHour[i];

  //Calc pressure

  pressure = myPressure.readPressure();

  //Calc dewptf

  //Calc light level

  light_lvl = get_light_level();

  //Calc battery level

  batt_lvl = get_battery_level();

}

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

  Serial.print(operatingVoltage, 3);

  float rawVoltage = analogRead(BATT);

  Serial.print(operatingVoltage, 3);

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

}

//Returns the instataneous wind speed

float get_wind_speed()

{

  float deltaTime = millis() - lastWindCheck; //750ms

  deltaTime /= 1000.0; //Covert to seconds

  float windSpeed = (float)windClicks / deltaTime; //3 / 0.750s = 4

  windClicks = 0; //Reset and start watching for new wind

  lastWindCheck = millis();

  windSpeed *= 1.492; //4 * 1.492 = 5.968MPH

  /* Serial.println();

   Serial.print("Windspeed:");

   Serial.println(windSpeed);*/

  return(windSpeed);

}

//Read the wind direction sensor, return heading in degrees

int get_wind_direction() 

{

  unsigned int adc;

  adc = analogRead(WDIR); // get the current reading from the sensor

  // The following table is ADC readings for the wind direction sensor output, sorted from low to high.

  // Each threshold is the midpoint between adjacent headings. The output is degrees for that ADC reading.

  // Note that these are not in compass degree order! See Weather Meters datasheet for more information.

  if (adc < 380) return (113);

  if (adc < 393) return (68);

  if (adc < 414) return (90);

  if (adc < 456) return (158);

  if (adc < 508) return (135);

  if (adc < 551) return (203);

  if (adc < 615) return (180);

  if (adc < 680) return (23);

  if (adc < 746) return (45);

  if (adc < 801) return (248);

  if (adc < 833) return (225);

  if (adc < 878) return (338);

  if (adc < 913) return (0);

  if (adc < 940) return (293);

  if (adc < 967) return (315);

  if (adc < 990) return (270);

  return (-1); // error, disconnected?

}

void sendWeather()

{

    WeatherData weatherData = WeatherData();

    calcWeather(); //Go calc all the various sensors

    weatherData.setTemp(temperature);

    weatherData.setHumidity(humidity);

    weatherData.setWindDir(winddir);

    weatherData.setWindSpeed(windspeedmph);

    weatherData.setWindGust(windgustmph);

    weatherData.setWindGustDir(windgustdir);

    weatherData.setWindSpeedAvg2m(windspdmph_avg2m);

    weatherData.setWindDirAvg2m(winddir_avg2m);

    weatherData.setWindGustAvg10m(windgustmph_10m);

    weatherData.setWindGustDirAvg10m(windgustdir_10m);

    weatherData.setDailyRain(dailyrainin);   

    weatherData.setPressure(pressure);   

    weatherData.setBatteryLevel(batt_lvl);   

    weatherData.setLightLevel(light_lvl);

    int statusCode = client.sendWeather(weatherData);  

}
2 Likes

Hey,

How interesting, when you originally fixed the requestFrom(int, uint16_t&) error, did you force it to uint_16 by switching it, or forcing a lossy conversion? (That shouldn’t matter, but if other issues pop-up in future it may be worth trying the other method to that which you used) also, what was the original older revision you used? I’ll see what differences there were between the two boards (there isn’t many that would affect this, but it’s worth a check)

Hey Bryce

I did the conversion by lossy, just declared it as an int.

The older board was an XC4111 I got from Jaycar - they no longer carry it. You set whether your programming Uno or ESP8266 by 8 way DIL.

With regards to pigeon hole collision. I’ve reset the addresses back to original values - I’m guessing this will still clash with the crypto chip? The Sparkfun shield uses 0x40 for the Humidity and 0x60 for the pressure.

Regards

Rob

Hi Bryce
I take it is sent via the serial port?
i2cdetect -y 1

Hi Rob,

Sorry my mistake, the code in that reply was meant for another post that was doing something very similar with a Pi rather than an Arduino. Can you try the script for the link below to check?

1 Like

Hi Bryce
All good. I sort of thought it might have been for the Pi as when I googled it that’s what all the references mention and I found the above and ran that.

I2C Scanner
Scanning...
I2C device found at address 0x60  !
done

Looks like it’s only picking up the crypto chip at 0x60 and not the Sparkfun chips at 0x60 and 0x40.

Hi Bryce I also checked on the XC4111 (Uno+ESP8266)

I2C Scanner
Scanning...
I2C device found at address 0x40  !
I2C device found at address 0x60  !
done

So it picks up the the humidity and pressure sensors.
It wouldn’t be a faulty board would it?

Regards
Rob

Hi Bryce
So I solved the interrupts issues and have got my wind and rain interrupts workin.
The issue was the original code for old Uno w/Wifi was…

  attachInterrupt(digitalPinToInterrupt(0), rainIRQ, RISING);
  attachInterrupt(digitalPinToInterrupt(1), wspeedIRQ, RISING);

Because the old Uni only had to interrupts 0 & 1 and were pins 2 & 3.

When reading the bottom of the page at


I realised that with the rev2 the interrupt is the is the actual pin. Therefore
  attachInterrupt(digitalPinToInterrupt(2), rainIRQ, RISING);
  attachInterrupt(digitalPinToInterrupt(3), wspeedIRQ, RISING);

works fine.

As for the I2C. I’m tempted to remove the crypto chip but since my unit will be on the roof I was going to get my real temp, hum & pressure from sensors located on ground.

Thanks for steering me in the right direction.

Regards
Rob

2 Likes

That’s excellent Rob!

Glad to hear that you’ve sorted it out and thanks for sharing your outcome so that others with similar issues in the future can find the answer. If there’s anything that you need please let us know. Have a Merry Christmas!