I'm building a weather logger and I'm having trouble with the humidity sensor. It works with an Arduino, but not with my Netduino.
Basically, it's a capacitive sensor, so you have to set the CPU pin to an output and set it high, wait a second, and then set it low. You then read the pin to measure the voltage decay in the circuit.
The Arduino code looks like this:
long RCtime(int sensPin) { long result = 0; pinMode(sensPin, OUTPUT); // make pin OUTPUT digitalWrite(sensPin, HIGH); // make pin HIGH to discharge capacitor - study the schematic delay(1); // wait a ms to make sure cap is discharged pinMode(sensPin, INPUT); // turn pin into an input and time till pin goes low digitalWrite(sensPin, LOW); // turn pullups off - or it won't work while(digitalRead(sensPin)) { // wait for pin to go low result++; } return result; // report results }
Like I said, it works fine with an Arduino.
This is my testing code for the Netduino:
double result = 0; OutputPort RCTime = new OutputPort(Cpu.Pin.GPIO_Pin1, false); RCTime.Write(true); Thread.Sleep(1000); RCTime.Write(false); //InputPort Rtime = new InputPort(Cpu.Pin.GPIO_Pin1, false, Port.ResistorMode.Disabled); while (RCTime.Read()) { result++; } result = ((result * 1.3181042) / 10); Debug.Print("Humidity: " + result + " %");
Using the InputPort function after using OutputPort throws an exception, so I'm just reading the OutputPort. Unfortunately, pullup resistors have to be disabled for this to work, and InputPort has no write method. I think the Netduino code is relativiely similar to the Arduino code, but I'm doing something worng.
Any thoughts would be appreciated.
Thank you.