Arduino GIGA R1 Rain Gauge Interrupt Issue

Hello everyone, I'm building a weather station and I'm trying to connect a rain gauge to the Arduino GIGA R1. The rain gauge is a device used to measure rainfall; it sends an electrical pulse to the Arduino, which is read through a digital output. To capture that digital signal, I used an interrupt. The issue I'm facing is that the Arduino GIGA R1 doesn't seem to capture the interrupt or I don't know what might be happening. I tested this same code and connection with the Arduino Uno, the ESP32, and the Arduino Mega, and it works fine. The problem appears to be specific to the Arduino GIGA; it's as if nothing is connected.

I'll briefly explain the code I used. The first thing I did was define a variable, 'counter,' and the interrupt pin. Inside the setup() method, I declared the interrupt. Finally, I declared a method called 'LitersCounter,' which runs each time the sensor sends a digital signal. This method counts the number of pulses sent by the Arduino GIGA.

The connection involves attaching one cable from the sensor to GND and another to a digital pin. It's straightforward. If you want to know more, I based this on the information in this Spanish video: https://youtu.be/hvD2rsqDduU. The connection is shown at the 3:06 mark.


 int ISRCounter=0;
 const byte interruptPin = 3;
void setup() {

  pinMode( interruptPin  , INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin),LitersCounter, RISING);
  Serial.begin(9600);
}
void LitersCounter(){
    ISRCounter++;
    Serial.println(ISRCounter);
  }

void loop() {
  // put your main code here, to run repeatedly:
}

According to the documentation, I can use any GPIO pin for an interrupt; you can check it here, it's towards the bottom: https://docs.arduino.cc/tutorials/giga-r1-wifi/cheat-sheet

#1. Variables modified inside the ISR and referenced elsewhere need the keyword 'volatile' in the variable declaration.

#2. Don't use Serial.print inside an ISR - because interrupts are disabled during the interrupt and Serial.print uses interrupts to function.

1 Like

Friend, thank you so much. You're right; I didn't know that. My code works perfectly now.

:+1:t4:

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