Another Switch Help Thread

Hi all,

I can’t seem to figure this out. From what I understand, if I use a switch to bridge the signal and ground of one of the GPIO channels on the Digital Sidecar, then when the switch is closed I ought to get a reading of 0 and when it is open I ought to get a reading of 1. As far as I’m aware, the DSC has an internal resistor and I do not need an additional one. And also, as far as I’m aware, the following code should work:

	DigitalInput* digi10= new DigitalInput(4,10);
	if (digi10->Get())
		printf("Pin 10: TRUE

else if (!digi10->Get())
printf("Pin 10: FALSE

So why is digi10->Get() always false no matter what the switch position is?

Also, before I tried to get a simple switch to work, I was attempting to use the photoswitch to work (the one provided in the 2006 KOP). Both the receiver and source require 12v which I supply from the power distribution board. The green/white wires are each a signal, one is NC and one NO. I tried plugging one of these into a GPIO port but that didn’t work…The photoswitch itself is working though–it has a red light on the receiver that turns on when the beam is unbroken.

Any suggestions?

First, try:

DigitalInput* digi10= new DigitalInput(4,10);
if (digi10->Get()) printf("Pin 10: TRUE
else printf("Pin 10: FALSE

If it is not true, its false…

We typically test for the closure of a switch,
the digital input going to zero, so to speak.
Which way you go here can depend on which
way you want a wiring failure to influence your
control logic.

Next, for your switch case, make sure that you are closing
a connection between the ground (-) and the signal input,
leaving the 5 volt power line not connected to anything.

For the banner sensor, make sure that it is an NPN unit
and wire the 12 volt line directly to a breaker, the
ground line to the ground (-) connection on the digital
input and the line that closes appropriately to the signal
line. Make sure that you refer to correct documentation
for the sensor, as the wire colors are non-intuitive. On the
sensor we are using, the brown is 12V, the blue is ground
or (-) and the white and black lines are the signal lines,
one NC and one NO.

Have fun,

For most switches, you’ll have wiring options for NC and NO - normally closed and normally open. When wired to use the normally closed option, the switch “assumes” that when it is NOT pressed, it should make a connection, and when it is pressed, it shouldn’t - in other words, it’s false when not pressed, true when pressed. The normally open configuration is opposite.

Now, lets make sure things are wired up properly. Do you have a multimeter available? Set it to measure resistance, unplug the switch from the side car and put one probe on the ground wire from the switch, and the other on the signal wire - what do you see? Now have a friend depress the switch - what do you see? You should see infinite resistance (often represented by a “1” on the far left of the readout) in one case, and 0 (or close to it) in the other.

You can do a similar test with the photosensor to ensure it’s working. However, it will need to be powered, and you’ll want to check voltage between ground and the two signal wires - you should see it go between 0V and 5V.

Once you’ve eliminated the switch and the wires… Then i would suspect something with code, but as I’m pretty unfamiliar with the libraries for the cRio (I switched from being a programming mentor to an electrical mentor right before FIRST switched from IFI), I’m probably not the best person to help there.