Good evening all,
I am actually programing a Adafruit Feather MO with a AMD21 cortex processor as the Arduino Zero.
I connected a rain gauge in A4 to count the drops AND to wakeup the board when it's in sleep mode.
I use the library RTCZero to put the board in Sleep mode.
Here is how I set up the intterup on A4
const int pin_arrosage = A4; // A4 of Feather board
void setup() {
//...
pinMode(pin_arrosage, INPUT_PULLUP);
//digitalWrite(pin_arrosage, LOW);
attachInterrupt(digitalPinToInterrupt(pin_arrosage), triggeredDropArrosage, CHANGE);
//...
}
void triggeredDropArrosage()
{
if(digitalRead(pin_arrosage)==HIGH)
{
vcountDrops=vcountDrops+1;
led_state = !led_state;
/*
display.clearDisplay();
display.setCursor(0,0);
display.print(vcountDrops);
display.display();
*/
}
delayMicroseconds(100000); // Without this, it does not count 1+1
}
When the bunket move from a side to another side, the drops is counted fine.
The above code work fine until I setup the RTCzero library.
With TRCzero, at the some point, we have to setup the interrupt, which willwakeup the board after a laps of time
sleep.attachInterrupt(triggeredAlarm);
I observed that wehn the above line is uncommented, the drops is counted 5-7 time and then the terminal do not answer, freez. It's look like if the board stop running.
Here is the code about the RTCZero configuration. I will add anode where the RTCZero interrupt is actived.
First I add the library
#define LOWPOWER
#if defined(LOWPOWER)
//#include <LowPower.h>
#include <RTCZero.h>
/* Create an rtc object */
RTCZero sleep;
// Set how often alarm goes off here
// If you change the frequence, do not forget to adapte
// for (int i=0; i<int(TX_INTERVAL/10); i++) { in complete event, lin 469
const byte alarmSeconds = 10;
const byte alarmMinutes = 0;
const byte alarmHours = 0;
#endif
Then in setup() below the drop interrupt, I added this
setup(){
//...
pinMode(pin_arrosage, INPUT_PULLUP);
//digitalWrite(pin_arrosage, LOW);
attachInterrupt(digitalPinToInterrupt(pin_arrosage), triggeredDropArrosage, CHANGE);
sleep.begin();
delay(100);
rtczero_resetAlarm();
// When I comment the following line, my rain gauge counts the drop
// When I uncomment it, it's look like if thee is a conflict the the attachInterrupt of he rain gauge, because the drops are counted 4-8 time before the terminal stop displaying the Serial.print of the loop()
sleep.attachInterrupt(triggeredAlarm);
//...
}
The following functions are need by the above code and works fine.
void rtczero_resetAlarm(){
//https://github.com/ProjectsByJRP/M0_Sleep_Wake_on_RTC_int/blob/master/Sleep_wake_on_RTC_alarm.ino
#if defined(LOWPOWER)
// Variable to set a reference in the time.
byte seconds = 0;
byte minutes = 0;
byte hours = 0;
byte day = 1;
byte month = 1;
byte year = 1;
// Set time reference
sleep.setTime(hours, minutes, seconds);
sleep.setDate(day, month, year);
// set alarm (wake up RTCZero)
sleep.setAlarmTime(alarmHours, alarmMinutes, alarmSeconds); // By default we set at 10 sec, 0 mn, 0 hours
sleep.enableAlarm(sleep.MATCH_HHMMSS);
#endif
}
void triggeredAlarm(){
#if defined(LOWPOWER)
sw.digitalWrite(wakeup_led,HIGH);
#endif
}
void rtczero_sleep(){
#if defined(LOWPOWER)
sw.digitalWrite(wakeup_led,LOW);
rtczero_resetAlarm();
sleep.standbyMode(); // Sleep until next alarm match
#endif
}
As since I commented
sleep.attachInterrupt(triggeredAlarm);
my rain gaude work fine.The drop are counted because of the first interrupt
attachInterrupt(digitalPinToInterrupt(pin_arrosage), triggeredDropArrosage, CHANGE);
I wonder if both interrupt can work together as two interrupt are define.
How can I make sure that none of the interrupts, do not disturb each other???
I pain your attention that my problem become before putting my board in sleep mode
Many thank for your help and suggestion
Cheers