user1708: I have followed this tutorial on flashing my Arduino R3 to turn it into a "USB keyboard", but the article doesn't explain how the hex works, it's just for granted. Where can I learn about how to make my own hex file so that I can learn how to make my Arduino mimic any USB device?

user368: The HEX file is simply a translated version of the AVR executable, which is in turn a translated version of AVR source code.
There are many tools available for turning (compiling) AVR source code into an AVR executable, including but not limited to the Arduino IDE, Ino, AVR-GCC, and Atmel Studio. Note that all four tools will compile the code the same way, since AVR-GCC is used under the hood by the other three.
avr-g++ -mmcu=atmega328 source.cc -o executable

Once you've compiled the code, you can use avr-objcopy to extract the appropriate sections from the executable into HEX files for programming into the flash and EEPROM.
avr-objcopy -j .text -j .data -O ihex executable executable.hex

You can then use AVRDUDE to upload the various HEX files to the target device.
avrdude -c arduino -P /dev/ttyUSB0 -b 19200 -p m328 -U flash:w:executable.hex:i

Note that the USB libraries in Arduino/Ino and AVR LibC are limited; you will need to use Atmel Studio if you want full USB capabilities.

user60: There are plenty of sites out there that document how to make/build such. 
Example: http://hunt.net.nz/users/darran/ 
or https://github.com/harlequin-tech/arduino-usb
GOOGLE: build usb keyboard 16u2

Please note that when attempting this on the Uno R3, the DFU is updating the code on the 16U2 and not the 328p. 
I would suggest for novices to use the Leonardo. Where there are stock examples in the IDE for using the application directly as USB HID. Avoiding any alterations to either the boot loader or the USB to Serial co-processor chip (the 16u2). Making it much simpler.

user2741: It is possible, but it's kind of hard(especially if you want to mod both the 8u2 AND the 16u2. I'd recommend the Teensy(https://www.pjrc.com/teensy/index.html) I recently posted a question about a question similar to yours and after hearing about all the pitfall I decided to go with the Teensy. I has much richer USB/HID support by default (You can start on your project right away rather than trying to mod the UNO). Teensys are also relatively cheap ranging from $18 to $24. 
By comparison, UNOs are $27.18 and are out of stock. To be fair both are probably cheaper used. This is probably moot since it seems you already have one. For more info, see my question (Feasability of flashing Arduino UNO r3 with teensy firmware for HID (keyboard) emulation purposes)

user2785: You don't need to do something magical. Here's how you can use the Arduino IDE's affiliates.
Once you compile or upload a sketch, the .hex file is automatically created and stored in your computer's drive that has the OS installed (I've found this on Windows). You can access it by navigating to the directory containing temporary files.
Typically, the path will be something like this:
C: > Users > Admin > AppData > Local > Temp
Now you'll see (a lot of) directories with names that go like "build"... followed by a big number. One of these directories contains compiler-generated files of the code you're looking for. From this location, you can search (using Windows Explorer, for example) and identify the .hex file you're looking for by the date and time of last modification.
Once you've got your .hex file, you can upload it to your Arduino using Atmel FLIP after setting your Arduino's microcontroller to the Device Firmware Upgrade (DFU) mode. Atmel FLIP, an acronym for FLexible In-system Programmer, can be used very easily, thanks to its minimal UI.
Here's how to use FLIP:

Go to File > Load HEX File... and select the file.
Choose your microcontroller by selecting the first icon on the bar.
Choose your programming interface from the small list.

I've used this with ATXmega that supports USB but it's not the same for all.

1708: <p>I have followed <a href="http://mitchtech.net/arduino-usb-hid-keyboard/">this tutorial</a> on flashing my Arduino R3 to turn it into a "USB keyboard", but the article doesn't explain how the hex works, it's just for granted. Where can I learn about how to make my own hex file so that I can learn how to make my Arduino mimic <em>any</em> USB device?</p>
 368: <p>The HEX file is simply a translated version of the AVR executable, which is in turn a translated version of AVR source code.</p>

<p>There are many tools available for turning (compiling) AVR source code into an AVR executable, including but not limited to the <a href="http://arduino.cc/en/Main/Software" rel="nofollow">Arduino IDE</a>, <a href="http://inotool.org/" rel="nofollow">Ino</a>, AVR-GCC, and <a href="http://www.atmel.com/tools/atmelstudio.aspx" rel="nofollow">Atmel Studio</a>. Note that all four tools will compile the code the same way, since AVR-GCC is used under the hood by the other three.</p>

<pre><code>avr-g++ -mmcu=atmega328 source.cc -o executable
</code></pre>

<p>Once you've compiled the code, you can use avr-objcopy to extract the appropriate sections from the executable into HEX files for programming into the flash and EEPROM.</p>

<pre><code>avr-objcopy -j .text -j .data -O ihex executable executable.hex
</code></pre>

<p>You can then use <a href="http://www.nongnu.org/avrdude/" rel="nofollow">AVRDUDE</a> to upload the various HEX files to the target device.</p>

<pre><code>avrdude -c arduino -P /dev/ttyUSB0 -b 19200 -p m328 -U flash:w:executable.hex:i
</code></pre>

<p>Note that the USB libraries in Arduino/Ino and AVR LibC are limited; you will need to use Atmel Studio if you want full USB capabilities.</p>
 60: <p>There are plenty of sites out there that document how to make/build such. </p>

<pre><code>Example: http://hunt.net.nz/users/darran/ 
or https://github.com/harlequin-tech/arduino-usb
GOOGLE: build usb keyboard 16u2
</code></pre>

<p>Please note that when attempting this on the Uno R3, the DFU is updating the code on the 16U2 and not the 328p. </p>

<p>I would suggest for novices to use the Leonardo. Where there are stock examples in the IDE for using the application directly as USB HID. Avoiding any alterations to either the boot loader or the USB to Serial co-processor chip (the 16u2). Making it much simpler.</p>
 2741: <p>It is possible, but it's kind of hard(especially if you want to mod both the 8u2 AND the 16u2. I'd recommend the Teensy(<a href="https://www.pjrc.com/teensy/index.html" rel="nofollow noreferrer">https://www.pjrc.com/teensy/index.html</a>) I recently posted a question about a question similar to yours and after hearing about all the pitfall I decided to go with the Teensy. I has much richer USB/HID support by default (You can start on your project right away rather than trying to mod the UNO). Teensys are also relatively cheap ranging from $18 to $24. </p>

<p>By comparison, UNOs are $27.18 and are out of stock. To be fair both are probably cheaper used. This is probably moot since it seems you already have one. For more info, see my question (<a href="https://arduino.stackexchange.com/questions/2878/feasability-of-flashing-arduino-uno-r3-with-teensy-firmware-for-hid-keyboard-e/">Feasability of flashing Arduino UNO r3 with teensy firmware for HID (keyboard) emulation purposes</a>)</p>
 2785: <p>You don't need to do something magical. Here's how you can use the Arduino IDE's affiliates.</p>

<p>Once you compile or upload a sketch, the <em>.hex</em> file is automatically created and stored in your computer's drive that has the OS installed (I've found this on Windows). You can access it by navigating to the directory containing temporary files.</p>

<p>Typically, the path will be something like this:
<em>C: > Users > Admin > AppData > Local > Temp</em></p>

<p>Now you'll see (a lot of) directories with names that go like "build"... followed by a big number. One of these directories contains compiler-generated files of the code you're looking for. From this location, you can search (using Windows Explorer, for example) and identify the <em>.hex</em> file you're looking for by the date and time of last modification.</p>

<p>Once you've got your <em>.hex</em> file, you can upload it to your Arduino using Atmel FLIP after setting your Arduino's microcontroller to the Device Firmware Upgrade (DFU) mode. Atmel FLIP, an acronym for FLexible In-system Programmer, can be used very easily, thanks to its minimal UI.</p>

<p>Here's how to use FLIP:</p>

<ol>
<li>Go to <em>File > Load HEX File...</em> and select the file.</li>
<li>Choose your microcontroller by selecting the first icon on the bar.</li>
<li>Choose your programming interface from the small list.</li>
</ol>

<p>I've used this with ATXmega that supports USB but it's not the same for all.</p>
