Rain gauge not working with arduino UNO WiFi

Hi,
I am trying to use a rain gauge (https://images.app.goo.gl/cMo9FG6oEzXPDaTc7) with Arduino UNO WiFi rev2. The rain gauge works using reed switch. I tried to dowload the sketch attached to Arduino UNO R3 and it works fine.
I compiled the same program with the UNO WIFI Rev2. No problem.
I downloaded it on the card, always OK. A launch the sketch, it seem to work; but nothing happens.
I have already delete "digitalPinToInterrupt" in the line attachInterrupt(2, Basculata, FALLING);.
Are there any other errors? Maybe I have to change some settings on Arduino IDE?
Why doesn't it work?

Thanks in advance


#include <SPI.h>

float TotPioggia = 0;
int nbasculata = 0;
int conto;
boolean blnWrite=false;

void setup()
{
  Serial.begin(9600);
  Serial.println("Start");
  attachInterrupt(2, Basculata, FALLING); //LOW CHANGE RISING FALLING
}
 
void loop()
{
  interrupts();
  delay(1000);
  if (blnWrite==1)
  {
    blnWrite=false;
    Serial.println("Pioggia mm: " + (String)TotPioggia);
    delay(50);
    conto = nbasculata/3;
    Serial.println("Numero basculata: " + (String)conto);
    delay(50);
    Serial.println("--------------------------");
    delay(50);
  }
}
 
void Basculata()
{
  noInterrupts();
  //TotPioggia = TotPioggia + 0.3;
  nbasculata++;
  TotPioggia = (nbasculata/3)*0.3;
  delay(500);
  blnWrite=true; //segnalo che è avvenuta una basculata
}

Interrupts are disabled during an ISR execution, you do not have to disable them.

Interrupts are disabled during an ISR, delay depends on interrupts. See a problem there?

The processors are different between the Uno (mega328) and WiFi Uno (mega4809) so the pins may not be the same. Like the SPI pins.

According to the doc, all digital pins should be able to take interrupts on the Uno Wifi Rev2 - see attachInterrupt() - Arduino-Referenz

The delay() function does not work within an interrupt function.

1 Like

Actually if I delete the command it still doesn't work, but thank you anyway.....

I've tried deleting the delay and it works, thank you! I'm still holding the "noInterrupts();" and it gives me no problem!

Can some help me to understand why it counts 3 instead of 1 each time the reed switch "clicks"? I have to divide it by 3, if I don't do that I read a wrong information....

Please explain the above line.

Contact bounce might explain excess counts.

I'm still holding the "noInterrupts();" and it gives me no problem!

Of course not. Interrupts are already turned off.

0,3 is the rain gauge's tray's capacitance [mm]. 0,3 multiplied the number of nbasculata = mm rain fall in a day for example. nbasculata means the number of times reed switch clicks.

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