-
Notifications
You must be signed in to change notification settings - Fork 412
How can I connect 32 (or some other large number) of buttons to an Arduino Leonardo or Arduino Micro that only has 13 digital pins and 6 analog/digital pins?
There are various ways this can be done.
- The Arduino website has a good example of how this can be done using a one or more SN74HC165N shift registers (see https://playground.arduino.cc/Code/ShiftRegSN74HC165N).
- Another possibility is using an encoder, like the 74LS348.
- A key matrices can also be used. A good article on key matrices can be found at http://pcbheaven.com/wikipages/How_Key_Matrices_Works/.
I can only see 32 buttons. Can the library support more than 32 buttons?
The library can support more than 32 buttons, however most applications cannot see that many buttons. Different applications use different APIs to read data from the Joystick. The number of buttons supported is typically limited by the API used by the application. For example:
XInput supports maximum of 4 axes, 10 buttons, 2 triggers and 8-direction digital pad per controller, compared to DirectInput's support for 8 axes, 128 buttons, and full-range POV. (The number of axes, buttons and triggers XInput supports corresponds directly to the Xbox 360 controller.)
From https://en.wikipedia.org/wiki/DirectInput
The built-in Windows 10 Joystick test application can only see 32 buttons, even if more than 32 are defined:
Pointy's Joystick Test can support up to 128 buttons:
When I plug my Arduino Leonardo or Arduino Micro into a machine running Linux, the joystick does not appear.
or
I only see one joystick when I connect my Arduino Leonardo or Arduino Micro into a machine running Linux, but I have 2 (or more) defined.
To get this to work on Linux, you may need to adjust a setting on the usbhid driver. This can be done by editing the /boot/cmdline.txt file. Add one of the following strings to the end of the line of text in this file (there should only be one line of text in this file):
- For the Arduino Leonardo
usbhid.quirks=0x2341:0x8036:0x040
- For the Arduino Micro
usbhid.quirks=0x2341:0x8037:0x040
See the following blog article for more details: http://mheironimus.blogspot.com/2015/09/linux-support-for-arduino-leonardo.html
Thanks go out to @faxm0dem for this question and answer.