I have a project where I have to create a custom keyboard with limited set of keys. I have an Arduino Mega 2560 board for this, as it has enough inputs to handle the ~30 keys. I'd like to use the onboard USB connection for this, so that I can avoid buying any additional hardware like USB shield.
I found this lib http://arduino.cc/en/Reference/MouseKeyboard but it is only for Leonardo, Micro, or Due. My code that uses Keyboard.begin(); just doesn't compile for Mega 2560. So, I read that I need to rewrite the board's firmware to make it appear to PC as a keyboard.
Since this is terra incognita for me, I don't want to screw things up - to brick the board or lose the ability to flash new programs using the standard Arduino IDE (as one guy warns here: arduino mega 2560 as HID USB keybaord - Programming Questions - Arduino Forum). I don't understand why it is so different for Leonardo, why the Mega firmware couldn't act as transparently as Leonardo's, to allow both HID functions and loading programs from IDE simultaneously.
I don't understand why it is so different for Leonardo, why the Mega firmware couldn't act as transparently as Leonardo's, to allow both HID functions and loading programs from IDE simultaneously.
Take a look at the hardware involved. Both use an ATMega chip for the processing, but the USB to serial converter chip is quite different between the Leonardo and the Mega. It is that hardware that determines how the Arduino appears to the PC.
Ok, I accept that. But is it impossible to put Mega 2560 in such a mode that it can both push keystrokes to the PC over the built-in USB, and accept programming from IDE? If not, what is the best way to deal with that? Attaching another USB socket to couple of pins and emulating HID on them?
@kowalski, the number of keys (I need about 30) is too large for Leonardo to handle. That is, unless some smart system of wires and controllers is introduced to translate the key presses to smaller number of pins. But that would introduce a risk that simultaneous key presses are misinterpreted.
@guix Yes, that would be a way to go, if the "appear to PC as a normal keyboard" solution turns out to be so hard to get that it is not worth the effort.
@Passiday, I realize this post is from over two years ago, but I'm wondering if you were able to figure out a solution? I'm working on a project that has similar requirements--enough pin inputs to need a Mega, but also needing it to function as a computer keyboard. If you have any input on how you got your project to work, I'd appreciate it.
I know its been a while since the last post here, however I'm replying just in case someone (like me) finds this topic on Google while having the same problem.