PIC-based APRS Weather Station     


PIC APRS 
Weather Station

 

Schematic

 

Block Diagram

 

Source Code

 


Back to 
Digital Homebrewing Home Page


Part 1 - Overview & Initial PIC Circuit

I’m Dave Ek, NK0E, and N2APB has graciously granted me some space on his regular Digital QRP Homebrewing web pages so I can share my latest project with you as it develops. I’ve been a ham now for about six years, and I’ve been playing with the PIC16F84 microcontroller for three of those years. My first design was a system of digital setting circles for an astronomical telescope using rotary encoders and a serial link to a PC (see http://home.earthlink.net/~digicircles). More recently, I designed the Serial CW Sender, a circuit that allows you to key your CW rig via contesting software running on your Palm PDA. The Serial CW Sender was featured in the July 2001 issue of QRP Quarterly, and you can read more about it and the accompanying software at http://home.earthlink.net/~golog/.

Lately I’ve been experimenting with packet radio and APRS (Automatic Position Reporting System). APRS is quite different from your typical packet BBS. Instead of connecting to a single BBS system, you use APRS software (like WinAPRS or UIView) to periodically beacon your station position on the standard APRS frequency (144.39 MHz), and to plot on a map the positions of other APRS stations heard. Some APRS stations act as digipeaters so that your beacon (and others) is heard over much wider areas. It’s typical for my APRS software to show locations of stations all over the state and also in neighboring states. In addition, some stations act as internet gates, rebroadcasting position beacons onto the internet where they’re heard and displayed at http://www.findu.com/. It’s pretty neat to see my station beacon, sent from my station as RF, show up seconds later on the internet!

“So what?” you say? Good question. It turns out that APRS packets aren’t limited to position information. I can send messages, send short emails (I can do this through satellites or even the International Space Station), and even broadcast weather conditions using APRS. Weather, of course, is especially near and dear to the hearts of many hams, since many of us are active as weather spotters during storm season. It occurred to me that being able to automatically beacon weather conditions at my QTH would be especially cool. But alas, I had no weather station, and I couldn’t see myself spending several hundred bucks to buy one.

But hey, I could design and build a weather station, again using a PIC microcontroller as its brains. This is the kind of project that I live for. I know that I can make it work, but I’m not exactly sure what it’s going to look like when it’s done. You know what I mean - it’s full of opportunities to learn. After all, it’s the journey, not the destination, right?

So, over the next few issues, N2APB has invited me to use his column to share my progress as I tread this path. I’ll do my best to include enough information so you can follow along if you also want to end up with a cool homebrew weather station. You’ll see that there are many QRP applications both for PICs and also for the circuitry we’ll be using to interface our weather sensors. You can even tag along when I venture down those blind alleys and dead ends — after all, we learn as much from our mistakes as our successes. And rest assured that, as I write this, I really don’t know how this project is going to look at the end. I only know that it’ll provide some great entertainment over the next several months.

So, let’s get started!

Requirements

It’s generally good to know what you want your end product to do when you start a project like this. Quite simply, I want to be able to measure the weather conditions at my QTH, record them on my PC, and then broadcast them periodically using my APRS software and station. In particular, I want to be able to measure temperature, relative humidity, barometric pressure, wind speed and direction, and rainfall. I also want to be able to easily control the time interval between measurements and allow different intervals to be used for different quantities (say temperature every minute and relative humidity every 10 minutes). I don’t want to require that all sensors be present  because I’ll probably implement them one at a time. I also want to be able to use my PC to do any calibration and conversion so that the weather station itself only has to return raw data (this allows me to fine-tune my sensor calibrations without having to modify the weather station firmware). This will require me to write some PC software, but that’s not a problem for me.

I’ve already decided to use the PIC16F84 microcontroller for this project. I’m using it because it’s cheap, easy to program, and I know that it’ll do everything I need to do. The PIC will have the job of gathering sensor data and transmitting it to the PC whenever the PC asks for it. The PIC and the PC will communicate via a serial port on the PC. Some of you smart guys know that the PIC16F84 doesn’t have serial communications capabilities built in, but I have an answer for that. I’ll tell you about it next time.

Shown below is a block diagram of how I envision the design of the PIC Weather Station. Obviously, the sensors need to be located outside. I anticipate locating the controller board with the PIC near the sensors outside. I need three lines - two for data and one for ground - for communications between the controller and the PC. If I use 4-conductor phone cable, I can use the spare conductor to provide power to the controller board from inside the house. The PC will be running software that will periodically request sensor data from the controller. When it gets the data, it will process it to turn the raw measurements like voltages into the desired values and then pass the data to the APRS software, which will periodically broadcast it using the TNC and transceiver. Those of you with broadband Internet connections might choose to relay the weather data over the web, too.

 PIC Weather Station block diagram.

I really don’t know what this thing will look like when it’s finished, but I do know that some of the sensors will need to be “enclosed” to ensure that they give accurate consistent readings. For example, the temperature sensor needs to be shielded from direct sunlight. I’ll think more about this as we go on.

Getting Started

In order to use PICs in electronics projects, you need to be able to do three things:

1)Write the program that goes into the PIC
2)Compile the program
3)Put the program into the PIC

The first two are handled by software you run on your PC. I use a program called MPLab from Microchip, the maker of the PIC chips. MPLab is free and you can download it from Microchip’s web site at  www.microchip.com. It includes a source code editor and a compiler and can be used to write code for any of Microchip’s PIC microcontrollers. MPLab can also directly control many of the commercial PIC programmer devices on the market; these are the hardware modules used to transfer the code into the chip itself. If you use MPLab to write your PIC code, you’ll be using assembly language. It looks cryptic and daunting, but it’s not nearly as hard as many people make it out to be. Nevertheless, if you prefer to program in C or BASIC, you can also buy other development tools. I’ll be using the free MPLab tool for this project. Although I’m not going to try to teach you everything you need to know about writing code in assembly, I’ll try to point out the highlights and make sure my code is commented well so you can figure it out. If you’re interested in learning how to program PICs in assembly language, get a book by David Benson (not K1SWL) titled Easy PIC’n. It’s a good introduction. Also read the article by John Hansen W2FS in the October 1998 QST Magazine titled “Using PIC Microcontrollers in Amateur Radio Projects.” That article got me started with PICs.

Besides being able to write and compile the code for the PIC, you also need to be able to load the code into an actual PIC chip. That’s where the PIC programmer comes in. This is a hardware device, usually controlled by software running on your PC, that transfers the compiled PIC code into the chip’s ROM memory where it will stay forever, or until you overwrite it with another program. If you’d rather go with a commercial PIC programmer, one economical choice is the EPIC Plus programmer made by Micro Engineering Labs. The EPIC Plus can be purchased from a variety of sources. Jameco (http://www.jameco.com/) sells it for about sixty bucks. If you’re cheap like me, and I’ll bet you are, you’d rather build one for a few bucks that works just as well. The QST article by W2FS describes a programmer called the Ludipipo (or JDM) that can be built easily. In fact, you can even get a PC board from FAR Circuits. Another popular homebrew programmer is the No-Parts PIC Programmer by Michael Covington. I use software called IC-Prog to control my Ludipipo. It’s free and can be downloaded from http://www.ic-prog.net/. IC-Prog works with quite a few different programmers and shows schematic diagrams of several of them on the web page.

A great thing about this PIC chip is that it can be easily reprogrammed without any lengthy erasure process. With some types of EPROMs, it is necessary to expose the chip to UV light for a lengthy time to erase it prior to reprogramming. The PIC16F84 is an EEPROM (electrically-erasable programmable read-only memory) and can be reprogrammed simply by running it through the programming process again.

I should stress that there are many web pages devoted to various designs for homebrew PIC programmers, and there are quite a few programs that can be used to control them. I suggest the Ludipipo and IC-Prog simply because I’m familiar with them and I know that they work. If you’re brand new to PICs, using these should help to guarantee success. If you’re adventurous or experienced, use whatever tickles your fancy.

What PICs Do

Before we get too far down the road with programming PICs, we should probably discuss what they are and how they work. A PIC microcontroller is a single-chip package that combines a microprocessor, ROM program memory, and RAM variable memory, along with several input and output logic gates. This makes them a one-chip computer, with an operating system supplied by you, the programmer. The PIC16F84 has 13 digital input/output lines. As inputs, they can either be high (+5V) or low (ground). As outputs, they can either be driven high or low. You can decide which lines are inputs and outputs, and can even switch a line from being an input to being an output during program execution.

The PIC16F84 requires a few external components in order to operate. A simple circuit for a PIC is shown on the next page. First, a regulated voltage supply is needed. The PIC16F84 can use a supply voltage from 3 to 6V DC. I usually use a 78L05 voltage regulator to provide +5V DC to the chip. A clock signal is also needed. There are a few different ways to do this, but I’m using a 4 MHz crystal for high speed and precise timing. We’ll need both later for this project. A 4 MHz crystal, along with two 22 pF capacitors running from either lead to ground, will yield an ultimate instruction speed of one million instructions per second in the PIC. The only other component needed is a 10K resistor to hold the reset line high. Taking this line low will cause the PIC to reset, which will start execution of its program from the beginning, like it would when first powered up.

Simple PIC16F84 Circuit (with test components)

The circuit includes a few extra components so that we can demonstrate that the PIC actually does something after we program it and stick it in the circuit. D1 is an LED that can be turned on and off using pin 6 of the PIC. R2 limits the current flowing through the LED. Pin 6 needs to be defined as an output in this case, and you should be able to see that when pin 6 is high (+5V), no current will flow through D1. When we take pin 6 low (to ground),  current flows through the LED and it lights. S1 is a switch we can use for input, connected to pin 17, which must be defined as an input. Pin 17 is normally held high but goes low when S1 is pressed. We can make the LED light when S1 is pressed, or we can make it go out—whichever we prefer. A sample PIC program on the Digital QRP Homebrewing web page uses S1 in this manner to control the lighting of D1.

That’s going to wrap up this first installment of the PIC Weather Station project. Your homework assignment is to build a programmer for the PIC16F84 (like the Ludipipo), and then download some programming software (like IC-Prog) and the MPLab software from Microchip. After that, lay out the circuit shown above (use a solderless breadboard—it works great for PIC circuits) and then download and try out the the sample PIC program I have on this page. Next time, we’ll cover adding serial communications capabilities to the circuit so it can easily communicate with a PC. After that, we’ll be ready to start adding sensors to our weather station.

73, Dave NK0E


Page last modified:  July 31, 2002

Copyright 2002 G. Heron, N2APB