Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Reading Tri-direction Scan Switch (C&C TPC Series)

  1. Jan 1, 2013 #1
    I'm trying to figure out a bit of a weird looking switch. Data sheet is in the Literature box marked "Download TPC catalog pages".

    The electrical sketch on page two is what's confusing me. How would I read this switch to figure out what its state is? This switch is going to be on the far side of an I2C connection along with a few other buttons, so I was thinking about using a GPIO Port Expander like the chip I linked to to read it, but I'm confused about how to do that.

    Would it even be possible to deduce the state of the switch from a single reading? Or would I have to take multiple readings, fiddling with the input/output settings of the bits to figure it out?

    EDIT: That should be C&K in the title. Could a mod please correct that?
    Last edited: Jan 1, 2013
  2. jcsd
  3. Jan 20, 2013 #2
  4. Jan 21, 2013 #3

    jim hardy

    User Avatar
    Science Advisor
    Gold Member

    Well the switch looks like it has six positions
    and with three bits you can decode eight states..

    Datasheet shows three switches that connect four terminals, see "electrical sketch" on page 2.
    If you applied voltage to one pin, maybe pin 1-
    The other three pins would decode to switch position.
    Presumably you can read in a word from that port expander and examine the individual bits.

    Be sure the program handles all eight states - you dont want it to crash if the switch breaks and gives you one of the two missing codes.
  5. Jan 21, 2013 #4
    None of that tells me anything I didn't already know. This switch configuration looks quite unorthodox, and I've never dealt with it before and have no idea how to deal with it. I was looking for more specific advice on a configuration or sequence of steps I could use to read the switch state.

    If something other than a generic GPIO port expander is necessary to do that, I could work with that. Component count needs to be kept to an absolute minimum though. I2C is also required.

    The actual project I'm looking to do with a switch like this is modifying a Wii Nunchuck to add some extra controls and interface it to a computer as a USB HID device. This is one switch I was looking at to act as a mouse scroll wheel.
  6. Jan 21, 2013 #5

    jim hardy

    User Avatar
    Science Advisor
    Gold Member

    Connect switch pins 0,1,2,3 to port bits 0,1,2,3 .
    connect +5V to pin 1.
    Read the four bits, pin high = 1
    Initial = 0101
    Scan Left = 1100
    Scan Right = 0100
    Select Left = 1101
    Select Right = 0111
    Select mid = 1111

    Note the drawing itself is ambiguous about select left & right
    http://www.mouser.com/ds/2/60/TPC_31aug10-23106.pdf page 2
    but a simple continuity check with multimeter will show for sure how it's wired.

    I was unable to discern from datasheet whether you'll need pulldown resistors,

    If that's not the answer then i misunderstood the question.
  7. Jan 25, 2013 #6
    That is exactly what I was looking for, thank you.

    A more optimal solution, especially since this would be used in a space-constrained project, is to ground pin 1 (or 2, since it's symmetrical) and use the internal pullups on the GPIO chip, instead of requiring 3 external pulldowns.
  8. Jan 25, 2013 #7

    jim hardy

    User Avatar
    Science Advisor
    Gold Member

    YES !!! I knew that you knew and just needed to be convinced of it !

    Thanks for that reponse.

    BUt work it out on paper - be sure each position gives a unique code, and remember to handle the impossible ones so program wont bomb on stuck switch.
    I usually declare 'impossible' code to be same as 'off', so user sees switch malfunction as failure to respond.

    old jim
    Last edited: Jan 25, 2013
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook