Arduino

How to Get Hex File from Arduino IDE

Arduino IDE is a development platform used to upload code in Arduino boards. Arduino boards are based upon microcontrollers. To communicate with a microcontroller IDE is used. IDE is an editor for writing, debugging, and uploading sketches to Arduino boards. IDE is programmed in C or C++ with some additional methods and functions. Microcontrollers understand machine language. Once Arduino code is compiled, IDE converts C++ language program into a Hex file. Now, we will describe how to get this Hex file from Arduino.

How to Get Hex File from Arduino IDE

Arduino IDE uses Hex file format to store C/C++ code into hexadecimal form. This Hex file is commonly referred to as machine code. Microcontroller cannot understand normal C language; it only takes instruction in the form of 1 and 0 also known as Binary. Arduino IDE transfers these instructions to microcontroller RAM and EEPROM through Hex file.

By following the steps described below we can get the Hex file of Arduino sketch.

Step 1: Open Arduino IDE software on PC.

Step 2: New window will open showing us the Arduino IDE interface. Here one can write his own code or load an example sketch from IDE. We will continue with the LED blink example and try to extract its Hex file.

Step 3: Now open the LED blink example, go to: Files>Examples>Basics>Blink:

Step 4: After opening the LED example a new window will open. If you are writing your own program, recheck all the Arduino sketches. To generate a Hex file, we need a location where the Hex file is stored. To get Hex file location follow below steps. Go to: File>Preferences or press ctrl+comma.

Step 5: When you click the preferences option a new window will open here tick the Compilation option in the verbose output section. After selecting it press Ok to continue. This will help us to extract Hex file location from the Output section once the program is compiled.

Step 6: Now compile the Arduino program using the tick sign at top right window. Once the program is compiled successfully, a “Done compiling” message will appear in the output window.

Step 7: In the output section find the “.hex” file of the compiled Arduino program. Last line of verbose output is the Hex file.

Step 8: Copy the path to the Hex file.

Step 9: First remove the Hex file name from the path copied.

Open My PC, select the address bar and paste the file path here then press Enter. You will see a file with .hex extension This is the required Hex file we are looking for.

Note: If the address copied from the Hex file is not working try to remove double Backslash ( \ ) symbols which are repeated in Hex file address.

Conclusion:

Here we have discussed all steps required to extract a Hex file from Arduino IDE. The Arduino board uses this Hex file to run instructions. Sometimes when we connect an Arduino board directly with a PC and upload code to Arduino it does not create a Hex file, so using the method explained above we can easily get a Hex file and use it in any Arduino project.

About the author

Kashif

I am an Electrical Engineer. I love to write about electronics. I am passionate about writing and sharing new ideas related to emerging technologies in the field of electronics.