How to generate, save and load HEX files in Arduino

  • The .hex file is essential for programming microcontrollers, but in Arduino it is hidden.
  • The save path of the .hex file can be customized by modifying the preferences.txt file.
  • A .hex file can be loaded using the command prompt or tools like XLoader.
  • It is important to select the correct version of the .hex file with or without bootloader depending on the needs of the project.

binary to hexadecimal

If you work with microcontrollers, you will surely be familiar with the files .hexThis file is the result of compiling the code and is crucial for programming microcontrollers directly. However, if you are using Arduino, you will have noticed that the process to obtain this file is not so obvious.

Although the Arduino IDE generates the HEX file as part of the compilation process, it is hidden in a temporary folder on the system. In this article, we will explain how to access this file, how to store it in a desired location, and how to load it onto your Arduino or other microcontrollers.

Generating the HEX file in the Arduino IDE

arduino-3 hex file

To start, one of the easiest ways to generate the file .hex In the Arduino IDE, it is via the Preferences menu. Go to the “File” menu and select “Preferences.” Here, it is advisable to activate the checkboxes that show detailed results during compilation.

Once you have completed these steps, when you compile or upload your program to the Arduino, the file .hex will be saved to a temporary location on your computer, specifically in the AppData\Local\Temp\ folder. The exact file name and path will appear in the Arduino IDE console after the compilation process.

From this point, you can copy the file .hex to any other location on your computer for later use.

Modify the save location of the HEX file

If you prefer the file .hex To ensure that your Arduino IDE is always saved to a specific folder, you can change the settings in the Arduino IDE. To do this, go back to the “File” menu and select “Preferences.” At the bottom of the preferences window, you will find a link to the location of a file called preferences.txt. Click this link and close the Arduino IDE before continuing.

Open the file preferences.txt with a text editor and look for the line that says build.path. This line may not exist, in which case you will need to add it yourself. Define the path where you want the files to be saved .hexFor example, you could define a route like build.path=C:\MyFolder\arduino\hex.

After making this modification, save the file preferences.txt and reopen the Arduino IDE. From this point on, any code you compile will save the generated files directly to the path you specified.

Loading a HEX file into Arduino

There are two main ways to upload files .hex on an Arduino. The first is by using the Windows command prompt. When you load a program from the IDE, a command line is generated that can be copied and run in the command prompt. You just need to change the file path .hex to the new location where you saved it. By pressing “Enter”, the program will be loaded directly into your microcontroller.

The second option is to use external software such as XLoader. This program allows you to select the file .hex you want to load, choose the correct port and set the baud rate (usually 115200). Once configured, simply press the “Load” button to flash the microcontroller with the file .hex.

Upload a file .hex Directly on an Arduino is useful when you need to program several boards with the same code, as it saves you time by avoiding having to use the Arduino IDE in each case.

Additionally, it is a great option if you want to allow other people to upload your code without them needing to have the IDE, allowing for efficient distribution of your programs.

Additional considerations

When working with files .hex, it is important to note that if you are programming a microcontroller without using the Arduino bootloader, you must make sure that you are using the correct file. When compiling a program, the Arduino IDE generates two versions of the file .hex, one with the bootloader and one without.

Selecting the correct file is crucial depending on whether your microcontroller requires the bootloader or whether you can burn the program directly to the chip without it.

With the steps described, you will not only be able to easily obtain the file .hex of your projects, but you also have full control over where they are stored and how to load them to your Arduino devices or other compatible microcontrollers.


Be the first to comment

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.