Post Image
By Matt GaidicaJanuary 22, 2020In Uncategorized

Including INO Files in Arduino Compilation as a Library

Libraries help consolidate code and reuse it across multiple Arduino sketches. However, what if you want to reuse Arduino sketch code/functions? The Arduino Build Process states the following pre-process step:

All .ino files in the sketch folder (shown in the IDE as tabs with no extension) are concatenated together, starting with the file that matches the folder name followed by the others in alphabetical order, and the .cpp extension is added to the filename.

This doesn’t help re-use sketch code, though. I discovered a symlink will allow you to maintain a sketch in a central location and compile it with your sketch in a another location.

  1. Place the “library sketch” anywhere you want (let’s call it, myFunctions.ino).

  2. Open Terminal and create a symlink: >> ln -s /path/to/sketchfolder myFunctions.ino

Now you should have a symlink in your sketch folder that acts like an actual file. You can edit myFunctions.ino in a central location and it will compile with the other sketch.

svgEnergy Harvesting and Charging Lithium Polymer Batteries
svg
svgLow Power Showdown: uSD Card Sleep and Write Current Draw