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
}
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.......
@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.
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-.