On MKR WAN 1300 board I added pulldown resistors to 0,1,4,5,6,7,8 pins to count pulses.I can catch interrupts, but sometimes pulses occur on other pins even though they are not touched. For example, button pulses are generating on pin 2 but shows pins 3 is also triggered , it shows like pin 2=1 pin 2=2 pin 2=3 pin 2=4 pin 2=5 pin 2=6 pin 3=1 pin 2=7
What can be the reason ? How can I solve it ?
#include <MKRWAN.h>
#define debugSerial Serial
#define loraSerial Serial1
int DEBUG = 0;
/* Pins of External Interrupts */
const byte WATER_METER_1 = 0;
const byte WATER_METER_2 = 1;
const byte WATER_METER_3 = 4;
const byte WATER_METER_4 = 5;
const byte WATER_METER_5 = 6;
const byte WATER_METER_6 = 7;
const byte WATER_METER_7 = 8;
volatile int watMeterPulseArray[7] = {0, 0, 0, 0, 0, 0, 0};
unsigned long pulseTime[7] = {0, 0, 0, 0, 0, 0, 0};
unsigned long lastTime[7] = {0, 0, 0, 0, 0, 0, 0};
const long interval = 2000;// interval for next pulse
int watMeterPulseArraySize = sizeof watMeterPulseArray / sizeof watMeterPulseArray[0];
void checkAndVerifyPulse(int pin) {
pulseTime[pin] = millis();
if (pulseTime[pin] - lastTime[pin] > interval ) {
lastTime[pin] = pulseTime[pin];
watMeterPulseArray[pin] ++;
printlnToScreen("pin " + String(pin) + "=" + String(watMeterPulseArray[pin]));
}
}
void incrementWatMeter1() {
checkAndVerifyPulse(0);
}
void incrementWatMeter2() {
checkAndVerifyPulse(1);
}
void incrementWatMeter3() {
checkAndVerifyPulse(2);
}
void incrementWatMeter4() {
checkAndVerifyPulse(3);
}
void incrementWatMeter5() {
checkAndVerifyPulse(4);
}
void incrementWatMeter6() {
checkAndVerifyPulse(5);
}
void incrementWatMeter7() {
checkAndVerifyPulse(6);
}
void setup() {
debugSerial.begin(115200);
// If debugSerial is available(device connected to PC) set debug
while (!debugSerial && millis() < 10000) ;
if (millis() < 10000) {
DEBUG = 1;
}
delay(100);
pinMode(WATER_METER_1, INPUT_PULLDOWN);
pinMode(WATER_METER_2, INPUT_PULLDOWN);
pinMode(WATER_METER_3, INPUT_PULLDOWN);
pinMode(WATER_METER_4, INPUT_PULLDOWN);
pinMode(WATER_METER_5, INPUT_PULLDOWN);
pinMode(WATER_METER_6, INPUT_PULLDOWN);
pinMode(WATER_METER_7, INPUT_PULLDOWN);
attachInterrupt(digitalPinToInterrupt(WATER_METER_1), incrementWatMeter1, RISING);
attachInterrupt(digitalPinToInterrupt(WATER_METER_2), incrementWatMeter2, RISING);
attachInterrupt(digitalPinToInterrupt(WATER_METER_3), incrementWatMeter3, RISING);
attachInterrupt(digitalPinToInterrupt(WATER_METER_4), incrementWatMeter4, RISING);
attachInterrupt(digitalPinToInterrupt(WATER_METER_5), incrementWatMeter5, RISING);
attachInterrupt(digitalPinToInterrupt(WATER_METER_6), incrementWatMeter6, RISING);
attachInterrupt(digitalPinToInterrupt(WATER_METER_7), incrementWatMeter7, RISING);
delay(100);
}
void loop() {
}
// If Serial port is available on PC, print message to screen
void printToScreen (String message) {
if (DEBUG) {
debugSerial.print(message);
}
}
void printlnToScreen (String message) {
if (DEBUG) {
debugSerial.println(message);
}
}```