Weather Station and the Raspberry Pi

USB to RS-485 Adapter
USB to RS-485 Adapter

One of the weaknesses with my weather stations was that they did not have the ability to accept incoming connections. This made remote debug a bit difficult, if not impossible. Basically, you program the thing, and hope there are no glitches. Surprisingly, this worked for many years with the occasional reset, but I finally decided to spend some time making some improvements to this aspect of the weather station system.

Originally, my weather stations consisted of an outdoor unit, which acted as a hub for all the outdoor sensors. The hub communicated with an RS-485 to Ethernet bridge (Arduino+Ethernet shield) inside the house near the router. This allowed long runs, and the ability to easily chain multiple hubs together on the RS-485 bus. I decided to keep the RS-485 bus model, and built a USB to RS-485 bridge to replace the Arduino and Ethernet shield that I used previously. The new USB adapter uses an FTDI chip and is compatible with most Mac, Linux, and Windows computers out-of-the-box. I was really happy to avoid the use of drivers. This adapter also features transient protection and other features that most cheap USB to RS-485 adapters do not have. This was important considering the long cable run out to the weather station. And, because the weather station hub runs at 3.3V and uses little power, the entire system can be powered from the USB port which provides 5V down the line.

I took this new USB adapter and hooked it up to a Raspberry Pi. Using a Python script I whipped up in a few minutes I was able to completely replace the functionality of the older Arduino-based system. While I haven’t added any new functionality yet, the Raspberry Pi allows for a lot more possibilities with its huge memory space, and the ability to SSH and VNC into it remotely. This solves the old problem of remote troubleshooting, which was basically impossible before. Local logs are also generated using the Python script to record errors and weather data in the event of an internet outage or other failure. I’m very happy with this improvement.

Grid Dip Meter

Grid Dip Meter
Heathkit HD-1250

A grid dip meter is, in it’s simplest form, an oscillator. One function of this device is to determine what frequency, or frequencies, a particular LC circuit is tuned to. This is accomplished by placing the device in close proximity with the LC circuit under test. Inductive coupling between the meter and the circuit being tested allows the resonant frequency to be measured. When the frequency of the meter is tuned to the frequency of the LC circuit under test a dip will be observed on the meters indicator. More information about how to use this device can be found on YouTube in a video by Alan, W2AEW.

HD-1250 Grid Dip Meter
Inside the HD-1250

I thought it would be interesting to take this little meter apart and see what’s inside. While most of us are familiar with how to use one of these meters, and what they look like on the outside, I’m guessing that unless you’ve assembled one of these nifty devices yourself that you won’t be quite as familiar with the parts inside.

In the photographs you will see some familiar components. The large device with the moving interweaving plates is the variable capacitor. This capacitor, along with the inductive probe chosen sets the frequency of the oscillator. Other big ticket items include the battery on the left, the variable potentiometer to set the gain of the front panel meter seen with the small thumb-wheel attached, and the single-sided circuit board on the bottom.

Grid Dip Meter Circuit Board
HD-1250 Circuit Board

I admire the simple sheet metal construction of these Heathkit devices. Their simplicity certainly contributed to their low cost, and high availability that made the Heathkit line so popular. I found the method they used to create a tapped mounting hole in the edge of the sheet metal to be particularly clever. This is a technique I could certainly use in the future.

The single-sided pcb in this meter looks like it was likely drawn by hand. This semi-artistic method of pcb design has gone by the wayside in favor of modern CAD software, but you can still learn a lot by studying these designs. I can appreciate the quality of the work here, especially considering it was done on paper.

Lightning Sensor

Over the last year or so I’ve been working on a lightning sensor system for my weather station. I originally found a circuit published by Charles Wenzel that I thought looked interesting, and I decided to give it a try. The circuit worked quite well. So well, in fact, that it picked up lights turning on and off around the house. It also goes wild when the stove-top in the kitchen is used. I guess the stove has a noisy PWM circuit or something. I made a PCB for the circuit, and integrated it into my weather station and have let it run for a few months now.

Weather Station Data
10 Days of Weather Data

As the summer draws near a flaw in this design has presented itself. The flaw is severe temperature instability. Hotter temperatures increase the sensitivity of the system, and on hot days the thermal noise of the circuit causes a significant amounts of false triggers. This will be addressed in an upcoming design change in an attempt to reduce the number of false triggers.

The event on May 4th was an actual lightning storm and strikes were observed by persons in the area. Note the large drop in barometric pressure preceding the rise in lightning strike counts.

38kHz TV Remote Hacking

Arduino nano with a VS1838 IR reciever, and a IR LED.
Arduino nano with a VS1838 IR reciever, and a IR LED.
Arduino Nano

Most remotes used by TVs, DVD Players, and other consumer electronics use infrared light to send commands from the remote to the device being controlled. This is done because of the low cost and simplicity that infrared-based remotes offer.

The technology behind these remotes is simple. The transmitter consists of an infrared LED that is modulated at 38kHz. The LED is activated for varying amounts of time to send the information required to control the device.

An Arduino can be used to implement an effective remote control system. The following code was compiled on an Arduino. It performs the following functions:

  • Receive and decode standard remote-control commands
  • Print decoded commands over the serial port
  • Retransmitt the decoded commands using an infrared LED

The basic result is a infrared remote repeater. It will emulate any remote it can successfully detect by sending the received commands back out via the infrared LED.

Parts List:
  • VS1838B 38khz Reciever (From Ebay)
  • 940nm Infrared Led (From Ebay)
  • Arduino Nano Clone (From Ebay)
Arduino Code:
#define IRRX_GND 3
#define IRRX_PWR 4
#define IRRX_OUT 2
#define IRLEDPIN A3

byte bosePwr[4]   = {0xBA, 0xA0, 0x4c, 0xb3};
long time;
byte counter;
bool flag;
byte message[4];

void setup() {
	attachInterrupt(0,interrupt,CHANGE);
	pinMode(IRRX_GND,OUTPUT);
	pinMode(IRRX_PWR,OUTPUT);
	pinMode(IRLEDPIN,OUTPUT);
	digitalWrite(IRRX_GND,LOW);
	digitalWrite(IRRX_PWR,HIGH);
	Serial.begin(9600);
	Serial.println("Ready");
}

void loop() {
	long timer = micros() - time;
	if(flag){
		flag = 0;
		if(timer > 1400 && timer < 2000){ //Logic 1 addBit(1); }else if(timer > 450 && timer < 650){ //Logic 0 addBit(0); }else if(timer > 4000 && timer < 5000){ //START clearBits(); }else if(timer > 2000 && timer < 2500){ //REPEAT sendRpt(); clearBits(); } } if(counter >= 32){ //Recieve 32 or more bits successfully
		printBits();
		delay(50);
		sendCommand(message);
		clearBits();
	}

	if(timer > 10000 && counter > 0 && counter < 32){ //10ms Timeout
		Serial.println("Incomplete code");
		clearBits();
	}
}

void addBit(byte data){
	byte block = counter / 8;
	byte spot = counter % 8;
	byte mask = data << spot;
	message[block] |= mask;
	counter++;
}

void clearBits(){
	counter = 0;
	for(int i = 0; i < 4; i++){
		message[i] = 0;
	}
}

void printBits(){
	for(int i = 0; i < 4; i++){ byte low = message[i] & B00001111; byte high = (message[i] & B11110000) >> 4;
		Serial.print(high,HEX);
		Serial.print(low,HEX);
		Serial.print(" ");
	}
	Serial.println();
}

void interrupt(){
	if(!digitalRead(IRRX_OUT)) flag = 1;
	else time = micros();
}

void sendCommand(byte command[]) {
	sendHeader();
	for(int i = 0; i < 4; i++){
		sendByte(command[i]);
	}
	sendFooter();
}

void sendByte(byte data){
	byte mask = B00000001;
	for(int j = 0; j < 8; j++){
		if(mask & data) send1();
		else send0();
		mask <<= 1; } } void send1(){ send38KHz(560); delayMicroseconds(1690); } void send0(){ send38KHz(560); delayMicroseconds(560); } void sendHeader(){ send38KHz(9000); delayMicroseconds(4500); } void sendFooter(){ send38KHz(560); } void sendRpt(){ send38KHz(9000); delayMicroseconds(2250); send38KHz(2250); } void send38KHz(long microsecs) { while (microsecs > 0) {
		// 38 kHz -> 26 uSec (Duty cycle = 1/3)
		digitalWrite(IRLEDPIN, HIGH); //takes ~ 5uSec
		delayMicroseconds(6);
		digitalWrite(IRLEDPIN, LOW); //takes ~ 5uSec
		delayMicroseconds(10);
		microsecs -= 26;
	}
}

Remote Weather Station Installation

IMG_0292
QI2C485 in enclosure

Over the Thanksgiving holiday I was on vacation with family in Spokane where I installed an improved remote weather station. This entire operation is mainly a learning experience, but at the same time offers significant insight into the trends and patterns in the weather. The objectives of this mission were to design and build a weather station that offered accurate and precise weather reporting, in an package that could be deployed without too much difficulty at multiple locations around the world.

The foundation of the system is the processor board I recently finished: the QI2C485. I’ve been working on this board for a few months and after about 5 different revisions, I’ve finally completed the development of this board. The system was installed in Spokane. Following a few rounds of firmware adjustments and tweaks it has been successfully collecting data for a few days now.

Modularity was always on my mind when making this device. The main processor board (QI2C485) provides a lot of flexibility in this sense. It is essentially a RS485-I2C bridge, that has 2 I2C ports and 2 RS-485 ports. The RS-485 ports allow the board to be mounted a significant distance from any artificial heat sources, or other things that might affect weather readings. The I2C ports allow multiple sensor boards to be connected. Currently, a BME280 is connected to one of the I2C ports and is programmed to make temperature, pressure, and humidity readings every 15 minutes.

IMG_0294
Stevenson Screen

In the future, a combination brightness sensor and thermopile will be installed in the second port to make sky observations used to determine cloud conditions. Also in the works are wind speed, and rainfall sensors. The modularity of the process board will allow for easy addition of these sensors in the future, requiring only firmware modifications. The second RS-485 port on this board is designed to either terminate the RS-485 line, or allow it to pass through to other QI2C485 boards.

The QI2C485 host also includes a lightning detection circuit that will count electromagnetic pulses in the vicinity. All of this information is uploaded via a php script to an SQL database where it is currently stored for access later. It can be displayed via a php page on my website that is currently under development.

The future will likely hold an additional revision, and added modularity, but for now the current design will undergo a full test for the remainder of the cold Eastern Washington winter.