WeatherRack Raspberry Pi Python Drivers Released

WeatherRack Weather Sensors

WeatherRack Raspberry Pi Python Drivers Released

The new release of the of the Raspberry Pi Pure Python Class driver software for the inexpensive 41-tvY+gqZLWeatherRack Weather Sensors is now available on github.com/switchdoclabs.  Support for the WeatherPiArduino board and the ADS1015 A/D converter has been added.  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.  The Arduino Drivers are available here.

WeatherPiArduino

To the right is the fully populated WeatherPiArduino board.  It was designed to interface

with the SwitchDoc Labs WeatherRack along with some auxiliary I2C units:

Weather
WeatherPiArduino and Raspberry Pi B+
  • 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)

The WeatherPiArduino board comes with the DS3231 RTC, AT24C32 EEPROM and the BMP180.

Note:  Because the Raspberry Pi B+ does not have Analog to Digital Converters, you will need to use the optional ADS1015 ADC board, or wire your own AD converter.

SDL_PI_Weather_80422 Class Library for Raspberry Pi

The SDL_Pi_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 pure python class.

The library is easy to use and hides the complexity of the interface to the sensors.  The Python  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 (ADS1015 if you are using the WeatherPiArduino driver).  Note that the Python 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, we use SDL_MODE_SAMPLE because we can tolerate not having an instantly available current value of wind speed.

Here is example output from the Sensors using the SDL_Pi_Weather_80422 class.

---------------------------------------- 
----------------- 
 SDL_Pi_Weather_80422 Library
 WeatherRack Weather Sensors
----------------- 
Rain Total= 0.02 in
Wind Speed= 2.39 MPH
MPH wind_gust= 2.32 MPH
Wind Direction= 315.00 Degrees
Wind Direction Voltage= 2.880 V
----------------- 
-----------------

The example code for the SDL_Weather_80422 library is shown below:

#!/usr/bin/env python
#
# SDL_Pi_Weather_80422 Example Test File
# Version 1.0 February 12, 2015
#
# SwitchDoc Labs
# www.switchdoc.com
#
#


#imports

import time
import sys

sys.path.append('./Adafruit_ADS1x15')


import SDL_Pi_Weather_80422 as SDL_Pi_Weather_80422

#
# GPIO Numbering Mode GPIO.BCM
#

anenometerPin = 23
rainPin = 24

# constants

SDL_MODE_INTERNAL_AD = 0
SDL_MODE_I2C_ADS1015 = 1

#sample mode means return immediately.  THe wind speed is averaged at sampleTime or when you ask, whichever is longer
SDL_MODE_SAMPLE = 0
#Delay mode means to wait for sampleTime and the average after that time.
SDL_MODE_DELAY = 1

weatherStation = SDL_Pi_Weather_80422.SDL_Pi_Weather_80422(anenometerPin, rainPin, 0,0, SDL_MODE_I2C_ADS1015)

weatherStation.setWindMode(SDL_MODE_SAMPLE, 5.0)
#weatherStation.setWindMode(SDL_MODE_DELAY, 5.0)

totalRain = 0
while True:


        print "---------------------------------------- "
        print "----------------- "
        print " SDL_Pi_Weather_80422 Library"
        print " WeatherRack Weather Sensors"
        print "----------------- "
        #

        currentWindSpeed = weatherStation.current_wind_speed()/1.6
        currentWindGust = weatherStation.get_wind_gust()/1.6
        totalRain = totalRain + weatherStation.get_current_rain_total()/25.4
        print("Rain Total=\t%0.2f in")%(totalRain)
        print("Wind Speed=\t%0.2f MPH")%(currentWindSpeed)
        print("MPH wind_gust=\t%0.2f MPH")%(currentWindGust)

        print "Wind Direction=\t\t\t %0.2f Degrees" % weatherStation.current_wind_direction()
        print "Wind Direction Voltage=\t\t %0.3f V" % weatherStation.current_wind_direction_voltage()

        print "----------------- "
        print "----------------- "

        time.sleep(10.0)

2 Comments

  1. Hi Dr. John C. Shovic,

    I test your code with Rpi & anemometer, but the wind speed seems get maximum at 4.7 mph.
    I checked that on your code written:

    GPIO.add_event_detect(pinAnem, GPIO.RISING, callback=self.serviceInterruptAnem, bouncetime=300)

    why did you put bouncetime = 300 on the interrupt?
    what if the wind speed is very high so the switch triggered at interval less that 300?

    thanks for your explanation.
    regards,

    Kasyful

    • Hi Kasyful,

      Tell me which specific software you are looking at and I will take a look at it. 300 milliseconds seems like too long of a delay, which could explain your issue. It is debounced in software in the interrupt routine. Sounds like this is a real bug. Remove the bouncetime=300 and let me know the results.

      SDL

1 Trackback / Pingback

  1. Raspberry Pi Python Drivers Released on SwitchDoc - SwitchDoc Labs

Comments are closed.