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.
I seem to be having an issue reading the TMP36 Temperature sensor. I setup the sensor using a SB(Solorbotics) Protoshield following the tutorial at the following link : http://www.ladyada.n...sors/tmp36.html. I have the sensor setup on the Netduino exactly as shown in the below Arduino Picture:
Here is the code I am using to attempt to read the sensor:
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
namespace NetduinoApplication2
{
public class Program
{
static AnalogInput Tmp36 = new AnalogInput(Pins.GPIO_PIN_A0);
public static void Main()
{
// write your code here
while (true)
{
double voltage = Tmp36.Read() * 5.0 / 1024;
double tempC = (voltage - 0.5) * 100;
double tempF = (tempC * 9 / 5) + 32;
Debug.Print("Temp in C is: " + tempC);
Debug.Print("Temp in F is: " + tempF);
Thread.Sleep(1000);
}
}
}
}
The above code seems to be fine, but I dont appear to be getting back any proper data from the sensor. I am getting a reading in the mid 800's all the time using this code...even without the sensor plugged in. I was wondering if someone could help me figure out what I might be doing wrong. It is possible (I am new to microcontroller projects, but work as a .net programmer...) that the temperature sensor may be defective, and I have not yet attempted to test it with a multimeter. Its also possible the issue might be with my protoshield. I have not attempted to connect the sensor without it.
Can anyone see any issues with the way I am trying to read this sensor before I check it with a multimeter?
I seem to be having an issue reading the TMP36 Temperature sensor. I setup the sensor using a SB(Solorbotics) Protoshield following the tutorial at the following link : http://www.ladyada.n...sors/tmp36.html. I have the sensor setup on the Netduino exactly as shown in the below Arduino Picture:
A few quick things:
1. Netduino's analog inputs are 3.3V (instead of 5.0V). Power the temperature sensor from the 3.3V power header instead of the 5.0V power header.
2. The ARM chip on the Netduino (Rev A) does not have an internal analog reference (unlike the AVR used on the Arduino)--so you'll need to wire the 3.3V power header to the AREF pin header.
Other than that, I believe you should be good to go!
P.S.
We could add an "internal 3.3V analog reference" option in a future board revision. Would that be a valuable feature for everyone here? We'd make it optional and selectable in code.
Chris
We could add an "internal 3.3V analog reference" option in a future board revision. Would that be a valuable feature for everyone here? We'd make it optional and selectable in code.
Chris
It seems like this would be useful. Especially so for people who are "porting" Arduino projects.
A few quick things:
1. Netduino's analog inputs are 3.3V (instead of 5.0V). Power the temperature sensor from the 3.3V power header instead of the 5.0V power header.
2. The ARM chip on the Netduino (Rev A) does not have an internal analog reference (unlike the AVR used on the Arduino)--so you'll need to wire the 3.3V power header to the AREF pin header.
Other than that, I believe you should be good to go!
Chris
Chris,
Thanks for you help, I should have caught that by doing a little reading. I will make the changes and try that again tonight. I will let everyone know the outcome.
Taking Chris's advice from above, I was able to get the TMP36 working easily this evening. To do this I did the following:
Using the following picture's as reference:
1. I connected the left pin to 3.3v.
2. I then Connected 3.3v to Aref as suggested in Chris's previous post.
3. I connected the center pin to Analog0.
4. I connected the Right pin to Ground.
Next up, I wrote the following code to handle the temperature in C and F.
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
namespace temperature1
{
public class Program
{
public static void Main()
{
//Declare your analog input
AnalogInput a0 = new AnalogInput(Pins.GPIO_PIN_A0);
while (true)
{
// Read the temp sensor
int read = a0.Read();
//convert the reading to voltage
Double voltage = read * 3.3 / 1024;
//calculate Celsius from voltage
Double tempC = (voltage - 0.5) * 100;
//calculate Fahrenheit from Celsius
Double tempF = (tempC * 9 / 5) + 32;
//Print your results
Debug.Print("Temp in F is: " + tempF + " -- Temp in C is: " + tempC);
//sleep and do it all over again.
Thread.Sleep(1000);
}
}
}
}
As you can see in the below debug output, I am now receiving a more accurate temperature reading:
We could add an "internal 3.3V analog reference" option in a future board revision. Would that be a valuable feature for everyone here? We'd make it optional and selectable in code.
I also had a question about pull-up resistors. In wiring my I2C clock chip, I used external pull-up resistors. Is it possible to use the internal pull-up for this? I'm not really using the pins as input per-se, but if I plug in an I2C device, it likely needs pull-up resistors. Yes, I'm a hardware newbie... I'll bet it shows.
I also had a question about pull-up resistors. In wiring my I2C clock chip, I used external pull-up resistors. Is it possible to use the internal pull-up for this? I'm not really using the pins as input per-se, but if I plug in an I2C device, it likely needs pull-up resistors. Yes, I'm a hardware newbie... I'll bet it shows.
You'll want to use external resistors. I2C will sometimes work with the internal pull-ups, but they're fairly weak.
If you search for I2C on the web, there are some general algorithms which help you figure out which resistors to use (2.2K and 1.8K are pretty typical with one device--but there are more exact ways to measure it).
Fun note for those new to I2C: with I2C, the Netduino only "pulls down" the current to 0V. This allows you to choose your I2C line voltage (5V or 3.3V) which is fed through the pull-up resistors. This also helps make Netduino compatible with the I2C capabilities of Arduino shields (which may use 5V or 3.3V for I2C).
I'm a total noob with hardware and this is my first project, enjoying it so far!
I've got this exact same setup but the analog readings coming from the TMP36 vary wildly. I took samples of the reading coming from the pin every 700ms for ~30 seconds and put the results into Excel:
As you can see the reading is all over the place with a low of 228 and a high of 239; this translates to a low F temperature of 74.2578125 and a high of 80.63867187 over a period of ~30 seconds.
Anybody have an idea why this is happening? Here's the code I use:
Jim,
If you create the AnalogInput once (as a class-level variable for instance) and then read the value each time, are your readings more consistent?
Chris
I'm a total noob with hardware and this is my first project, enjoying it so far!
I've got this exact same setup but the analog readings coming from the TMP36 vary wildly. I took samples of the reading coming from the pin every 700ms for ~30 seconds and put the results into Excel:
As you can see the reading is all over the place with a low of 228 and a high of 239; this translates to a low F temperature of 74.2578125 and a high of 80.63867187 over a period of ~30 seconds.
Anybody have an idea why this is happening? Here's the code I use:
I hooked up a multimeter to the pins and took a video of the results. Basically, the sensor's analog reading is holding steady but the netduindo's reading is fluctuating wildly. I also noticed that the power voltage is fluctuating a tiny bit but I don't know if that's enough to throw off the readings. I don't fully understand how the internal aref port works; wouldn't you want to read the voltage at the same time as the sensor voltage to get a better comparison instead of hard-coding a value of 3.3??
http://dl.dropbox.com/u/421021/IMG_0999.MOV
As long as the AC adapter is 7.5V-12V, center positive...it should work nicely.
Chris
Okay, I'll try it with a wall cord tonight and see if I get any more stable of values but Jason Smith was just using his USB cable.
Jason, it looks like your results are much more stable than mine looking at your VS2010 screenshot, did you ever see this behavior? You also have a shield on top of your Netduino, do you get the same results if you don't use the shield?
Okay, I'll try it with a wall cord tonight and see if I get any more stable of values but Jason Smith was just using his USB cable.
Jason, it looks like your results are much more stable than mine looking at your VS2010 screenshot, did you ever see this behavior? You also have a shield on top of your Netduino, do you get the same results if you don't use the shield?
I couldn't find a wall cord. I'll try rear USB ports instead of front?..