Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

ADC Question / Issue


  • Please log in to reply
8 replies to this topic

#1 QuantumPhysGuy

QuantumPhysGuy

    Advanced Member

  • Members
  • PipPipPip
  • 30 posts
  • LocationKentucky, USA

Posted 14 October 2012 - 02:49 AM

I am trying to get a reading from a TMP36 temperature sensor from my Netduino Go. I currently have my breadboard setup where I see the reading from the TMP36 on my multimeter and also have the signal sent to the NGO.

One thing I am noticing right off is the difference from the voltage my multimeter is reading versus the NGO. Currently my multimeter is showing 0.72V coming from the TMP36, but my NGO is showing 0.685v - 0.690v.

Here is my conversion for the ADC:

ShieldBase shieldBase = new ShieldBase(GoSockets.Socket8);
AnalogInput aiTemp = new AnalogInput(shieldBase.AnalogChannels.ANALOG_PIN_A0);
Double dVolts = aiTemp.Read() * (3300 / 1024F);

So you can see when I do the math to convert the volt reading to degrees I am coming up with not so acurate readings. Using the multimeter the temp would be 22° C which is correct for the room I am in, but the NGO shows ~66° C.

Does anyone have any tips on this?

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 14 October 2012 - 02:54 AM

Hi QuantumPhysGuy,

One thing I am noticing right off is the difference from the voltage my multimeter is reading versus the NGO. Currently my multimeter is showing 0.72V coming from the TMP36, but my NGO is showing 0.685v - 0.690v.

What voltage are you measuring on the 3V3 header of your Shield Base?

Also, just curious: why multiply by 3300 and then divide by 1024?

Chris

#3 QuantumPhysGuy

QuantumPhysGuy

    Advanced Member

  • Members
  • PipPipPip
  • 30 posts
  • LocationKentucky, USA

Posted 14 October 2012 - 02:57 AM

Hi QuantumPhysGuy,


What voltage are you measuring on the 3V3 header of your Shield Base?

Also, just curious: why multiply by 3300 and then divide by 1024?

Chris


Voltage is showing 3.35.

I was doing that to account for the 3.3V and also the bits from the ADC. Is that not correct?

#4 QuantumPhysGuy

QuantumPhysGuy

    Advanced Member

  • Members
  • PipPipPip
  • 30 posts
  • LocationKentucky, USA

Posted 14 October 2012 - 03:00 AM

Here is something odd, once I removed the terminal and jumper wires I had on the breadboard the readouts from the NGO went to normal and they are close to what my multimeter said by about ~0.01 volts... Is it possible it was causing "noise" on the ADC?

#5 Gutworks

Gutworks

    Advanced Member

  • Members
  • PipPipPip
  • 363 posts
  • LocationOttawa, Ontario

Posted 14 October 2012 - 03:27 AM

Hi QuantumPhysGuy,

You may have found some sample code for this sensor that was written using the 4.1 .Net MF. The 4.2 .Net MF has introduced some changes to the AnalogInput class. The Read() function in 4.2 behaves much differently than it's predecessor, and it now returns a value between 0.0 and 0.9999, which technically provides you with better precision. The shield base is also using a 12 bit ADC unlike the Netduino Plus which is 10 bit. The old Read() returned the raw AD value, a number between 0-1023, and so if you wanted to replicate this value you can use the new to 4.2 ReadRaw() function. The ReadRaw() will return a value in the range of 0-4095.

If you read this post over, you will see some of the work carb has done using this sensor and a Touch Display. A little further down I converted his sample to C#. Hopefully you can find a couple hints or useful snippets to help you along the way, such as the formula used and a way to average the sample to filter out some of the ADC noise.

Cheers,
Steve

#6 QuantumPhysGuy

QuantumPhysGuy

    Advanced Member

  • Members
  • PipPipPip
  • 30 posts
  • LocationKentucky, USA

Posted 14 October 2012 - 03:44 AM

Hi QuantumPhysGuy,

You may have found some sample code for this sensor that was written using the 4.1 .Net MF. The 4.2 .Net MF has introduced some changes to the AnalogInput class. The Read() function in 4.2 behaves much differently than it's predecessor, and it now returns a value between 0.0 and 0.9999, which technically provides you with better precision. The shield base is also using a 12 bit ADC unlike the Netduino Plus which is 10 bit. The old Read() returned the raw AD value, a number between 0-1023, and so if you wanted to replicate this value you can use the new to 4.2 ReadRaw() function. The ReadRaw() will return a value in the range of 0-4095.

If you read this post over, you will see some of the work carb has done using this sensor and a Touch Display. A little further down I converted his sample to C#. Hopefully you can find a couple hints or useful snippets to help you along the way, such as the formula used and a way to average the sample to filter out some of the ADC noise.

Cheers,
Steve


Thanks! That makes much more sense. The sample I was looking at was from the 2010-2011 time frame.

#7 QuantumPhysGuy

QuantumPhysGuy

    Advanced Member

  • Members
  • PipPipPip
  • 30 posts
  • LocationKentucky, USA

Posted 14 October 2012 - 03:56 AM

If you read this post over, you will see some of the work carb has done using this sensor and a Touch Display. A little further down I converted his sample to C#. Hopefully you can find a couple hints or useful snippets to help you along the way, such as the formula used and a way to average the sample to filter out some of the ADC noise.


Ok, now that I made the change. My readings are off by 3.5°. Here is my code:

    	private static AnalogInput aiTemp;

    	public static void Main()
    	{
        	ShieldBase shieldBase = new ShieldBase(GoSockets.Socket8);
        	SevenSegmentDisplay ssDisplay = new SevenSegmentDisplay(GoSockets.Socket2);
        	Double dTemp;

        	aiTemp = new AnalogInput(shieldBase.AnalogChannels.ANALOG_PIN_A0);
        	
        	while (true)
        	{
            	dTemp = GetAverageTemperature() * 9 / 5 + 32;
            	ssDisplay.SetValue(dTemp.ToString("N1") + "F");
            	Thread.Sleep(1500);
        	}
    	}

    	private static Double GetAverageTemperature()
    	{
        	Double dTotalTemp = 0;
        	Double dAverageTemp;

        	for (Int32 i = 0; i <= 19; i++)
        	{
            	dTotalTemp += GetTemperature(aiTemp.Read());
            	Thread.Sleep(50);
        	}

        	dAverageTemp = dTotalTemp / 20;

        	return dAverageTemp;
    	}

    	private static Double GetTemperature(Double dReadValue)
    	{
        	Double voltage = dReadValue * 3.3;
        	Double temp = voltage - 0.5;

        	return temp * 100;
    	}

Suggestions?

#8 QuantumPhysGuy

QuantumPhysGuy

    Advanced Member

  • Members
  • PipPipPip
  • 30 posts
  • LocationKentucky, USA

Posted 14 October 2012 - 03:59 AM

Ok, now that I made the change. My readings are off by 3.5°. Here is my code:

    	private static AnalogInput aiTemp;
...

Suggestions?


Maybe I should check circuits before asking questions.

I added a 0.1uF ceramic disk capacitor on the out pin of the TMP36 and my readings match the multimeter...

Thanks for the help Chris and Gutworks.

#9 Geancarlo2

Geancarlo2

    Advanced Member

  • Members
  • PipPipPip
  • 70 posts

Posted 14 October 2012 - 05:55 AM

In any case, if you still have problems you can use linear regression for calibration.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.