Before you do anything else, load up ebay and buy a couple of cheap clone Arduino - uno’s or nano’s (I find the nano more convenient - buy I also despise the male dupont jumpers). Stuff happens, and you don’t want to have your project put on hold for weeks for that. Heck I let the smoke out of a nano just a couple days ago. should have put the housing on the dupont jumper before plugging it in (power and ground were touching, and it was a nano with that undersized diode that’s easy to burn out. Particularly annoying, because it was an unusually nice nano clone, and I’d just been thinking about how nice it was when I plugged it in and smoke came out.)
Okay, now that you’ve ordered a couple of cheap replacements for when (not if) you trash your board
If you just need the board running at 8MHz (not the 8MHz bootloader, then it’s easy-peasy… the annoying part is going to be uploading - but even that’s not too bad… Install MCUDude’s MiniCore, that gives you an 8MHz board def ready to go no baggage…
With verbose upload enabled in preferences, do an upload with 16MHz selected (doesn’t matter what sketch, of course, it should upload no problem). Scroll up in the console window to find the avrdude invocation, something like this:
C:\Users\Pete\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude -CC:\Users\Pete\Documents\Arduino\hardware\MiniCore\avr/avrdude.conf -v -patmega328p -carduino -PCOM11 -b115200 -D -Uflash:w:C:\Users\Pete\AppData\Local\Temp\arduino_build_665436/jtag2updi.ino.hex:i
(of course, different paths, different sketch names).
Copy-paste it into a text editor.
Now, go to your real sketch, select an 8MHz board definition.Don’t bother trying to upload them (they won[t upload successfully, because the 8MHz bootloader uses a different baud rate - but you’re uploading to an 16MHz board; may or may not be worth it to actually make a board def for this; that’s beyond the scope of this post). To make your board run at 8MHz instead of 16, we just want to divide the clock by 2, starting as soon as we can. At the beginning of setup, do:
That sets the prescaler to 2. And since you’re compiling for 8MHz, but the board has 16MHz crystal, as soon as your sketch starts running, that will halve it’s clock speed so it will be running at the desired 8.
To upload that:
Sketch → export compiled binary
Sketch → Show sketch folder
Copy-paste the name of sketch and the path to the folder into that text file.
Replace the path to the .hex in the original avrdude invocation with that one, save it, and paste it into a command window (could even make it a batch file if you’re going to be doing this alot with one sketch name)