Archive for December, 2018

Updated Weather Station

Working on updating my weather station currently. It’s been out of commission for a year or so. The rubbermaid box I had it in didn’t last in the elements so I’m having to rethink my mounting process. I’m also looking into getting a larger battery because the 6000 maH one I’m using doesn’t last that long.

I’m also going to be improving it. I’ve put together a circuit to measure how much battery I have left so I can have it turn itself off when the battery is too low. Also have a few more calculations that I can add in to my reporting like heat index which will be useful for the summer.

I’ve also reordered my posts so you will see the updated weather station posts below this one to try to group them in an order of build process

Mast

With this post I wanted to do a full overview of my mast, which I’ve spoken some on before. This will provide instructions on how to build as well as archiving things in case I need to rebuild it in the future. (I just had to re-wire everything and it was pretty difficult remember and figuring out where everything went) The mast is only one part of my weather station; the enclosure, which houses some other sensors as well as the RPi, will be in another post. The way my weather station works is the mast gathers info from the 5 sensors that are contained on/in it via the micro controller. It then sends the data to the Raspberry Pi that resides in the enclosure via I2C to be archived, along with data from the other sensors, within my database tables.

The mast is built out of PVC. This allows me to attach my homemade sensors easily as well as protecting the micro controller that resides inside that runs the sensors.

Main Mast Build:

Most of the mast is made from 1″ PVC with different connectors and such.  There are a few places in which the 1″ is not used, for example, where the micro controller resides.  (You can see it as the larger section). It uses 3/4″ PVC inside 1.5″ PVC.  It is built this way to provide some waterproofing for the micro controller.  The other section is for the temperature & humidity sensors.  It uses some 3″ PVC as a sun shield for the sensors.  As for the wiring of the sensors, I will detail that a little later, but all the wiring for the sensors comes together at a point where the larger section starts.  It’s there where I  “harness” everything together and will detail that later.

Sensors:

As I said, there are 5 sensors within the mast.  3 are sensors I have built myself and two are not.  For the sensors I have built myself, I have linked to the posts in which I detail how to build them.

  1. Wind Vane – Link to post
  2. Anemometer – Link to post
  3. Rain Gauge – Link to post
  4. Temp Sensor – Link to post
  5. Humidity Sensor – Link to post

Microcontroller & Wiring:

In previous versions of the mast, I have used an Adafruit Trinket board, but when I attempted to add some additional sensors (which failed miserably due to waterproofing) it didn’t have the needed pins required, so I switched to a Arduino Pro Mini 3V.  The Pro Mini is slightly larger, more powerful and allows me to power it with 5V coming from the Raspberry Pi.

As I said before, I communicate with the Pro Mini from the RPi via I2C.  To do this, I have a cat 5 cable running from the enclosure to the Pro Mini (I only need 4 of the wires, but it’s nice to have a spare 4 in case something happens) and then another piece of cat 5 that runs from the Pro Mini to the wiring harness.  I’ll make another post regarding the wiring for the micro controller and the wiring harness as I believe this one has gotten a little long. Link to post

Stay tuned for more…

To start off, I wanted to say that I know there are other sensors that can do what the sensors that I use can do and possibly even do it better, but I’ve had these two sensors for several years now and they have done exactly what I’ve needed them to without fail.

For temperature I use a DS18B20 and for humidity I use a Honeywell HIH-5031.  The DS18B20 is a very popular temperature sensor which uses the 1 wire protocol.  the HIH-5031 is an analog humidity sensor that runs on 3V.  The DS18B20 outputs a temp in C with the Arduino code, but the HIH-5031 only outputs a voltage which requires some code to translate into humidity.  I’ll post all of that later when I post about the code I use on the Raspberry Pi.

Sensor Wiring:

For wiring these sensors, each has 3 pins, a power, ground & read pin.  Because each sensor really needs to be exposed to air to reach correctly, I soldered several single wires to their pins and then used shrink tube to cover the connections and then another piece of shrink tube to collect the 3 wires together and cover a bit of the end of the sensor.  (You can see this in the pic above)  The two sets of 3 wires are brought together into a single cat 3 cable (4 wires).  I wire the power of each sensor to a red wire, the ground of each sensor to a black wire, then the read pins of each sensor to it’s own wire.  This allows me to be able to have only 4 wires in the wiring harness for these two sensors instead of 6.

 

Sensor Mounting:

As you can see above, I use an offshoot of my main mast to hold these two sensors.  The sensors themselves sit within a piece of 1 inch PVC that has holes drilled in it to allow for air flow.  This is covered with a 3″ PVC pipe that protects from solar radiation as well as rain.  I don’t have many of the details on all the PVC connections I used to make this happen, but all I did was go to the hardware store and start piecing things together to get what I wanted.

In a previous post I mentioned that I would make a separate post regarding the micro controller wiring as well as the wiring harness.  Again, for the micro controller I am using an Arduino Pro Mini 3V.  Link to code  Below are a few pics and wiring details:

Microcontroller Pics:

A few pics of the micro controller wiring and waterproofing tube.  As you can see in the below pic, the micro controller sits within some 3/4″ PVC with caps on each end that have holes for the wires to come out of.  My suggestion would be to make the “top” hole waterproof by putting silicon or something around the cat 5 cable coming out and leave the bottom one free to slide in case you need to get to your micro controller for repair reasons.

Micro Controller Wiring:

I’ll include the micro controller pin as well as the wire color and “direction” of wire in this format: Pin on Pro Mini – Wire/direction – (wire color.)  (Some will have multiple wires attached)

  • Raw – 5V from RPi – (blue)
  • GND – GND from RPi – (blue-white)
  • A4 – SDA from RPi – (green)
  • A5 – SCL from RPi – (green-white)
  • Vcc
    • Power to wiring harness – (brown)
    • 4.7k Ω resistor for DS18B20 to Pin 10
  • GND
    • Ground to wiring harness – (orange)
    • Ground to wiring harness – (brown-white)
    • 65k Ω resistor for HIH-5031 to Pin A2
  • A1 – read pin for wind vane in wiring harness – (green)
  • A2
    • read pin for HIH-5031 in wiring harness – (orange-white)
    • 65k Ω resistor for HIH-5031 to GND
  • D2 – interrupt for rain gauge in wiring harness – (blue-white)
  • D3 – interrupt for anemometer in wiring harness – (blue)
  • D10
    • read pin for DS18B20 in wiring harness – (green-white)
    • 4.7k Ω resistor for DS18B20 to Vcc

Wiring Harness Pics & Wiring:

The wiring harness is where all the wires from the sensors come together with the wire coming from the Pro Mini.  I solder the wires together and use shrink tube to protect them, but I ran out of shrink tube and had to use these other connectors…don’t use these connectors.  It’s a mess…

For the wiring, I’ll list the wire color coming out of the micro controller and what wires are attached to it from the sensors.

  • Brown-white
    • GND for rain gauge
    • GND for anemometer
  • Brown
    • These two are tied together and I’ll explain in another post
      • 3V for DS1B20
      • 3V for HIH-5031
    • 3V for wind vane
  • Blue-white
    • 3V for rain gauge
  • Blue
    • 3V for anemometer
  • Green-white
    • read pin for DS18B20
  • Green
    • read pin for wind vane
  • Orange-white
    • read pin for HIH-5031
  • Orange
    • These two are tied together and I’ll explain in another post
      • GND for DS1B20
      • GND for HIH-5031
    • GND for wind vane

Mast – Micro controller code

Below is the arduino code I use for the Pro Mini.  I’m going to post it in block quotes as well as a link to a txt file with the code.  I feel that it’s commented well so I’m not going to go into details here.  It uses the standard Wire, OneWire & AVR/Interrupt libraries as well as some found code for the DS18B20 reading.  I’m planning on loading all my code to Github in the future so it’s all in one place.  I just have to figure out how to do that appropriately.  (Since some of the libraries I use for sensors come from other sources, ie: Adafruit)

#include <Wire.h>
#include <avr/interrupt.h>
#include <OneWire.h>

// defining which I2C addres to use
#define SLAVE_ADDRESS 0x05
// setting he number used to request data from pro mini to send back to the pi
int number = 0;

//setting up pins for sensors
const byte rainGauge = 2;
const byte windSpeed = 3;

// setting up variables for sensors
volatile int rainCount = 0;
volatile int windCount = 0;
volatile int windCountSend = 0;
volatile int windCountSendMax = 0;
long rainDebouncingTime = 300; //Debouncing Time in Milliseconds
volatile unsigned long rainLastMicros;
long windDebouncingTime = 100; //Debouncing Time in Milliseconds
volatile unsigned long windLastMicros;
volatile int windDir = 0;

int temp = 0;
// pin for DS18B20
OneWire ds(10); // on pin 10

void setup() {

// initialize i2c as slave
Wire.begin(SLAVE_ADDRESS);

// define callbacks for i2c communication
Wire.onReceive(receiveData);
Wire.onRequest(sendData);

// setup pins for sensors and attach interrupts
pinMode(rainGauge, INPUT);
digitalWrite (rainGauge, HIGH); // internal pull-up resistor
attachInterrupt (0, debounceRain, FALLING); // attach interrupt handler
pinMode(windSpeed, INPUT);
digitalWrite (windSpeed, HIGH); // internal pull-up resistor
attachInterrupt (1, debounceWind, FALLING); // attach interrupt handler
Serial.begin(9600);

}

void loop() {

//***********************************
// Read DS18B20
int HighByte, LowByte, TReading, SignBit, Tc_100, Whole, Fract;

byte i;
byte present = 0;
byte data[12];
byte addr[8];

if ( !ds.search(addr)) {
ds.reset_search();
return;
}

ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end

delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.

present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad

for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();

}

LowByte = data[0];
HighByte = data[1];
TReading = (HighByte << 8) + LowByte;
SignBit = TReading & 0x8000; // test most sig bit
if (SignBit) // negative
{
TReading = (TReading ^ 0xffff) + 1; // 2’s comp
}
Tc_100 = (6 * TReading) + TReading / 4; // multiply by (100 * 0.0625) or 6.25

temp = Tc_100;

//************************************

// get wind speed
windCount = 0;
delay(10000);
windCountSend = windCount;
if (windCountSend > windCountSendMax){
windCountSendMax = windCountSend;
}

}

// callback for received data
void receiveData(int byteCount){

while(Wire.available()) {
number = Wire.read();
// setup to reset rain count. R-Pi sends this at midnight to reset
if (number == 8){
rainCount = 0;
}

}
}

// callback for sending data
void sendData(){
byte sendData[2];
int sendVal = 0;
if (number == 1){
sendVal = rainCount;

}
// wind speed
else if (number == 2){
sendVal = windCountSend;

}
// wind direction
else if (number == 3){
sendVal = analogRead(1);
}
// wind gust speed
else if (number == 4){
sendVal = windCountSendMax;
windCountSendMax = 0;

}
// temperature
else if (number == 5){
sendVal = temp;
}
// humidity
else if (number == 6){
sendVal = analogRead(2);
}

else {
sendVal = number;
}
// sending requested data to the Pi
sendData[0] = (byte) sendVal & 0xFF;
// Serial.println(sendData0, HEX);
sendData[1] = (byte) (sendVal >> 8) & 0xFF;
// Serial.println(sendData1, HEX);
Wire.write(sendData, 2);
//Wire.write(sendData0);
//Wire.write(sendData1);
}

// debouncing of interrupt sensors so only count once per action
void debounceRain() {
if((long)(micros() – rainLastMicros) >= rainDebouncingTime * 1000) {
rainFunc();
rainLastMicros = micros();
}
}

void debounceWind() {
if((long)(micros() – windLastMicros) >= windDebouncingTime * 1000) {
windFunc();
windLastMicros = micros();
}
}

// incrementing the variables used for counting sensors
void rainFunc() {
rainCount++;
Serial.print(rainCount);
}

void windFunc() {
windCount++;
Serial.println(windCount);
}

Link to file

Enclosure

In my original version of my weather station, the enclosure sat inside my greenhouse and was protected from the elements as well as being powered by electricity coming from the house.  I’ve since gotten rid of the greenhouse and attempted to use a rubbermaid enclosure and purchased some solar power equipment to make it wireless.  I had issues with the battery not lasting long in the winter time due to the reduced sunlight as well as the rubbermaid could not handle the elements.  This has led to me not having my weather station for several years now.  With a renewed interest, I am attempting a new enclosure and adding battery monitoring. I’ll be listing the parts that I’m using as well as linking to where you can purchase them.

Hardware:

Power Equipment:

Electronics & Sensors

  • Raspberry Pi Zero W
  • MCP 3008 ADC – could use something smaller, I just had this so I used it
  • BMP180 Pressure Sensor – this has been discontinued, but linking to a newer version that should work
  • MOD-1016 Lightning Sensor – I really want this sensor to work correctly, but I’m still ironing out the details

Mounting Hardware:

As you can see above, the cable gland is placed on one side of the junction box, the solar panel requires a hole in the top to run the wire, but I use velcro to attach. (Have not placed the velcro on the lid of the junction box yet)  The electronics are mounted to a piece of the clear acrylic sheet using the nylon standoffs arranged in a way that everything fits nicely.  The battery sits underneath the acrylic sheet.

There are some wires that come from the different hardware pieces that I wanted to call out now and will discuss more in the next post regarding the perma-proto board and the sensor communication with the Raspberry Pi.  As you can see there is a cat 5 cable that runs from the cable gland to the perma-proto board.  This is the communication from the mast.  There are also two wires that come from the power boost to the perma-proto board.  One is from the low battery indicator pin, and the other is the ground pin.

Solar Charging circuit:

Just a quick explanation of how this is wired.

  1. Solar panel plugs into the USB/DC/Solar Li/LiPO charger as well as the battery into the “BATT” terminal
  2. Using a 2 female JST cable from “LOAD” on the Li/LIPO charger to the black JST connector on the Powerboost 1000 Basic
  3. USB A to USB micro from the Powerboost 1000 to the raspberry pi.  I used a small 6″ cable.

 

 

With this new enclosure, I have created a new sensor board that brings all my sensors together in one location as well as setting up 10 pins on the board for bringing together like wires for communication back to the Pi.  Due to the need of the mast needing 5V, I am using 2 separate voltages on the opposite rails.  The rail on the left is 5v and the one on the right is 3.3v

There are 3 sections that I’m going to cover:

  • Battery Circuit – for monitoring of the battery charge
  • Sensors – The wiring of the sensors within the enclosure as well as the communication back from the mast
  • Sensor board to RPi communication

Battery Circuit Wiring:

  • GND from Powerboost to GND on board
  • Low Battery indicator from Power boost to voltage divider on board.  Resistors: R1 = 2.2kΩ, R2 = 5.1kΩ (If you’re not familiar with how this works, LBI goes to rail containing one side of R1, Other side of R1 goes to rail that contains one side of R2 as well as read wire.  Other side of R2 goes to ground.  This is used to cut down voltages.  The powerboost is outputting 5V, but the MCP30008 ADC can only handle 3.3v which is why the divider circuit)
  • Voltage divider read wire to CH0 on MCP3008
  • MCP3008 wiring
    • Vdd & Vref to pin 10 on board (3.3V power rail)
    • AGND & DGND to pin 9 on board (3.3v ground rail)
    • CLK to pin 5 on board
    • Dout to pin 6 on board
    • Din to pin 7 on board
    • CS to pin 8 on board

Sensor Wiring

  • BMP180
    • Vin to pin 1 on board (5V power rail)
    • GND to pin 0 on board (5V ground rail)
    • SCL to pin 3 on board
    • SDA to pin 2 on board
  • MOD-1016
    • Vcc to pin 1 on board (5V power rail)
    • IRQ to pin 4 on board (interrupt pin on RPi)
    • SCL to pin 3 on board
    • SDA/MOSI to pin 2 on board
    • GND to pin 0 on board (5V ground rail)
  • Mast
    • Blue-white to pin 0 on board (5V ground rail)
    • Blue to pin 1 on board (5V power rail)
    • Green-white to pin 3 on board
    • Green to pin 2 on board

Board pinout to Rasberry Pi

  • Pin 0 (5V GND) to pin 7 on Pi
  • Pin 1 (5V Power) to pin 4 on Pi
  • Pin 2 (SDA) to pin 3 on Pi
  • Pin 3 (SCL) to pin 5 on Pi
  • Pin4 (Int) to pin 11 on Pi (GPIO 17)
  • Pin 5 (SPI CLK) to pin 12 on Pi (GPIO 18)
  • Pin 6 (SPI OUT) to pin 16 on Pi (GPIO 23)
  • Pin 7 (SPI IN) to pin 18 on Pi (GPIO 24)
  • Pin 8 (SPI SC) to pin 22 on Pi (GPIO 25)
  • Pin 9 (3V GND) to pin 20 on Pi
  • Pin 10 (3V Power) to pin 17 on Pi

 

it will take a while before I post the Python code on the Pi.  I am still testing/working on the code for the battery monitoring.  Once I’m done, I’ll post it all here as well as on Github.