I know it is not a traditional use of the analog breakout board to attach toggle switches, as most people use potentiometers or some other sensors, but this year we have used up the 14 inputs on our Digital Sidecar. I have 4 questions before trying this and a search on here didn’t pop up a solution.
Instead of adding a whole sidecar for the other 3 switches our current design needs, I was wondering if I could wire them to the Analog Breakout board instead? (I have to have an analog board for the battery jumper so I should go ahead and use it as much as possible and save some weight and failure points)
Do I need to have a resistor in the line between my switch and analog board, or can I strictly wire my switch to the analog breakout like I do the digital board, with just the white and black wire?
Has anyone done this before, if so what issues did you have?
Bonus question: Can I do the switch to the analog input on the driver station cypress chip as well, using the same method that I would hook it up to the robot analog breakout board?
You can definitely do this, you are probably going to want (need?) a pull up resistor. Solder a resistor from signal to pwr and wire the switch from signal to ground, flipping the switch will toggle between the power voltage and 0v.
I think the easiest way to make it work is to add a pullup resistor (10k or so) from signal to +5 volts, and connect the switch from signal to ground. You’ll read 5v when the switch is off, and 0v when the switch is on.
You could even use a half dozen or so resistors to make a rudimentary D-to-A conversion circuit, which would let you connect all three of your switches to a single analog input, but that’s probably a bit fancier than you need to get.
Darren,
Teams do this all the time. There are a variety of applications. A simple single throw, single pole switch can be used tied to a 10 k resistor which has one end connected to a 5 volt supply. One side of the switch is tied to power common and the other side to the resistor. The switch when open allows a 5 volt input to the analog module and when closed, provides a zero volt signal. A double throw switch can be wired for three states, a multi pole switch can be wired for even more. We use an modified Radio Shack switch to provide 11 different positions for selecting different modes or auto programs in this way, either at the robot or on the driver’s station. 9.1k resistors are tied between each contact and the switch then provides 12 levels of voltage between 5 volts and zero volts.
Thank you everyone! This was the information I needed. This helps me keep our controls to one digital sidecar. I don’t think we will have a weight problem, but on our team we always look for any weight savings throughout the entire build so we don’t have a problem at the end. Using the existing, mandated analog board saves us 1.2 lbs between the additional sidecar, big cable and cRio module.
I am the programming mentor so I know how to tweak the settings on that side, I wasn’t sure of how to wire it correctly. I don’t like to test theories on expensive robot components when a quick question gets me an answer from teams that have already solved the problem.
I just want to make sure I understand this wiring, we are at the point we are about to use the analog to digital trick. I assume this is how I wire it from you guy’s instructions?
---/Switch/---------
| | |
| | 10k Resistor
| | |
| | |
B W R
Where B is the black wire, W is white wire, and R is red wire on a standard PWM cable. Basically tie the white wire and the red wire through a resistor onto one side of the switch and the black wire on the other?
If you are going to the analog board, it does not have pull up resistors so you have to use the SPDT to switch between +5 and zero volts. If you use a digital input, the pullup would allow you to simply open or close a connection to the common to give two states.
Sorry, Al, but I have to disagree. If you put a 10k pullup resistor between the analog signal and +5 power pins, a simple SPST switch between signal and ground will give the desired results. The schematic Darren posted is exactly how I would do it.
Attached is a picture for SPST (Al, please correct me if I am wrong but this should give him two states (Closed =0v Open=~5v) using a Single Pole Single throw switch on the Analog inputs which seems to be what he wants to do.
Yes, You guys are right. I have to stop answering these questions while I am working on interfaces here. Alan, can you add something about programming so that switch bounce doesn’t confuse the readings?
Switch bounce would affect switches connected to a digital input at least as much as it would analog inputs. Most of the time, the programming is going to be such that it simply doesn’t care whether the switch gets detected several times in quick succession.
For reading a switch on an analog input, the WPILib “analog trigger” function is what you want. That rejects glitch-type noise as part of its implementation.
Edit: Looks like I need to type faster if I am going to post in the same threads as Al and Alan. But what I posted may still be usefull so I will leave it up.
I am not Alan but I should be able to help here any way. To debounce a switch in software what you want to do is ensure that the press that was detected was a true press, not just noise or bounce. The easiest way to do this is once a press is detected start a counter, if the counter reaaches a certain value (10ms is probably acceptable for FRC Applications) then acknowledge that the switch is pressed. If the switch is released before counter times out the reset the counter and ignore the bounce.
Psuedo Code
Create Counter- Initialize to Zero
Assuming Switch sampling occusr every ~1ms
If (Software_representation of switch = not-pressed)
If switch is not pressed
Reset Counter
Set Software representation of switch to not-pressed
else (switch is pressed)
increment counter
end if
if counter > 10
Set software representation of swtch to pressed
end if
Then you can reverse the switched/not-switched cases for then the butto is pressed if you need to detect the release as well.
Cool discussion, I am happy I can use my SPST switches. I already had a bunch purchased and laying around. I also appreciate the pseudocode. Thanks again.