Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 12 of 12

Thread: 4-8 key "keyboard" with long cables?

  1. #1
    Junior Member
    Join Date
    Aug 2017
    Location
    Sweden
    Posts
    7

    4-8 key "keyboard" with long cables?

    Hi,

    So I've just started building stuff with hardware coming from a software background. My plan is to build a device that works like a keyboard for the computer it's connected to, but is a set of 4-8 buttons (yet to be decided) where each button might be pressed up to 3 times per second, and they might be pressed at the same time. Google suggested the Teensy2++ and thus I have a few questions about it

    a) would a teensy be able to handle 8 simultaneous key presses?

    b) could i use a common ground for the buttons? I assume I would have to connect diodes in some way for that to work?

    c) a keyboard matrix would need three wires per switch, right? Row, col and ground? Would I need a keyboard matrix for 8 buttons or could I get away with just 2 wires per button by connecting each to its own positive pin and a common ground?

    d) would it work with 10-20m cable between the teensy and each button? I'm still looking into what cables and connectors I could use, but as a sound technician I'm thinking about using what I have: audio cables and mono phono connectors (6.3mm)

    e) would USB power be enough?

    What do you think? Thanks in previous! And I really hope this isn't the completely wrong place to ask! (also posted on r/teensy)
    Last edited by swantzter; 08-05-2017 at 04:07 PM.

  2. #2
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,928
    For a. - answer is yes, but USB HID will constrain things because the keyboard message structure limits how many keys can be sent as 'down' at the same time
    https://www.pjrc.com/teensy/td_keyboard.html
    see 'micro managment way' for how to send multiple keys.

    b/c is mixing up several things. With 4-8 keys the easyist method is to just wire each to a GPIO pin and ground, set pinmode(x,INPUT_PULLUP) and for better results use the bounce library https://www.pjrc.com/teensy/td_libs_Bounce.html

    If you want lots of inputs you can use port expander ICs on 2-3 pins, the matrix library https://www.pjrc.com/teensy/td_libs_Keypad.html for a pin per row and column (6 for 9 buttons in 3*3, also 6 for 8 in 2*4) or you can be old school and use a diode matrix, which won't support multiple keys down. Would suggest at least to start with use one button per input.

    d. Cable length would be a problem, will still work but there will be time delays and quite possibly EMI issues. Depending on risk best method may be to try it and see, if it doesn't work then the method would be to add another teensy at the buttons and use a serial interface with balanced lines and error correction to send the data

    e. USB power will be enough as long as you don't need high current (lights/displays) at the remote keypad, or you try to fix noisy wiring by boosting the current with lower pullup values.

    Re Teensy choice T2++ will do the job and have lots of examples around the place, but the newer LC or 3.2 will get you newer and more robust USB stack. Note that while you can get a cheap T2++, if they cost less than the ones on the PJRC store then you are buying a counterfeit. For your first project suggest making sure you get a real one, since the failure rate of counterfeits for all arduino types is high and you really want a known good item for your first project. Ditto if you can afford it strongly suggest ordering at least two of whatever device you choose, so if things stop working you have another right there to compare with.

  3. #3
    Junior Member
    Join Date
    Aug 2017
    Location
    Sweden
    Posts
    7
    Thank you!

    Well I think hooking each one to a separate pin would be enough then!unfortunately putting a teensy at each button wouldn't be a suitable/cost effective option as the buttons themselves will be 15-20 meters from the main teensy, and 10-15 meters apart from each other... So I'll just hope it'll work, or maybe I should resort to a twisted pair cable?

    For the bounce library, would that be a working option for self built switches? (basically metal touching metal) or would I add a 10k resistor on the positive lead for it to work?

  4. #4
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,928
    Bounce is just a library to handle the fact that switches don't toggle just once when pressed or released so a great idea to use for any mechanical switch, but critical with homebrew designs that chatter.

    See photos here for what your code has to deal with
    https://www.pololu.com/docs/0J16/4

    You don't have to use it, but you will need to handle switch bounce in some form.

    Twisted pair will help, though the big thing will be current. The more stray currents from EMI and capacitive effects you have the more current you need through your switch to get a clean read. So the easy design using the internal pullups may not work reliably, and you need to add a 1k or power pullup and live with the much higher current draw. from your power supply. Main thing will be to build it and see, it can certainly be made to work with a bit of tinkering.

    What was your intention with the 10k resistor?

  5. #5
    Junior Member
    Join Date
    Aug 2017
    Location
    Sweden
    Posts
    7
    Ah, thank you!
    I didn't really have any thought with the 10k resistor, I just saw someone else reccomended it for another project and thought it might apply to this as well.

    What effect would adding a 1k resistor as you wrote give? Would it somehow stabilize it? And by power pullup, do you mean something software, or would I add an external battery to the teensy to give it more power?

  6. #6
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,906
    Where do you want to use it ? At home or in a more "robust" environment ?
    I think, very simple and robust, for a beginner is to use relays - the buttons switch the relays (use a dedicated 2nd power supply - 12V or better 24V for example), and the teensy reads them. Needs more current of course (for the short time when a button is pressed) but is very robust. You can place the relays near the teensy. Just make sure that the Teensy NEVER gets in contact with the 12V.. it will die.

    Relays are easy to use, proven and reliable since >100 years

    For use at home or similar, this is not needed, i think.

    Edit: I'd use a Teensy LC or 3.2
    Edit: The combination of relays and 32-bit microcontrollers is a bit "steampunk", too.. use some with visible mechanics
    The next step would be optocouplers.. but they are a bit more complicated to use.
    Last edited by Frank B; 08-06-2017 at 10:00 PM.

  7. #7
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,928
    @ swantzer


    The easy method to wire buttons is as described here
    https://learn.adafruit.com/adafruit-...nputs/overview
    using the internal pullups
    https://en.wikipedia.org/wiki/Pull-up_resistor
    So the micro controller uses high value internal resistors to keep the pin a 3.3V when the button is open, and the whole wiring system gets pulled to gnd when the button closes. So in physical terms you could think of it as having a small spring that pushes a valve closed when you release it a lever. Problem is there are a number of effects that may overcome that fairly week spring either temporarily (noise) or make it slow to respond (when you release the button). If that is the case adding a lower value resistor makes the 'spring' stronger and more reliable, at the cost of more current flow when the switch is closed. Note that even going to a 1K resistor thats 3.3 mA so 8 of them will not come close to the 250mA you have availible from USB after powering the Teensy. Obviously if you had a 80+ key true keyboard then that 3.3mA per key when pressed wouldn't looks so good, but for 8 may be the sensible option.

  8. #8
    Junior Member
    Join Date
    Aug 2017
    Location
    Sweden
    Posts
    7
    It'd be more of a robust environment, ultimately. I'll have to have a look at relays. Thanks

  9. #9
    Junior Member
    Join Date
    Aug 2017
    Location
    Sweden
    Posts
    7
    @GremlinWrangler ah, that explains it. Thanks!

    I'm planning to build the switches into tally counters as these ones: https://s3-ap-southeast-2.amazonaws....s_metallic.jpg either in an analog one, or by using the switch on a digital one. So the phase I'm currently at is that I've ordered 2 of each which I'll test building switches into/of that connects properly and try to get a reliable reading over 20m cable. Using the methods you and @Frank B have suggested

  10. #10
    Junior Member
    Join Date
    Aug 2017
    Location
    Sweden
    Posts
    7
    Also, I only have ten 1k resistors at home, but I suspect a 1.2k or 820 would work as well if I run out if 1k while testing?

  11. #11
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,928
    For this pretty much any resistor will work, though if putting a shopping list together getting a grab bag of resistors in sets of ten may be worthwhile. If you have trouble getting your counters to reliably count you may find magnets and either reed switchs or the more complex hall effect sensors can you a contact closure that's good for large numbers of cycles. Going for hall effect though will mean you end up with three wires (power/gnd/signal) and most likely some hardware so would be a third tier choice.

  12. #12
    Junior Member
    Join Date
    Aug 2017
    Location
    Sweden
    Posts
    7
    Ah, great! I'll have a look at different switch options there as well, they do look interesting. And if I'm going to use what cables I have I could perhaps then just go with a stereo audio cable (which I have like 400 meters lying around...)

    I have a complete set of E12 resistors, 10 of each, because I once needed one 6k8 resistor as a replacement, and that was the smallest pack my local reseller had...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •