HOWTO: Store Projects settings (like F_CPU, USB, Keyboard-layout)

Frank B

Senior Member
HOWTO: Store Project Settings

- Advanced users only -

I found a way to store project-settings.
Why ?
I often need different setting for projects, and often I forget to select the correct options in the IDE.

The following shows a way to store them on a per-project-basis.
For example: A Sketch needs - or works best - with F_CPU=144Mhz

Copy the attached platform.txt to Arduino\hardware\teensy\avr\platform.txt (overwrite the existing, but make a backup before)

- It adds the following command to the commandline of GCC:"@{build.path}\sketch\defs.h"
- If the file does not exist, it writes an empty defs.h to prevent error-msgs during compilation

Create a file "defs.h" in your project-directory (where the .ino file is)
Example file: (overrides the F_CPU setting)

- The first line undefines the existing definition
- The second line defines a new F_CPU (144MHz in this case)

You're done.
void setup() {

void loop() {}
1. Create the mentioned defs.h file above in the same directory.
2. Compile the sketch with - for example 24MHz - and watch the output.

The file-extension ".h" is not the best - i tried an other one, but it did not work (the file was not copied to the build-directory)

In the attached platform.txt is a line: /c if not exist "{build.path}\sketch\defs.h" "echo.>{build.path}\sketch\defs.h"
[edit]We need one more line for MAC:

Would be great if someone can test this and says "Yes, works!" :cool:

EDIT: Replaced platform.txt with a non-TYQT-version

EDIT: Find platform.txt for Arduino 1.8.5 in this post:

EDIT: Find platform.txt for Arduino 1.8.7 in this post:



  • platform.txt
    4.9 KB · Views: 253
Last edited:
One was to do it is to use conditional compilation to use #error if the settings aren't right.

For example TeensyTransfer uses the following to make sure the speed is 120 Mhz or less:

#if F_CPU>120000000
#error LOWER CPU SPEED TO 120MHz!!! ...or remove this line and know that the printed Serial and MAC will not be correct :)
Other possibilites:

Want to use a special optimization-level ?:

In addition, it allows to publish projects with a set of options.
Last edited:
Hi Frank,

Looks interesting.

It is sort of along the lines I was asking about yesterday in the posting:

In particular if you look at the standard AVR platform.txt file, it has a section in the file:
# This can be overridden in boards.txt

# These can be overridden in platform.local.txt

That it looks like there is a setup to be able to use platform.local.txt, but I have not figured out where these files can be setup.

Then their receipes use these symbols, like:
## Compile c++ files
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
So was asking if this worked this way, if it made sense to add these to the Teensy version of platform.txt.

Thanks Frank
So far I have not seen any good documentation on it yet, only some forum posts and the like up on Arduino forum... May have to pull out a non-teensy board and see what it does
And, finally, this is a way to prevent inclusion of unused serial-devices and their RAM-consuming buffers.
Frank: Quick update, I tried making a simple blink program, that allowed me to define the blink rate... tried putting in platform.local.txt into the sketches folder and it was not picked up.

I see back at the Arduino issues:
matthijskooijman said:
I added platform.local.txt but never got around to documenting it once the PR got merged.

The main usecase for platform.local.txt is to allow overriding values in a platform.txt file which is being tracked by e.g. git, so you prevent having modified files. I think it does not allow modifying platform.txt from another directory (e.g. I don't think you can put a sketchbook/hardware/arduino/avr/platform.local.txt file to override arduino_install_dir/hardware/arduino/avr/platform.txt).

You say you cannot override the compiler.c.flags? I think I had an override for that for a while (to add C++11 support), though I'm not entirely sure now. Where is your platform.local.txt?
So it looks like it is simply a way for you to add your own settings for all projects that use that platform, as to not edit the main github file...

So I think your approach is looking more promising.

6 Downloads, and nobody told me that the platform.txt was the TYQT version (does not work without it) ???

Post #1 updated.
Last edited:
Sorry, I meant to mention it. Also it was specific to I believe the 32 bit version of TyQt...

Yes - So of hard to decide what file name to use, I understand the idea of the .h as you can then see the file as part of your sketch.

Actually I wish there was a way that the options could be specified as part of the main .ino file. I believe I remembered some other IDEs in the past where you could have something like either special comments or #pragma like statements that could specify things like, which processor and maybe comm port... But my guess is that would be a lot more work...

.h : The builder does not copy other files to the buidl-directory. I tried an other extension, but this does not work.
But seeing the file in the Ardio-IDE is not bad..

Other IDEs: Yes.. Arduino is the only "IDE" I know, that does NOT store project settings. It would be so easy to add it. I have no idea why they don't add this feature.:mad:
Last edited:
I guess, the line should be something like
recipe.hooks.sketch.prebuild.1.pattern.linux= bash -c "[ -f \"{build.path}/sketch/defs.h\" ] || touch \"{build.path}/sketch/defs.h\""
But it complains about a missing "]"
I'm not that linux expert ...
Ok, I found the problem. Linux works now. I have updated the platform.txt in post #1
MAC: still a TODO.
Last edited:
Good work Frank - Everyone should use TYQT - it would have worked for me :)

When you build a sketch there is a JSON file in that directory - shown on verbose output:

Not sure where this comes from >> That file in my case has this empty entry: >> "customBuildProperties": "",
"builtInLibrariesFolders": "I:\\arduino-1.6.11\\libraries",
"customBuildProperties": "",
"fqbn": "teensy:avr:teensy31:usb=serial,speed=96opt,keys=en-us",
"hardwareFolders": "I:\\arduino-1.6.11\\hardware,C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages",
"otherLibrariesFolders": "C:\\tCode\\libraries",
"runtime.ide.version": "10611",
"sketchLocation": "C:\\tCode\\RTC_time\\RTC_millis\\RTC_millis.ino",
"toolsFolders": "I:\\arduino-1.6.11\\tools-builder,I:\\arduino-1.6.11\\hardware\\tools\\avr,C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages"

There is also this from preferences:: "C:\Users\xyzz\AppData\Local\Arduino15\preferences.txt"

I didn't catch a hook there?

But I do see it has a list of not just the '10 recent' sketches - but what looks like a pages long complete list of each sketch I touched. Would be nice if the IDE gave a way to display those.
Hm, yes, I think i don't understand... how would that be useful, without editing Arduino or Teensyduino-source ?
Tim, it works with TYQT, too. Just clik "integrate into Arduino" again, after overwriting the file "platform.txt"
Last edited:
Hm, yes, I think i don't understand... how would that be useful, without editing Arduino or Teensyduino-source ?

I just looked there and hoped maybe there was a way to use that I didn't know about - based on the name it seemed like it

Tim, it works with TYQT, too. Just clik "integrate into Arduino" again, after overwriting the file "platform.txt"

Of course I'd do that - and posting without that is right - I was just wondering how many are using TYQT of the 6 downloads - and trying to add something useful to get on the notify list for thread updates.
I just found something else that might make a good compile time editable #define value that is currently a constant - DELAY during init:

in Pins_teensy.c - the 400 in delay(400)::
void _init_Teensyduino_internal_(void)
[COLOR="#FF0000"]    // ...[/COLOR]
	// for background about this startup delay, please see these conversations
	// [URL=""][/URL]
	// [URL=""][/URL]
[COLOR="#FF0000"]    // Last two lines show this wait to call setup()[/COLOR]

On my Windows 10 machine (With Beta T_3.6 and a T_3.0) I just replaced this with 40 - and it works to get into setup() at 40 not 400.

USB is online printing to the newest TYQT in under 500ms [409-434 on a few resets] instead of ~800ms.

Also this delay() time seems to be ever present, not just when USB is in use.

Tried again at delay(4) or REMOVED and USB is online even faster at 400ms [395-413 on a few resets].
If i remember correctly, this delay was introduced for I2C Chips, mainly.
But, nevertheless, this sounds good.
Indeed this thread is :: - Advanced users only -

If you click the thread hyper links copied with the code they cover some of that. One issue at the time was T_3.2's not starting right - I didn't have a T_3.2 at this desk.

THIS WORKS :: Just typing this - Wondering if just reworking those last lines and doing USB_init like this for the same net time delay before setup() - but USB online 300ms faster::


Made a pull request to let Paul consider this. The net USB online time with that is again 405 ms!

* :: this will need testing on other OS's against the Teensy family

[Hey KurtE - I did my very only pull request - using online web github again]

<edit> : temporary fail on github again - here is a PULL to Paul - not to myself ::
Last edited:
Looks like it does not work anymore- because of Arduino 1.8.5 ?
Any Ideas how to fi this ? I was away some time... Has anyone solved that yet?
fixed Arduino 1.8.5

Ok. Fixed.

Platform.txt for Arduino 1.8.5 as attached.


  • platform.txt
    6.2 KB · Views: 228