Note: This guide covers installing the Arduino bootloader on ATmega processors so they can be programmed and used just like full Arduinos. For the guide on configuring the Arduino IDE to program ATtiny microcontrollers directly, click here.
WARNING: breadboards.co.nz takes no responsibility for third-party software you install on your computer. We can't vouch for anything that you don't download from us.
Sometimes you want to use an AVR microcontroller instead of a full-blown Arduino; after all, they can do anything an Arduino can, yet they are so much cheaper. The good news is, you don't have to use AVR Studio or any special kind of programming; because Arduinos are essentially just carrier boards for AVR microcontrollers, you can code them directly from the Arduino IDE!
Most Arduino boards carry ATmega processors. What makes them special is the bootloader, which allows the microcontroller to be programmed via a normal serial port. The steps in this guide cover the installation of the bootloader onto the ATmega328 processor, the same processor that is on the Arduino Uno.
Step 1: Get the Arduino IDE
If you don't already have it installed, you can download and install the Arduino IDE from here. Note though that we do not recommend the Web Editor - when last we checked (June 2017) it is limited in functionality, and installs a root certificate authority on your computer. We are inclined to trust Arduino as a company, but this is a scary prospect!
Once installed, you can continue with the rest of these steps.
Step 2: Connect the programmer to the microcontroller
We don't cover this step in this guide yet; it will be covered in a future tutorial. In the meantime, you can look up the pinouts of the programmer, and look up the connections of the ATmega processor you're using via its datasheet. You will want to use the standard programming interface, i.e. MISO, MOSI pins for the next few steps.
Step 3: Set up the IDE to talk to the microcontroller
In the Tools menu, open the Boards: ... submenu and select the Arduino/Genuino Uno. This board carries the ATmega328, which we are using for this example; for another ATmega, simply choose the corresponding Arduino board from the menu (e.g. for the ATmega2560, choose the Arduino/Genuino Mega or Mega 2560).
Next, in the Tools menu again, open the Ports menu and select the correct port for your USBasp programmer.
This next step will only need to be done once. In the Tools menu again, under the Programmer: ... menu, select the USBasp option (unless you're using a different programmer; if you are, select that one.)
Step 4: Burn the bootloader
Don't worry, nothing actually gets burnt!
In the Tools menu, simply select "Burn Bootloader". This will flash the Arduino bootloader onto your ATmega.
Step 5: Switch to the ATmega's serial interface
From this point on, your ATmega will now behave just like an Arduino, so you will need to use the FTDI board to communicate with it instead. You can now disconnect the programmer.
We will cover the actual connections of the FTDI board in a future, but you will want to connect it to the ATmega's primary UART pins (Rx, Tx). Have a look at its datasheet for the right pins to use.
Note that you may need to connect the DTR pin to the ATmega's reset pin so that the IDE can auto-reset the device.
Step 6: Code!
Congratulations, you've made yourself a lightweight Arduino Uno - without most of the extra baggage, and at a much lower cost. You can now code it and upload sketches like you would any other Arduino.