Weather Station:
  1. Temperatures
  2. Circuitry
  3. Mistakes

Data Logging Circuitry

A rite of passage for all hobbyists is to make an electronic device that logs data. The data may be intrusion detection, noises, or in my case, temperature and solar data.

Weather station circuit board

Weather station circuit board.

1. Connectors for two power sources (a solar panel and battery backup) along with reverse-battery protection diodes. Nearby is a Microchip MCP1700 3.3 V linear voltage regulator and a bunch of capacitors. The MCP1700 has a low voltage dropout and consumes very little current.

2. Atmel AT25DF321 32 megabit Flash solid-state storage. More about this later on in the article.

3. Serial port set to 115200 baud. You can send commands to set the date/time, format the flash, or retrieve data. A 3.6864 MHz crystal was chosen for the microcontroller clock because it can be divided by 32 (a power of 2) to provide the perfect baud rate. Also, using a crystal rather than an internal oscillator provides a more accurate clock for the data timestamp.

4. Atmel AVR ATmega644PA. The “PA” revision uses less power and has an extensive voltage range from 5.5 V to 1.8 V. The chip has plenty of program space (64 KB) and RAM (4 KB). But, I chose it for the large number of pins and eight analog-to-digital converters (ADC).

5. The power sources are connected to pairs of 10 kilohm resistors to form voltage dividers. I used metal-film, 0.1% tolerance, 50 PPM/°C resistors (Vishay/Dale RN55C1002BB14) for the entire project because they aren’t affected too much by temperature changes and the high-precision reduces temperature reading errors. That translates to ±35 ohms for a 10000 ohm resistor over a 100 °C range.

The high-quality resistors aren’t as cheap as the standard 5% carbon film resistors. They are moderately priced at around 22 cents in quantity 100 from Mouser Electronics. That’s a little less than $2 per weather station.

6. There are six connectors for sensors. (This is an identical arrangement to the motor chip temperature analysis project.) They don’t have to all be temperature sensors. In fact, I’d like to add a barometer, wind speed, rain gauge, and humidity detector at some point.

7. To save power, all of the sensors and battery voltage measurements are connected to a Zetex ZTA1047A low-saturation voltage transistor instead of ground. The microcontroller enables the transistor immediately before reading the sensor values, and then disables the transistor to save power while the circuit sleeps.

The ZTA1047A is leftover from the Bipolar Motor Driver project. It was selected because the “ground” voltage it produces is typically only 0.024 V above ground. That means it doesn’t introduce a significant voltage offset error into the sensor readings.

8. During the sensor reading, an LED is enabled to show that the weather station is working. While this consumes power, it is very brief. Yet, the flash of light is more than enough for the human being to see that the station is working when the LCD is removed. At night, it looks a little bit like a firefly.

9. The two columns of black sockets on the left and the right of the PCB are for a standard 14-pin LCD display, with a couple of extra pins for the backlight. Because the Atmel Flash chip does not work at 5 V (like most of my old LCDs), I purchased a NHD-0420H1Z-FL-GBW-3V3 Newhaven display for $17 from DigiKey. It is a 4x20 character-based LCD that is compatible with the industry-standard 14-pin interface and command protocol, but operates at 3.3 V. That saved me the time of having to code a whole new display library.

Although the manufacturer’s specification claims the display typically consumes 4 mA, I measured much better results on the weather station. The display appears to only use 0.5 mA. I wonder if that’s because I’m not constantly writing to the display?

Of course, the display uses a lot more power (150 mA @ 3.3 V) when the backlight is enabled. The weather station has a transistor to drive the backlight, but it is turned off by default.

Weather station LCD readout showing temperature voltage and heartbeat

Weather station LCD readout showing temperature voltage and heartbeat.

The top row of the display shows the current day of the year (183 = July 2) followed by the time in military format (hh:mm:SS). The next couple of rows show the temperatures of various sensors. The last row shows the battery voltage and the solar panel voltage.

The next-to-the-last character on the far right of the LCD is a sun icon if solar powered or a battery icon with graphical fill-level if battery powered. Beside that is a heartbeat icon, which is the same feature I’ve been using for ten years on projects such as Bugdozer and All Right.

Atmel Serial Flash Chip

With 4 KB of RAM and 2 KB of EEPROM, the microcontroller could store a limited amount of data internally. Or, the logging project could be connected to a computer via a wire and send it to a personal computer for storage. But, I really want a standalone logger that can be placed anywhere.

SparkFun Electronics sells a variety of data storage boards, the best of which includes the ability to write files to a microSD card. In that case, your project has access to many gigabytes of storage and you can pop the card into a laptop or computer. However, the boards cost $50 or more.

Instead, I chose the current top-of-the-line 8-pin serial flash from Atmel.

Atmel AT25DF321 4MB Flash

Atmel AT25DF321 4MB Flash.

The Atmel AT25DF321 stores 32 megabits (divided by 8 = 4 megabytes) of data and can be written to a byte at a time if desired. It is fast, uses little power when sleeping, and only costs a couple of dollars. Most importantly, it retains the data without power just like a microSD card or USB thumb drive.

Although it stores a lot more data, there are several disadvantages to this chip compared to classic serial EEPROMs:

PCB layout for Atmel serial memory chip AT25DF321

PCB layout for Atmel serial memory chip AT25DF321.

I usually prefer I2C chips, because I can attach many of them to a single set of microcontroller pins. But, for rapid reading and writing, SPI absolutely rules.

You can attach the AT25DF321 to the ISP6PIN connector that is used to program the AVR microcontroller. One more pin is needed, usually slave-select, to enable or disable the chip. To avoid unintentional commands being randomly issued at power up, the enable pin should be pulled high by a resistor (such as 47 kilohms). That is, a high value on this pin tells the flash chip to ignore all input.

Number of Samples

The eight ADC pins are read as 10-bit values. Cramming the upper bits together into two bytes means that 10 bytes are needed to store the data. The day of the year and timestamp take 4 bytes when converted to an unsigned long that represents the number of seconds since the start of the year. That means each sample consumes 14 bytes.

Because the flash chip is easiest to address when a write doesn’t cross a 256 byte boundary, it would be most convenient to store the records in 16 byte chunks. So, after accounting for the first 14 bytes, the extra two remaining bytes of each sample packet can be either set to 0 or used to represent the bit values of digital pins.

Storing a 16-byte sample every minute to a 4 MB flash means that 173 days worth of data can be stored.

Next Up

As with any prototype, there are some problems with the weather station. Let’s examine those issues...