Arduino Mega2560 - Interuptions

Good afternoon.
I am working with an Arduino Mega and with interrupts.
I have set up a Hardawar mintage with PULL_DOWN resistencies.
When I measure with the tester, pin 18 and 19, I measure 0V DC, which is what I expect to have. At pins 20 and 21 I measure 1.2V DC. I don't know why I have this voltage.
I am attaching the program I use and a drawing showing how I have mounted the 4K7 resistors.
Could it be that the Arduino is bad?
(pins 20 & 21 are not available to use for interrupts while they are used for I2C communication:
I am not using I2C)
Thanks.

#define INTERRUPT_Celula 18 // Celula
#define INTERRUPT_Mes1 19   // +1
#define INTERRUPT_Menys1 20 // -1
#define INTERRUPT_Reset 21  // Reset

#define BtPausa 23          // Pausa
#define BtResetTotal 25     // Reset Total
#define PinZumbador 27      // Pin Zumbador

const int timeThreshold = 150;
long startTime = 0;
volatile bool state = false;

void setup() 
  {
  Serial.begin(9600);
  // Botons i interrupcions************
  pinMode(INTERRUPT_Celula, INPUT);
  pinMode(INTERRUPT_Mes1, INPUT);
  pinMode(INTERRUPT_Menys1, INPUT);
  pinMode(INTERRUPT_Reset, INPUT);
  pinMode(BtPausa, INPUT);
  attachInterrupt(digitalPinToInterrupt(INTERRUPT_Celula), IntCelula, RISING);
  attachInterrupt(digitalPinToInterrupt(INTERRUPT_Mes1), IntMes1, RISING);
  attachInterrupt(digitalPinToInterrupt(INTERRUPT_Menys1), IntMensy1, RISING);
  attachInterrupt(digitalPinToInterrupt(INTERRUPT_Reset), IntReset, RISING);
  //*************************
  Serial.println("Setup OK ******************");
  
  }

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

  }

void IntCelula()  //Change led state
  { 
  Serial.println("Celula");  
  if (millis() - startTime > timeThreshold)
    {
    state = true;
    startTime = millis();
    }
  } 

void IntMes1()  //Change led state
  { 
  Serial.println("Mes 1");   
  if (millis() - startTime > timeThreshold)
    {
    state = true;
    startTime = millis();
    }
  } 
  
void IntMensy1()  //Change led state
  { 
  Serial.println("Menys 1");   
  if (millis() - startTime > timeThreshold)
    {
    state = true;
    startTime = millis();
    }
  } 

void IntReset()  //Change led state
  { 
  Serial.println("Reset");   
  if (millis() - startTime > timeThreshold)
    {
    state = true;
    startTime = millis();
    }
  } 

Please note that as general rule you can't use Serial printing and millis() inside the interrupt handlers, so your code is need to be completely rewritten

Hint when you get the interrupt, set a flag. Then in your program test that flag, if it is true set it false and process it.

millis(), providing that you are not waiting for it to change, is OK in an Interrupt Service Routine.

Your diagram shows external pin pull down resistors and your code does not show any activated built in pullup resistors so you should not see 1.2 volts, at least not measured between the Arduino pin and ground.

Good morning.
If it is true that within the interruption there cannot be the Serial.print. In reality it is not there. This program is to be able to do a simple follow-up and verify the problem I have with the Voltages on pint 20 and 21. If I changed the resistance of 4k7 to one of 2K2, the voltage drops to 0.7v

Thanks.
My problem is the voltage.
I will check everything again, because I don't know what my mistake is.

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