Saturday, January 22, 2011

X10 Remote Temperature - Redo

I became interested in the ATtiny85 processor recently. Up till now, my projects were based on the ATmega328 or the ATmega644. The  ATtiny85 is just that, tiny - only 8 pins vs. 28 on the ATmega328. The photo on the left shows the new  X10 temperature transmitter, with the DS1621 temperature chip on the left and the ATtiny85 on the right.
(The CM17A X10 RF transmitter is not shown.)

This board replaces what I had in the original X10 Wireless Temperature Transmitter which I've been using for the past year and a half.  (post is here)

So why the redo? The rational part of the answer is that I wanted the batteries to last longer.

The original temperature transmitter drew a whopping 2.2mA while in sleep mode. It was powered by 2 NiMH AA batts stepped up to 5V with a boost inverter. I'd change the batteries every month or so.

The redo board draws about .07mA while in sleep mode. It's running directly on 4 NiMH AA batts.  I'm guessing I'll change the batteries every 1.5 years or so. I choose AA batts over a 3.7V LiPo because it's easier to replace the NiMH batts with fresh ones, and I wanted the higher voltage for better range on the X10 transmitter. However, it's worth noting that the processor draws less current at lower voltages.

Most of the power savings can not be attributed to using the ATtiny, however. Along the way, I discovered a few things.

The first had to do with how I was reading the temperature on the DS1621. I was using "continuous mode" (most examples use this mode) which would give me a reading as soon as I asked for it, but at the cost of almost 1mA! I switched to "one-shot" mode which makes me wait ~750ms for a reading, but at a huge savings.

The second thing I found is that the CM17A library I made left the RTS & DTR lines high after transmitting. Setting them low, results in about a .5mA savings. Note that if you are using this lib and want to try it, be sure to give a nice delay before transmitting after you set the lines high. (There's always a trade off!)

I always use sleep mode for the lowest power usage when not transmitting. It's set to transmit about once every 6 minutes. There are several sleep mode routines for the ATmega processors, but the ATtiny needs entirely different registers set. I found good info on sleep mode, and good tutorials for the ATtiny at brownsofa.org and Inside Gadgets.

The way to do the things mentioned above will be much clearer when you look at the the example code, which will be provided later in this post. But now, I would like to describe how to go about using the Arduino environment to work with the ATtiny85 chip, and most of all, how to get I2C working on them so you can communicate with the DS1621, real time clocks, and even 2x16 displays - all with an 8 pin chip!

The first thing you must do is to get the ATtiny "core files" for the Arduino environment. There are several out there - each supporting more or less of the standard Arduino features. Core files, and instructions on how to get started with the Tiny85 can be found here, however, I prefer the core files from here.

You can use the ArduinoISP as a way of downloading the sketch into the ATtiny. I've used it and it works fine - just be sure to disable the automatic reboot after load! For me, an easy way to do that is to use a serial cable instead of the USB cable. However, there are other ways to do it. Keep in mind, you only need to hit reset when you load the ArduinoISP on to your Arduino. Once it's an ISP, change the Board type to ATTiny85, and just hit "Upload" (don't press "reset"). After you work with the ArduinoISP a while, I think you will want a real ISP Programmer to load the ATtiny. They are cheap and much easier!

Finally, get at least the TinyWireM "master" library for this project. I made a Playground article that explains this library and has a link to download it. The Playground article is here.

OK, almost done. To get the source code for the new X10 Remote Temperature Transmitter, you can download it here. (a new version as of 3/13/11)


2 comments:

  1. You'll need to change the NiMH batteries much more often than every 1.5 years. NiCd and NiMH batteries have a high self-discharge rate. If replacing batteries infrequently is a goal, ordinary alkaline cells are a better choice, and lithium cells are an even better choice.

    ReplyDelete
  2. It appears that it won't be that much more often.

    I put in fresh eneloope batteries on 3/13/11. 13 months later it's still going strong and sending the temperature every 5 minutes.

    The eneloope NiMH have a much improved self discharge rate.

    Alkaline bats put out too much voltage to use 4 in series. LiPo's are inconvenient to replace.

    ReplyDelete