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

Status
Not open for further replies.

Robhilken

Member
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
 
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/tutorial-using-analog-input-for-multiple-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:
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:
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?
 
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.
 
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-MCP23017-Arduino-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.

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/onehorse/tca9548a-i2c-multiplexer/.

Note, there are distance constraints with i2c.
 
Last edited:
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.
 
Status
Not open for further replies.
Back
Top