In order to be able to play with ATtiny devices, you need a programmer. Unlike Arduinos, which have a boot loader using which you program it directly over the USB serial connection, ATtinys don’t have such a direct connection. You need a separate device that can put the ATtiny into programming mode, and send it the code. You can use an Arduino to do that, by using a specific sketch that handles the programming protocol and that passes on the code to the ATtiny it is talking to.
The are many to wire up the Arduino and the AVR device that you want to program. One schematic I found adds 3 status LEDs to the setup, so that you can visually monitor whether the device is being programmed. I modified the schematic to include both an 8 pin socket and a 28 pin socket, so that it can be used to program both ATtinys and ATmegas. I also added a 4th LED that is wired to digital pin 0 on both the ATtiny and the ATmega socked. This can be used to test a chip, by downloading a “blink” sketch to it that pulsates digital pin 0.
I turned this into a “shield” that can be plugged onto an Arduino, to have a semi-permanent programmer at my disposal. The PCB for this looks like this:
Bottom of the PCB
Top of the PCB, with component indications. The red traces symbolise jumper wires.
The finished programmer looks like this:
I forgot to put an external crystal on the board for the ATmega socket, so I wired this in place after the fact; it’s ugly, but it works…
The Arduino IDE
You have to update your Arduino IDE to be aware of the ATtiny / ATmega programmer. Install the definitions below in your Arduino IDE to make this work (references 2 and 3). When programming, you select the MCU type (Arduino328 or ATtiny), and select “Arduino as ISP” as the programmer.
The shield can be used to program ATtinys (45 / 85) directly. For ATmegas, I haven’t succeeded in programming them directly. However, I did succeed to upload the Arduino bootloader to ATmega328 chips using the board. The chips can then be plugged into an Arduino (replacing the original chip) to program them with a sketch. It’s not as nice as direct programming, but it does provide a way to start playing with bare Arduinos. (See e.g. Katootjes jukebox 2: revisited.)