Arduino where is my BIN/HEX file.

Posted by Clifford Agius | CA-Software Ltd on Saturday, May 8, 2021

TOC

TLDR!

I ramble on here about IOT IDE’s etc but if you just want to know how to set the Output Build path then just scroll down to the section called Can this be changed you ask?

Arduino IDE

If like me, you love IOT development then you will no doubt at some point use the Arduino platform or one of it’s derivatives like Teesny or Adafruit. Now this means your hard core and writing in Arduino C/C++ rather than Circuit Python but that doesn’t mean you are using the Arduino IDE; you could be using VSCode or even full fat Visual Studio… (more on that below!)

However, lets start with the default IDE it’s been stuck at version 1.8 for what seems like forever but recently the IDE got a big overhaul and released as version 2.0 but currently in Beta. The new Beta version installs side by side with the current stable so well worth downloading and taking for a spin.

New IDE Improvements

The new IDE even though it’s still in BETA is a huge improvement over the old one and now allows code completion and intellisense which makes it feel more like an IDE than a fancy version of Notepad. However, it still annoyingly opens a new instance of the IDE if you open a new project or .ino file which for some odd reason drives me nuts.

The other gains which are explained much more deeply in their recent blog post are the inclusion of a form of debugging if you are using one of the supported boards and have a JTAG debugger, this for me is very good as we all know we don’t write perfect code first time (No you don’t so don’t lie to yourself… 😉) so being able to test and debug without having Serial.Print() statements everywhere or blinking an LED for error codes is awesome if you ask me.

I will be playing with the IDE more to see if it’s worth using for this alone and if it will pull me away from VisualStudio…

Yes, I use Visual Studio

Yes, I really do… I use Full fat Visual Studio for my development and work with IOT boards, this is because I am happier with the VS19 IDE as it’s where I live day to day either with IOT or Xamarin/MAUI Projects so my muscle memory of key binding etc is happier there. I have an amazing extention installed called VisualMicro which you can get Here now it’s not a free extention but for the small fee it’s more than worth it and works with all versions of Visual Studio even the free community edition.

Visual Micro Toolbar

Under the hood it’s using the Arduino tooling for the builds and library’s etc, but it adds Debugging and F9 works! it’s freaking amazing.

You can stay in Visual Studio and manage all the Librarys and config of the board you are targeting there really is not reason to leave.

As for debugging yes thats F9 breakpoints, it works by injecting a little bit of code into your Binary to pause with a WHILE loop and wait at the breakpoint and sends the data via the serial port (This is my understanding anyway!) it just works.

This means you can use the normal VS19 debug tooling to add conditionals/actions etc to your breakpoints as well. However, as it is injecting this snippet of code into your binary adding/removing breakpoints isn’t like debugging your C# DotNet program, you do need to build and upload the code to the board for changes to take effect.

How about VSCode

VScode is amazing and a great light weight IDE, again it uses the Arduino tooling under the hood but is more closely tied to the tooling so it’s essentially (As far as i’m concerned anyway) the Arduino IDE but in a much better editor. VSCode is of course free and super light weight and runs everywhere so if you’re a Mac/Linux user or even doing IOT development on an IOT board like a raspberryPi VScode would be my choice over the Arduino IDE or at least the current stable version 1.8 anyway.

Currently there is no F9 debugging in VSCode to my knowledge but with this coming to the new V2.0 Arduino IDE I assume it will come to VSCode in the near future.

But Cliff this Blog is titled about some Bin/Hex thing.

Well yes, it is but I wanted to promote the VisualMicro extention and highlight that you’re not stuck with the Arduino IDE if you don’t want to be, but here is the stuff about the Bin/Hex file.

As I am sure you know you write your awesome code and have the LED’s dancing, or you Temp and Humidity sensor is reporting it gets warmer and wetter when you breath on it and you’re uploading from your chossen IDE (Any of the 3 mentioned above!) and its great it works.

But now you want to go into production and load the code to 10 device or 200 so you need the Binary or HEX file to upload directly but where is it hidden…

As all the IDE’s use the Arduino IDE under the hood they all save the file where it’s set to be saved in the Arduino IDE, and the default for this is deep in some Temp folder thats hard to find and gets blown away if your disk clean-up tool runs to find you some much needed hard drive space so not ideal.

Now it would be nice if the output window shows where the file is located but that sadly doesn’t happen…

IDE Build Output Window

Even in Visual Studio with the VSMicro extention it’s not shown!

Visual Studio Output Window

But if you do some digging you will find it buried in CurrentUser/Appdata/Local/Temp/Arduino_build_XXXX

File Explorer showing where the file is located

Can this be changed you ask?

Why yes it can but it’s not obvious how and hence this blog post as I needed to change it on my current laptop and forgot how so I am really writing this for future cliff (Hope you don’t regret this cake I am about to eat #SorryNotSorry!)

The way this is done and it’s the same if you’re using any of the IDE’s is to open the Arduino IDE and go to File->Preferences.

Arduino IDE Preferences window

as you can see there is a link to the underlying preferences.txt file so click that to open the folder and then open the txt file in your favorite editor which is obviously VSCode right…

This link is missing from the new Arduino IDE 2.0

Preferences File location link

As you can see all the settings used by the IDE’s can be set/changed in here if you really want to.

Preferences.txt file contents open in VSCode

But to change the location of the Build output we need to add a simple line of

build.path = C:\MyNewSaveLocation\Shipit

Obviously set the folder location to where you want it on your machine/network.

Build.Path added to the Preference.txt file

IMPORTANT NOTE

This has caught me out more than once and did again when I did it this time…

It’s very easy to click the link to open the file and make a change, then close VSCode/Notepad etc and crack on expecting your change to be there. You then close the IDE and open it again and the change didn’t take so you repeat and start along the developer’s line to insanity.

For the change to take effect you NEED to make sure that the Ardiuno IDE is closed BEFORE you save the txt file with your changes otherwise it will be ignored and overwritten.

Once you have saved your changes you can open which ever of IDE’s you have picked to develop with, which I hope is Visual Studio with the VisualMicro Extention and the builds will now output to this new location.

Final Notes.

As I do a lot of development and switch around between IOT and DotNet Land I prefer to stay in Visual Studio, but if you are tinkering and playing with IOT then don’t feel you have to buy VSMicro it is awesome and priced nice and low. But you can get just as far with VScode and there is a growing list of VSCode extentions for IOT developement you can try out.

Thanks enough from me so,

Happy Coding!