Stop button Attiny85 [SOLVED]

I searched a lot about reset button in attiny85. I want to know what happens if I connect a button to pin gnd and Reset Pin (P5). When I press what happens? I burn it?
Or, there is another metod like connect one pin to gnd and the other to like P2? And from script I say (at the beginning of the code, before void loop): if button is LOW --> run into infinite loop.

I found this tutorial but I don't know if I should trust him becuase I have Digispark Attiny85: Adding a Button to the $8 Rubber Ducky!! - YouTube

Does this help ? Useless Pin 5 in all Digispark ATtiny85 boards? [SOLVED]

The "reset button" featured on many Arduino boards is an "NO" (normally open, ie not connected) switch connected between the RESET pin and Ground. Grounding the reset pin will put the chip into reset state until the pin is allowed to rise back to nearly Vcc.

There are two exceptions:

  1. If the RSTDISBL fuse is set, to turn the Reset pin into a (shitty) general purpose I/O pin. On those parts, there is no hardware reset capability). This can only undone using "high voltage serial programming" with a special programmer (there are a few designs floating around for devices which use HVSP to turn off RSTDSBL so the rest of the reprogramming can be done with other means).
    The OFFICIAL kickstarter Digispark boards were sold with RSTDISBL set, like the parts you got when you backed the kickstarter campaign. I have bought a bunch of digispark clones, and (thankfully! I would have been pissed if I had to build an HV fuse doctor to get a proper reset pin back) - you can easily set RSTDISBL on a chip where it is not set (eg, with megaTinyCore's tiny85 micronucleus definition, you would choose bootloader burn mode ISP programmer, set the reset pin menu, connect your ISP programmer (usbasp, arduino running arduino as ISP, USBTinyISP, etc - all under $5 shipped), and "burn bootloader; see the documentation for the core you are working with if you're using another core.
    Going the other direction (To get reset functionality back) is a big production - if reset has a diode to Vcc, you have to desolder that, you need to build an HVSP fuse doctor and upload the proper firmware to that, then connect that, press abutton or w/e (per documentation for that firmware) and then re-bootload the board with a normal ISP setting and reset not disabled. When I accidentally disable reset, I just throw them into a bin labeled "needs HV prog" (I have around a dozen in that bit by now) and eventually when there's enough of them in there, I'll build an HV programmer to unbrick them). So yeah, definitely a good thing that the clones dont ship with reset disabled :slight_smile:

  2. If the LOW pulse that brings RESET to ~ground comes from another pin on the same device. This results in the pin being tristated, allowing the RESET pin to rise back to ~Vcc (When the pin is configured as reset, the internal pullup is always enabled). This may or may not result in a clean reset, as the pulse duration is less than the specified minimum (though many people have success with it, it's terrible practie - if you want to do a reset from software, trigger a WDT reset and make sure that the very first thing you do in setup is turning off the WDT (that can be omitted for code that will only run on chips with Optiboot or Micronucleus bootloaders, which are smart enough to do that themselves, before passing control to the user code. To do a software reset on a post-2016 AVR (uno wifi rev 2, nano every, or anything supported by megaTinyCore, DxCore, or MegaCoreX) you can just do _PROTECTED_WRITE(RSTCTRL_SWRR,0x01) because they finally implemented a proper software reset; WDT reset on those parts also doesn't leave the WDT on after the reset)

I say reset as I/O is shitty for two reasons:

  1. The pin's output drivers are incredibly weak, a fraction the strength of the other ones. You're lucky to get an mA or two out of them.
  2. The pin is extremely sensitive to interferance, which can result in resets due to ambient electrical noise, even if reset is disable (a positive voltage spike that triggers the antistatic protection will often reset it, a guy who I spoke with for a while was having that problem with a very expensive and clever board he'd designed, because he was 1 pin short of what he needed, and he didnt know about the new ATtiny1616 (with 17 usable I/O pins) and needed the ultra tiny package, so used a 841 - which has only 11 usable I/O pins)

So you say to put one of the two pins of the button to GND and then the second to pin P5 (reset) and set a code that when the script starts, first sees if the voltage is LOW, and if so, let the code enter a endless loop? Because I would like that when I insert the usb, if the button is LOW (i.e. pressed) then you do not continue with the code, otherwise you do all the code ...
Ex (gnd and P5):

void Setup(){
pinMode(1, INPUT_PULLUP);
if (digitalRead(1) == LOW){
while(1);
}}

II thought it was pin 5, not pin 1, so your example wouldn't make sense no matter what.

Well, is reset configured as reset or I/O? Quick tests would be:
If you have a volt meter/DMM: Upload a sketch that simply does pinMode(pin,OUTPUT), digitalWrite(pin,LOW); in setup (replace pin with the number of the reset pin). and nothing else. Measure the voltage between that pin and ground. If it's 0, then the pin is configured as GPIO, because you were able to write it low. If it's ~Vcc, then it's reset, because your GPIO commands didn't work and it always has the internal pullup enabled when it is configured as reset.

if you don't have a DMM, just upload blink so you have a blinking LED and then connect ground to P5/reset. If the LED stops blinking (the led that was blinking will stop and turn off) then reset is configured as reset, if it keeps bnlinking, than reset is an I/O pin.

If the pin is configured as reset, you do not have to write any code. As long as reset is held low, the chip will be in reset state, all pins will be set input and it won't do anything until reset is released. As soon as it is released, the sketch will begin executing.

If reset is configured as an I/O pin? What you posted will ALMOST work if the intent is for it to not run the code and never run it if the button was pressed at startup, regardless of the present state of the button, until you power cycle or otherwise trigger a reset (but I don't see how else you could without resetpin and your code in an infinite loop).
As written though, you're relying on digitalRead being slow enough that the weak pullup will have had time to pull the pin up by the time it actually looks at the pin. That's not a safe assumption, as that s a very weak pullup if it's the reset pin, and ATTinyCore's digitalRead is faster (and uses less flash!) than t does on most parts, so it's only a few clock cycles, and you lose 2 to the digital input buffer's synchronizer. A simple delayMicroseconds(1) after the pinMode in your code will harden it against that sort of problem (or #include <util/delay.h> at top and then _delay_us(1) - if short on flash; that s a better implementation of microsecond delay, but only if the argument is known at compile time - otherwise _delay_us() doesn't work; 2.0.0 of ATTinyCore will automatically use _delay_us() for compile-time-known delays.

void Setup(){
pinMode(1, INPUT_PULLUP); // CHECK THE PIN NUMBERS!!!
delayMicroseconds(1);
if (digitalRead(1) == LOW){
while(1);
}}

If you instead want to delay code execution UNTIL that button is released (ie, almost emulate what the pin would do if it were a reset pin),

void Setup(){
pinMode(1, INPUT_PULLUP);  // CHECK THE PIN NUMBERS!
// No need for delay - the below loop will delay for the fraction of a microsecond it takes to pull the pin up if nothing is connected.
while(digitalRead(1) == LOW);
}

Oh my god, great! it was just what I was looking for! thank you very much, now I know how to temporarily reset the sketch, now I know how to wait for the sketch to start until I let go of the button! thank you very much clear. However, pin P5 was set as reset by default. Love you <3

Glad this was useful. And yeah between the three commercially available digispark-like boards (boards that use VUSB/Micronucleus bootloader to upload directly from USB.), I've got around 20 of the damned things (never ever buy one of something cheap, number one rule of buying parts) and not a single one had reset disabled, thankfully.

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