The Weather Station
These are the components used to build and deploy the Weather Station on the platform in the middle of the vineyard.
Components
Raspberry Pi 3 Model B Vi.2ย
Raspberry Pi clear case
USB - microUSB cable
SanDisk Extreme 64GB MicroSD
MicroSD - SD adapter
Laptop computer w/ Arabic keycaps
Ethernet cable and adapter
The Weather Board Interface boardย
Adafruit 12Bit I2C Analog to Digital converter ADS1015
header pins and cables
Anemometer
Rain gaugeย
Wind direction indicator
WIFI Access Point
ย
External 74GB USB drive (for backup)
Raspberry Piย
Headless Raspberry Pi Setup
Step 1. Download Raspbianย Image
Head on overย hereย to grab a copy of the Raspbian image. The โLiteโ version will do.
Step 2. Write Image to SDย Card
Write the image to SD card. You can find detailed instructionsย here.
Insert the SD card.
Find the device name
mbarrow$ diskutil list
/dev/disk3 (internal, physical):
ย ย #: ย ย ย ย ย ย ย ย ย ย ย TYPE NAMEย ย ย ย ย ย ย ย ย ย SIZE ย ย ย IDENTIFIER
ย ย 0: ย ย FDisk_partition_schemeย ย ย ย ย ย ย ย ย ย ย ย *63.9 GBย ย disk3
ย ย 1: ย ย ย ย ย ย ย Windows_NTFS ย ย ย ย ย ย ย ย ย ย ย ย 63.9 GBย ย disk3s1
Unmount the device
mbarrow$ diskutil unmountDisk /dev/disk3
Unmount of all volumes on disk3 was successful
Copy the Raspbian image to the SD card:
(This process can take several minutes)
mbarrow$ sudo dd bs=1m if=/Users/mbarrow/Documents/proyectos/OpenVino/raspbian/2017-11-29-raspbian-stretch-lite.img of=/dev/disk3 conv=sync
Step 3. Add โSSHโ File to the SD Cardย Root
Enableย SSHย by placing a file named โsshโ (without any extension) onto the boot partition of the SD card:
MTB-MBP:boot mbarrow$ pwd
/Volumes/boot
MTB-MBP:boot mbarrow$ touch ssh
MTB-MBP:boot mbarrow$ ls -la ssh
-rwxrwxrwxย 1 mbarrowย staffย 0 Jul 16 15:43 ssh
Step 4. Setup a fixed IP address for access over ethernet or wifi
ย
(******THIS SECTION NEEDS REVISION******)
ย
a) Change to the pi network directory:
MTB-MBP:~ mbarrow$ cd /Volumes/rootfs
ย
b) Edit the network interface file /etc/network/interfaces
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
ย
auto eth0
iface eth0 inet static
ย ย ย ย address 10.1.1.30
ย ย ย ย netmask 255.255.255.0
ย ย ย ย gateway 10.1.1.1
ย
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
ย
c) Unmount SD card and pop it into the pi with a network cable.
Step 5. Configure your IPย Address
ย
Step 6. SSH into yourย Pi
Use SSH to access the Pi. The default credentials are:
username: pi
password: raspberry
Step 7. Configure the Pi
Thatโs it! You can nowย configure your Piย viaย sudo raspi-config
ย
Change the hostname to openvinopi and the timezone to:
Current default time zone: 'America/Argentina/Mendoza'
Local time is now:ย ย ย Tue Jul 25 22:52:19 ART 2017. (Happy Birthday!)
Universal Time is now:ย Wed Jul 26 01:52:19 UTC 2017.
Step 8. Configure wifi
Edit the file /etc/wpa_supplicant/wpa_supplicant.conf to look like this:
country=GB
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
ย
network={
ssid="costaflores"
proto=RSN
key_mgmt=NONE
}
Step 8. Update the Pi
Secure your login with a rsa key authentication and enabling it only the port 22.ย Here a guide.
A classic system update is also suggested:
sudo apt-get update
sudo apt-get upgrade
Step 9. Set a static IP address
Start by editing the dhcpcd.conf file
sudo vi /etc/dhcpcd.conf
ย
Scroll all the way to the bottom of the file and add one, or both of the following snippets. Depending on whether you want to set a static IP address for a wired connection or a wireless connection eth0 = wired, wlan0 = wireless.
ย
ย
#configure a static ethernetIP address
interface eth0
static ip_address=192.168.8.252/24
static routers=192.168.8.1
static domain_name_servers=192.168.8.1
ย
interface wlan0
static ip_address=192.168.8.253/24
static routers=192.168.8.1
static domain_name_servers=192.168.8.1
Step 10. Reboot
sudo reboot
sudo route add default gw 192.168.1.1
Weather Board
ย
Theย Weather Boardย is a weather station controller board designed to interface to Arduino and Raspberry Pi computers. It is an interface board developed byย SwitchDoc Labs.ย
ย
It contains a built in I2C BMP280 Barometer/Temperature sensor and a DS3231 RTC/EEPROM. The board contains interfaces for the following:ย
WeatherRack Anemometer/Wind Vane/Rain Bucketย
Embedded Adventures I2C Lightning Detectorย MOD-1016 board
Adafruit HTU21D-F Temperature/Humidity breakoutย board
Adafruit 32KB FRAM /ADS1015ย
SwitchDoc Labs Grove ADS1116 16 Bit ADC Boardย
ย
A Grove connector is a four pin standardized size connector used to plug into base units and Grove modules. ย
ย
ย
DS3231/EEPROM Real Time Clockย
The DS3231 is a low-cost, extremely accurate I2C real- time clock (RTC). The device incorporates a battery input, and maintains accurate timekeeping when main power to the device is interrupted. The integration of the crystal resonator enhances the long-term accuracy of the device.ย The DS3231 also has an on board temperature sensor.
Why use a Real Time Clock?
A realtime clock is necessary for any project requiring accurate time keeping especially when you donโt always have an Internet connection. The Raspberry Pi keeps pretty good time, but only if it is connected to the Internet. The Pi uses NTP to set the clock on power up if the Internet is available. It then calls the NTP servers (some are actually hosted by the National Institute of Standards and Technology (NIST) and linked to their atomic clocks). You arenโt going to get atomic clock accuracy using NTP, but it is pretty good.
ย
The SwitchDoc Labs DS3231/EEPROM combination is included with the Weather Board board. It is plugged in by the user into JP11, taking care to having the battery facing the top of the board.ย Connected to the Weather Board, the DS3231 RTC looks like this:
ย
ย
The DS3231ย library is onย https://github.com/switchdoclabs/RTC_SDL_DS3231.
Example Code for theย DS3231
There is a testSDL_DS3231.py included with the library. Here is the bare code needed:
#!/usr/bin/env python
#
# Test SDL_DS3231
# John C. Shovic, SwitchDoc Labs
# 08/03/2014
#
#
# imports
import sys
import time
import datetime
import SDL_DS3231
# Main Program
print โโ
print โTest SDL_DS3231 Version 1.0 โ SwitchDoc Labsโ
print โโ
print โโ
print โProgram Started at:โ+ time.strftime(โ%Y-%m-%d %H:%M:%Sโ)
filename = time.strftime(โ%Y-%m-%d%H:%M:%SRTCTestโ) + โ.txtโ
starttime = datetime.datetime.utcnow()
ds3231 = SDL_DS3231.SDL_DS3231(1, 0x68)
ds3231.write_now()
# Main Loop โ sleeps 10 minutes, then reads and prints values of all clocks
while True:
currenttime = datetime.datetime.utcnow()
deltatime = currenttime โ starttime
print โโ
print โRaspberry Pi=\tโ + time.strftime(โ%Y-%m-%d %H:%M:%Sโ)
print โDS3231=\t\t%sโ % ds3231.read_datetime()
time.sleep(10.0)
<\code>
ย
You should see a result like this:
ย
Test SDL_DS3231 Version 1.0 - SwitchDoc Labs Program Started at:2014-08-03 19:29:58 Raspberry Pi= 2014-08-03 19:29:58 DS3231= 2014-08-03 19:29:58
The wind and rain sensors
A standard anemometer measures wind speed by closing a contact as a magnet moves past a switch. One contact closure a second indicates 2.4 km/h. If you use a different anemometer, this constant can be changed in software. The Wind vane has 8 switches, each connected to a different resistor. The Weather Board measures the resistance value of the resistor by measuring the voltage on a resistor divider (with 10 K Ohm resistor).ย
ย
The tipping bucket rain gauge makes one momentary contact closure per 0.2794 mm of rain.ย
ย
ย
To Set North on Wind Vane
ย
Wind Vane screwย Should Point North โ This is South
North is the screwย hole on the base (without the tab).
There is a tiny little S near the top of the round base of the wind vane and a small N on the other side.
Anotherย way you can calculate it is hand setting the wind vane to north, ย reading fromย the software, and marking the base to indicate North.
If you accidentally mount it incorrectly, you can always adjust the direction in software.
Raspberry Pi Drivers are here atย github.com/switchdoclabs/SDL_Pi_Weather_80422.
ย
Cabling the weather vane and rain gauge
The rain gauge and wind gauges come cabled with short cables with RJ-11 connectors. This is a problem, because we need longer, more protected cabling to go to the WeatherPi. So we need to replace the current cabling, using a single Cat5 RJ45 to connect both instruments, in a sort of daisy chain.
ย
Rain Gauge
First run the RJ45 cable to the rain gauge.
Remove a short section of the RJ45 cable shield, to enable access to the wiring pairs.ย
Replace Rain Gauge RED wire with RJ45 GREEN, and Rain Gauge GREEN wire with GREEN/WHITE
Tape the cabling in place for stability, but insure that no taping interferes with the rain gauge mechanism.
ย
ย
Original Cable | New Cable | RJ-11 pins |
Green | Green/White | 3 |
Red | Green | 4 |
ย
ย
Wind Gauges
The wind direction indicator is cabled to the anemometer through a short RJ11 cable. We can leave this connection as is. But the cable that goes to the WeatherPi needs to be replaced with the tail of the cable we used from the Rain Gauge.
ย
First remove the wind indicator from the T-bar support.
Remove the three screws holding the first cable guide.
Remove the three screws holding the sensor board in place.
Remember the position of the sensor board with reference to the weather vane.
Cut the weather board cable.
Route the new Cat-5 cable through the first cover.
Cut away to the GREEN/WHITE and GREEN cables. These are already used by the Rain Gauge.
Remove the silicon protector and unsolder the existing four cables.
Replace with new cables as below:
Replace the covers, and route cables accordingly. Connect anemometer RJ11
ย
Original Cable | New Cable | RJ-11 pins |
Black | Blue | 5 |
Red | Blue/White | 4 |
Yellow | Orange/White | 3 |
Green | Orange | 2 |
ย
Split the other Cat-5 cable extreme with two RJ11 connectors per the original configurations seen above.
ย
AM2315 Temperature/Humidity Sensor
The AM2315 I2C is a temperature and humidity sensor.. It uses special temperature and humidity acquisition technology, to ensure that the sensor has high reliability and excellent long-term stability.ย While it is not waterproof, it is weather resistant. ย This sensor does far better for sensing temperature and humidity where there might be wind and rain.
Comes with attached Grove connector
3.3V to 5.5V I2C interface and powerย
10 mA max current use during conversion
Good for 0-100% humidity readings with minimum 2% accuracy
Good for -20 to 80ยฐC temperature readings ยฑ0.1ยฐC typical accuracy
Updated every 500ms (0.5 Hz)
Body size 98mm x 16mm diameter
20 inch long - 4 wire cable
This board/chip uses I2C 7-bit address 0x5C.
Here is the complete datasheet.
Connect the AM2315 to connector J7 on the Weather Board.ย
ย
To test the AM2315, load the program testAM2315.py onto the Raspberry Pi:
ย
import time
from tentacle_pi.AM2315 import AM2315
am = AM2315(0x5c,"/dev/i2c-1")
for x in range(0,10):
temperature, humidity, crc_check = am.sense()
print "temperature: %0.1f" % temperature
print "humidity: %0.1f" % humidity
print "crc: %s" % crc_check
print
time.sleep(2.0)
This program requires the following modules:
sudo apt-get install python-pip
sudo apt-get install libi2c-dev
sudo apt-get install python-dev
sudo pip install tentacle_pi
ย
ย
Now you can test:
pi@openvinopi:~ $ sudo python testAM2315.pyย
temperature: 13.1
humidity: 52.5
crc: 1
ย
Yes, the temperature in my house is 13.1ยบC, and my hands are cold.
ย
Connecting the Weather Board and Sensors to the Raspberry Pi
This is how the Weather Board gets wired to the Raspberry Pi.ย
ย
Weather Board | Reference | Color | GPIO-PIN |
JP2-2 | Rain Bucket | Grey | 37 |
JP2-3 | Anemometer | Gold | 40 |
JP1-1 | Power GND | Black | 6 |
JP1-2 | Power VDD | Red | 1 |
J7 (Grove) | AM2315 Temp | - | - |
JP4-1 | I2C-SCL | Yellow | 5 |
JP4-2 | I2C-SDA | Orange | 3 |
JP11 | DS3231 RTC | - | - |
JP5 | ADS1015 | - | - |
ย
ย
ย
ย
ย
Configuring I2C
I2C is a very commonly used standard designed to allow one chip to talk to another.
So, since the Raspberry Pi can talk I2C we can connect it to a variety of I2C capable chips and modules.
ย
We need to configure the Raspberry Pi to use I2C. To do this, run the following commands to install the i2c-tools utility:
sudo apt-get install -y python-smbus
sudo apt-get install -y i2c-tools
ย
Then edit /etc/modules
sudo vi /etc/modules
Add the following lines:
i2c-bcm2708
i2c-dev
You will also need to update theย /boot/config.txtย file. Editย /boot/config.txtย and add the text:
dtparam=i2c1=on
dtparam=i2c_arm=on
Then reboot and test:
sudo reboot
pi@openvinopi:~/RaspberryPi-WeatherPiArduinoV2 $ sudo i2cdetect -y 1
ย ย ย 0ย 1ย 2ย 3ย 4ย 5ย 6ย 7ย 8ย 9ย aย bย cย dย eย f
00:ย ย ย ย ย -- -- -- -- -- -- -- -- -- -- -- -- --ย
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --ย
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --ย
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --ย
40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --ย
50: -- -- -- -- -- -- -- 57 -- -- -- -- 5c -- -- --ย
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --ย
70: -- -- -- -- -- -- -- 77
ย
ย
It is necessary to execute twice in rapid succesion the i2cdetect command to insure that the "sleeping" AM2315 temperature sensor responds.
After you hook up your SwitchDoc Labs DS3231 Module to the Raspberry Pi (3.3V, GND, SCL, SDA), run the following command:
ย
pi@openvinopi: sudo i2cdetect -y 1
The results should be similar to this. ย
ย
This shows that four I2C addresses are in use:
Device | Address |
DS3231 Realtime Clock | 0x68 |
AM2315 Temperature Sensor | 0x5C |
AT24C32 eeprom. | 0x57 |
BMP085 Barometric Pressure Sensor | 0x77 |
Temperature Sensor | 0x48 |
ย
Install the WeatherPi test software:
ย
Now test:
pi@openvinopi:~/RaspberryPi-WeatherPiArduinoV2 $ sudo python WeatherPiArduinoV2.py
----------------------------------------ย
-----------------ย
ย WeatherRack Weather Sensors
-----------------ย
Rain Total= 0.11 in
Wind Speed= 4.14 MPH
MPH wind_gust= 8.45 MPH
Wind Direction= 225.00 Degrees
Wind Direction Voltage= 2.022 V
-----------------ย
-----------------ย
ย DS3231 Real Time Clock
-----------------ย
Raspberry Pi= 2017-08-11 18:24:08
DS3231= 2017-08-11 18:24:07
DS3231 Temperature= 15.00 C
-----------------ย
-----------------ย
ย AT24C32 EEPROM
-----------------ย
writing first 4 addresses with random data
address = 0 writing value=153
address = 1 writing value=34
address = 2 writing value=34
address = 3 writing value=55
-----------------ย
reading first 4 addresses
address = 0 value = 153
address = 1 value = 34
address = 2 value = 34
address = 3 value = 55
-----------------ย
-----------------ย
ย BMP280 Barometer
-----------------ย
Temperature = 15.22 C
Pressure = 90.10 KPa
Altitude = 979.76 m
Sealevel Pressure = 90.10 KPa
-----------------ย
-----------------ย
ย AM2315 Temperature/Humidity Sensor
-----------------ย
AM2315 temperature: 13.8
AM2315 humidity: 53.4
AM2315 crc: 1
-----------------ย
-----------------ย
ย HTU21DF Temp/Hum Not Present
-----------------ย
-----------------ย
-----------------ย
ย AS3935 Lightning Detector Not Present
-----------------ย
-----------------ย
-----------------ย
ย FRAM Not Present
-----------------ย
-----------------ย
ย
Sleeping 10 seconds