ATiny85 Simple Sketch upload issue

Hi all,

I am trying to upload a simple sketch below to my ATiny85. I am using a UNO as ISP programmer. The IC programs and operates fine i.e LED connected to each output, flash in turn. When I come to reflash the code either with the same or another code, it does not allow programming or the bootloader to be burnt again. I have not used the physical pin 1 for anything as it is the RESET pin and other online posts report it should be avoided. I can run different sketches that I created in the past that can be re-flashed many times over using a fresh IC.

I don’t require this code for anything, just trying to learn what is happening. Thanks in advance!!

                               ATtiny85

                                -------u-------

            RST - A0 - (D 5) --| 1 PB5   VCC 8 |-- +5V

                               |               |

                  A3 - (D 3) --| 2 PB3   PB2 7 |-- (D 2) - A1  -->

                               |               |

                  A2 - (D 4) --| 3 PB4   PB1 6 |-- (D 1) - PWM --> 

                               |               |

                        Gnd ---| 4 GND   PB0 5 |-- (D 0) - PWM -->

*/






int pin2 = 3;

int pin3 = 4;

int pin5 = 0;

int pin6 = 1;

int pin7 = 2;




void setup()

{

  pinMode (pin2, OUTPUT);

  pinMode (pin3, OUTPUT);

  pinMode (pin5, OUTPUT);

  pinMode (pin6, OUTPUT);

  pinMode (pin7, OUTPUT);

}




void loop()

{

  digitalWrite (pin2, HIGH);

  delay(100);

  digitalWrite (pin2, LOW);

  digitalWrite (pin3, HIGH);

  delay(100);

  digitalWrite (pin3, LOW);

  digitalWrite (pin5, HIGH);

  delay(100);

  digitalWrite (pin5, LOW);

  delay(100);

  digitalWrite (pin6, HIGH);

  delay(100);

  digitalWrite (pin6, LOW);

  digitalWrite (pin7, HIGH);

  delay(100);

  digitalWrite (pin7, LOW);

} 

Do you have anything connected to the programming pins (Pin 5 (PB0) MOSI, Pin 6 (PB1) MISO, Pin 7 (PB2) SCK)? I’m just thinking that if e.g. you had a LED directly connected to one of those pins it may be causing an issue with the logic levels.

When I flash the programme into it, it’s only connected to the UNO. After that, I insert it into the breadboard and can see it has flash fine because the LED light up. If I then try to re-flash it, it does not re-program. The old code stays in only. If I upload the code below I can re-flash the code over and over:

*/




int thermisterPin = A2;

int thermisterReading;

int fanPWMPin = 1; //Is 1 on tiny85




int pwmStep = 0;




void setup() {




  pinMode (fanPWMPin, OUTPUT);

  //  Serial.begin(9600); // open the serial port at 9600 bps, used for testing purposes only.




}




void loop() {




  thermisterReading = analogRead(thermisterPin);




  //  Serial.print("Thermister: ");// The following serial prints are for debugging purposes only.

  //  Serial.println(thermisterReading);

  //  Serial.print("pwmStep:: ");

  //  Serial.println(pwmStep);

  //  Serial.print("Fan Triggered? 0=False, 1= True?: ");

  //  Serial.println(fanTriggered);




  if (thermisterReading > 770)    // 3.8V = ~50degC

  {

    while (pwmStep < 255)//Ramps up to 100% PWM without interuption.

    {

      pwmStep++;

      analogWrite (fanPWMPin, pwmStep);

      delay(4);//was 7

    }

  }




  else if (thermisterReading < 675)//3.3V = ~40degC

  {

    while (pwmStep > 0) //Ramps down to 0% PWM without interuption.

    {

      {

        pwmStep--;

        analogWrite (fanPWMPin, pwmStep);

        delay(4);//was 7

      }

    }

  }




}

not surprising, why did you define the RST pin as a pin, after that it will naturally not be programmed

Are you saying that if the sketch tries to use the reset pin as an output, then something alters the fuses to make it a GPIO pin without the user explicitly changing the fuses?

I understand that the chip will be constantly reset? or not?

Not because

int pin5 = 0;

(Although the reset or GPIO functionality is fixed with a fuse)

The reset pin isn’t defined. Pin 1 (physical) is the reset pin.

No, as per post#7, Pin5 is PB0 and not the reset pin. Once the chips is flashed, it outputs fine. I just cannot reprogram it again or burn the bootloader.

I am not using the reset pin for anything. I am just using the other available output portb: 0 to 4.

So let me get this straight, you can flash and re-flash any code onto the ATtiny except for this one, which you can flash onto a fresh Attiny but not onto one that has this code on it ?
(i have removed any excess white lines and spaces for sake of overview)

int pin2 = 3; int pin3 = 4; int pin5 = 0; int pin6 = 1; int pin7 = 2;

void setup() {
  pinMode (pin2, OUTPUT);
  pinMode (pin3, OUTPUT);
  pinMode (pin5, OUTPUT);
  pinMode (pin6, OUTPUT);
  pinMode (pin7, OUTPUT);
}

void loop() {
  digitalWrite (pin2, HIGH);
  delay(100);
  digitalWrite (pin2, LOW);
  digitalWrite (pin3, HIGH);
  delay(100);
  digitalWrite (pin3, LOW);
  digitalWrite (pin5, HIGH);
  delay(100);
  digitalWrite (pin5, LOW);
  delay(100);
  digitalWrite (pin6, HIGH);
  delay(100);
  digitalWrite (pin6, LOW);
  digitalWrite (pin7, HIGH);
  delay(100);
  digitalWrite (pin7, LOW);
} 

You pin numbering system makes sense to you and i understand why you did it, but it does cause some confusion to other responders i guess. Anyway, there isn't anything in the code that can interfere uploading a fresh code through ISP. So the only other thing that can be the cause is in the upload connections.

Thing is i can not re-create your problem.

I dug up an ATtiny85 (which i rarely use any of) Uploaded Arduino as ISP to my UNO, Attached the adapter i use to upload for ATtiny85 & 13 etc.
Selected ATtiny 25/45/85 no Bootloader from the ATtinyCore and with 8MHz internal selected did 'Burn Bootloader'

Then i uploaded this sketch to verify it is working.

const byte ledpin = 4; 
uint16_t ms = 100;
bool increase = true;


void setup() {
  // initialize digital pin 13 as an output.
  pinMode(ledpin, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(ledpin, HIGH);
  delay(ms);
  digitalWrite(ledpin, LOW);
  delay(ms);
  if (ms > 250) increase = false;
  if (ms < 20) increase = true;
  if (increase) ms = (ms * 10) / 9;
  else ms = (ms * 9) / 10;
}

I have a LED on the adapter so i don't even need to remove the ATtiny.

Then i uploaded your code, without issue, and then re-flashed my code again also without issue.

My connections are exactly as defined within the Arduino as ISP example and that is also what is set as the programmer.

What are you doing differently ?

You are correct, it is only the code below that I cannot flash into the ATiny85 more than once. I have uploaded other code over and over without issue. Which is why the setup must be correct. Did you upload my code more than once?

int pin2 = 3; int pin3 = 4; int pin5 = 0; int pin6 = 1; int pin7 = 2;

void setup() {
pinMode (pin2, OUTPUT);
pinMode (pin3, OUTPUT);
pinMode (pin5, OUTPUT);
pinMode (pin6, OUTPUT);
pinMode (pin7, OUTPUT);
}

void loop() {
digitalWrite (pin2, HIGH);
delay(100);
digitalWrite (pin2, LOW);
digitalWrite (pin3, HIGH);
delay(100);
digitalWrite (pin3, LOW);
digitalWrite (pin5, HIGH);
delay(100);
digitalWrite (pin5, LOW);
delay(100);
digitalWrite (pin6, HIGH);
delay(100);
digitalWrite (pin6, LOW);
digitalWrite (pin7, HIGH);
delay(100);
digitalWrite (pin7, LOW);
}

Yes no issue at all. Don't know why you would want to upload the same code twice though hence i alternated between 2 different ones first.

This is the ATiny85 programmer wiring. The example Arduini ISP has been loaded into the UNO. Correct ATiny85 selceted with 8Mhz internal clock. Programmer set to ‘Arduino as ISP’. Any difference to your setup?

Understand your frustration, but I too cannot reproduce your problem.

I uploaded your sketch and it blinked the single LED I'd connected to phys pin. 2. I then uploaded a different sketch and ran that. Then I successfully uploaded your sketch again.

I assume you had a 10 uF electrolytic in place?
And rechecked board and port and programmer before each upload?
Did you have a 0.1uF ceramic cap in place across 5V & GND?

Failing those, try a 10K resistor on phys 1 (reset) to 5V.

The only difference is that i have a led connected to the 'heartbeat', which may matter if the UNO somehow goes out of sync in some way. It happens that i need to reset the UNO to make sure that the sketch on the UNO is running properly. Reset the UNO before each upload just in case, and use 'Upload using programmer'
There may be a difference in core version, but it should not at all matter, and as you said, all the other sketches work. It makes no sense at all.

Yes, good point. I addded all these components but no change. It’s the same sketch that bricks the IC again. Thanks for everyone’s suggestions.

I uploaded this sketch to the board three times in a row, there are no problems with loading, the problem is something else

I uploaded a different sketch 5 times without issue. One upload of the simple sketch bricked another ATiny85. I may buy a purpose built USB programmer as this method isn’t working. This is the current programmer schematic with the protection added.

You have the 10uF wrong!
During uploading it should be on the Uno.