Go Down

Topic: ATtiny44/84 built in temperature sensor (Read 860 times) previous topic - next topic


I noticed on a datasheet that ATtiny44 and ATtiny84 have built in temperature sensors.  Is there a way to access the value of the chip's temperature?  I know its not good for ambient air temperature but curiousity runs wild with me.

Jack Christensen

Sure, the datasheet describes it. I fiddled with it once on an ATmega328P but didn't really spend enough time with it to even know if I had it working right.

Jack Christensen

Here is a sketch that seems to work with an ATmega328P-MU. I get around 365mV, which would be about 75°C according to the example in the datasheet. Room temp is currently around 26°C, so that seems a bit high, but it's not a precise thing. Can the internal chip temp be that hot? The package certainly isn't that hot. It does respond fairly quickly (increases) when I put my finger on it. So maybe it's just not well-calibrated.

I thought maybe this could be coded just with standard Arduino function calls, but I don't think so; I ended up manipulating the registers directly. Something similar should work with the ATtinies, but the register definitions are not identical, so be sure to review them.

Code: [Select]
#include <Streaming.h>    //http://arduiniana.org/libraries/streaming/

void setup(void)

void loop(void)
    float v;
    ADMUX = 0xC8;                 //channel 8
    ADCSRA = 0xC7;                //start the conversion
    while (ADCSRA & _BV(ADSC));   //wait for it to complete
    v = 1.1 * ADC / 1024.;
    Serial << _FLOAT(v, 3) << endl;

Go Up