Short on ATtiny85 pins. Can I use reset and ADC pins differently

Hello I am short on pins of ATtiny85. I must read button input from the reset pin but I don't want to destroy the programmer. I am planning to set the reset pin high internally and put a 20k resistor which is smaller than the input_Pullup resistor (50k) between the reset pin and ground. I shouldn't pull the reset pin to ground otherwise the MCU will reset but also I should be able to trigger the "pinchange" interrupt. Would the code below and the resistor I picked do the trick? Also is the pin number 5 correct for reset pin?

#define ButtonPin 5
unsigned long t1;

void setup() {
pinMode(ButtonPin, INPUT_PULLUP);
  sbi(GIMSK, PCIE); //Turn on pin change interrupt
  sbi(PCMSK,PCINT5); // Which pins are affected by the interrupt
}

ISR(PCINT0_vect){ // button interrupt
  waitingbuttonresponse = true;
  t1 = millis();
  }

Also, I wanted to trigger another external interrupt on rising edge. The code is below, would it work? Notice I want to sleep the MCU that's why I can't detect rising or falling edges in the regular way using " MCUCR" register.

#define PIRPin 2

void setup() {
pinMode(PIRPin, INPUT);
 GIMSK |= (1<<INT0);
}

ISR(INT0_vect){  // sensor interrupt
  if (digitalRead(PIRPin))  waitingPIRresponse = true;
  }

You can see that it makes a digital read to determine if it is high or low before giving the flag. I couldn't do the same for the button as the button is not pulled to ground completely.

One more thing is, I need to turn on a buzzer from a pin which I also must read potentiometer from. I am redefining buzzer pin as output each time I want to ring it, and I think AnalogRead() already defines the pin necessarily. So would the sample code below work? Notice A3 and pin3 are the same.

#define BuzzerPin 3 // Put 220R pulldown resistor to pot to prevent burns when pot is set small and buzzer activates

void loop(){
alarmDelay = map(analogRead(A3),0,1023,0,60);
delay(500);
pinMode(BuzzerPin,OUTPUT);
digitalWrite(BuzzerPin, HIGH);
delay(500);
alarmDelay = map(analogRead(A3),0,1023,0,60);
}

I am planning to use a MOSFET to act upon the voltage at the pin, I will apply voltage to ADC just for brief moment to read value and turn it off so no worries about buzzer being constantly on when potentiometer is turned to the right.


According to the datasheet the reset pin has a different pull-up resistor. Between 30 and 60K.
So if you put a 20K between reset and GND, you will create a voltage divider and pull the reset pin below. 50% of VCC.. According the datasheet as long as you are higher than 0.9Volt on the reset pin it will read it as HIGH.

If you use the Reset pin as a GPIO pin, then it no longer functions as a reset pin.

Also, once defined as a GPIO pin you will no longer be able to upload code to the MCU.

You need a 12v programmer to be able to set the correct fuse bits to be able to change between GPIO and Reset usage for the pin.

This is quite a good video on the subject

Going from memory you can use the reset pin for other purposes, but it required some tricky setup. It won't be a reset pin anymore, so you don't have to worry about that.

Edit: Looks like the post above took care of everything I was typing.

Thank you guys, I needed 2 extra pins and I realized I was try harding to keep using Attiny85, now I switched to Attiny24A instead. I didn't know just by configuring reset pin as GPIO I was going to loose ability to reprogram it normally. I will keep the video in mind when I need to use Attiny85 again. Thanks

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.