1

Hello I have flashed my Arduino Uno with USB keyboard firmware from this tutorial http://mitchtech.net/arduino-usb-hid-keyboard/#comment-6786, and I have been successful sending individual key presses but, not when trying to press an hold a key. I am attempting to use this firmware to create a custom Game Pad to USB adapter, the only issue is sending simultaneous keystrokes (not sending them one at a time). If you know how to accomplish this task I would be very happy. The technical term for this is "Key Rollover"

  • Howmany buttons are you checking and to which pins do you have them connected? – aaa Apr 30 '15 at 11:39
  • My game pad has 12 buttons, and they are connected with shift registers so only 3 pins. Checking the button states isn't the issue. I am trying to use the game pad as a keyboard with the Keyboard firmware from the tutorial above but, to play games I need to be able to press many keys simultaneously. – Brandon Bahret Apr 30 '15 at 22:23
  • The easiest option would be to switch to an Arduino that has a USB-capable main MCU, such as the Leonardo. – Ignacio Vazquez-Abrams Apr 30 '15 at 22:58
  • I understand why this would be a good way to do this since the people from arduino provide a keyboard library for the Leonardo but, with my arduino uno I have already got to be plug n' play as a keyboard. The problem is getting more than one button press at a time. I need to add simultaneous key presses "Key Rollover" – Brandon Bahret Apr 30 '15 at 23:06

3 Answers3

0

You don't want to send random keys do you?

Well consider using the code below as your base. It's using Port Manipulation to read the buttons (Digital 0 to 7).

void setup() 
{
  Serial.begin(9600);//Start serial connection.
  DDRD = 0b00000000; //Set Data Direction Register of port D to inputs (attach keys to digital pins 0to7;
  delay(200); //Misc delay.
}

void loop() 
{
  Serial.write(PIND, 8);    // Send states of PORTD (digital 0 to 7)
}

I strongly suggest you use pull-down/up resistors on the buttons also. Adjust your code to the amount of keys you're using, or pull the pins low if not used. To avoid receiving random/floating pin values.

aaa
  • 2,695
  • 2
  • 24
  • 40
  • The problem is not with the '328P itself but with the communications channel with the USB chip. – Ignacio Vazquez-Abrams Apr 30 '15 at 12:01
  • @IgnacioVazquez-Abrams Thanks, I skipped a bit too fast through the article. The new answer should fit the needs of the 'asker'. – aaa Apr 30 '15 at 14:55
  • Sorry, this is not what I am having issues with. I have all ready have the game pad and have been able to read the input values from the controller. When I press one button sending the keystroke is easy. It is when I need to have many key presses as held keys. Other wise the game will think I am repeatedly pressing different buttons. – Brandon Bahret Apr 30 '15 at 20:39
  • Than you should only send the state of your key when it's changed? – aaa May 01 '15 at 06:15
0

After closer research on this topic I have found the answer to my problem but,thank you to all that have tried to help. In order to do "Key Rollover" I needed to write the additional key states to the remaining values of the buffer array then write the values with Serial.write(buf,8). I can now use my Arduino Uno + My Game Pads as controllers for all my computer games.

0

Could you post an example of your updated code? I'm working on a similar project but a complete n00b as far as using the Arduino goes.

user21031
  • 1
  • 1