Projects‎ > ‎

Programmable AVR 1-Wire Thermostat

Introduction

To support experiments for the Meter Gateway Architecture, I developed a programmable thermostat based on a single-board computer with an Atmel AVR ATmega128 microcontroller. The board is an Olimex AVR-MT-128, described here. The design of this embedded system is given below with all the details you need to build one of your own!

Hardware Components

Besides the Olimex development board, I used a Dallas DS18S20 1-wire thermostat to actually measure the temperature, a standard PC floppy drive cable to connect the DS18S20 to the development board, and one of the 12V power supplies offered by MC Pros (where I bought the development board). I used an Atmel AVR JTAG ICE mkII programming and debugging tool, which I connected to the development board using the "squid cable" included with the programmer. Finally, I used a standard serial cable to connect the thermostat to my PC. This board can be operated in a standalone mode as well. The fully-assembled system is depicted below:

To assemble this system, simply plug the floppy cable onto the EXT1 and EXT2 headers, with the key on the cable pointing away from the center of the board. The floppy cable should fit perfectly on the headers, with no room to spare. Then, plug the DS18S20 into the other end of the cable, as shown below. Make sure you pay attention to the direction the key on the cable is pointing. It is critical that you plug the thermostat chip into the exact socket holes shown below.

Finally, you must wire up the JTAG cable to the back of the board, as is partially shown in the following picture. Then, you're ready to program the device.

I have released the firmware I developed for this project available as a convenience for the community as an attachment at the bottom of this page.  It is heavily based on the excellent sample code made available by Olimex for this board, as well as the AVR318 Atmel application note which provides code for interfacing with 1-wire devices.  The attachment includes a setup script to download that code and then patch it with my modifications.  Follow this process to build the project:

  1. Download the attachment at the bottom of this page to a Linux computer.
  2. Untar the archive: tar xjf avr-thermo-0.2.tar.bz2
  3. Change into the new directory: cd avr-thermo-0.2
  4. Run the setup script: ./setup
  5. Copy the whole avr-thermo-0.2 directory to a Windows computer running AVR Studio and connected to the board using a JTAG cable.
  6. Open the Atmega128_MT.aps project file within the avr-thermo-0.2 directory using AVR Studio.
  7. Build the project and download it to the board over the JTAG cable.

When it powers up, the thermostat should display low (L:) and high (H:) temperature setpoints, and the current ambient temperature. When the temperature exceeds the high setpoint, the relay will close, and will not reopen until the temperature falls below the low setpoint. This relay can be used to control some device, presumably one that influences the ambient temperature.

The thermostat has three distinct controls. You can adjust the high and low setpoints of the device, and control whether it beeps when the relay changes its state. To adjust the low setpoint, hold down the "southern" button on the thermostat and either the western or eastern button to adjust the setpoint down or up, resp. Hold down the northern button to adjust the high setpoint. Currently, the thermostat does not perform any sanity checks on the setpoints, so you are responsible for ensuring the low setpoint is actually lower than the high setpoint, etc. Press the center button to toggle the beeping mode.

Finally, you may wish to monitor and control the thermostat from your PC. To do so, you must first connect a serial cable between your PC and the thermostat. By examining the source code in Atmega128_MT.c, you can figure out the simple protocol that you must use.

See the attachment for license information.

Enjoy!

Č
ċ
ď
avr-thermo-0.2.tar.bz2
(9k)
Michael LeMay,
Apr 26, 2011 10:20 AM