I have added a RAK1902 sensor and inserted sketch requriements into existing sketch. Once this was uploaded to board (4631), the rainfall incremented by one count every time. I then added it to a simple sketch just to test the interrupt (raincounter). Same problem. If I comment out the 1902 requirements, it works perfectly, and when I add it in, the counter increments by one every time. Any thoughts as to why this is happening?
Here is the sketch…
#define rainPin WB_IO1
int rain = 0;
//Barometric Pressure
#include <Adafruit_LPS2X.h>
#include <Adafruit_Sensor.h> // Click here to get the library: http://librarymanager/All#Adafruit_LPS2X
Adafruit_LPS22 g_lps22hb;
//*****************************
void setup() {
Serial.begin(115200);
//*****Barometric Pressure*****
if (!g_lps22hb.begin_I2C(0x5c))
{
Serial.println(“Failed to find LPS22 chip”);
while (1)
{
delay(10);
}
}
g_lps22hb.setDataRate(LPS22_RATE_10_HZ);
//*******************************************************************************
pinMode(rainPin,INPUT_PULLUP);
attachInterrupt(rainPin,raincounter,FALLING);
}
void loop()
{
Serial.println("");
Serial.println("");
Serial.println("");
Serial.print("Rain = ");Serial.println(rain);
delay(2000);
//Barometric Pressure******************************************************************
sensors_event_t tempbox;
sensors_event_t pressure;
g_lps22hb.getEvent(&pressure, &tempbox);
Serial.print(“Temperature: “);Serial.print(tempbox.temperature);Serial.println(” degrees C”);
Serial.print(“Pressure: “);Serial.print(pressure.pressure);Serial.println(” hPa”);
Serial.println("");
delay(1000);
//********************************************************************************************************************
}
void raincounter() {
//Debounce switch
static unsigned long last_interrupt_time = 0;
unsigned long interrupt_time = millis();
// If interrupts come faster than 200ms, assume it’s a bounce and ignore
if (interrupt_time - last_interrupt_time > 200)
{
rain = rain + 1;
}
last_interrupt_time = interrupt_time;
}
And here is the screenshot of the serial…
Regards, Andrew.