Tutorial: Part 11 -Building a Solar Powered Raspberry Pi Weather Station – GroveWeatherPi
The Raspberry Pi is a fabulous device to on which to build your projects. The GroveWeatherPi project is designed to show the capabilities of this computer while remaining accessible to a diverse Maker community.
GroveWeatherPi is a Solar Powered Raspberry Pi WiFi connected weather station designed for Makers by SwitchDoc Labs ( www.switchdoc.com). This is a great system to build and tinker with. All of it is modifiable and all source code is included.
This tutorial for building your own Solar Powered Weather Station based on the Raspberry Pi consists of 14 parts.
[include-page id=”gdplinks”]
The Raspberry Pi Python Software
A big part of the GroveWeatherPi project is the software. All of the python software for this project is up on github at the switchdoclabs section ( github.com/switchdoclabs/SDL_Pi_GroveWeatherPi ). We also included all of the various libraries for the I2C devices we are using.
Non-Normal Requirements for your Pi
You will need to add the following software and libraries to your Raspberry Pi
MySQL
There are lots of tutorials on the net for installing MySQL. Here is the one we used (https://howtoraspberrypi.com/mariadb-raspbian-raspberry-pi/).
sudo apt-get install python-mysqldb
MatPlotLib
This is the graphing subsystem with a great interface to Python. It is a bit more complex to install, so we wrote a tutorial on how to install it on SwitchDoc.com ( https://www.switchdoc.com/2014/01/matplotlib-raspberry-pi-mysql-and-project-curacao/ ). Note that the installation takes a long time, about 8 hours on a Raspberry Pi B+ (mostly unattended).
The GroveWeatherPi Python Software
The GroveWeatherPi software is pretty simple. The application was much less complex than the Project Curacao software( https://www.switchdoc.com/project-curacao-software-system-part-6/ ) so we decided not use the apscheduler package and decided just to use a simple loop with a “every 15 seconds” type of control.
Here is the main loop:
secondCount = 1 while True: # process Interrupts from Lightning if (as3935Interrupt == True): try: process_as3935_interrupt() except: print "exception - as3935 I2C did not work" if (config.TCA9545_I2CMux_Present): tca9545.write_control_register(TCA9545_CONFIG_BUS0) # process commands from RasPiConnect print "---------------------------------------- " processCommand() if ((secondCount % 10) == 0): # print every 10 seconds sampleAndDisplay() patTheDog() # reset the WatchDog Timer blinkSunAirLED2X(2) # every 5 minutes, push data to mysql and check for shutdown if ((secondCount % (5*60)) == 0): # print every 300 seconds sampleWeather() sampleSunAirPlus() writeWeatherRecord() writePowerRecord() if (batteryVoltage < 3.5): print "--->>>>Time to Shutdown<<<<---" shutdownPi("low voltage shutdown") # every 15 minutes, build new graphs if ((secondCount % (15*60)) == 0): # print every 900 seconds sampleWeather() sampleSunAirPlus() doAllGraphs.doAllGraphs() # every 30 minutes, check wifi connections if ((secondCount % (30*60)) == 0): # print every 900 seconds WLAN_check() #WLAN_check() # every 48 hours, reboot if ((secondCount % (60*60*48)) == 0): # reboot every 48() hours seconds rebootPi("48 hour reboot") secondCount = secondCount + 1 # reset secondCount to prevent overflow forever if (secondCount == 1000001): secondCount = 1 time.sleep(1.0)
Note that we reboot the Pi every two days. Why do we do that? We have noticed that after heavy usage of MatPlotLib and/or MySQL, that sometimes after a long time, you run out of resources, giving all sorts of odd behavior. Since the RaspberryPi A+ has a small amount of RAM, rebooting is the easiest way of fixing it.
Check out all the code up on github.com ( github.com/switchdoclabs/SDL_Pi_GroveWeatherPi ).
There is a typo in the wifi checking comment 30 x 60 = 1800 not 900…
Got it! Fixed. And now the default is to check every 1800 seconds for WLAN connections. Shorten this if you need to for poor WiFi.
SDL
What are the sudo commands to install the software? There are no instructions on GitHub
Hi Ken,
to install the software:
git clone https://github.com/switchdoclabs/SDL_Pi_GroveWeatherPi.git
Follow the instructions in the README.md for the drivers installation.
SDL
It would be great if we could use Adafruit’s Weatherproof TTL Serial JPEG Camera with NTSC Video and IR LEDs.
https://www.adafruit.com/products/613
Is it possible to comment out the MSQL and Matpilot.
Yes, you can go through the source code and comment out the calls.
SDL
>>>>>>>>>>>>>>>>>>><<<<<<<<<<>>>>>>>>>>>>>>>>>><<<<<<<<<<<
Traceback (most recent call last):
File "GroveWeatherPi.py", line 216, in
weatherStation = SDL_Pi_WeatherRack.SDL_Pi_WeatherRack(anemometerPin, rainPin, 0,0, SDL_MODE_I2C_ADS1015)
File “./SDL_Pi_WeatherRack/SDL_Pi_WeatherRack.py”, line 192, in __init__
self.ads1015 = ADS1x15(ic=ADS1015, address=0x48)
File “./Adafruit_ADS1x15/Adafruit_ADS1x15.py”, line 138, in __init__
self.i2c = Adafruit_I2C(address)
File “./Adafruit_ADS1x15/Adafruit_I2C.py”, line 43, in __init__
self.bus = smbus.SMBus(busnum if busnum >= 0 else Adafruit_I2C.getPiI2CBusNumber())
IOError: [Errno 2] No such file or directory
Hello,
What version of Python is this code tested against? I have both 2.x and 3.x installed.
From above:
<<>>
This tutorial executes the following line: sudo apt-get install mysql-server python-mysqldb, which installs a Python2 library
Thanks,
Tim
This software is tested against Python 2.x.
We currently don’t support Python 3.x.
Best regards,
SDL