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

Has anyone successfully used a HS1101 humidity sensor?


  • Please log in to reply
2 replies to this topic

#1 Zoot

Zoot

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts

Posted 27 April 2014 - 02:48 AM

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.



#2 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 27 April 2014 - 08:24 AM

You should be able to use TristatePort for that:

// Initially set to input mode
var port = new TristatePort(Pins.GPIO_Pin_D0, false, false, ResistorModes.Disabled);

port.Active = true; // set to output mode
port.Write(true);
...
port.Active = false; // set to input
port.Read();

Note: In your original code, you'd have to dispose the port object before another one can be created - add RCtime.Dispose() before ... = new InputPort(...).



#3 Zoot

Zoot

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts

Posted 27 April 2014 - 03:51 PM

Thanks CW2, that worked great.  A change of pins and a new coefficiant and I'm good to go.

 

Thanks again! :)






1 user(s) are reading this topic

0 members, 1 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.