Friday, 20 March 2015

Arduino Tips & Tricks:

 Where is the hex file in the Arduino environment?

The thing that made Arduino a big big success is its ability to hide all the complexities and yet give the user so much freedom to create new things. Working on 8051 or bare avr  after writing and compiling  a code in keil uvision or avr studio  a .hex is generated which is burnt into the micro-controller IC  by placing the IC in a zip socket on the burner or using an ISP(in system programmer). But in case of arduino ,the arduino environment takes care of everything and for a long time i even dint know if there is a hex file that is also here in a background.
The clever Arduino environment first checks the code to make sure it is in confirmation with the c /c++ . then the code is passed to a compiler called avr-gcc which converts the code from human readable to machine readable and the code is linked with standard  arduino libraries. and after all this a single hex file is created which contains all the information of your code and then through the com port  ,using an avr chip (this is an avr micro-controller apart from the main controller where you put your code )programmed to handle usb to serial conversion this file is uploaded to your chip's program memory and your arduino board executes the code.

Where is the .hex actually stored? 

To locate the hex file created by your arduino IDE. follow the following snapshots

1. Go to file>Preferences. And check the box next to compilation . 

2. Now compile or upload your program. As you will compile or upload after you check that box you will get a path to a folder where there are temperary files of your system like this C:\Users\HP-PC~1\AppData\Local\Temp\build8697542525264515009.tmp. Copy this path and paste it as shown,remove the name of hex  file. 

3. Once you will hit enter after pasting your path you will reach the place where your hex file is stored.

What is the advantage of knowing about the location of hex file?

There are some great advantages of knowing this information.
  1.  If  you don't actually have a Arduino board, but you want to use the arduino libraries and the ease of coding  in Arduino environment or a code from big arduino community that you want to run .And all you have is  any AVR chip and an ISP programmer like mk-II  or a USB-ASP or some other varient you can compile the program using arduino IDE ,obtain the .hex file and can burn it using the software provided with your programmer. 
  2. There is a software named Proteous which can simulate a microcontroller. You just put in a .hex file and it will simulate and execute the code just like on real hardware. The hex file obtained by the above method can be used to do that too. 

No comments:

Post a Comment