Switch to Optiboot Causes Sketch to No Longer Compile

I just upgraded a couple boards to Optiboot 3 not realizing it would have any impact on my sketches. I thought after burning the bootloader I could just switch board types and start enjoying a little extra flash, optimized boot logic, and faster serial. Now my sketch won't compile.

I'm using Arduino 22, just grabbed Optiboot V3 (dropped in sketches/hardware folder), the new board types showed up, and I burned Optiboot v3 on my Seeeduino v1.1 (Atmega168) and Diecimila (Atmega168) with my USBTinyISP and everything went perfectly there. My sketch compiles fine as long as I have the board set to 'Arduino Diecimila, Duemilanove, or Nano w/ Atmega168'. If I just change the board to '[Optiboot] Arduino Diecimila, Duemilanove, Nano, NG w/ Atmega168' the sketch won't compile anymore. I get the following errors:

C:\Arduino\libraries\SPI\SPI.cpp: In static member function 'static void SPIClass::begin()': C:\Arduino\libraries\SPI\SPI.cpp:23: error: 'SCK' was not declared in this scope C:\Arduino\libraries\SPI\SPI.cpp:24: error: 'MOSI' was not declared in this scope C:\Arduino\libraries\SPI\SPI.cpp:25: error: 'SS' was not declared in this scope

I'm obviously using SPI.h in a C++ library. The most research I've been able to do leads me to speculate that this is related to some definitions somewhere in the Arduino cores for these pins that I'm not getting with the Arduino 18 cores included with Optiboot? If I switch the board type back to 'Arduino Diecimila, Duemilanove, or Nano w/ Atmega168' it compiles just fine. I'm stumped since I clearly don't understand the build process, cores, and libraries well enough to effectively troubleshoot this. Can someone point to some information somewhere the details what exactly is included with Optiboot, what ramifications this has on my sketches, etc?

I'm not sure of my next steps and I haven't been able to Google anything usable... any help?

Perhaps you need to create a new boards.txt entry? Take the entry that works, clone it renamed and then change just the bootloader lines?

I checked the boards.txt and the only differences were the required differences. I played with a few alternatives anyway but seemed to be a dead end there.

I did, however, overwrite the included Arduino 18 cores included with Optiboot V3 with the Arduino 22 cores that came with the IDE and my sketch now compiles, uploads, and runs fine. I'm not sure if this was the proper fix or exactly what effect this will have but I pulled the tip from the most recent bug report on Optiboot's issue tracker here: http://code.google.com/p/optiboot/issues/detail?id=43#c0

. from: C:\Arduino\hardware\arduino\cores\arduino . to: C:\Users[user]\Documents\Arduino\hardware\optiboot\cores\arduino

If anyone has any more info on what happened here I'd love to know more about how/why the IDE pulls cores from different locations based on the bootloader selected. I'd also like to understand more about that bug report (denied as a bug by Westfw) linked above that describes this same behavior with String that I was also able to replicate.

I’m using Arduino 22, just grabbed Optiboot V3

From where?

Same issue as the OP with SPI.cpp. Got v3 optiboot from http://code.google.com/p/optiboot/ as I assume the OP did.

Here is another example: SD lib - ReadWrite example - ReadWrite:47: error: 'class File' has no member named 'println'

Wasn't [u]sure[/u] if it was something about my configuration, or if it's an an issue with the optiboot package.

Replacing . . . hardware\optiboot\cores\arduino with hardware\cores\arduino from Arduino-0022 allows the sketches to compile. (Stream.h, WCharacter.h, WString.h, WString.cpp are not included in the optiboot cores)

(Reading the response to the OPs bug report, it sounds like String won't be supported, but I wasn't clear on what the rest of the response meant.)

From one of the readme files…

So a copy of the Arduino 18 core is included here.

The problems are because optiboot includes an old core #. I suggest staying away from that version of optiboot.

Use the optiboot version westfw has graciously provided…

# I will refrain from making harsh sarcastic comments about why bundling a core with a new bootloader is a bad idea. And why abandoning the download site is cruel.

Thanks, I didn't realize there were two versions of this, and that one was so old. I downloaded westfw's branch, but I'm not clear on what I must do to integrate it into the IDE. I take it that it must be compiled?

I have another issue as well. It seems my "basement machine" won't load the sketch at that speed. (My other PC's do.) Not sure where the problem is - USB? Serial? I installed the latest FTDI drivers with no joy. It's the same issue I posted where 1 out of 10 new ATmega328's wouldn't take a sketch on that machine. (You posted a nice picture of a gremlin regarding that problem.) I'm not asking for a solution to this unless someone has an idea.

Regarding a switch to optiboot, if I understand correctly, the two current options are; use one that's easy to install but is based on Rel 0018, or learn how to install westfw's beta. However with as many vendors selling chips pre-loaded with optiboot, it seems I must be missing something. If not, I think I'll have to wait until it's ready for prime time, as I have users that would have to deal with adding it.

There are three choices available: You can download the source code and rebuild. My understanding is that westfw has made this process virtually painless.

You can download "optiboot_atmega328.hex" from westfw's first message or from here... https://github.com/WestfW/Arduino/tree/master/hardware/arduino/bootloaders/optiboot ...and replace the file in the Arduino directory. It should be located in "{ArduinoRoot}\hardware\arduino\bootloaders\optiboot\". When burning a bootloader, select "Arduino Uno".

Or, you can use the OptiLoader sketch... https://github.com/WestfW/OptiLoader ...which essentially turns an Arduino compatible board into an automatic bootloader burner. I suggest this option.

It seems my "basement machine" won't load the sketch at that speed ... You posted a nice picture of a gremlin regarding that problem.


I'm not asking for a solution to this unless someone has an idea.

Try OptiLoader. If nothing else, it will make the process much simpler (and easier to troubleshoot). liudr even added a beep-when-finished to facilitate mass production... http://arduino.cc/forum/index.php/topic,64105.msg558305.html#msg558305

I'm under the impression that once I have an ATmega loaded with optiboot, I still need a boards.txt for optiboot in order to download a sketch to the chip.

If I have the wrong impression, and you can just use the stock IDE that would be great! (The gremlin on my basement machine may have been hiding this fact.)

I've tried the OptiLoader program and it's lightning fast, just couldn't load a sketch with my funky machine.

optiboot bootloader = Uno. As long as the target is running at 16 MHz and you are using the 0022 version (or newer) of the Arduino IDE you just select Arduino Uno. No need to do anything with "boards.txt".

I've tried the OptiLoader program and it's lightning fast


just couldn't load a sketch with my funky machine.

I've said it before and I'll say it again... http://arduino.cc/forum/index.php/topic,61825.msg472270.html#msg472270


Yea, or moths in the tubes! Great news, thanks! John

Howdy, OP here... :D I went away for a few days working on a charging circuit and this thread really picked up some life!

I did indeed grab Optiboot from the first (seemingly fresh) link when I google "optiboot" here: http://code.google.com/p/optiboot/downloads/list . I did get around this just by copying over Arduino 22 cores and it compiled right up and has been working since.

The link to the new Optiboot above does indeed shed some new light here and I'll be grabbing that fork from github. I knew there were some issues for Uno owners but didn't realize it had been forked and fragmented like this. I'll dig in a bit more, burn that version, and report back if I have any issues. The posts here were very helpful and I imagine this should take care of my issue in a more supportable way.

The whole issue makes a lot more sense now too... Thanks guys!

I've never understood why the optiboot downloads included parts of the Arduino core, and the readme file isn't helping any. It probably had something to do with being able to load optiboot back in the days before the Uno. Now that Arduino already includes optiboot, just move the contents of the bootloaders/optiboot directory from the optiboot repository to the .../hardware/arduino/bootloaders/optiboot directory inside your Arduino installation, replacing what is already there.

Now: what is already there is approximately the same as the "version 3" that you downloaded as a zip file. The sorce for optiboot has bugfixes PAST that point (call it "version 4.0", sort of.) So you should get the source rather than the .zip file. Meanwhile. Arduino was hitting bugs (eg with the UnoSMD) that implicated the bootloader, and started modifying the bootloader themselves when the normal optiboot maintainer seemed to have disappeared. About this time I got overatures to take over optiboot for arduino, and I have been doing stuff. The version in my reposetory combines the latest source from the optboot project, the changes from the Arduino project, AND my own enhancements. Mine is the one to try out; it's the one that is most likely to make it onto real arduino boards once testing is complete. And I'm doing the response to questions and additionally reported bugs... So download the individual source files for optiboot from the https://github.com/WestfW/Arduino and put it in the directory where the old files were...

The Readme file is bigger now as well. and has some hints on doing build.

@westfw Just to say thanks for your work and clarification, and also to point out what lead to [u]my[/u] confusion, [u]in case it helps[/u].

The search took me to the bootloader with the core, along with your beta testing thread. "Naturally" I picked the bootloader with core. ;-).

This gave me "[optiboot] xxx" lines in the boards menu. So I assumed you needed a different boards setting to load a sketch to a chip with optiboot. (Even though this didn't make sense considering that optiboot is now being sold with pre-loaded ATmega328s.)

However, it did make some sense, because it wasn't obvious from what I read that you just use the Uno as the target. (I have an old Diecimila). So I thought I did need a boards entry to get the higher baud for uploads. It wasn't until CodingBadly mentioned the Uno that the light went on, and it's all good.

So that's my tale of woe (whoa!). Not complaining, but if I had read something like a "How To use Optiboot" it would have saved a lot of, well, woe. (It does fit in with my tag line, however.) Cheers!