juanpaexpedite
Posts: 15
Joined: Fri May 15, 2015 10:27 am

Analog measuring (Temperature with thermistor)

Fri May 15, 2015 10:35 am

I am a newbie in the world of Raspberry and I have seen there are several solutions for reading analog, this example for measuring temperature:

http://raspberrypi.powersbrewery.com/pr ... hermistor/ Is is very simple to understand, discharging, wait and charge and read the time takes to charge.

I have made the following code:

Stopwatch pulseLength;
public void Charge()
{

pulseLength = new Stopwatch();
pulseLength.Start();
FirstGpio.SetDriveMode(GpioPinDriveMode.Output);
SecondGpio.SetDriveMode(GpioPinDriveMode.Input);

FirstGpio.Write(GpioPinValue.High);

while(SecondGpio.Read() == GpioPinValue.Low)
{

}
pulseLength.Stop();
Temperature = pulseLength.Elapsed.TotalMilliseconds;

}

private void Discharge()
{
FirstGpio.SetDriveMode(GpioPinDriveMode.Input);
SecondGpio.SetDriveMode(GpioPinDriveMode.Output);
SecondGpio.Write(GpioPinValue.Low);
}

public async void Initialize()
{
Discharge();
await Task.Delay(100);
Charge();
await Task.Delay(100);
Initialize();
}

And I get this random values 2.6,2.6,1.9,1.9,2.6,2.6,10.6,10.6 really random.

Might be I need to use ValueChanged, but I am not sure what is the best way to follow, any idea how to solve that?

User avatar
mikronauts
Posts: 2708
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: Analog measuring (Temperature with thermistor)

Fri May 15, 2015 2:07 pm

Cheap solution:

PCF8591 module, 8 bit resolution, CHEAP

Medium solution:

MCP3008, 10 bit resolution, easy to hook up and use

Good solution:

MCP3208, 4.096V voltage reference, possibly voltage divider for 8.192V range

http://www.mikronauts.com/raspberry-pi/ ... and-howto/
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

juanpaexpedite
Posts: 15
Joined: Fri May 15, 2015 10:27 am

Re: Analog measuring (Temperature with thermistor)

Tue May 26, 2015 8:11 am

Finally I managed a solution working with uF and Valuechanged, I made a post http://bit.ly/1cWcUJO in my blog about how to measure temperature with GPIOs in Windows 10 IoT. It is the most accurate I can do. I also have found that is possible to do with a fixed voltage source, but it is more inestable.

It took me a bit of time to know that the Rpi2 has debounce time 0 that means I should use ValueChanged, and that works really well and is a non blocking event so it's great.

Apart thank you for the ADC I am still waiting they arrive.

juanpaexpedite
Posts: 15
Joined: Fri May 15, 2015 10:27 am

Re: Analog measuring (Temperature with thermistor)

Mon Jun 01, 2015 9:42 am

To begin in the SPI world, I follow the steps in here:

https://www.hackster.io/windowsiot/potentiometer-sample

I have followed the steps with a MCP3002 and I have an issue with the values.
I fixed the pot at 5 Kohm and I get the values as follows

0,317,143,0,283,18,0,66,227,0,0,317,128,311,237,316,0,171,108,213,145,13,319,234,0,0,0,0,0,200,0,316,316,0

I understand there is something wrong in the frecuency it gets the values, but I am new in this and I do not know what
is the best way to follow.

Return to “Windows 10 for IoT”