Arduino Uno - HID Device - Special Characters Help

Hi.

I set up my arduino UNO R3 as a HID device today. using :

i basically reflashed the 16u2 with a hid library. all the standard characters work perfectly. But i cant get the volume up/ volume down / mute to work.

Most of the other things work like page up / page down etc etc but nothing i do seems to make the volume settings work.

The code im using in the sketch is:

int led = 13;
uint8_t buf[8] = { 
  0 }; 	/* Keyboard report buffer */

void setup() 
{
  Serial.begin(9600);
  delay(200);
  pinMode(led, OUTPUT); 
 
}

void loop() 
{

delay(3000);

  buf[2] = 127;	  
  Serial.write(buf, 8);	// Send keypress
  releaseKey();
  
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000); 
  
}

void releaseKey() 
{
  buf[0] = 0;
  buf[2] = 0;
  Serial.write(buf, 8);	// Release key  
}

Can anyone help?

Thanks guys

You really haven't provided enough information for anyone to help you. I will assume you have a PS2 keyboard plugged into the Arduino?
My best guess is you need to look in the sources files because, what you have posted in no way describes your keyboard at all.
Do the vol+ and vol- keys give you any feedback in the serial monitor?

Also, right there on the site you posted is, this.......

/* Arduino USB Keyboard HID demo
* Volume+/Volume-/Mute keys
*/

uint8_t buf[8] = {
  0 }; /* Keyboard report buffer */

#define PIN_VOLUME_UP 5
#define PIN_VOLUME_DOWN 6
#define PIN_MUTE 7

int state = 1;

void setup()
{
  Serial.begin(9600);
  pinMode(PIN_VOLUME_UP, INPUT);
  pinMode(PIN_VOLUME_DOWN, INPUT);
  pinMode(PIN_MUTE, INPUT);
  // enable internal pull-ups
  digitalWrite(PIN_VOLUME_UP, 1);
  digitalWrite(PIN_VOLUME_DOWN, 1);
  digitalWrite(PIN_MUTE, 1);

  delay(200);
}

void loop()
{
  state = digitalRead(PIN_VOLUME_UP);
  if (state != 1) {
    buf[2] = 128;	// Volume up key
    Serial.write(buf, 8);	// Send keypress
    releaseKey();
  }

  state = digitalRead(PIN_VOLUME_DOWN);
  if (state != 1) {
    buf[2] = 129;	// Volume down key
    Serial.write(buf, 8);	// Send keypress
    releaseKey();
  }

  state = digitalRead(PIN_MUTE);
  if (state != 1) {
    buf[2] = 127;	// Mute key
    Serial.write(buf, 8);	// Send keypress
    releaseKey();
  }
}

void releaseKey()
{
  buf[0] = 0;
  buf[2] = 0;
  Serial.write(buf, 8);	// Release key
}

@OP: Is your PC OS supporting the Vol+, Vol- and Mute keys of a standard USB keyboard? The Arduino is just sending keystrokes and nothing more. If your PC doesn't react on the keystrokes you have to change the software there.

I just looked all over darren's site and found that he mentioned this :

I did a bit of research and found this: Introduction to Human Interface Devices (HID) - Windows drivers | Microsoft Learn. 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.

everyone had been using linux up till then. I'm hoping darren compiles and releases a driver that announces itself as a multimedia keyboard.

This may help you out. I hope so.

You can remap the windows volume to another keyboard key!
You can do the reg hack yourself or you can use a program.

See.

EDIT:
I just tested this and it works perfectly!
I remapped NUM- to Vol- and Num+ to Vol+. I restarted my PC and now those buttons work as VOL+ and VOL-.

I used the latest version from here.
http://www.randyrants.com/2011/12/sharpkeys_35.html

Win7 HPx64
PS2 Keyboard. Without Volume control. Or at least it used to be!