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"

asked Apr 30, 2015 at 8:06
4
  • Howmany buttons are you checking and to which pins do you have them connected? Commented Apr 30, 2015 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. Commented Apr 30, 2015 at 22:23
  • The easiest option would be to switch to an Arduino that has a USB-capable main MCU, such as the Leonardo. Commented Apr 30, 2015 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" Commented Apr 30, 2015 at 23:06

3 Answers 3

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.

answered Apr 30, 2015 at 11:49
4
  • The problem is not with the '328P itself but with the communications channel with the USB chip. Commented Apr 30, 2015 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'. Commented Apr 30, 2015 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. Commented Apr 30, 2015 at 20:39
  • Than you should only send the state of your key when it's changed? Commented May 1, 2015 at 6: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.

answered Apr 30, 2015 at 23:59
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.

answered May 13, 2016 at 18:56

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.