Trouble using analogRead when ethernet shield is plugged into the arduino

Is there something about the ethernet shield that would cause a problem with the ADC on the mega328? I made a small voltage divider that incorporates a 100K resister and a thermistor and when it is plugged into the arduino directly it works fine but when it is plugged into the arduino through the ethernet shield I get values that are completely off. Can anyone shed any light on this for me? Sketch is below.

/*
 * BBQControl.c
 *
 * Created: 8/7/2011 12:34:32 PM
 *  Author: Saleem and Leslie
 */ 

 

#define LCD_Command_A 0x7C
#define LCD_Command_B 0xFE
#define LCD_Clear_Screen 0x01
#define LCD_Cursor_Position(a)	{Serial.print(LCD_Command_B,BYTE); Serial.print(a+128,BYTE);}
#define chipSelect 10
#define thermPin A1
	
#include <math.h>
#include <stdint.h>
#include <PID_v1.h>
#include <stdio.h>
#include <string.h>

//PID Variables
double Input = 0;  //Our Current Temperature
double Output = 0;  //Our Control Variable
double Setpoint = 0;  //Our Setpoint
double Kp = 10;      //Proportional
double Ki = .1;      //Integral
double Kd = 50;      //Derivative

PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
  
void setup()
{
	pinMode(thermPin,INPUT);  //Thermistor is connected to A1
	Serial.begin(9600);
        myPID.SetMode(AUTOMATIC);  //start PID
}        



void loop()
{
    uint16_t ADCVal;
    uint16_t temperature;
    
    //String dataString = "";
    
    //ADCVal = analogRead(thermPin);
    
    //temperature = (get_temperature(ADCVal));  //get temperature conversion
    
    for(int i = 0;i<100;i++)
    {
      ADCVal = analogRead(thermPin);
      temperature += (get_temperature(ADCVal));  //add 99 more conversions
    }
    
    temperature = temperature/100;  //average them
    Input = (double)temperature;    //load new temperature into our PID Algorithm
    myPID.Compute();                //compute new output value
    //Serial.println(Input);          //print output to out monitor
    //Serial.println(Output);
    
   if(Serial.available())   //check to see if the user has sent
                                   //any new parameters
    {
      char myString[40];   //buffer to hold my received string
      char *str;           //pointer for strtok function
      receive_serial(&myString[0]);  //get serial data
      //Serial.println(myString);      //debugging
      double PID_Params[4];          //array to hold my new parameters
      double *my_params = PID_Params;
      str = strtok (myString,",");   //split mystring into 4 pieces using comma delimiter, reference:
      while (str != NULL)            //http://www.cplusplus.com/reference/clibrary/cstring/strtok/
      {
        *my_params = atof(str);    //convert strings segments to doubles
        my_params++;
        //Serial.println(str);
        str = strtok (NULL, ",");  //strtok expects a NULL pointer for all 
      }                            //subsequent calls after the first call
      Setpoint = PID_Params[0];
      myPID.SetTunings(PID_Params[1],PID_Params[2],PID_Params[3]);
      
      
    }
    
    //Send all of the data to our monitor in comma delimited format
    Serial.print(temperature);    
    Serial.print(",");
    Serial.print(ADCVal);
    Serial.print(",");
    Serial.print(Setpoint,0);
    Serial.print(",");
    Serial.print(myPID.GetKp(),4);
    Serial.print(",");
    Serial.print(myPID.GetKi(),4);
    Serial.print(",");
    Serial.println(myPID.GetKd(),4);
    
    delay(100);
}

void receive_serial(char *String)
{
  int i = Serial.available(); //Serial.available returns number of bytes
  delay(10);                  //in the Serial buffer
  
  //wait to make sure that all bytes have been received
  while(i != Serial.available())  //if i does not equal Serial.available then
  {                              //that means we are still receiving bytes.
    i = Serial.available();
    delay(10);
  }
  
  //Read serial data into address pointed to by String
  while(Serial.available())
  {
    *String = Serial.read();
    String++;
    *String = '\0';
  }

}



void get_parameters(uint16_t ADCvalue, uint16_t *beta, float *r_infinity)
{
	
	if      (ADCvalue < 15)   {*beta = 5191; *r_infinity=0.07028;} 
	else if (ADCvalue <= 39)  {*beta = 5085; *r_infinity=0.08597;} 
	else if (ADCvalue <= 158) {*beta = 4942; *r_infinity=0.11637;} 
	else if (ADCvalue <= 530) {*beta = 4767; *r_infinity=0.17766;} 
	else if (ADCvalue <= 577) {*beta = 4671; *r_infinity=0.23249;} 
	else if (ADCvalue <= 670) {*beta = 4641; *r_infinity=0.25289;} 
	else if (ADCvalue <= 757) {*beta = 4604; *r_infinity=0.28168;} 
	else if (ADCvalue <= 832) {*beta = 4566; *r_infinity=0.31618;} 
	else if (ADCvalue <= 892) {*beta = 4526; *r_infinity=0.35779;} 
	else if (ADCvalue <= 938) {*beta = 4485; *r_infinity=0.40755;} 
	else if (ADCvalue <= 1023){*beta = 4453; *r_infinity=0.45243;}
	return;
}


//*************Hardware SetUp***************
//
//		    ADC Input
//		       |
//	       Rpad    |  Rtherm
// Vcc--------/\/\/\------/\/\/\------ground
//
//******************************************


float get_temperature(uint16_t ADCVal){
	//temperature in kelvin = beta/ln(R/Rinfinity)
	uint16_t beta = 0;
        uint8_t servo_command;
	float Ri = 0;
	float Rpad = 100000;
	float Rtherm = Rpad/(1-((float)ADCVal/1024.0)) - 100000;
	float Temperature;
	float t;
	//Serial.println(Rtherm);	
	get_parameters(ADCVal, &beta, &Ri);
	
	t=beta/log(Rtherm/Ri);
	t = ((9.0/5.0)*(t-273))+32;
	Temperature = t;
	
		
	//Out to LCD
	//LCD_Cursor_Position(72);
	//Serial.print(ADCVal);
        //Serial.print("    ");
	//LCD_Cursor_Position(28);
        //Serial.print(beta);
        //Serial.print("    ");
	//LCD_Cursor_Position(8);
	return Temperature;
		
}

Don't bother calling pinMode on analog pins. It is unnecessary.

All analog pins have the issue or just the one?

Explain what "completely off" means. Random or off by the same amount?

I tried it on two of the pins and it happened on both of them. I have the divider set up, with a 100K resistor from the arduino 5V pin to A1, and a thermistor connected from A1 to the arduino ground pin. When I connect it this way directly to the arduino without the shield I measure 4.97 volts across the 5V and ground pins, 330mv across the 100K resistor and 4.64V across the thermistor. When I use the exact same configuration, except I connect it to the arduino through the ethernet shield I get 4.97V across the 5V and ground pins, 30mv across the 100K resistor and 4.94V across the thermistor. So it's not really the ADC that is the problem.

Looking closely at the ethernet shield, I do actually see some tracks leading off of the A0 and A1 pins. I can't really tell where they go because the tracks are jumping from the top of the board to the bottom. A2 through A5 look clean so I will try those when I get home tonight.

Where did you buy your Ethernet Shield from?

Looking at the official schematic and the Eagle BRD file, there's nothing connected to J2 which is the analog headers (near top right in schematic). I've also attached a screenshot of J2 from the board file.

Files available from:

Screen Shot 2012-07-19 at 9.38.38 AM.png

I purchased it here:

http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItemVersion&item=320917833445&view=all&tid=914068615011

I will post a detailed picture of the shield when I get home where you can see the traces. I will try to figure out where they go and if they aren't important i may just cut them.

That link doesn't work.

eBay? Good luck then. All bets are off on what it is. But hey, at least you saved a few bucks, right?

A picture of the board is pointless. Only a schematic will tell you what is going on.

Sorry this was the item:

http://www.ebay.com/itm/Ethernet-Shield-W5100-Arduino-2009-UNO-Mega-1280-2560-/280916824651?_trksid=p5197.m1992&_trkparms=aid%3D111000%26algo%3DREC.CURRENT%26ao%3D1%26asc%3D14%26meid%3D722189686334089343%26pid%3D100015%26prg%3D1006%26rk%3D1%26

To be fair....the board does what it is supposed to do in terms of providing internet connectivity for my arduino as I have tested it in this capacity. There seems to be some differences in the connections to the pin headers which I can hopefully resolve.

In case anyone runs into this same problem I will post the solution. The ebay seller replied that the board is based off of the arduino ethernet shield v5. I have attached a link to the schematic for that. Sure enough pins 1 and 2 are connected to X1 which was causing a problem. I changed my ADC input pin to A2 and it worked just fine.

I had the same problem with pins A0 and A1 already connected on an Arduino Ethernet shield, purchased from Amazon

Described as Ethernet Shield W5100 for Arduino Main board 2009 UNO
Pins A2 and A3 worked correctly

Thanks for the post

As was pointed out by SurferTim in a more recent thread:

FYI: Some ethernet shields use A0 and A1 as the SD card "card present" and "write protect" pins.

http://forum.arduino.cc/index.php?topic=297193.msg2072924#msg2072924