HID device with too many inputs

Hello everyone.
I'm working on an HID device, so I'm planning on using an Arduino Pro Micro for it.
The device is essentially a button box, but it contains way too many buttons, so I've considered using an I/O expansion chip.

In particular, ideally the device would have:

  • 4 analog inputs
  • 74 digital inputs

Here are some bullet points of my project and assumptions I made, correct me if I'm wrong:

  • I need the 4 analog pins for analog inputs, which leaves me with 14 digital pins
  • A matrix of 7x7 buttons will still not be enough, so I'm thinking about adding an MCP23017 to expand the inputs, which will require 2 of those digital pins (SDA and SCL).
  • That'd leave me with a matrix of 6x6 and 16 additional I/O pins, which is still not enough, as I have still 34 more inputs to add.

So the way I see it, either I:

  • Use two Pro Micros (which if possible I'd like to avoid), then I wouldn't need the MCP
  • Use an MCP and either build two matrix of buttons, or a larger matrix, using a combination of Pro Micro and MCPs pins (is that possible?)

Is it even possible to have that many inputs in one board? I know Leo Bodnar's boards have a max of 64, but I don't know if that's a Windows limitation or what.
I might not have an option but to use 2 boards, but I'd like to read your feedback.

Thank you

Could You draw a logic block diagram showing the major parts?

Not sure what you mean. Something like this?


Or you want me to draw all the 74 digital and the 4 analog inputs? It's basically a bunch of buttons, switches and potentiomenters.

No, for heavens sake! Maybe You could include the interface between the box and the Arduino? You had some ideas about expander...

The options/alternatives You mentioned are also shown well in a drawing like You did.
Usually, when helpers get it all clear they suggest good ways to go.

I don't see how could I draw something that would make it clearer, but let me try to rephrase my question, as I think it wasn't very clear in my first message.

I want to build a button box, recognizable by the computer as a gaming controller, using the joystick library. Ideally and if possible, I would like to only have one cable going to the computer, so it's detected as only one device.
It needs 74 buttons, and the most efficient way to do that is with a matrix (it should be a 9x9 matrix). But I need the 4 analog inputs (unless I used a multiplexer, but even then, I wouldn't have enough digital inputs).
If it can't be done, I know how to do it with 2 boards, two cables and two devices being detected by the computer, I've done multiple button boxes of over 40 inputs.
So my question is, can it be done only with one cable going out? And if so, in a very general way, how would you suggest to do it?

I was expecting replies in the lines of:

  • No, you can't do that. Windows won't recognize any gaming device with more than 64 inputs.
    Or
  • Yes, you just need to add x number of I/O expanders in parallel

So at this point I'm not looking for a specific solution, just want to know if it's even possible.

Full code below for reference:

#include <PCF8575.h>
#include <Keypad.h>
#include <Joystick.h>

PCF8575 pcf8575(0x20); 

#define NUMROWS 9
#define NUMCOLS 9
#define joyX A3
#define joyY A2
#define joyRX A1
#define joyRY A0
#define gain A10
#define lev A9

byte buttons[NUMROWS][NUMCOLS] = {
  {0,1,2,3,4,5,6,7,8},
  {9,10,11,12,13,14,15,16,17},
  {18,19,20,21,22,23,24,25,26},
  {27,28,29,30,31,32,33,34,35},
  {36,37,38,39,40,41,42,43,44},
  {45,46,47,48,49,50,51,52,53},
  {54,55,56,57,58,59,60,61,62},
  {63,64,65,66,67,68,69,70,71},
  {72,73,74,75,76,77,78,79,80},
};

byte rowPins[NUMROWS] = {P0,P1,P2,P3,P4,P5,P6,P7,5}; 
byte colPins[NUMCOLS] = {P8,P9,P10,P11,P12,P13,P14,P15,7}; 

Keypad buttbx = Keypad( makeKeymap(buttons), rowPins, colPins, NUMROWS, NUMCOLS); 

//Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_JOYSTICK, 81, 0, true, true, false, true, true, false, true, true, false, false, false);
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_JOYSTICK, 81, 0, true, true, false, true, true, false, false, false, false, false, false);

const bool initAutoSendState = true;

int xAxis_ = 0;
int yAxis_ = 0;
int rxAxis_ = 0;
int ryAxis_ = 0;
int rudder_ = 0;
int throttle_ = 0;

void setup() {
  Joystick.begin();
  pcf8575.begin();
}

void loop() { 

  CheckAllAxis();
  CheckAllButtons();
}

void CheckAllAxis(void) {
  xAxis_ = analogRead(joyX);
  xAxis_ = map(xAxis_, 0, 1023, 255, 0);
  Joystick.setXAxis(xAxis_);

  yAxis_ = analogRead(joyY);
  yAxis_ = map(yAxis_, 0, 1023, 0, 255);
  Joystick.setYAxis(yAxis_);

  rxAxis_ = analogRead(joyRX);
  rxAxis_ = map(rxAxis_, 0, 1023, 0, 255);
  Joystick.setRxAxis(rxAxis_);

  ryAxis_ = analogRead(joyRY);
  ryAxis_ = map(ryAxis_, 0, 1023, 0, 255);
  Joystick.setRyAxis(ryAxis_);

  rudder_ = analogRead(gain);
  rudder_ = map(rudder_, 0, 1023, 0, 255);
  Joystick.setRudder(rudder_);

  throttle_ = analogRead(lev);
  throttle_ = map(throttle_, 0, 1023, 0, 255);
  Joystick.setThrottle(throttle_);
}

void CheckAllButtons(void) {
      if (buttbx.getKeys())
    {
       for (int i=0; i<LIST_MAX; i++)   
        {
           if ( buttbx.key[i].stateChanged )   
            {
            switch (buttbx.key[i].kstate) {  
                    case PRESSED:
                    case HOLD:
                              Joystick.setButton(buttbx.key[i].kchar, 1);
                              break;
                    case RELEASED:
                    case IDLE:
                              Joystick.setButton(buttbx.key[i].kchar, 0);
                              break;
            }
           }   
         }
     }
}

Thanks

Can you be certain there will only be one button pressed at a time?

Some of the inputs are toggle switches, so no, there might me occasions when more than one button will be pressed at the same time. There's actually two two-stage triggers, which by definition will have at least two buttons pressed at the same time (first and second detents)

I just realized I actually need 6 analog pins :sweat_smile:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.