Complete Noob - looking for guidance

Yes, you need to use the keyboard library. Read about it here.

Is there a way to test code without the hardware?

From what I am finding, the arduino "keyboard" is just pressing an already existing key. So it would be like programming push button 1 as a second keybind for the "P" key. Is that a correct assessment?

FYI, I hit my max posts for one day as a new user. I will either edit this post or wait until tonight

Wildbill, from post #24; I do not have access to a breadboard for testing. Is there a free software that will emulate the hardware so I can test the code?

Yes, broadly. You could program one of your buttons to send multiple keystrokes of course.

Also, as I said, it depends on the game. Some sims will take inputs over serial or Ethernet.

As to testing without hardware, can you breadboard a few buttons for initial tests?

Well, that would depend on whether that is actually a ground connection attached to other grounded things, or just a common connection. Matrix connections necessarily work with some common connections.

Let's see. If you had 11 buttons in a single matrix, you need only 7 pins to read them rather than 11 separate. But if there is a risk of more than two buttons pressed simultaneously, you need a diode for each button.

If you had to separate out two buttons on individual pins, the nine others would require six pins in a matrix, so you would be using eight pins. Still worthwhile if you are short on pins; you save three, but if the 11 pins are available and will not be needed for a later upgrade you can argue it makes coding a little easier - but not a lot, because with a matrix you natively debounce all buttons together.

With correctly written debounce code, that delay will be about 5 milliseconds. Note that I say correctly written debounce code which waits for stability for a multiple of the period of a bounce rather than a multiple of the total bounce time.

Hi,

That can make how you configure your switches and read them very important.

Can you draw a basic diagram as to how you would connect 11 push buttons to a Micro as well as custom joysticks, you may need a port expander.
How many inputs for the joysticks, 2 or 4 analog needed?
How will you communicate between your controller and the PC?

Can you please tell us your electronics, programming, arduino, hardware experience?

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

The whole idea of using a Micro is to use it as a HID device.

First, sorry for the late reply. As a new member I could not post anymore until now.

@wildbill

I do not have access to a breadboard for testing. Is there a free software that will emulate the hardware so I can test the code?

There are two grounds running to the head of the joystick. One is there from previous buttons on the head the other other is for my modification. The original ground wire goes to the PCB, which also gets all of the wiring from the original buttons plus 2 new wires for 2 more buttons. Then the other new ground is for 9 new buttons. I am not sure that a matrix is doable to it's full potential the way I have the wiring done in the head of the joystick.

There is a risk of more than 2 buttons being pressed at the same time, in fact I believe 2 buttons will be pressed at the same time more than only one pressed at once. This is a version 1 design for this project, I foresee it getting redesigned in the future, but the way I have it now will use the most amount of buttons possible. So the current design will use the most amount of pinouts on the Arduino.

To me, 5 ms does not seem too bad for a gaming controller. Do you know what the typical controller delay is?

@TomGeorge

I guess I should have started will a diagram of my wiring from the beginning and maybe explained how I am doing this project. Please see the quick drawing below as a reference wiring diagram.

Red boxes - buttons.
black - gnd
blue - original wiring (no arduino)
purple - new wiring (arduino)

I am using a set of Thrustmaster t16000 joysticks. Originally the head of the joystick has 8 functions (trigger, 3 buttons and a hat switch). I am remodeling the grip and head of the joystick completely. The 8 wires and ground from the original head are being used on a PCB with tact switches. Then I have 12 wires in addition running to the head for additional buttons and another ground. The original 8+gnd are still wired into the joysticks PCB and will not be added to the Arduino. The 11 extra wires are what I am worried about.

I cut the USB cable off the joystick and soldered it onto a USB hub. The Arduino will be connected to the USB hub as well. Then the output of the hub will be one wiring coming out of the base just like original.

My experience with coding is extremely minimal. I used MatLab in college, but that is nothing like C++ or Python. Electronic work I try and stay away from. Modeling and mechanics... I live it.

I am looking to learn from this project and I came here because I thought the community would be helpful and so far I am impressed with the support. I appreciate it greatly.

Yecch! :woozy_face:

Well you would need a diode for each button in a matrix. Obviously this does not apply to buttons wired per pin.

I am sure it would not be.

No idea! :grin: I am not a gamer.

I can't quite figure why you would do that!

Looks like I'll be wiring a pin per button, so no diode required.

I did it because I only wanted one USB coming out of the base of the joystick. I'm sure there is a better way to do it, but I thought it was a good idea at the time.

Simulators exist. I don't know how clever they are at giving you bounce on buttons though. I'd strongly suggest that you get a breadboard or whatever other mechanism you need to do live testing to eliminate surprises before you solder everything up.

OK, so I gather you are trying to fit it all into a small space and removing the male and female connectors in order to do so. No problem with that.

Yes, where all the buttons are is very tiny and difficult to work with. The less I have going on up there the better. Now down in the base is another story. I have room to work with so adding a USB hub inside made the most sense to me.

I have been traveling for work the past week and did not have a chance to work on this project. I would love to work on it some more this weekend.

Would it be easier to rewire everything into a matrix instead of what I am doing currently?

I could use the PCB, but wire grounds straight to the pin on he button instead of using the common ground that is within the PCB.

I think the wiring setup I have now will work, but it does not seem like a conventional thing to do for a button box.

If you have enough pins to do it without a matrix arrangement, stick with what you have.

I think I touched on this before, but I am not sure I was clear enough.

If the code has

Keyboard.print("d");

for one of my pushbuttons, then the game will recognize that the d key was pressed and whatever the d key is binded to in the game that function will be done?

That's it.

I am getting this error, but I do not understand why it is an error

Sketch uses 2140 bytes (6%) of program storage space. Maximum is 32256 bytes.
Global variables use 256 bytes (12%) of dynamic memory, leaving 1792 bytes for local variables. Maximum is 2048 bytes.
An error occurred while uploading the sketch

This is the bit of code I am working with:

#define key1 2 //connect wire 1 to pin 2
#define key2 3 //connect wire 2 to pin 3
#define key3 4 //connect wire 3 to pin 4
#define key4 5 //connect wire 4 to pin 5

void setup() {
Serial.begin(9600);
pinMode(key1, INPUT_PULLUP);// set pin as input
pinMode(key2, INPUT_PULLUP);// set pin as input
pinMode(key3, INPUT_PULLUP);// set pin as input
pinMode(key4, INPUT_PULLUP);// set pin as input
}

void loop() {
int key1S = digitalRead(key1);// read if key1 is pressed
int key2S = digitalRead(key2);// read if key2 is pressed
int key3S = digitalRead(key3);// read if key3 is pressed
int key4S = digitalRead(key4);// read if key4 is pressed

 if(!key1S){
  Serial.println("key 1 is pressed");
 }
 if(!key2S){
  Serial.println("key 2 is pressed");
 }
 if(!key3S){
  Serial.println("key 3 is pressed");
 }
 if(!key4S){
  Serial.println("key 4 is pressed");
 }          
 delay(100);

}

with 2 switches the example uses an if-else instead of switch-case.

// with 2 buttons, this is how the button branches to the right action.
        if ( buttonIndex == 0 )  // button zero starts and stops blink
        {
          if ( waitBlink == 0 ) // toggle action tied to button press
          {
            waitBlink = 500; // makes the blinking start
            startBlink = millis(); // gets the low 16 bits
          }
          else 
          {
            waitBlink = 0; // makes the blinking stop
          }
        }
        else // press button 2 changes the blink rate
        {
          if (( waitBlink -= 100 ) < 100 ) // setting a var in an expression is okay C
          {
            waitBlink = 1000;
          }
        }

Your sketch compiles okay but won't upload. There can be different reasons why, check if the port shows up in the IDE. You may check wiring.