I´m trying to program an interrupt with Arduino one but the ISR is never called.
Can anyone help me?
Thanks in advance.
prueba_interrupcion.ino (573 Bytes)
I´m trying to program an interrupt with Arduino one but the ISR is never called.
Can anyone help me?
Thanks in advance.
prueba_interrupcion.ino (573 Bytes)
pinMode(2, INPUT);
attachInterrupt(0,count, CHANGE);
are you using PULLUP or PULLDOWN resistors on Pin 2?
People don't like to open unknown files. Read the How to posts at the top of the Forum, especially the one about using code tags when listing your code.
In your code, the second argument to attachInterrupt() is a function name, not a variable. I don't see a function named count. It won't work until you add a function to that call.
bool estado=LOW;
volatile int contador;
volatile long tiempo;
void setup() {
Serial.begin(9600);
pinMode(2, INPUT);
attachInterrupt(0,count, CHANGE);
interrupts();
contador=0;
tiempo=millis();
}
void loop() {
Serial.print("estado :");
Serial.println(estado);
delay(1000);
Serial.print("num veces:");
Serial.println(contador);
delay(1000);
Serial.print("tiempo ");
Serial.println(tiempo);
Serial.println(millis());
estado=!estado;
digitalWrite(2, estado);
delay(3000);
}
void count(){
tiempo=millis();
contador++;
}
BulldogLowell:
pinMode(2, INPUT);
attachInterrupt(0,count, CHANGE);
are you using PULLUP or PULLDOWN resistors on Pin 2?
I don't have nothing on Pin 2. I´m trying with interrupts.
Interrupt zero is on pin 2.
How do you think interrupts happen?
You need to read the information shown here. Note towards the bottom that pin 2 on the Uno is actually Interrupt 0 and that pin 3 is interrupt 1. Therefore, this code:
int physicalPin = 2;
attachInterrupt(digitalPinToInterrupt(physicalPin), count, CHANGE);
you are using pin 2 of the Arduino to activate INT0 (interrupt vector 0). So if you attach a switch to pin 2 (via a resistor) and press the switch, you will generate a INT0 interrupt on pin 2. At that instant, it will call the function you've named count.
So, to have an external interrupt is it mandatory to have something connected to pin 2? Can´t it be simulated?
telemoquina0:
So, to have an external interrupt is it mandatory to have something connected to pin 2? Can´t it be simulated?
Why would you want to detect a fictitious interrupt?
What are you actually trying to achieve?
I want to know if it works. I´ve bought some devices to connect to Arduino but I won't receive them until a few days. Meanwhile I have to go ahead with the program.
So, what sort of interrupts do these devices generate?
telemoquina0:
So, to have an external interrupt is it mandatory to have something connected to pin 2? Can´t it be simulated?
Hang on a bit. Let's start from the beginning. Have you ever used external interrupts before?
Also.... 'simulated' .... yes ....... if the software/hardware is purposefully configured so that the interrupt is triggered by a condition where the voltage at the pin goes from low-to-high (or vice versa), then you could get the interrupt to trigger ----- by doing just that. Know where your external interrupt pin (whatever that pin is) is ... configured as an external input interrupt pin. Maybe connect a 1K resistor or something to that pin. So resistor terminal A will be connected to either GND or to 5V, while terminal B of the resistor is connected directly to the interrupt pin. Then use whatever means you can to change the voltage at terminal "A" (of the resistor).... like have it connected to gnd for one moment, then connect it to say 5V (or 3.3V) the next moment.
Can´t it be simulated?
Yes.
If you can attach the external interrupt to the pin, you can use digitalWrite() to set it HIGH and LOW and the interrupt will be triggered.
cattledog:
If you can attach the external interrupt to the pin, you can use digitalWrite() to set it HIGH and LOW and the interrupt will be triggered.
Another option that might be more appropriate for the testing the OP wants to do is to connect a jumper from another I/O pin to the interrupt pin and use digitalWrite() on the other I/O pin.
Even better, use a second Arduino to simulate the yet-to-arrive device.
...R