Arduino 1.6.12 – adding Optiboard boards.txt

Optiboot is the default bootloader for Arduino Uno, and I use it other Arduinos (eg Nano) for all the good reasons Arduino put it on Uno.

To make that work conveniently, I append the Optiboot boards.txt file to the Arduino distribution.

Above is a screen dump of the options added by the appended file.

Here is the modified boards.txt in for Arduino 1.6.12.

Arduino 1.6.12 seems to use the boards.txt located at %LOCALAPPDATA%\Arduino15\packages\arduino\hardware\avr\1.6.15 in my Win10 installation… but it could be in difference locations in different Arduino and Windows versions. Find it and replace it with the one in the zip to added the full Optiboot options.

Note this will probably be overwritten by version updates of either Arduino IDE or perhaps even just the board manager. Arduino has not come to a good solution for user extension to boards.txt… not yet anyway.

Here is a bat script that I use to perform the work, it needs to be rerun after board manager has been run, it might be the basis for your own work.

@echo off

rem generate a unique workfile name
set /a workfile=%RANDOM%+100000
set workfile=work-%workfile:~-4%.tmp
echo rand is %workfile%
if exist %workfile% goto tryworkfileagain

set BOARDSDIR=%LOCALAPPDATA%\Arduino15\packages\arduino\hardware\avr\

rem get directory listing
dir /ad /on /b %LOCALAPPDATA%\Arduino15\packages\arduino\hardware\avr\ >>%workfile%
rem get the last entry 
for /F %%f in (%workfile%) do set BOARDSDIR=%BOARDSDIR%%%f\

rem strip optiboot section from end if it exists
rem sed -nf AddBoards.sed <"%BOARDSDIR%boards.txt" >"%BOARDSDIR%boards.bak"
sed -bne "/#DO NOT MODIFY BELOW/q;p" <"%BOARDSDIR%boards.txt" >"%BOARDSDIR%boards.bak"

rem copy /b /y "%BOARDSDIR%boards.txt" "%BOARDSDIR%boards.bak"
echo #DO NOT MODIFY BELOW, it may be overwritten (AddOptiBoards.bat). >%workfile%
copy /y /b "%BOARDSDIR%boards.bak" + %workfile% + optiboot\boards-1.6.txt "%BOARDSDIR%boards.txt"
del %workfile%

Note the location of the Optiboot boards file. Arduino IDE is not very stable so path names may change rendering the script ineffective. One day, Arduino IDE might contain a feature for painless user extension of the boards file.

A Python script to do the same thing…

#Script to append optiboot boards.txt to Arduino boards.txt
import os
import re
import io
import sys


def SubDirPath(d):
    return filter(os.path.isdir, [os.path.join(d,f) for f in os.listdir(d)])

def LatestDirectory(d):
    return max(SubDirPath(d), key=os.path.basename)


#strip opti from boards.txt to bak'\\boards.txt', 'rt',newline=None)'\\boards.bak','wt',newline=None)
p=re.compile('^\#DO NOT MODIFY BELOW.*\(AddOptiBoards\)')
for line in boards:

#write original from bak to boards'\\boards.txt', 'wt',newline=None)'\\boards.bak','rt',newline=None)
for line in bak:

#write opti to boards
boards.write(u'#DO NOT MODIFY BELOW, it may be overwritten (AddOptiBoards)\n'),'rt',newline=None)
for line in opti:
boards.write(u'#END (AddOptiBoards)\n')

if sys.version_info[0]==2:
    raw_input("Press ENTER to continue.")
    input("Press ENTER to continue.")

Both or these scripts assume they are run from the Optiboot distribution directory (cloned from the repo).