Pin Change Interrupt overly sensitive

Hi All,

I've been working on a logger using a ProMini an RTC, SD etc which sleeps and is woken up by the RTC interrupt / Pin 2 change.

I've been having problems with the ISR sporadically firing. When probing with my meter I found I could accidentally trigger the ISR, even with a pull up fitted. Assuming meter impedance was casing this I (clutching at straws) removed the lead from the meter and found that even the bare test lead connected to nothing triggered the ISR.

Assuming hardware issues or some odd coding mistake, I adapted a small code to test I was implementing ISR use and uploaded to a genuine uno. I find that even if I hard tie Pin 2 to 5v, touching pin 2 with even a small dupont patch lead triggers my ISR - Any thoughts on this, I would have imagined it would need to be pulled totally to ground to achieve the ISR, not create what is effectively some noise on the line? Can any one else test/replicate ? It is as if Pin change ISR is massively over sensitive

const byte LED = 13;
const byte BUTTON = 2;

// Interrupt Service Routine (ISR)
void switchPressed ()
{
    digitalWrite (LED, HIGH);

}  // end of switchPressed

void setup ()
{
  pinMode (LED, OUTPUT);  // so we can update the LED
  digitalWrite (BUTTON, HIGH);  // internal pull-up resistor
  attachInterrupt (digitalPinToInterrupt (BUTTON), switchPressed, FALLING);  // attach interrupt handler
}  // end of setup

void loop ()
{
  // loop doing nothing 
}

I find that even if I hard tie Pin 2 to 5v, touching pin 2 with even a small dupont patch lead triggers my ISR -

That's' hard to believe!!!!

Plus, there is no ISR in your code... So there may be a bug in the code you're not showing us...

That's' hard to believe!!!!

I agree, hence me writing the small code as shown above to ensure I was using ISR's correctly and norrow down the issue, but this behavior is still exhibited. Happy to post a video of this one as it's got me. ISR is test code void switchPressed () is shown?

Thanks

  digitalWrite (BUTTON, HIGH);  // internal pull-up resistor

Should work, but better use:

  pinMode (BUTTON, INPUT_PULLUP);  // internal pull-up resistor

You're not using a pin change interrupt in that code, but a so-called "external interrupt" (dunno how they came up with that name) which is available only on pins 2 and 3 while all pins on an Uno have a pin change interrupt available.

Anyway, your symptoms don't make sense at all.

+1

The reported symptoms do not make sense.

I could however invisage that dodgy wiring, in particular in relation to the grounds, could produce such symptoms.

Thanks, I appreciate you are all far more specialized in this field than myself, but to eliminate wiring issues on my main project is the very reason I wrote the small sketch outside of my actual code, and ran it on an Uno to isolate the problem to my lack of understanding ISR's on the arduino - and this is my finding .

So I experience the issue with the above code on Pro Mini, and Uno. USB powered. Multiple USB PSU, Multiple USB Leads. At a loss

Again, i'm happy to video the symptom.

but to eliminate wiring issues on my main project is the very reason I wrote the small sketch outside of my actual code, and ran it on an Uno to isolate the problem to my lack of understanding ISR's on the arduino -

So YOU wrote that sketch? Funny because it was posted here years ago: Gammon Forum : Electronics : Microprocessors : Interrupts

const byte LED = 13;
const byte BUTTON = 2;

// Interrupt Service Routine (ISR)
void switchPressed ()
{
  if (digitalRead (BUTTON) == HIGH)
    digitalWrite (LED, HIGH);
  else
    digitalWrite (LED, LOW);
}  // end of switchPressed

void setup ()
{
  pinMode (LED, OUTPUT);  // so we can update the LED
  digitalWrite (BUTTON, HIGH);  // internal pull-up resistor
  attachInterrupt (digitalPinToInterrupt (BUTTON), switchPressed, CHANGE);  // attach interrupt handler
}  // end of setup

void loop ()
{
  // loop doing nothing 
}

Great minds think alike huh? Right down to the comments even.

I loaded the sketch on an Uno rev3, stuck a jumper in pin 2 hole and grounded it. It works just fine.
When the jumper is not grounded, led13 is ON and when it is grounded (had to wipe dust off the USB port box to get a good ground) led13 is OFF.

I've been having problems with the ISR sporadically firing. When probing with my meter I found I could accidentally trigger the ISR, even with a pull up fitted. Assuming meter impedance was casing this I (clutching at straws) removed the lead from the meter and found that even the bare test lead connected to nothing triggered the ISR.

Probing with your meter? Please detail how you did that?

A bare test lead connected to nothing that is not charged relative to ground will take current from a 5V relative to the same ground source until it is charged to 5V. Especially at the start the current flow will be more than 5V through a 20K to 50K resistor which is what INPUT_PULLUP supplies hence the voltage drop on the pin and interrupt trigger.

The default startup pin mode for all IO pins is INPUT with the pin LOW. From there to INPUT_PULLUP takes digitalWrite(pin,HIGH), the pin is HIGH when not grounded and LOW when grounded through even 10KR though it might take a short time.

Electrons do not need a circuit to flow, just a place in a conductor more positive than where they are. If that were not true, radio would not have been invented.

Just so you know, I was interested in static electricity back in HS over 40 years ago. Not just the HV stuff but all of it and I had learned basic DC prior and aced physics early on. This stuff is SO basic that most people skip right over it before they trip, right over it.