Eleven & USB HID - Arduino-Keyboard not working

The "Eleven" is our Uno-equivalent Arduino-compatible board, but with a number of improvements including prototyping area, a mini-USB connector, LEDs mounted near the edge, and the D13 LED isolated using a FET. [Product page]
Post Reply
Jez_A
Posts: 10
Joined: Thu Nov 17, 2011 8:16 am
Location: Melbourne

Eleven & USB HID - Arduino-Keyboard not working

Post by Jez_A » Tue Mar 10, 2015 11:48 am

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() 
{
  Serial.begin(9600);
  randomSeed(analogRead(0));
  pinMode(13, OUTPUT);
  delay(2000);
}
 
void loop() 
{
  int randomChar = random(4, 130);
  long randomDelay = random(1000, 10000);
 
  delay(randomDelay);
 
  buf[2] = randomChar;	  // Random character
  Serial.write(buf, 8);	// Send keypress
  releaseKey();
}
 
void releaseKey() 
{
  buf[0] = 0;
  buf[2] = 0;
  Serial.write(buf, 8);	// Release key   
}
Note: This code was taken from the following web page:

http://mitchtech.net/arduino-usb-hid-keyboard/

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.
Jez

angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

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

Post by angusgr » Wed Mar 11, 2015 5:22 am

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!


Angus

Jez_A
Posts: 10
Joined: Thu Nov 17, 2011 8:16 am
Location: Melbourne

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

Post by Jez_A » Wed Mar 11, 2015 7:43 am

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.

Cheers
Jez

Post Reply