WeatherPiArduino Software Released for WeatherRack Sensors

Arduino Adafruit SparkFun
Fully Populated WeatherArduino Board

WeatherPiArduino Software Released for SwitchDoc WeatherRack – SDL_Weather_80422 Class Library

WeatherPiArduino Fully Populated
WeatherPiArduino Fully Populated

We have now released the first version of the Arduino C++ Class software for the WeatherRack weather sensors, interfacing with the WeatherPiArduino.  The full WeatherPiArduino article was  published in Raspberry Pi Geek magazine in September 2014.  A second article talking about the lightning detector will be published in April 2015.  It was designed to interface with the SwitchDoc Labs WeatherRack along with some auxiliary I2C units:

  • DS3231 RTC
  • Adafruit 32KB FRAM I2C breakout board
  • Adafruit ADS1015 4 Channel A/D I2C board
  • Lightning Sensor
  • Humidity Sensor
  • Barometer and Temperature Sensor (BMP180)

Above is the fully populated WeatherPiArdino board (now available on the SwitchDoc Store).   Non-US Customers, it is available on tindie.com.    It is shown with all of the optional I2C boards.

The SDL_Weather_80422 class library for Arduino is located on github at https://github.com/switchdoclabs/SDL_Weather_80422

SparkFun WeatherArduino
WeatherRack  Weather Meter Sensors

The SDL_Weather_80422 class library is designed to provide all the functions of the SwitchDoc Labs WeatherRack and the SparkFun Weather Meters SEN-08942 in one C++ class.

The library is easy to use and hides the complexity of the interface to the sensors.  The C++ class has two Interrupt Service Routines (ISR), one each for the anemometer and the rain bucket.  The wind vane is connected to an Analog to Digital Converter (ADC) input pin on the Arduino.  Note that the C++ class is designed to be a singleton, in other words, you only can interface one sensor package without some additional work (mostly involving Interrupts).  The article in Raspberry Pi Geek magazine discusses this in detail.

There are two main modes for the class.

SDL_MODE_SAMPLE

SDL_MODE_SAMPLE mode means return immediately after asking for the wind speed. The wind speed is averaged at sampleTime or since you last asked, whichever is longer. If the sample time has not passed since the last call, the class returns the last calculated wind speed. That means that you will never see changes faster than the specified sample time. This allows you to not wait for the wind speed, you can just grab the last valid reading.

SDL_MODE_DELAY

SDL_MODE_DELAY mode means to wait for the set sample time to expire and return the average wind speed at the expiration. You would use this if you want to make sure you have the latest value and your program architecture allows you to pause for the sample time before continuing. Which mode you use depends on the specific software architecture of your Arduino application.

Typically, I use SDL_MODE_SAMPLE because I can tolerate not having a current value of wind speed.

The example code for the SDL_Weather_80422 library is shown below:

/*
  SDL_Weather_80422_Library.ino - Example for using SDL_Weather_80422 Library
  For SwitchDoc Labs WeatherRack
  For Weather Sensor Assembly 80422.
  Imported by Argent Data Systems
  Created by SwitchDoc Labs July 27, 2014.
  Released into the public domain.
*/
#include 
#include 

#include "SDL_Weather_80422.h"

#define pinLED     13   // LED connected to digital pin 13
#define pinAnem    18  // Anenometer connected to pin 18 - Int 5
#define pinRain    2   
#define intAnem    5
#define intRain    0

// for mega, have to use Port B - only Port B works.
/*
 Arduino Pins         PORT
 ------------         ----
 Digital 0-7          D
 Digital 8-13         B
 Analog  0-5          C
*/


// initialize SDL_Weather_80422 library
SDL_Weather_80422 weatherStation(pinAnem, pinRain, intAnem, intRain, A0, SDL_MODE_INTERNAL_AD);


uint8_t i;




float currentWindSpeed;
float currentWindGust;
float totalRain;
void setup()
{ 
  Serial.begin(57600);  
  

 Serial.println("-----------");
 Serial.println("WeatherArduino SDL_Weather_80422 Class Test");
 Serial.println("Version 1.0");
 Serial.println("-----------");
      
      
      weatherStation.setWindMode(SDL_MODE_SAMPLE, 5.0);
      //weatherStation.setWindMode(SDL_MODE_DELAY, 5.0);
      totalRain = 0.0;
}


void loop()
{
  Serial.println("----------------");

  currentWindSpeed = weatherStation.current_wind_speed()/1.6;
  currentWindGust = weatherStation.get_wind_gust()/1.6;
  totalRain = totalRain + weatherStation.get_current_rain_total()/25.4;
  Serial.print("rain_total=");
  Serial.print(totalRain);
  Serial.print(""" wind_speed=");
  Serial.print(currentWindSpeed);
    Serial.print("MPH wind_gust=");
  Serial.print(currentWindGust);
  Serial.print("MPH wind_direction=");
  Serial.println(weatherStation.current_wind_direction());
  

  
  delay(1000);
  
  
}

When you run this, you should get a result similar to this:

-----------

WeatherArduino SDL_Weather_80422 Class Test
Version 1.0

-----------
----------------
rain_total=0.00 wind_speed=13.20MPH wind_gust=12.40MPH wind_direction=90.00
----------------
rain_total=0.00 wind_speed=9.60MPH wind_gust=9.48MPH wind_direction=90.00
----------------
rain_total=0.00 wind_speed=10.20MPH wind_gust=9.23MPH wind_direction=90.00
----------------
rain_total=0.00 wind_speed=11.10MPH wind_gust=9.84MPH wind_direction=90.00

12 Comments

  1. Quick question… as you are thousands of Km. from the project, why mechanical for wind speed and direction? Mechanism for failure is large.
    Been thinking a few days ago if an audio solution is posible….
    Here goes:
    3 tramsmiter-reciever pairs. One ‘pings’, others ‘listen’ for it, and by correlation measure the distance between. Natch, of the wind’s in the wrong direction, then one of the others has to ‘ping’. I reckon if the sensors are a couple of metres apart…BY phase correlation, direction as well as velocity could be detemined.
    Sure someone has already done it, but…

    • Great comment! Yes, since the project is so far away, I am concerned about moving parts. That’s one reason I am just adding more solar panels rather than putting a mechanical sun tracking system in place. It will break in the tropics eventually. I’m seeing a little wear on my servo motor controlling the camera cover but it’s still good enough.

      You can buy ultrasonic wind sensors (search on that) but they are pretty pricey, so I decided to stick with the $70 SparkFun system.

      That would be a fun thing to experiment with in the future. Maybe a build your own project. Good idea!

      John

      • Just to update, the problem was that I was disabling interrupts when my radio was sending data. Removing that section of code fixed the spurious data, now I just have to hope it’s not going to break anything 🙂

  2. Hi

    I’ve converted the Wind Vane’s voltage table over to 3.3v and though you may want to include it and allow VCC customization (maybe on initialization?) or detect VCC from the internal bandgap voltage.

    You could also use the actual ADC values and then VCC voltage wouldn’t actually matter, although you’d still need the fuzzy search, anyway this is the table.

    2.53
    1.31
    1.49
    0.27
    0.30
    0.21
    0.60
    0.41
    0.93
    0.79
    2.03
    1.93
    3.05
    2.67
    2.86
    2.26

    Now on to my actual question. I’m getting, what appear to be wind values that are 10 times to high. I’ve removed the MPH conversion factor of 1.6 and get reports of 20km/h wind and gusts of 70km/h when I’m only slowly spinning the anemeter with about 1 rpm.

    Any ideas?

    • Hi Dave,

      Sounds like you are getting too many interrupts. Put a counter in the Interrupt routine to count interrupts and then print the value in the main loop. See if you are getting 10 times as many as you should.

      Maybe you have to change the debounce period.

      If you are running on 3.3V, there is less margin for noise, so that could be a problem too – false interrupts. I assume you are running 3.3V into the interrupt inputs on the Arduino?

      Let me know what you find.

      John

    • The kph/Hz factor in the SparkFun data sheet is wrong. For a cup anemometer the linear speed of the cups is ~ 1/3 the wind speed. There are two on-off clicks/rotation so I come up with ~0.283 kph/Hz. I may be off by 10-20% but it agrees fairly well with other measurements.

  3. First, I must say this is the only one of many solutions I have tried that works! Thank you. How would I convert The “float” variable for wind direction to N,E,S,W, etc.?

    • Thank you! It is being installed in Project Curacao as we speak.

      To convert the float direction variable to text:

      if (winddirection == 0.0)
      {
      textDirection = “N”;
      }
      …. etc

      John

  4. Thank you, again. I have noticed the rain bucket count increments over time, WITHOUT the bucket moving! (like .01/hour) I wonder if this has something to do with the “TIME.h” file? There are 2 different TIME.h files out there, and I may be using the wrong one.

    • David,

      I don’t *think* it has anything to do with time.h. How long is your cable run to the rain bucket? You could be picking up noise.
      Add a 0.1uf ceramic decoupling cap to the line. It should help.

      What interrupts are you using? You could be coupling from one interrupt to the other if they are next to each other. Adding decoupling capacitors can help that too.

      Best regards,

      John

  5. Correct again, John! I discovered it was not incrementing with the bucket disconnected. So it had to be cable related. A .o1 mfd. at the board solved the problem. Thank you again.

  6. Would it be possible to see the changes that were made for the “N,S,E,W” conversion?
    I’m having a lot of trouble getting it to work. Thank you.

6 Trackbacks / Pingbacks

  1. WeatherArduino RasPiConnect Control Panel - SwitchDoc Labs
  2. WeatherArduino SDL_RasPiGraphLibrary Library Released - SwitchDoc Labs
  3. Wind Power and WeatherArduino in the Caribbean - SwitchDoc Labs
  4. WeatherArduino Complete and Ready for the Caribbean - SwitchDoc Labs
  5. WeatherRack Weather Sensors Released - SwitchDoc Labs
  6. Weather Station updates – Argent Data Systems wind-rain sensors. – kalauao research

Comments are closed.