Programming Virgin Arduinos
Once your PCB’s arrive, the microcontrollers are completely blank. They will run at 1Mhz using the internal oscillator, and don’t have an Arduino bootloader.
1. Programmer and Drivers
I’m using a USBasp Clone. Use Zadig to install the libusbK driver. Don’t use libusb-win32, it doesn’t play well with the Arduino version of avrdude.
It is very important to close JP3 on the USBasp for setting initial fuses as the target clock is less than 1.5Mhz. Otherwise avrdude won’t be able to communicate with the microcontroller.
Before the fuses are set, the AVR will use the internal oscillator and run at 1Mhz). Once the initial fuses are set, open JP3 again for faster programming. If nothing is working, you probably just forgot to close JP3. Don’t ask how i know.
The connection between the USBasp and the ICSP header should be self-explanatory, MOSI to MOSI, MISO to MISO, SCK to SCK etc.
As of Arduino IDE 2.0, the USBASP Clone works out the box. After installing the libusbK driver, your should be good to go. The instructions below are retained for reference.
Also, the default USBasp settings in Arduino IDE won’t work with a USBasp clone. We need to modify programmers.txt in the Arduino IDE root directory and add an entry for USBasp Clone:
usbaspclone.name=USBasp Clone
usbaspclone.communication=usb
usbaspclone.protocol=usbasp-clone
usbaspclone.program.protocol=usbasp-clone
usbaspclone.program.tool=avrdude
usbaspclone.program.extra_params=-Pusb
At this point, you can try to “Burn Bootloader” in the Arduino IDE. Make sure to select your new “USBAsp Clone” as programmer. If you are lucky, it will work and you can stop here. If not, follow the next steps below:
2. Avrdude
Avrdude is the software used to communicate with the microcontroller, we need this to set fuses before the microcontroller will work as an Arduino. I use the 6.3 version found here, the one bundled with Arduino IDE doesn’t seem to work until the fuses are set.
3. Setting Fuses
The fuses set some very basic settings on the microcontroller, like telling it to use the external crystal at 16Mhz instead of the internal oscillator. Make sure JP3 is bridged for the initial connection.
First read the fuses to verify avrdude works and can talk to the microcontroller:
avrdude -cusbasp-clone -patmega328p -Pusb -b 19200 -U lfuse:r:-:i -v
The end of the output should look like this on a blank ATmega328p
avrdude: safemode: hfuse reads as D9
avrdude: safemode: efuse reads as FF
avrdude: safemode: Fuses OK (E:FF, H:D9, L:62)
avrdude done. Thank you.
Now we are ready to set the fuses:
Arduino Nano Fuses | Arduino Mega Fuses |
---|---|
avrdude -cusbasp-clone -patmega328p -Pusb -b 19200 -e -Ulock:w:0x3F:m -Uefuse:w:0xFD:m -Uhfuse:w:0xDA:m -Ulfuse:w:0xFF:m | avrdude -cusbasp-clone -patmega2560 -Pusb -b 19200 -e -Ulock:w:0x3F:m -Uefuse:w:0xFD:m -Uhfuse:w:0xD8:m -Ulfuse:w:0xFF:m |
The output should look like this:
avrdude: safemode: hfuse reads as DA
avrdude: safemode: efuse reads as FD
avrdude: safemode: Fuses OK (E:FD, H:DA, L:FF)
avrdude done. Thank you.
4. Burning the Arduino Bootloader
Now we’re ready to burn the Arduino Bootloader to enable future programming from the Arduino IDE via the FTDI header. Open the Arduino IDE and select Tools -> Programmer -> USBasp Clone. Then select the proper board in Tools -> Board. Finally Burn the Bootloader with Tools -> Burn Bootloader. There will be a lot of noise from avrdude which should end in something like this:
avrdude: verifying …
avrdude: 1 bytes of lock verified
avrdude done. Thank you.
Now i suggest you run the Blink example to verify all is good. You can upload the sketch using the USBasp as well, just go to Sketch -> Upload using Programmer. If you have a LED on D13 it should now be blinking once per second. Congratulations!
![](https://i0.wp.com/warthogathome.com/wp-content/uploads/2022/09/ezgif-2-3deeed1375.gif?resize=320%2C180&ssl=1)