Page 1 of 1

Eleven & USB HID - Arduino-Keyboard not working

Posted: Tue Mar 10, 2015 11:48 am
by Jez_A
I am trying to utilise the Arduino-Keyboard USB HID firmware on a Freetronics Eleven. I have uploaded the .hex file (using a Freetronics USBasp ICSP Programmer) using the following command:

avrdude -p m328p -F -P usb -c USBasp -U flash:w:Arduino-keyboard-0.3.hex

The upload appears to complete successfully.

I then upload a test sketch via the ICSP Programmer, to send a random character to the attached Macbook Pro.

Code: Select all

/* Arduino USB HID Keyboard Demo
 * Random Key/Random Delay
uint8_t buf[8] = { 
  0 }; 	/* Keyboard report buffer */
void setup() 
  pinMode(13, OUTPUT);
void loop() 
  int randomChar = random(4, 130);
  long randomDelay = random(1000, 10000);
  buf[2] = randomChar;	  // Random character
  Serial.write(buf, 8);	// Send keypress
void releaseKey() 
  buf[0] = 0;
  buf[2] = 0;
  Serial.write(buf, 8);	// Release key   
Note: This code was taken from the following web page:

The random characters do not appear in a running text editor application, however they do appear in the Serial Monitor of the Arduino IDE, which seems to point to the USB HID firmware as not functioning as expected.

Is anyone able to assist me in pointing out where I may be going wrong?

Many thanks, in advance.

Re: Eleven & USB HID - Arduino-Keyboard not working

Posted: Wed Mar 11, 2015 5:22 am
by angusgr
Hi Jez,

The HID firmware actually loads onto the secondary atmega16u2 (8u2 in the blog post, but the 16u2 is just an 8u2 with more flash storage). This chip acts as a USB serial device under normal operation, and the alternative firmware reprograms it to be a USB HID keyboard device.

So the avrdude line will need to have the argument '-m m16u2' not '-m328p'.

To connect to the ISP header on the atmega16u2, you'll need to populate the secondary header marked "ICSP-USB", near the top left of the board. Or you can use the 'dfu-mode' programmer, as described in the post.

The USBAsp will come in handy to program sketches to the main atmega328p after you can no longer use it as a serial port, though!


Re: Eleven & USB HID - Arduino-Keyboard not working

Posted: Wed Mar 11, 2015 7:43 am
by Jez_A
Thank you Angus, for setting me straight.

Obviously I was trying to flash the wrong chip!! D'Oh!!!

I'll add the headers on to the board and try again.

Your assistance is greatly appreciated.