# Programming an ATtiny 85 with Arduino

I followed this tutorial and got the following error when trying to compile upload the attiny85 sketch:

avrdude: usbdev_open(): did not find any USB device "usb"


The attiny is already soldered on a circuit (with two leds, a buzzer, button and a brightness sensor). Can this cause the error?

Also, the attiny already has a program on it (that I want to overwrite) so I assume I don't need to install the bootloader?

I found two files with the attiny hardware files, one that adds ATtiny85 (w/ Arduino as ISP) and one that adds ATtiny 85 (internal 1Mhz clock) to the Board menu. When using the first one (Arduino as ISP) i can only compile the blink sketch when I add

#include <Arduino.h>
#include <wiring.h>


otherwise it says "OUTPUT" was not declared in this scope.

UPDATE: Tried it with setting programmer in the tools menu. I changed it to Arduino as ISP. The error is now a different one (with upload as well as upload using programmer):

avrdude: stk500_getsync(): not in sync: resp=0x00


- Board: ATtiny85 w/ Arduino as ISP - Programmer as ISP - COM port correct (I also tried the other one)

Sometimes I get this error (only with normal upload), which indicates a successful upload according to the tutorial, but the ATtiny still performs the program that was installed before.

avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85
avrdude: stk500_program_enable(): protocol error, expect=0x14, resp=0x50
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.

avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51

-
 And the question is...? – stevenvh Aug 19 '12 at 15:47 @stevenvh What can cause the error?, How can I circumvent it? – Toast Aug 19 '12 at 16:04 Are you following these instructions? – Dean Aug 19 '12 at 18:46 @Dean Yes, these instructions are the same. They provide different "board" files (that go to the hardware folder) but both of them lead to the same error. – Toast Aug 19 '12 at 19:48 This is almost certainly an error in not telling avrdude how to talk to the arduino as a programmer (or not preventing it from resetting the arduino), rather than anything to do with the chip/board you are trying to program. – Chris Stratton Aug 19 '12 at 21:33

UPDATE 2

If the tiny is running a sketch then it must already have a bootloader.

I think there are a lot of factors to be wrong here because the tutorial was written pre arduino 1.0. I think the 1mhz one is a problem and best avoided for now. The tin85 w/ Arduino ISP sounds to be pre-arduino 1.0 and needs to compile correctly.

In a few days I will have some time so if you haven't fixed it by then I hope to give you some info.

First I will take 2 arduinos, one as ISP and one as normal arduino. We need to prove the ISP sketch is working correctly when uploading blink to a 2nd arduino.

Once the ISP is proven with arduino 1.0 we need to see why normal compile of the tiny85 fails. It might be there is an updated tiny85 hardware folder for arduino 1.0 on the web but if not then we can change the tiny85 hardware folder sources to use 1.0 instead (hopefully).

FYI: You mention the arduino.h, in versions earlier than arduino 1.0 the file was called wprogram.h, arduino 1.0 also expects a few other differences. If the tiny85 is including wprogram.h I think it will be a problem to also include arduino.h

IDEA

If you have some time spare why not go onto the arduino.cc and down load version 0023 of the arduino IDE. (All of the older version of arduino are available). Upload the Arduino ISP example to the UNO using 0023 then try the upload to the tiny85 (w/ arduino ISP) for the blink sketch. I would expect 0023 to work exactly like the video, so if it fails you can look to the wiring of the tiny85 for the problem. It it works we will know we need to update the tiny85 hardware folder to arduino 1.0 format

If it works in 0023 then you should follow Deans instructions above for Arduino 1.0.1.

UPDATE

The only way I can find to reproduce the error you see is if I attempt to "Upload using programmer" when the programmer is set to "AVRISP". If I upload the ISP sketch to an arduino and attempt to program an unconnected tinyxx I get different errors.

So sorry if these are time wasting questions but.. are you clicking "Upload" in the arduino ide or "Upload using programmer"? You should be clicking "Upload" after selecting the ATTiny (w/ Arduino ISP) as the board.

Info..

It is a bit confusing but the board definition for ATTiny xx (w/ Arduino ISP) forces the correct programmer settings for the normal arduino "Upload". In the arduino ide, the menu item "Upload using programmer" uses whichever programmer is selected on the "Tools>Programmer" menu, in this case probably AVRISP mkII which, if unconnected, will produce the error you have reported.

-
 I checked this part of the ISP code and it originally had a delay of 20. – Toast Aug 21 '12 at 18:20 Okay, so what I tried now is disconnected all wires from the arduino, uploaded the ArduinoISP sketch, then attached a 5uF capacitor between reset and ground with - to ground and unplugged and replugged the Arduino. The device manager displays the Arduino UNO, but no ISP. Am I supposed to see an ISP entry in the device manager? – Toast Aug 21 '12 at 20:07 Ignore my comment about device manager. More info posted above as can only seem to add a 1 line comment – Visual Micro Aug 22 '12 at 14:05 I updated the question and reported what happens if I set a programmer. – Toast Aug 22 '12 at 15:34

Do you have AVRStudio installed as well? If so, your PC might use a "wrong driver" for your AVRISP mkII programmer.

The driver that comes with AVRStudio is not compatible with avrdude. Re-install the driver (the one that comes with avrdude/Arudino IDE) or use a different PC.

-
 There does not appear to be an avrisp mkII involved – Chris Stratton Sep 13 '12 at 12:39 I dont have AVRStudio installed on my PC. – Toast Sep 21 '12 at 13:24

Unplugging and re-plugging may fix it. Otherwise you may want to look at a similar question here.

-