Hi guys,
I am having erratic/unpredictable behavior on a Arduino Mega and as it's been around 3 days of debugging without finding out the issue I though to share this hoping that I may receive some ideas/advice on what would be the cause.
The sketch uses a interrupt to count the number of button presses and prints it on the serial port every 200ms.
Sometimes the uC freezes (as in it doesn't execute the loop anymore), sometimes it restarts (re-executes setup), sometimes it prints the same number over the serial port at high speed (as if the 200ms delay much smaller such as 1ms). From one day to another the issue can show up more often or less often. When I made the video, the issue was visible very often.
Fuses are (low, high, ext): 0xFF, 0xD0, 0xFC I also tried 0xF7 for the low fuse (full swing oscillator).
I remember that at some point it was misbehaving even if having "buttonPressed" declared as volatile (even though in this video it wasn't declared). At the moment I am having difficulties getting the error to shop up so I can't redo the video with the "volatile" keyword.
#define measureBtnSense 21
int buttonPressed;
void setup() {
//button
pinMode(measureBtnSense,INPUT_PULLUP ); //Measure button
attachInterrupt(digitalPinToInterrupt(measureBtnSense), btnPressedFct, RISING);
buttonPressed=0;
//debug over serial port
Serial.begin(9600);
delay(10);
Serial.println(" -------------------------------> Arduino Mega restarted");
}
void loop() {
Serial.println(buttonPressed);
delay(200);
}
//button
void btnPressedFct(){
buttonPressed++;
}