Arduino UNO Keyboard HID version 0.3

I've updated the Keyboard firmware to support key usage codes greater than 101. The maximum code is now 231 so you can send all of the key usage codes defined in HID Usage Tables (e.g. 128 Volume Up and 129 Volume Down).

A big thank you to Feiltom for discovering the problem and the cause - the keyboard report descriptor was limiting the maximum key code to 101.

Download file "Arduino-keyboard-0.3.hex"
Download file "Arduino-keyboard-0.3-mega2560.hex"
Download file "arduino-keyboard-0.3.tar.gz"
Download file "kbd_usb_demo.pde"

Comments

vcazan (unauthenticated)
Apr 18, 2011

Thanks for this! We are building a softkeyboard for children with disabilities and this is exactly what we were looking for.

Jason (unauthenticated)
May 8, 2011

Hi

Do you have steps on how to use this. I am relatively new to Arduino?

Cheers

Jason

darran
May 8, 2011

Hi Jason,

I've put details in my earlier posts (e.g. http://hunt.net.nz/users/darran/weblog/faf5e/Arduino_UNO_Keyboard_HID_part_2.html).

Cheers,
Darran.

Girts (unauthenticated)
May 9, 2011

Hey Darran,

thanks for the library! I was debugging an issue with the library and looking at arduino-keyboard-0.3/Descriptors.c. Is the extra zero on the following line intentional?

0x26, 231, 0, /* Logical Maximum (231)

My issue turned out to be unrelated to this though.

Cheers,
Girts

darran
May 11, 2011

Hi Girts,

yes the 0 is intentional because I've used a 2-byte logical maximum there (0x25 is one byte, 0x26 is two bytes). I did this because it seems to be the only way to get the increased range (231) working on Linux, OSX, and Windows.

Cheers,
Darran.

TempQ (unauthenticated)
May 14, 2011

Hey,
I am new to the whole Arduino Environment and I have successfully used your firmware to emulate a keyboard with an Uno as one of my first projects, thanks for that btw., but now I am wondering if it is possible (I tried and failed, maybe because it is impossible) to only build the firmware directly, bypassing the Arduino IDE, so another board, an ATMEGA8U2 Breakout Board ( http://www.sparkfun.com/products/10277 ) would be able to emulate a key press, lets say ctrl+h every second, with only the hex file.
Thanks in advance.

TQ

darran (unauthenticated)
May 17, 2011

Hi TempQ. I think you should be able to build firmware just for an atmega8u2. The LUFA project is the best place to look for example code.

TempQ (unauthenticated)
May 21, 2011

Thanks for your reply darran, I have spent countless hours trying to get the full LUFA Project to work on Linux and Windows but it wasn't really that beginner friendly and I got a bunch of complications and understanding the whole thing was a bit too much for me.
I ended up using Teensyduino librarys ( http://pjrc.com/teensy/td_keyboard.html ). It fully integrates into the Arduino IDE and spits out a hex you can then flash onto AT90USBxxx (and other) devices. Got what i wanted working within 15 minutes of first discovering it.

ddtof (unauthenticated)
May 31, 2011

Hi,
Do you think I can use that for Arduino Duemilanove with ATmega328? The bootloader seems to be 2K while it is 0.5K for the UNO :(
Thanks.

ddtof (unauthenticated)
May 31, 2011

I just see that the Duemilanove has not a ATMEGA8U2 but a FT232RL :(
Does it change something ?
Do you have any idea how I could transform it as a Keyboard HID ?
Thanks a lot in advance.

darran
Jun 2, 2011

Hi ddtof,

the firmware here is only for the atmega8u2, or just the Arduino UNO and Mega2560. Unfortunately the Duemilanove FT232RL cannot be reprogrammed to be an HID device. You can get a shield with USB support or try the Virtual USB approach here: http://www.practicalarduino.com/projects/virtual-usb-keyboard .

Regards,
Darran.

Paul (unauthenticated)
Jun 12, 2011

Thank you so much. Got this working. Using it to help a friend with CP make a custom keyboard. This is really wonderful. Thank you.

darran
Jun 15, 2011

Hi Paul, cool to hear that its working for you. Cheers, Darran.

MatthewAveryUSA (unauthenticated)
Jul 2, 2011

Darren,
Great stuff, thanks. There's a tiny mistake in your demo code where you swapper CTRL and SHIFT keys. Should be:

#define KEY_LEFT_SHIFT 0x01
#define KEY_LEFT_CTRL 0x02
#define KEY_RIGHT_SHIFT 0x10
#define KEY_RIGHT_CTRL 0x20

-Matt

MatthewAveryUSA (unauthenticated)
Jul 2, 2011

Darran,
Disregard the first comment, this is the modifier mapping (all 8 bits):

#define KEY_LEFT_CTRL (1<<0)
#define KEY_LEFT_SHIFT (1<<1)
#define KEY_LEFT_ALT (1<<2)
#define KEY_LEFT_GUI (1<<3)
#define KEY_RIGHT_CTRL (1<<4)
#define KEY_RIGHT_SHIFT (1<<5)
#define KEY_RIGHT_ALT (1<<6)
#define KEY_RIGHT_GUI (1<<7)

darran
Jul 5, 2011

Hi Matthew, thanks for the feedback. I'll check it out and update the sketch.

Cheers,
Darran.

JoLau (unauthenticated)
Sep 22, 2011

Hi Darran,
Thanks for your keyboard driver. Now I have successfully loaded it on my Arduino UNO with Flip. I have tested your processing script from this page. The 'normal' keys like 'A' are working perfectly, but the keys Volume Up and Down don't work. Have you any idea why?

JoLau

Au (unauthenticated)
Oct 6, 2011

Hey Darran,

I am using a Mega 2560 and have been able to successfully flash the -0.3-mega2560.hex code onto it using Flip. However, when I do, the chip seem to start constantly outputting junk (random beeps from windows when sitting on the desktop, or if I open up a text editor it shows a constant stream of garbage). It also seems to be causing something like the shift key (and possibly alt as well) to be held down, even after I unplug the device, forcing me to reboot. When connected, my device manager shows a new HID device, but not the Arduino (not sure if that's the normal case or not).

So, I went ahead and flashed back to the default usbserial (everything working as normal), re-downloaded the -0.3-mega2560.hex file (just in case), and flashed it back on. Same result. Any suggestions?

Thanks,

-Au

darran
Oct 10, 2011

Hi Au,

that's weird. What sketch did you have loaded before you flashed the hex code with Flip?

Darran.

darran
Oct 10, 2011

Hi JoLau,

how are you testing the volume up and down keys? Do you have a sketch sending them? Can you post the sketch on http://pastebin.com/ and send me the link - I'll take a look and see if I can spot any problems.

Thanks,
Darran.

Au (unauthenticated)
Oct 12, 2011

Hmm... so, I went ahead and loaded an empty sketch - for sanity check - and now it seems to be fine. To the best of my knowledge there wasn't anything too crazy going on in the sketch that I was trying to use (just bit twiddling of the IO pins), but I guess something in there was making things unhappy. If I narrow down what was causing the problem, it's reproducible, and isn't due me doing something obviously stupid I'll let you know.

And, just because I haven't seen it explicitly stated anywhere (though I may have missed it), I am assuming that I have to re-flash back to the ardiuno-usbserial firmware every time I want to upload a new sketch, yes? Or is there a way around that?

Thanks,

-Au

darran
Oct 12, 2011

Hi Au,

maybe the sketch was sending data to the serial port? That would make the USB driver in the 8u2 behave badly.

Yes you're right you'll have to reflash the arduino-usbserial firmware whenever you want to update the sketch.

Cheers,
Darran.

Franz (unauthenticated)
Oct 19, 2011

Hello darran! Thank you a lot for the effort you are putting into this, I tried your keyboard demo and it's really nice!
I wanted to know if there's a way to make the arduino appear as a "combo" mouse/keyboard HID. I'm asking this since I wanted to build a 1-handed input system much like the twiddler, with one joypad for mouse and some buttons for chorded input of keys.
Is this doable without too much trouble? I am pretty new to the arduino and I can program a bit, but nothing too much low level :P

coopermaa (unauthenticated)
Nov 24, 2011

Hi darran, thank you for making this UNO Keyboard HID.
I have wrote a simple USBKeyboard library for your Keyboard HID. You can find it here:
https://github.com/coopermaa/USBKeyboard

Hope you will be interested with it!

Tom (http://thomaslevine.com) (unauthenticated)
Jan 3, 2012

avrdude suggests that the Arduino-keyboard-0.3-mega2560.hex is not compiled for the Mega 2560.

Further investigation agrees; it looks like you uploaded the Uno file twice.

$ wget http://hunt.net.nz/users/darran/weblog/b3029/attachments/03237/Arduino-keyboard-0.3.hex;wget http://hunt.net.nz/users/darran/weblog/b3029/attachments/b105c/Arduino-keyboard-0.3-mega2560.hex; md5sum *.hex #The md5sums match.

Could you upload the hex for the Mega 2560? (If not, I can build and upload it, thanks to the thorough guide in your earlier posts.)

Tom (http://thomaslevine.com) (unauthenticated)
Jan 3, 2012

avrdude suggests that the Arduino-keyboard-0.3-mega2560.hex is not compiled for the Mega 2560.

Further investigation agrees; it looks like you uploaded the Uno file twice.

$ wget http://hunt.net.nz/users/darran/weblog/b3029/attachments/03237/Arduino-keyboard-0.3.hex;wget http://hunt.net.nz/users/darran/weblog/b3029/attachments/b105c/Arduino-keyboard-0.3-mega2560.hex; md5sum *.hex #The md5sums match.

Could you upload the hex for the Mega 2560? (If not, I can build and upload it, thanks to the thorough guide in your earlier posts.)

JerwuQu (unauthenticated)
Jan 6, 2012

Would this work for other microprocessors? For example with the Teensy: www.pjrc.com/teensy/

darran
Jan 11, 2012

Hi Tom, I took a look at the code, and I realised that I don't make use of the ARDUINO_MODEL_PID define anywhere for the keyboard. I checked the arduino-usbserial code and it is used in Descriptors.c just to change the product string between "Arduino Uno" and "Arduino Mega 2560".

I don't have a mega board to test with, but would you mind trying out the sample pde and hex file and seeing if it works on the mega?

Cheers,
Darran.

darran
Jan 11, 2012

Hi JerwuQu,

the teensy has its own USB HID support that is a lot easier to use than the Arduino. For example take a look here: http://www.pjrc.com/teensy/usb_keyboard.html.

TECH GEEK (unauthenticated)
Jan 13, 2012

I have been trying to understand the HID keyboard example, but without any luck.
Will keep trying to understand how USB works.
Also I uploaded the 2560 .hex onto a R3's 16u2 successfully and it works well with the example.

TECH GEEK (unauthenticated)
Jan 15, 2012

Also if anyone could help me make/find/get code, (preferably .hex format) for a 4-axis (two sticks) + 4 button joystick, that would be really helpful !!

darran
Jan 17, 2012

Hi TECH GEEK,

good to know that the hex file works on a 16u2. I'll have to get an R3 to start experimenting with since the extra ram in the 16u2 should open up a lot more possibilities for the HID firmware.

You can extend the joystick example to add two more axes and two more buttons. I've run it with 30 buttons without any problems. You'd need to modify the Descriptors.h file to add two more axis and two more buttons to the report. Then change the USB_JoystickReport_Data_t structure to add the extra axes (the additional buttons will fit in the existing buttons field as bits 2 and 3). That will probably be enough for the firmware. Update the sketch so the report matches the new USB_JoystickReport_Data_t structure, and you should be good to go.

tuxtof (unauthenticated)
Jan 29, 2012

hi darran

firstly thanks you for your work, it's really cool
i have only one problem, i can't success wake up my pc like with a normal keyboard
how to do this ?

regards

DanB (unauthenticated)
Feb 6, 2012

Hi, I've tried to use this code to make a simple IR remote control for my PC (with volume controls and shortcuts for playing, skipping and selecting music etc.) I cannot get the volume keys to work with windows. The volume keys on my real keyboard work on windows without any special drivers so I know it is possible somehow but even the usage code doc says windows will not do it (works fine on linux though :-) score one for linux)

Also I cannot find a USB usage code for the @ symbol on a UK keyboard (being in the UK, this is a real pain in the neck.) the usage code document just says what it is for US keyboards (same as '2' key it is above the 2 key). How can I use @?

Fantastic program anyway, well done, works brilliantly (when I can find the right USB codes).

Thanks, Dan.

darran
Feb 7, 2012

Hi DanB,

I tried out the standard volume up and volume down key codes on my windows box and confirmed that they do not work. I did a bit of research and found this: http://msdn.microsoft.com/en-us/windows/hardware/gg462991.aspx. So it looks like windows requires a different HID device type for audio controls (unlike linux and OS X which support the standard keyboard codes). So one solution would be to write a new atmega8u2 driver that implements an HID audio controller, that could then send all the audio commands. Another solution would be to combine both HID audio control and HID keyboard into one driver.

I did a bit of googling regarding the UK @ symbol, but didn't get very far. I also don't have a UK keyboard so I can't capture the key code. I'll look into it some more. Let me know if you work it out.

Cheers, Darran.

darran
Feb 7, 2012

Hi tuxtof,

I didn't know you could wake a windows machine using the keyboard, interesting. I'm not sure why the arduino won't wake it up for you, but google seems to indicate many many possible causes. I'll try it out when I get a chance.

Cheers, Darran.

brendan (unauthenticated)
Feb 8, 2012

Hi Darran,

Thanks very much for the work you've done, it's made for some interesting reading. I'm interested in building a replica 737 Master Control Panel for Flight Simulator X, using several buttons, and some rotary encoders. Based on the research I've done so far, I've come up with a few ways to interface it with FSX:

1) Keyboard emulation - The most straightforward way would be to send a keycode for each individual button, however since I've never used 'grey code' encoders before, I don't know if this method would work.

2) Joystick emulation - I don't know how to modify the joystick firmware to add more buttons, as reading through the earlier comments, you mentioned "the additional buttons will fit in the existing buttons field as bits 2 and 3". Since I'm planning on using a fair few more than 2 buttons, I don't know how to modify the structures. Between keyboard and joystick, I don't know which would be a better option of the two.

3) Serial - I could write a helper app in VB, which I'm familiar with, to run in the background to pass serial data to the Arduino using the FSX SDK, but it seems like more effort than would be necessary.

Of the 3 options, which would be the best/easiest path to go down?

Thanks in advance!
Brendan

brendan (unauthenticated)
Feb 8, 2012

Edit: I've just had a look through the LUFA Joystick driver, and the USB_Descriptor_HIDReport_Datatype_t is a lot simpler than the one in your firmware. I've included it below:

const USB_Descriptor_HIDReport_Datatype_t PROGMEM JoystickReport[] =
{
/* Use the HID class driver's standard Joystick report.
* Number of Axis: 2 (X/Y)
* Min X/Y Axis values: -100
* Max X/Y Axis values: 100
* Min physical X/Y Axis values (used to determine resolution): -1
* Max physical X/Y Axis values (used to determine resolution): 1
* Buttons: 2
*/
HID_DESCRIPTOR_JOYSTICK(2, -100, 100, -1, 1, 2)
}

If I changed the axis descriptors so it read (0, 0, 0, 0, 0, 8), would this achieve the same effect?

Thanks,
Brendan

darran
Feb 11, 2012

Hi Brendan,

that HID_DESCRIPTOR_JOYSTICK macro is new - looks quite handy. Looks like I should upgrade to the latest LUFA code. There are other macros for keyboards and mice - nice!

I have a patch around to give you a 30 button joystick. I'll dig it up.

I'm not quite sure what you mean by (0,0,0,0,0,8)? Are those options for the HID_DESCRIPTOR_JOYSTICK macro? If so I'd say that would give you 8 buttons, and no axes. The PC may not be happy with 0 axes.

Cheers,
Darran.

Paul (unauthenticated)
Feb 16, 2012

Hey Darran,

I'm having an issue with a USB scanner(scanner emulates HID keyboard). I'm trying to store an 8 character bar-code however the scanner is sending key presses with little to no "inter-character-delay" causing the ArduinoUNO to essentially miss the last few characters. Any way this can be captured faster?

Storing keys like so:

void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
{
if (x <= 6)
{
x++; //increment keypress count first
str[x] = (key);
}

Thanks,
Paul

[ArduinoUNO]
[USB HostShield 2.0]

Danny (unauthenticated)
Mar 17, 2012

Hello Darran,
First of all: good job..! This is a very good job..
I'm writing because I've a question..
I have a project in my mind where I want to send mouse and keyboard input from one computer to another.

I thought to connect two Arduino UNO with two USB to RS232 TTL converter (for the mouse and the keyboard).

Basically I want to capture the input keyboard (and mouse) on the first PC and redirect them to the serial port of the "Arduino UNO", which will send them to another computer.

What do you think about that?

Sorry for my poor english..

Kind Regards
Danny

shebeique (unauthenticated)
Mar 28, 2012

Hi,Darran,
The problem of waking up the PC(WINDOWS) also comes to me!
I don't know how to do this,and can you give me some help?
Best wishes!

SuperPichu (unauthenticated)
Apr 8, 2012

Hello Darran,
Finally got this working. Is there any way to have a key be held down. I am trying to use a PS2 (Playstation2) DDR Pad with stepmania. I have it all working, I just need to be able to hold a key down.

dave_chatting (unauthenticated)
Apr 10, 2012

Hi Darran,

Thanks so much for this - I've tweaked the build for the Uno revision 3 (with the atmega16u2) - would you like the files to share here?

Cheers,
Dave

darran
Apr 11, 2012

Hi Dave,

good to hear. I've had no problems compiling for an atmega16u2 target either. I'm working on a combo serial+HID firmware load for the 16u2 that would support both serial for sketch uploads and debugging and an HID keyboard (or other HID device). Will post a new update if / when it works.

Cheers,
Darran.

darran
Apr 11, 2012

Hey SuperPichu,

to "hold" a key down, just keep it in each report that is sent. Or don't send any more reports until you want to lift the key. Either method should work, but the first method lets you send additional keys while keeping the original key held on.

gus (unauthenticated)
Apr 20, 2012

hi, ive been able to get the firmware up and running, and the example sketch that you put up fine.. but i am having trouble understanding what exactly is going on in the sketch, and how i can go about modifying the code to respond to the arduino's digital inputs..

i downloaded the libraries written by coopermaa (above) and managed to get a simple thing going just using if statements and the "Keyboard.sendKeyStroke()" function in coopermaa's library, but i am having the same problem as SuperPichu did, where it is constantly sending "on" "off" signals for each iteration of the loop..

what i am trying to do is build a simple 4 button system that is mapped to 4 different letter keys used to control a game, so it needs to be able to be "held" down, in order to function properly..

sorry for the stupid question, but any help you could give would be greatly appreciated.. if you can just explain briefly what is going on in the kbd_usb_demo.pde sketch, that would be a start at least.

thanks for your time

cheers
gus

Daniel (unauthenticated)
Apr 23, 2012

hi darran,

I'm having similar behavior to Au,
If I load the test sketch (kbd_usb_demo.pde) onto an Arduino mega 2560,
and flash the 8u2 with Arduino-keyboard-0.3-mega2560.hex,
Windows (7 ultimate ) sees it as an HID keyboard, and it sends the "hello world" as a keyboard,
after adding buttons and specifying keys ( from the USB HID document) to th sketch ( on the 2560 )

whenever i press a button windows seems to think i'm pressing windows key, or holding control or alt or some other command type key permanently, then i have to figure out which one to disable or reboot to get my system back to "normal",

I'm sending keys from a to s, and if i compare the output from the demo sketch to my sketch in a terminal program ( interpreting hex) the look the same( in this case the 8u2 is still a usb serial device, not a keyboard)

do you have any ideas?
i can also send my sketch your side if you want to take a look if i missed something, or did something silly.
its for a rather large arcade machine..

regards,
Daniel

Daniel (unauthenticated)
Apr 23, 2012

hi darran,
I got it working using coopermaa's library,
I think I was doing something silly, but the serial output seems to be padded with FF around the character, where it was al 00s before,

I will send my complete application your side if you like, gonna do a writeup soon-ish ( after afrikaburn)

Carl-Fredrik (unauthenticated)
May 7, 2012

Thanks a lot for this
Long ago I built a pedal board for the Ctrl-Alt-Shift keys (pictures and some text, so far only in Swedish, on this page: http://www.is.kiruna.se/~fredrik/elektronik/CFEmacspedal/ )
By upgrading to Arduino Uno and this firmware, it is now "plug and play" on any computer!

darran
May 8, 2012

Hey Carl, glad it was useful. Your project looks interesting - great that its now a native HID :-).

Jonathan (unauthenticated)
Jun 7, 2012

If my English isn't so good, it's because I'm from Germany.
I uploaded the .hex-file to my ARDUINO UNO SMD with Flip. But then I can't upload other programs, with I can send keyboard commands to the computer. Did I the right thing? Or what must I do, that I can send command to the computer?

Jonathan (unauthenticated)
Jun 8, 2012

Ah. Now I understand it. and it works.
Great work!

josh (unauthenticated)
Jun 23, 2012

hi darran thanks for your sharing. I've some questions.
first what im gonna do with the .hex and .pde files am i gonna upload them in the arduino file? and then i think i understand like that: we re gonna reprogram the atmega8u2 and then could we use it like we did it before when i first bought and use like?

darran
Jul 9, 2012

Josh,

yes - program the .pde file into the Uno the normal way. Then use DFU mode and the appropriate programmer tool (dfu-programmer for linux/OS X or flip for windows) to program the .hex file. When you want to change the sketch again you will need to use DFU mode to program back Arduino-usbserial.hex so you can again load the .pde or .ino in the normal way with the IDE.

XRONOS (unauthenticated)
Jul 13, 2012

I've made a 115,200 keyboard HID firmware for Arduino UNO. Thanks, Darren~
You could find the binary at my post.

http://make-culture.blogspot.kr/2012/07/arduino-uno-r2r3-usb-hid-115200bps.html

Mistrz (unauthenticated)
Jul 28, 2012

Hi. I need help. I wont to sleep my MacBook but i can't find the code for eject button in keyboard. I need Option+Command+Eject, dont' have eject :( Please help me

Mistrz (unauthenticated)
Jul 28, 2012

OK, I Found. If any need - Eject have 102 code ;)

LachlanMiller (unauthenticated)
Jul 31, 2012

Hi Darren, Read your comment that you made to DanB regarding windows requiring a mutimedia or audio keyboard in order to get the volume up / down working. And your solution of compiling a HID audio control and HID keyboard into one driver. Just wondering whether you had any plans to do this? or if i could convince you to? its where im stuck at in my project. I have a 3.2" touchscreen that i have programmed with icons for volume up and volume down, but its all dead in the water if i cant't get the keyboard commands happening. Let me know what you think.

cheers
Lachlan

Federico (unauthenticated)
Aug 18, 2012

Hi Darren. I've had the same problem as Jonathan, but using an Arduino UNO R2. I can upload your hex file, but then I can upload any sketch, because the Arduino is not being detected ("Serial monitor" in gray).

I've tested uploading the standard Arduino-usbserial-uno.hex again, and it worked, so I think the procedure that I'm applying is correct. I'm doing this on the terminal:

sudo dfu-programmer at90usb82 erase
sudo dfu-programmer at90usb82 flash --debug 1 Arduino-keyboard-0.3.hex
Validating...
4022 bytes used (98.19%)
sudo dfu-programmer at90usb82 reset

I have not got any errors... Where could be the problem?

Thanks!
Federico

Federico (unauthenticated)
Aug 21, 2012

Hi all!

I've understood my problem. I think it's not so straightforward given the instructions. Therefore I want to explain it here:

* First of all, you have to upload the sketch that you want to run, as normal. That sketch should have the instructions to work as a keyboard, such as sending a key if some input is high.
* Then, it's the time to change the firmware of the chip that makes the serial-USB communication between Arduino and the computer.
* After that, you won't be able to upload any code again. You'll have your sketch running in the loop you designed.

Thanks to Darran for developing it, and sorry for my English.

Regards,
Federico

Brian (unauthenticated)
Aug 24, 2012


Hi Darren. Thanks for putting together this keyboard firmware as well as all of the instructions and support since.

This question goes out to anyone that can help:

I'm new to the Arduino, but have been able to butcher code from Felix (Circuits@Home) to successfully read data from a card reader and strip out the information that I need using the USB 2.0 shield. My idea was to use the Arduino as a virtual keyboard to populate fields on the computer with this info to speed up data entry as well as to eliminate typos.

I was able to flash the Arduino with the keyboard-0.3.hex firmware successfully after uploading my program. Well, my program didn't work, & that's my problem to figure out.

My question is, does the keyboard-0.3.hex change the way the USB shield communicates as well? It doesn't look like the previously tested scanner portion of my code works anymore. The Arduino needs to be a HID device (a keyboard), but the card reader plugged into the USB shield doesn't.

Any suggestions would be greatly appreciated!

Thanks,

Brian

hbtan (unauthenticated)
Sep 26, 2012

Hi Darren. Thanks for the firmware.
howerver,I have try the 0.3 version but it still not work with the numbers above 100(eg. volume up and down).
i check the code of 0.2 version and 0.3 version:
in the 0.3 version:
USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] =
{
0x05, 0x01, /* Usage Page (Generic Desktop) */
0x09, 0x06, /* Usage (Keyboard) */
0xa1, 0x01, /* Collection (Application) */
0x75, 0x01, /* Report Size (1) */
0x95, 0x08, /* Report Count (8) */
0x05, 0x07, /* Usage Page (Key Codes) */
0x19, 0xe0, /* Usage Minimum (Keyboard LeftControl) */
0x29, 0xe7, /* Usage Maximum (Keyboard Right GUI) */
0x15, 0x00, /* Logical Minimum (0) */
0x25, 0x01, /* Logical Maximum (1) */
0x81, 0x02, /* Input (Data, Variable, Absolute) */
0x95, 0x01, /* Report Count (1) */
0x75, 0x08, /* Report Size (8) */
0x81, 0x03, /* Input (Const, Variable, Absolute) */
0x95, 0x05, /* Report Count (5) */
0x75, 0x01, /* Report Size (1) */
0x05, 0x08, /* Usage Page (LEDs) */
0x19, 0x01, /* Usage Minimum (Num Lock) */
0x29, 0x05, /* Usage Maximum (Kana) */
0x91, 0x02, /* Output (Data, Variable, Absolute) */
0x95, 0x01, /* Report Count (1) */
0x75, 0x03, /* Report Size (3) */
0x91, 0x03, /* Output (Const, Variable, Absolute) */
0x95, 0x06, /* Report Count (6) */
0x75, 0x08, /* Report Size (8) */
0x15, 0x00, /* Logical Minimum (0) */
0x26, 231, 0, /* Logical Maximum (231) */
0x05, 0x07, /* Usage Page (Keyboard) */
0x19, 0x00, /* Usage Minimum (Reserved (no event indicated)) */
0x29, 231, /* Usage Maximum (Keyboard Application) */
0x81, 0x00, /* Input (Data, Array, Absolute) */
0xc0 /* End Collection */
};

and in the 0.2 version:

USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] =
{
0x05, 0x01, /* Usage Page (Generic Desktop) */
0x09, 0x06, /* Usage (Keyboard) */
0xa1, 0x01, /* Collection (Application) */
0x75, 0x01, /* Report Size (1) */
0x95, 0x08, /* Report Count (8) */
0x05, 0x07, /* Usage Page (Key Codes) */
0x19, 0xe0, /* Usage Minimum (Keyboard LeftControl) */
0x29, 0xe7, /* Usage Maximum (Keyboard Right GUI) */
0x15, 0x00, /* Logical Minimum (0) */
0x25, 0x01, /* Logical Maximum (1) */
0x81, 0x02, /* Input (Data, Variable, Absolute) */
0x95, 0x01, /* Report Count (1) */
0x75, 0x08, /* Report Size (8) */
0x81, 0x03, /* Input (Const, Variable, Absolute) */
0x95, 0x05, /* Report Count (5) */
0x75, 0x01, /* Report Size (1) */
0x05, 0x08, /* Usage Page (LEDs) */
0x19, 0x01, /* Usage Minimum (Num Lock) */
0x29, 0x05, /* Usage Maximum (Kana) */
0x91, 0x02, /* Output (Data, Variable, Absolute) */
0x95, 0x01, /* Report Count (1) */
0x75, 0x03, /* Report Size (3) */
0x91, 0x03, /* Output (Const, Variable, Absolute) */
0x95, 0x06, /* Report Count (6) */
0x75, 0x08, /* Report Size (8) */
0x15, 0x00, /* Logical Minimum (0) */
0x25, 0x65, /* Logical Maximum (101) */
0x05, 0x07, /* Usage Page (Keyboard) */
0x19, 0x00, /* Usage Minimum (Reserved (no event indicated)) */
0x29, 0x65, /* Usage Maximum (Keyboard Application) */
0x81, 0x00, /* Input (Data, Array, Absolute) */
0xc0 /* End Collection */
};

it is different with the logical maximun and minimun:
0x15, 0x00, /* Logical Minimum (0) */
0x25, 0x65, /* Logical Maximum (101) */

0x15, 0x00, /* Logical Minimum (0) */
0x26, 231, 0, /* Logical Maximum (231) */

but I doubt whether the 0.3 version is right with"0x26, 231, 0, "

do anybody have any ideas?

sorry for my english.

vinasheva (unauthenticated)
Oct 22, 2012

Hi, can we use one arduino for both virtual keyboard and mouse just to plug in one USB connector? Thanks

Lemming (unauthenticated)
Dec 1, 2012

Hi

I am using a Mega 2560 and have flashed the -0.3-mega2560.hex code onto my board.

It works great. I really appreciate your hard work.

I do have a special request for either Darran or another capable person here.

I would like to use my mega 2560 as a keyboard encoder for a DIY arcade cabinet that is capable of pressing a lot of keys at the same time, similar to an iPac2 or iPac4 http://www.ultimarc.com/ipac1.html . The idea is that arcade joysticks and buttons for 2~4 players are attached to digital inputs on the mega, and the

The current version seems to be able to only handle up to 6 keys at a time.

I would really appreciate if someone were able to compile a version of the hex firmware that allows for more (perhaps up to 64 or 32 simultaneous presses).

Then I could scan for the inputs every loop and then add the appropriate key codes to an array, then send all of the required codes at once, instead of the max 6 at current.

I've had a look at the source code but it's out of my league.

So, would anyone consider compiling a hex for the mega 2560 that supports the above changes?

Seth (unauthenticated)
Dec 8, 2012

Hi Darren,
Thanks for the code and clear instructions.
Did you ever have any luck reading LED status from the host?

Thanks much,
Seth

Seth (unauthenticated)
Dec 8, 2012

Darran, Sorry I got your name wrong above -- copying from prior posts... -- Seth

(unauthenticated)
Jan 13, 2013

Hey Seth,

I haven't gone back to look at the LED status support. I'll take a look next weekend and see if I can work out what's wrong.

George (unauthenticated)
Jan 13, 2013

thankyou Darran for your work, I really appreciate the string feature for this, so much better than entering keyboard codes :)

ben (unauthenticated)
Mar 9, 2013

hi Darran,
I got make: *** No rule to make target `Arduino-keyboard.elf', needed by `elf'. Stop. when i do make.
do I need to create this file before use make ?

ben (unauthenticated)
Mar 9, 2013

I solved my problem!
in makefile, do not change LUFA_PATH to exclusive path. I changed it to /home/ben/Desktop/LUFA and it wont work . This path must be set from the root of where you run makefile for arduino-keyboard-0.3.

da-kid (unauthenticated)
Apr 14, 2013

Hey, Darran,
This diamond of code is unfortunately not working for me - I'm using a brand new Arduino UNO SMD - Edition, what's probably simmilar to the normal R3.
Will you be posting an update of this programm?

(unauthenticated)
Apr 21, 2013

Hi da-kid. The code I've posted will work with any Arduino with an 8u2 or 16u2 device providing the USB serial interface. Looking at http://arduino.cc/en/Main/ArduinoBoardUnoSMD, I see this does have an 8u2 so you can load new USB firmware.

No update is needed.

Tom (unauthenticated)
May 20, 2013

Hi Darran,

I've been having a play with your code for a few weeks now and am looking at using it for an arcade project in Auckland later this year,
Wondering if there would be a chance I could have a chat at some stage, I'm having a few issues and the real low level stuff is a bit beyond my understanding.
I'm currently struggling to get proper response while holding down multiple keys at once, which is pretty vital for arcade game stuff.

If you have any advice or would be keen for a chat/beer could you drop me an email on RabbleRoomArcade@gmail.com

Cheers

Tom

darran
May 23, 2013

Hey Tom, the keyboard driver should support up to 6 keys being pressed at the same time by setting the HID key codes in bytes 2 to 7 of the keyboard report. I imagine you could extend this further by defining additional keys in the USB descriptor. You might also find the big joystick driver useful: http://hunt.net.nz/users/darran/weblog/15f92/Arduino_UNO_Big_Joystick_HID_firmware.html. Drop me an email if you run into problems (darran at hunt dot net dot nz).

def1 (unauthenticated)
Jul 5, 2013

hey darran. do i miss something ? speeding up the baud rate to 57600 or other the sketch starts acting weird. why ? and can it be changed ?

darran
Jul 6, 2013

Hey def1. The baud rate needs to match the rate the atmega8u2 expected, which with the built firmware is 9600. If you want to run it faster, change the baud rate in Arduino-keyboard.c and rebuild the 8u2 firmware.

9600 should give you over 100 key presses per second, so its already pretty fast.

Don Solomillon (unauthenticated)
Jul 24, 2013

I've been working on this solution for the whole day and it is terribly frustrating to get the same error over and over. I am using the Ubuntu terminal to operate- followed the process step by step until the first plug-unplug, and sending the sketch from my PC to my Arduino Uno SMD. That part works perfectly, however, I'm only getting a "no device present" error from dfu-programmer from then on. What happened?

Henry (unauthenticated)
Nov 2, 2013

Thank you for your hard work! Flashing my UNO with your HEX file took minutes to figure out and test successfully.
My knowledge of working with strings is limited. Can anyone tell me why my "string2" won't gives me an error and any way I can fix it? I get: "error: no matching function for call to 'USBKeyboard::print(String&)'"
Thank you.

#include <USBKeyboard.h>
char string1 [] = {"teststring1"}; // good
String string2 = "teststring2"; // not good
void setup()
{
Keyboard.init();
Keyboard.print(string1); // good
Keyboard.print(string2); // not good
}
void loop()
{
}

Tiago Ferreira (unauthenticated)
Nov 20, 2013

Hello Darran,

In the first place: thank you very much for your great work. It works great!

Im trying to build an IR receiver with the arduino that receives codes from an IR remote and sends them to the computer as keyboard keys. This would be great because the solution would be plug and play on all computers. However, I have a little problem: as I have read in previous comments, if the Arduino is spitting anything else to the serial console, it'll perform as a keyboard spitting garbage. Unfortunately, that's happening to me because I receive the IR codes from the IR sensor trough serial. I am using the arduino mega 2560.

Is there anything I can do to make it work, even tought it is received other data in serial port? I was wondering if sending the keyboard key codes in another way would work.

In case anyone wants too see the code I am using, here it is: http://pastebin.com/x2bLVS3X

Thanks!

darran
Dec 13, 2013

Hi Tiago,

I think you can use one of the other hardware serial interfaces on the Arduino mega 2560 to interface to your IR remote.

IT-Wizard (unauthenticated)
Feb 5, 2014

To Henry,
This is a pure C language problem.
Keyboard.print(string2);
should be written :
Keyboard.print(*string2);

Char return a character
String return a memory address.

That's what the compiler means by this : 'USBKeyboard::print(String&)'
"String&" means that it received an address

Chosen (unauthenticated)
Feb 6, 2014

Hi Darran,

Been trying to add Multimedia key support but can't make it work, I've basicly replace the descriptor table with this one http://blog.derouineau.fr/category/technique/arduino/ to start with, but then the device is not longer working in Windows. I think I'm still not getting the whole HID descriptor thing (and it's relation with VID, PID and drivers). Any advice on how to proceed ?

Thanks !

darran
Mar 5, 2014

hey Chosen. Try taking at look at Dean Camera's LUFA site here: http://www.fourwalledcubicle.com/LUFA.php. The Arduino USB firmware is based on his work.