Hey folks,

Is there anything we should watch for if we want to use analog inputs as digital? i.e. wire up a binary switch onto one of the analog inputs. Should we wire ground and signal, +5 and signal, or all three?

Thanks,

Guy Davidson

Paly Robotics (FRC #8)

when the switch is closed you will have a 0

when the switch is open you will have full scale analog value (I don’t remember if it is 8 or 10 bit or what)

write some code that interprets

half-scale or lower as a switch closed
else
switch open

Ed,

Thank you very much. Sounds good.

Just as a reassurance, we are successfully using this on our OI panel this year.

-q

FYI, RC analog inputs are 10 bits, 0-1023. OI inputs are 8 bit, 0-255.

As have we, for many years. We don’t use the pullup resistor approach - the ground doesn’t appear in our method of wiring switches to analog input. I’ve never had a problem with this method.

Remember, on the OI, you don’t need to have a ground connection for an analog input pot reading - on the joysticks, it’s just five volts through the joystick axis pot straight to the analog input. We duplicate this method in wiring digital switches to our analog in’s.

For devices such as rocker switches or 3-position toggle switches where only one state can be active at one time due to the mechanics of the device, wire two resistors of differing values (each less than 100K - say 10k and 80k - whatever - I like to pick them to have a distinct separation that can easily be tested for in the code) between the +5V and the different poles of the device. 10k on one pole, 80k on the other. Wire the common of the device to a single analog input.

When you actuate the switch, you connect 5V through either 10k or 80k into the analog input, resulting in a distinct numeric value for each position. Use if statements to test for ranges centered around these values and set binary variables accordingly:

``````//Wrist Rocker switch on button box
if ((wristrocker > 218) && (wristrocker < 240))  //Wrist Reverse/Up rocker is active
{
wristfwd_sw = 0;
wristrev_sw = 1;
}
else if ((wristrocker > 73) && (wristrocker < 95)) //Wrist Forward/Down rocker is active
{
wristfwd_sw = 1;
wristrev_sw = 0;
}
else
{
wristfwd_sw = 0;
wristrev_sw = 0;
}
``````

We actually use a simlar method with an 11 position switch and 10 9.1K resistors wired to a joystick analog input, to give us a method of choosing different auto modes.

That’s right… we had that problem related to this in one of our practice matches at Chicago. When our automode started one time early on, the arm started trying to fold out while being closed. Turned out, one of the buttons on the OI panel was shorted out (the one for arm fold out) so I figured out that there must be one OI panel read before the autonomous mode enters (as there is one execution of the master uP routine before autonomous mode).

So anyhow, my question for clarification: Al: You guys use a switch on your OI panel, and it gets read by your robot before it starts to run autonomous?

If so… awesome!

-q

Q, I imagine that the OI is transmitting data throughout autonomous/hybrid mode - it’s just that we never find out because it’s hands-off.

Remember that the RC starts to run it’s (your) program when you turn it on. The OI does not get a autonomous command until much after you power the robot. During autonomous, all OI analog inputs are held at 127 and all digital inputs at “0”. See the IFI Programing Ref Guide for more information. I will let the software guys answer coding questions, electrical provides the switch wired to the inputs defined by the software team.

This is from back in the day, but it illustrates exactly how we get OI variables stored in memory for autonomous routines to utilize:

If you happen to read the rest of the referenced thread, ignore all the dissenting statements - we’ve used this method for years, and it still works fine, including this season.

Next year, with a new control system - who knows.

Just like Al and Travis’s teams, we’ve been using "AiDi"s through the various analog input ports for some years now. Like WildStang (heck we probably got the idea from you guys Al ) we use a rotating 6 to 10 position switch with resistors in series. And, like Travis pointed out, we leave plenty of “room” for selecting which position we want. Here’s a sample of how we do it.

``````
const uint8 AUTONOMOUS_ANALOGS[7] = {6, 140, 160, 190, 210, 235, 255};

uint8 AnalogToDigital(uint8 value, uint8 analogs])
{
uint8 loop;
for (loop = 1; loop <= analogs[0]; loop++)
if (value <= analogs[loop])
return ( analogs[0] - loop ) ;
return 255;
}

``````

The values in the array are the max loop counter, followed the boundaries between which the actual inputs will lie.

Eric

We did this as well in 2005-2006 robots.

Basically we had a thumbwheel through one of the joystick ports. thumb,trigger, aux1, aux2. BCD 1,2,4,8.

When we powered up, we captured the inputs from the joystick to a global varible that was frozen. When auto mode started, we read the global varible.

I had heard of some isses (something changed) in 2007 that it wasn’t the same. I think Nathan, our programmer worked through that, not sure what they came up with. So this year, I wasn’t sure what to tell them so I suggested to move them since we had so many modes on the robot, we decided to move the thumb wheels back to the RC controller because we have three thumb wheels now.

Team 85 has used three 12 position switches for several years now. One sets the autonomous path. Others are used for selecting debug information to be sent out the programming port and displayed on the OI. In the pit or on the field we can easily check backup battery voltage, joystick centering, and other values. We also mount a 100K pot to that’s handy when developing code or trying out parameters.

Hmm. I’m just about to wire the switch, and I’m wondering if I really need a connection to ground. Shouldn’t I just be able to wire: +5 aux -> 10k resistor -> switch -> analog input, all in series?

You’ve got it right. An open circuit will be read as 127, and with the switch closed you should see something like 230. No ground connection is needed (or wanted – it could trigger the open-circuit detector and be read as 127 too).

Awesome, thank you very much. This is all coming as a good use of our fix-it window to improve upon our control system.