problem with ADC on Attiny85 with NTC

Hi,

i've got a 5V powered board (power regulation via LP50CV from a 9V cell) with a attiny85 connected to a RFM12 module.

The attiny85 has to get a tempature from a NTC ( Hygrosens NTC-202) and send it to a Arduino connected to my pc.

First of all, everything ist running fine except of the reading from the NTC. I've tested the NTC and the Code to convert the ADC-value to a temperature on a breadboard with my
arduino before i've soldered on the board with the attiny85.

But now, the ADC of the Attiny seems to work "different"....i'm not getting the same values that i got before using the arduino (UNO).

I've connected it like this:

VCC->NTC->PB4/ADC2/PIN3->R4,7k->GND

I'm using analogRead(2) to read from the voltage divider and the value seems to change with the temperature. BUT.....seems not to be the same as on my arduino, so the (steinhard) conversion code delivers a temperature around -8 deegrees (celsius) where it should be around ~20 deegrees.

Does anyone have a clue what could be wrong? I'm out of ideas...

This is my code (just the important parts..):

#define TEMP_PRECISION 12

#define THERMISTORNOMINAL 2000 // Resistor at 25 deg Celsius - 2 KOhm
#define TEMPERATURENOMINAL 25 
#define NUMSAMPLES 5 
#define BCOEFFICIENT 3976 
#define SERIESRESISTOR 4700 

union{
  uint8_t b[4];
  float val;
}bf_convert;

float getTemperature( int THERMISTORPIN)
{
  int samples[NUMSAMPLES];
  byte i;
  float average, steinhart;
 
  // take N samples in a row, with a slight delay
  for (i=0; i< NUMSAMPLES; i++) {
   samples[i] = analogRead(THERMISTORPIN);
   delay(10);
  }
 
  // average all the samples out
  average = 0;
  for (i=0; i< NUMSAMPLES; i++) {
     average += samples[i];
  }
  average /= NUMSAMPLES;
 
  // convert the value to resistance
  average = 1023 / average - 1;
  average = SERIESRESISTOR / average;
  
  steinhart = average / THERMISTORNOMINAL;     // (R/Ro)
  steinhart = log(steinhart);                  // ln(R/Ro)
  steinhart /= BCOEFFICIENT;                   // 1/B * ln(R/Ro)
  steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
  steinhart = 1.0 / steinhart;                 // Invert
  steinhart -= 273.15;                         // convert to C
 
  return steinhart;
}

void setup(){
DDRB = _BV(PB1) | _BV(PB2) | _BV(PB3);
// MOSI, SCK, SEL
PORTB = _BV(PB3); // deselect RFM12
rf12_init();
}


void loop(){
         
        bf_convert.val = getTemperature(2); // trying to read from PB4, PIN3, ADC2       
    
        delay(2000);
       
	rf12_cmd(0x82,0x38); //Enable transciever
	rf12_send((uint8_t *)&bf_convert.b, sizeof(bf_convert.b));
       
        while (!rf12_read_status_MSB()); 
	rf12_cmd(0x82,0x08); //Disable transciever
        delay(2000);   
       
        
}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

The first thing that stands out from the code is that you are only using the first element in the samples buffer. Change sample by sample in your code.

Ok, thanks. That was a mistake i've done during debugging ...it has to be

samples[ i ] = analogRead(2);

of course!

I've already checked the wiring meanwhile. The resistor in the voltage divider circuit is definitly a 4,7k.

analogRead(2) delivers values of 705-720 at room temperature on the attiny85...

Problem solved!

i've replaced the resistor by a new 4,7k und changed the connection like this:

GND->NTC->PB4/ADC2/PIN3->R4,7K->VCC

now it works..