Can hardwarepath in preferences.txt be changed to test an alternate library?


The best way to accomplish this is by putting the boards platform (AKA "core") in the hardware subfolder of your sketchbook. In order to avoid a collision with the stock platform installation, you should change the vendor folder name from "arduino" to something unique like "arduino-development'.

So the folder structure would look something like this:

{sketchbook folder}
|_ hardware
|_ arduino-development
|_ avr
|_ boards.txt
|_ and so on...

This is actually the approach used by the Arduino platform developers.

You can find/set the location of the sketchbook folder in the IDE's File > Preferences > Sketchbook Location or in the sketchbook.path key of preferences.txt if you prefer (but make sure to close the IDE before editing preferences.txt).

which makes me wonder why put that... "parameter" there

I actually haven't noticed it before. It does seem unnecessary.

if the user has no control over it at all :roll_eyes: ?

Despite the file name, in additional to preferences settings, preferences.txt is also used by the IDE to store persistent data. Some of these keys are not of any use to the user and were never intended to be modified by the user. It's a bit of an undocumented mishmash in there. Fortunately, the vast majority of the Arduino users can control all preferences of any interest to them via the GUI, so only the more advanced users delve into preferences.txt. Even some of those may prefer to just use the --pref flag of the Arduino IDE command line interface to set preferences, avoiding ever being exposed to the contents of this file.


Ok, thanks, so done that. It's called Projects/Arduino/harduino. But when I compile the chosen hardware path is still that from /usr/share/arduino/hardware.

Here's the first line from the compile log for the "Fade" example:

/usr/share/arduino/arduino-builder -dump-prefs -logger=machine -hardware /usr/share/arduino/hardware -hardware /home/vinzc/Projects/Arduino/hardware -tools /usr/share/arduino/hardware/tools/avr -libraries /home/vinzc/Projects/Arduino/libraries -fqbn=arduino:avr:uno -ide-version=10807 -build-path /tmp/arduino_build_26838 -warnings=none -build-cache /tmp/arduino_cache_757667 -prefs=build.warn_data_percentage=75 -verbose /usr/share/arduino/examples/01.Basics/Fade/Fade.ino

I suppose there's something I've missed?

Yes. The boards platform must be installed under the "hardware" subfolder of the sketchbook. That specific folder is given special treatment by the builder, as you can see from this part of the arduino-builder command:

-hardware /home/vinzc/Projects/Arduino/hardware

therefore storing it as persistent storage makes no sense at all. At least to me.

I also makes no sense to me. The Arduino IDE installation folder location is determined programmatically, and the hardware folder will always be in a fixed location relative to that.

But perhaps it is possible to adjust this location during compilation via the command line using

arduino --verify --pref last.ide.1.8.7.hardwarepath=/foo/bar

This could be assist in testing the Arduino IDE's handling of the built-in hardware folder during development. As for why the key contains the version number, I have no clue.