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

Thread: Using individual push buttons to control individual LEDs on a ws2811 strip

  1. #1
    Junior Member
    Join Date
    Feb 2016
    Posts
    13

    Using individual push buttons to control individual LEDs on a ws2811 strip

    Hi,

    I would like to control each individual LED on a ws2811 strip with its own push button.

    I have seen people talk about using a deconstructed keyboard to do this.

    Is that the best option? I have 50 LEDs that need their own switch. They will light for a specific time only, so I don't need a 2 position switch.

    Any help gratefully received!

    Rob

  2. #2
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,256

    Cool

    Well three ideas come to mind to get 50 buttons:

    1) Use 4 mcp23017 i2c chips hooked to your i2c bus (pins A4 and A5, note on Teensy, you will need pull-up resistors, in the 2.2K - 4.7K range on each of A4/A5). You would have to set the address pins so each of the 4 mcp23017 chips has a different i2c address. Adafruit sells the mcp23017, but you can get them elsewhere as well: https://www.adafruit.com/products/732. You would only need 2 pins for the i2c support (normally A4/A5), and you can share the i2c bus with other i2c devices.

    2) Use resistor ladders, and hook up several buttons with specified resistors to multiple analog pins. Here is a tutorial I found via a google search. I don't know if the resistor values need to be adjusted for 3.3v: http://tronixstuff.com/2011/01/11/tu...tiple-buttons/. If you figure 5 keys per analog pin, you would need 10 analog inputs to disambiguate the input.

    3) Use the Matrix keypad library, perhaps 8x7: http://playground.arduino.cc/Main/KeypadTutorial. For a 8x7 matrix, you might need 13 digital pins (note analog pins A0..A9 can be used as digital pins, but A10..A14 cannot).
    Last edited by MichaelMeissner; 02-06-2016 at 07:24 PM.

  3. #3
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,710
    How many do you want to be able to access how quickly? Are they grouped for some function or wholly dispersed.

    You could connect one or more touch displays and put buttons on the screen to actuate them from software. For causal access you could make multiple pages of buttons - for more direct access you'd want multiple screens so you could get to all of them as the screen would get crowded near 25 and you might get mis hits. *though there isn't direct support for multiple screens at this time in the button code shown.

    ILI9341-and-XPT2046-for-Teensy-Touchscreen-320x240-display
    Last edited by defragster; 02-06-2016 at 11:53 PM.

  4. #4
    Junior Member
    Join Date
    Feb 2016
    Posts
    13
    Thanks for your replies. Unfortunately I can't use a touch screen although that's a neat solution. I need physical buttons next to each LED.

    I like the idea of using MCP23017 port expanders. I've never used the i2c bus before. Is it straight forward enough to set the address pins?

    The other solutions won't really work as buttons may be pressed simultaneously which would stop the resistor ladder method from working properly and the other method uses too many pins

    Has anyone any experience of using keys of a USB or PS2 keyboard to act as switches?

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,576
    The MCP23017 chips are a great solution. In these sorts of projects, reducing wiring work and troubleshooting is usually the key to success. These should keep the wiring mostly confined to groups of 16 buttons, with relatively few wires between them. It also has the nice advantage of easy-to-check DC voltage on every button.

    If your goal is to properly detect simultaneous pressing on many buttons, you probably should avoid using the electronics from a consumer PC keyboard. Most have circuitry that can only detect 6 (or fewer) simultaneous key presses.

  6. #6
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,256
    Quote Originally Posted by Robhilken View Post
    Thanks for your replies. Unfortunately I can't use a touch screen although that's a neat solution. I need physical buttons next to each LED.

    I like the idea of using MCP23017 port expanders. I've never used the i2c bus before. Is it straight forward enough to set the address pins?
    To set the address pins, you connect the pin to either ground or power. I found it simplest to use either a breadboard or a perma-proto board laid out like a breadboard (https://www.adafruit.com/products/1608).

    Adafruit has a library to access the pins: https://github.com/adafruit/Adafruit...rduino-Library

    If you want to optimize things, there are two pins (INTA and INTB) that are set high when their is a change to either the A bank of 8 pins or B back of 8 pins changed (you could attach these to a pin on an interrupt so you know when a button was pressed or released). Also, the protocol gets things in 8 bit chunks, so rather than doing an individual read via the digitalRead accessor function, you can use readGPIO to read 8 bits at a time or readGPIOAB to read all 16 bits. But if you are waiting for human input, it may be fast enough just doing it bit at a time.

    Also, if you are using the neopixels just as on/off lights, and not really using the color capability, you could use 7 MCP23017's, and put 8 buttons and 8 LEDs on each MCP23017 (you can use the MCP23017 as digitalRead or digitalWrite replacements.

    Quote Originally Posted by Robhilken View Post
    The other solutions won't really work as buttons may be pressed simultaneously which would stop the resistor ladder method from working properly and the other method uses too many pins
    I've seen designs for a resistor ladder where you can detect simultaneous button presses.

    Except for the Teensy 3.0, the 3.1/3.2/LC all have 2 i2c ports, so you could put 8 MCP23017's on one i2c port and 8 on the second. Going further, there are i2c multiplexers, such as onehorse's board: https://www.tindie.com/products/oneh...c-multiplexer/.

    Note, there are distance constraints with i2c.
    Last edited by MichaelMeissner; 02-07-2016 at 01:35 PM.

  7. #7
    Junior Member
    Join Date
    Feb 2016
    Posts
    13
    Quote Originally Posted by MichaelMeissner View Post
    Also, if you are using the neopixels just as on/off lights, and not really using the color capability, you could use 7 MCP23017's, and put 8 buttons and 8 LEDs on each MCP23017 (you can use the MCP23017 as digitalRead or digitalWrite replacements.
    The button will light the assigned LED but might trigger actions that also feature other lights, or potentially also trigger sounds etc so it needs to be as flexible as possible. I will definitely be using the colour capability of the ws2811 strip.

Tags for this Thread

Posting Permissions

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