My project involves the use of 6 buttons which the user presses to get things done (point a telescope in the right direction). I am looking for a solution to avoid running 6 wires from the buttons to corresponding digital inputs on the Arduino.
A R2R ladder is exactly what I'm looking for. Because of the number of buttons (more than 4), I've read that I will need a ladder built of precision resistances: 0.5% tolerance. The job of this ladder is to send on ONE line, 0 Volts when no switches are pressed, thru to 5V when all switches are.
Since I don't want to wire the 13 (or so) resistances, I am looking for a R2R ladder IC, but can't seem to find them anywhere.
Can anyone recommend a R2R ladder IC (SIP or DIP), and supplier, with 0.5% tolerance (or better) for the individual resistors?
As an alternative to R2R ladder
I've seen numerous DAC ICs out there, and I believe they're an overkill for my requirements. Also, being a newbie, I am confused at how to wire a DAC. The ONE aspect that puzzles me is the need to supply a Vee ( negative voltage) to the chip - the power supply for my application does not have a negative line. If the (much more widely available) DAC can be used without having to wire a negative voltage, then I would be glad to consider that instead of the simpler R2R ladder.
Any guidance or reference on the use of a DAC to encode the 6 buttons will be appreciated.
I don't think you need 0.5% resistors and you can probably just build a ladder on your own out of discrete components. 1% resistors are just as cheap as 5% resistors these days. You're only trying to discriminate 6 buttons so dividing up the 0V-5V range into 6 regions gives (ideally) 0.83V per region. That is very large and easily discriminated by an A/D converter even if the resistors are not precise.
--
The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, speaker, microphone, light sensor, potentiometer, pushbuttons
The idea I had with the DAC is to wire the buttons to the DAC inputs.
The output voltage of the DAC would represent an 'analog' value corresponding to the buttons pressed.
My application would only need to read the voltage, and translate this value to which button(s) is(are) pressed.
I've seen the logic for this elsewhere, have tried it, and it works fine!
I'd be curious to know which DAC you use that does not require a negative voltage.
This excel file will calculate the expected voltages http://www.crossroadsfencing.com/keypad_divider.xls
(right click, Save Target As.
Column H gives the expected AnalogRead(pin) value.
I am not seeing any packaged parts that will do this, I think the best you can do is "isolated" resistors in a SIP or DIP package, you will have to wire them up in series, and make the connection to your switches.
Concerning your idea for resistors in series
I looked briefly at the spreadsheet. Would the setup handle simultaneous button presses? I'm not sure, but I suspect not.
For example: J9 (at 3.75) would give a very similar result to J6 and J8 (also at 3.75).
Apologies for not mentioning in my original post. Handling simultaneous presses (as an R2R and DAC handle nicely) is a feature I am counting on in my application.
On the AD5424/AD5433/AD5445 in your reply
I'm an unfortunate newbie - doing a whole lot of reading for sure - but with big gaps in my current understanding.
In the case of these DACs, there's mention of "current output DAC", I guess as opposed to "voltage output DAC".
I'm assuming here (and beg to be corrected if mistaken on this point) that the Arduino analog inputs read a voltage. So would a "current output" from an AD5424 be correctly readable (evaluated) by an Arduino?
Assuming you want to power your control from the same supply as the telescope motoring device, and you want to read any combination of 6 switches then you will need to effectively create a 6 bit binary word where each bit (0 or 1) is an individual switch. These you feed into a 6 input (binary) logic device which will read the respective binary word and produce a single analogue value. As such you will need 3 wires for your hand control, 2 to supply power to the switches, DAC etc and one to return the respective analogue value.
However, 8 core security alarm cable is both flexible and of very small diameter so you might be trying to overcomplicating your requirements, when you could very neatly feed all 6 switches from your hand control back to the telescope.
Just add a simple op-amp to make it a voltatge output.
Your original request did not mention multiple buttons being pressed together.
If you do with the R2R ladder, then grounding R5 after R7 is already grounded for example would make no difference - grounding the middle of a string with both ends grounded would have no effect.
How about running 4 wires out to a shift register? Power, Ground, Parallel Load, Shiftout clock.
Sample at some rate, check the bits that come back for high/low to see which had buttons pressed indicating closed.
Lot cheaper than messing with a DAC if all you want to capture is button presses.
Often all you need to convert a current output to a voltage is a resistor to ground... Checkout the voltage compliance of the output to see what values it can range over.
Because of the number of buttons (more than 4), I've read that I will need a ladder built of precision resistances: 0.5% tolerance.
With normal 5% resistors, you should be able to resolve on the order of 1/5% different states (20. 4 switches is 16 states, so that's about the limit.)
But since you only have 6 buttons, you only have 64 states, and 1% resistors should be good enough. (and this assumes that you need to figure out all possible combonations of the 6 buttons, which is unlikely.
So, there's the rub - the R2R costs $1.78, and you save 2 wires (still have to run power,ground, get return signal back), sampling is determined by the ADC conversion time and its limitations and foibles and you may not get all 64 states (altho DACs are guaranteed monotonic, so maybe ...)
74HC 595 on the other hand is 62 cents, for the extra 2 wires (power, ground, parallel load clock, shiftout clock, data return) but you get crisp 0/1s back and you will definitely know the state of all buttons.
Coding might be simpler too -
button_read = shiftin(blah blah blah)
switch (button_read){
case 1:
//code
break;
case 2:
//code
break;
vs
analog_in = analogRead(A0);
if (analog_in>0 && analog_in < 100){ // or however the #s work out for up to 64 ranges
button_read=1;}
if (analog_in>100 && analog_in < 200){
button_read=2;
}
etc.
then follow with switch(button_read) code
or with individual button segregationcode
CrossRoads:
74HC 595 on the other hand is 62 cents, for the extra 2 wires (power, ground, parallel load clock, shiftout clock, data return) but you get crisp 0/1s back and you will definitely know the state of all buttons.
The 74HC595 is a serial in / parallel out shift register and it would be interesting to see how you would use this to read button states.
You may swap it with a parallel in / serial out component (or some I2C flavor with parallel input), but you also need to handle de-bouncing and add pull-up or pull-down resistors for each button input.
An R-2R ladder is designed to be driven from low-impedance logic level (each 'bit' either held at 0V or held at 5V in this context) This requires SPDT switches at least (very rare to find this in a push-button which are momentary-SPST). With SPDT switches you can get evenly spaced output voltages for every combination of switch states.
[SPST = single pole, single throw as opposed to SPDT - double throw (the central contact switches between two alternate contacts)]
With SPST switches you probably need R-2R-4R-8R-16R network and a constant-current source to achieve the same even spacing of voltages.
I've not found any monolithic R-2R networks but a reasonable approach is to get two resistor networks (typically 8 identical resistors in a 16 pin DIL package) one that's 10k and one that's 20k. 1% or better tolerance are readily available, but not at budget prices alas.
Anyway the shift register solution might be simpler (though arguably less fun to design).
I'm pretty sure the MCP23008 port expander has internal pull-ups, so you probably can get by without any additional resistors. I've used it's big brother, the MCP23017, for a nearly identical application as the OP. All he'd need are 6 momentary SPST's, the port expander, a few decoupling capacitors, and a 4-conductor cable. The I2C interface is pretty straightforward using Arduino and Wire.
For my application I mounted an RJ-11 jack (6P-4C) at the remote and connected it with a phone cord. Debounce per this reference: