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?