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

ND1 - Input is always TRUE


  • Please log in to reply
4 replies to this topic

#1 alesbedac

alesbedac

    Advanced Member

  • Members
  • PipPipPip
  • 63 posts

Posted 05 March 2014 - 10:24 AM

Hi all,

 

i have an issue with input ports on Netduino - (tested with FW 4.1 and 4.2)

 

Whatever port i will use (0-13) is always TRUE but i have no wired it.

 

Program is simple...:

public class Program
    {
        private static InputPort input = new InputPort(Pins.GPIO_PIN_D1, false, Port.ResistorMode.PullUp);
        private static OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
        private static bool inputState = false;

        public static void Main()
        {
            while (true)
            {
                inputState = input.Read();

                led.Write(inputState );
                Debug.Print("Input state = " + inputState.ToString());
                Debug.Print("------------------------");
                                
                Thread.Sleep(500);                
            }
        }
    }

Does anybody now why is this code not working. Becase i have tested it on Netduione 2 and there is it working.
 

Notice : Ii i have used the same ports in output mode...this is working perfectly.

 

Thanks for all help

 



#2 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 05 March 2014 - 11:45 AM

Quiz question: What return value do you expect from an unconnected input pin?

 

The thing is that you created input pin with ResistorMode.PullUp, which means the pin is in logic high (returns true), unless it is connected to other logic level (logic low, ground). Thus, if you want your input pin Read() method to return false, you have to wire the pin to GND.

 

If you use a port in output mode, its Read() method basically just returns the current state - i.e. the initial state passed via constructor parameter or what was set in the last call of Write() method.



#3 ShVerni

ShVerni

    Advanced Member

  • Members
  • PipPipPip
  • 138 posts
  • LocationNew York, New York

Posted 05 March 2014 - 06:25 PM

CW2 is completely correct, but just to expand a bit:

 

The pull-up resistor in the Netduino (there is no pull-down one built-in) connects the pin to 3.3V through a (I believe) 10 kOhm resistor. So the pin defaults to high unless there is an easier path (i.e. a lower resistance) to ground, say by connecting the pin directly to ground, or through a button to ground.

 

Without a pull-up resistor, and with no connection, the state of the pin is undetermined and considered "floating" which means it will fluctuate randomly between True and False.

 

You can find more details here:
https://learn.sparkf...ll-up-resistors

 

Hope that helps.



#4 alesbedac

alesbedac

    Advanced Member

  • Members
  • PipPipPip
  • 63 posts

Posted 05 March 2014 - 07:23 PM

Because on N2 and N2+ i have connected digital input with 3V then i get tue Value....

 

but i see that now it must be connected to the ground, becase on this digtal pin is potential 3V...en pull up activate internal resistor...

thanks for help



#5 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 06 March 2014 - 09:47 AM

Because on N2 and N2+ i have connected digital input with 3V then i get tue Value....

 
Hm, does that mean that on N2 and N2+ unconnected input pin created with ResistorMode.PullUp returns false? That does not seem to be right - it's either a bug or you've inadvertently used ResistorMode.PullDown (?)






0 user(s) are reading this topic

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