Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [interrupt]

Interrupts allow the processor to suspend normal operation temporarily so that a high-priority software or hardware event can be handled instead.

21
votes
3answers
5k views

Can a function be called automatically when an input changes?

Currently, my sketch is checking an input pin every time round the main loop. If it detects a change, it calls a custom function to respond to it. Here's the code (trimmed down to the essentials): ...
14
votes
2answers
27k views

How many interrupt pins can an Uno handle?

I am looking at using a 7 channel RC receiver with the Arduino Uno R3. In the documentation, there are mentions of a maximum of 2 interrupt pins, whereas on certain other blogs I have seen mentions of ...
14
votes
2answers
13k views

How precise can I get Arduino using rotary encoders?

Stepper motors are often pricey for a large motor. However, with a powerful, standard DC motor and a rotary encoder, you can "simulate" a stepper motor. How accurate are rotary encoders with Arduino ...
10
votes
3answers
30k views

Using millis() and micros() inside an interrupt routine

The documentation for attachInterrupt() says: ... millis() relies on interrupts to count, so it will never increment inside an ISR. Since delay() requires interrupts to work, it will not work if ...
10
votes
2answers
885 views

Are function pointer assignments atomic in Arduino?

The following snippets are from TimerOne library source code: // TimerOne.h: void (*isrCallback)(); // TimerOne.cpp: ISR(TIMER1_OVF_vect) // interrupt service routine that wraps a user defined ...
8
votes
1answer
14k views

How do interrupts work on the Arduino Uno and similar boards?

Please explain how interrupts work on the Arduino Uno and related boards using the ATmega328P processor. Boards such as the: Uno Mini Nano Pro Mini Lilypad In particular please discuss: What to use ...
8
votes
1answer
36k views

Counting pulses with interrupt

I have been trying to count pulses from a 12,500 Hz square wave to trigger an output. Here's the code I have so far. When the Arduino is reset it prints 315 to the serial over a 25 ms sample....
7
votes
3answers
5k views

Multiple independent LED patterns

I have an problem, which at first thoughts (and being new to Arduino) I though was a perfect application for an Arduino. However, after trying and failing to implement it I am doubting myself! Simply ...
7
votes
1answer
5k views

Is volatile needed when variable is accessed from > 1 ISRs, but not shared outside ISRs?

It's clearly documented that when global data is shared with an ISR and the main program, the data needs to be declared volatile in order to guarantee memory visibility (and that only suffices for 1-...
7
votes
2answers
3k views

How to update a variable in an ISR using Timers

I'm trying to check the frequency of Timer3 using a counter. The value of the counter, declared as volatile, is incremented in the ISR and every second the sum is shown in the main loop and the value ...
6
votes
2answers
495 views

Why is that any sensor signal need to be hooked up to the interrupt pins on Andruino boards?

I have come across some Andruino Sensors like Motion, Light and all recommend to be connected to pin 2 or 3 on Andruino Uno board which are interrupt pins. This is especially true if you are looking ...
6
votes
2answers
1k views

When setting hardware timers as interrupts, should I prefer a lower prescaler value or a lower CTC?

I'm currently playing with Arduino's hardware timers, and a question came to my mind. Let me explain it a bit. Let's suppose I want a certain function to execute every 1024 clock ticks. AFAIK, I ...
6
votes
5answers
9k views

Simultanous read and read/write on two serial connections

At the moment I'm using two softserials to connect to a GPS and an GSM module. It seems not possible to have two open software-serials. So I was looking for an solution After the initial-setup, the ...
5
votes
2answers
10k views

Why the need to use the volatile keyword on global variables when handling interrupts in Arduino?

I am familiar with the keyword Volatile being used to declare variables that are shared among multiple threads on a software application (basically on a multithreaded application). But why do I need ...
5
votes
2answers
1k views

interrupting an interrupt

What should be expected if the code in the timer interrupt ISR does not finish before the interrupt is called again? For example Timer0 ISR(TIMER0_COMPA_vect){} on the Uno. This is for debugging ...
5
votes
1answer
313 views

What is causing my Uno to wake up?

NOTE: this code was working perfectly fine in another program. I have a simple piece of code that puts the Arduino to sleep. When it is finished and intergrated into my project, it will only wake the ...
5
votes
1answer
1k views

Mic input and Speaker output using arduino

I am trying to make a small project. Firstly, I want to record voice using a small microphone(electret) for the time button is pressed and on releasing the button, the speaker of my laptop should ...
5
votes
1answer
1k views

ATmega AVR frequency measurement with timer/counter

I've been rehashing some existing libraries I found on some obscure forums to measure a frequency on digital pin 5, using the ATmega328P/ATmega2560 Timer/Counter modules and an interrupt based ...
5
votes
1answer
213 views

Is there a portable timer interrupt library?

I have a need for timer interrupt (for the sake of this exercise - say I need to execute something every second) I found code in many places on the internets that does this using ISR for 328/Uno. (...
4
votes
3answers
5k views

Is `millis()` affected by long ISRs?

I have a project that uses timers and interrupts frequently. A lot of CPU time is spent handling ISRs over an extended period of time. Would this affect code inside the main loop that relies on the ...
4
votes
2answers
123 views

Interrupts: use of the “volatile” keyword with a structure pointer for button debounce

I've written a small sketch targeted at the Arduino Uno (ATmega328P) to debounce a mechanical pushbutton using the summing/integration technique: #include <IntegratingDebounce.h> #define ...
4
votes
1answer
8k views

How to properly use volatile variables in Arduino?

I was doing a small project with an Arduino Uno. It involved interrupts as I am using encoders to measure how much the differential wheel system moves forward. My robot moves only forward. So I use ...
4
votes
2answers
5k views

Read RC receiver channels using Interrupt instead of PulseIn

I am designing my own quadcopter control algorithm, whereby I currently read 4 RC receiver channels using PulseIn on each loop in the following manner: ch1_raw = pulseIn(rcPin1, HIGH, 25000); In ...
4
votes
2answers
113 views

Trouble with Timer 0

I'm taking my first wobbly steps outside the Arduino IDE and I'm not having much success with timers / interrupts. I can set a pin to output and light an LED with registers fine but I cannot for the ...
4
votes
4answers
2k views

Running multiple tasks at once

For a school project we're working on a wearable device to track people's movement and heart rate. We use an Arduino Pro Mini with a heartbeat sensor and an accelerometer. The wearable device uses ...
4
votes
1answer
2k views

How to make XBee module interrupt/wake arduino

What I am trying to do is, to have arduino in low power mode and waking up only when a packet is received and is available to be read from the buffer. A scenario : Zigbee XBee module is not ...
4
votes
1answer
232 views

Interrupt fires a random number of multiple times for one pulse

This is my first time posting on this forum. I have tried to format this question properly, but let me know if I need to correct anything. I searched to see if someone else had a similar problem, but ...
4
votes
1answer
1k views

Leonardo-based tachometer?

I'm new here. I'm not a native speaker, so pardon my English. I just received my Arduino Leonardo today. I tried some basic calculations and stuff like blinking and LCD interfacing. Its interesting. ...
3
votes
2answers
8k views

Reading I2C sensors with a timer interrupt

I would like to read a sensor connected via I2C using Timer3 and Arduino Mega. Values are read from the sensor in the interrupt service routine and timer3 is set to trigger an interrupt at 200Hz. ...
3
votes
3answers
2k views

Using a lot of interrupts on a single Arduino

I'm doing a little project that requires a lot of sensors. Right now I'm using 4, but i want to reach up to 60 sensors, and a minimum of 16 (for me that's a lot). So, I have an Arduino MEGA 2560, and ...
3
votes
3answers
6k views

What happens if an interrupt is triggered while sending data via serial?

I would like to use an inertial sensor to measure acceleration and send the results to an Android app using a serial communication with a bluetooth Mate Gold module. The sensor provides a data ready ...
3
votes
3answers
4k views

Multiple Buttons on Single Analog Pin and Trigger Pin Arduino Uno

I've researched how to attach multiple buttons to a single analog input using a resistor network. Instructables has a good lesson on this: http://www.instructables.com/id/How-to-access-5-buttons-...
3
votes
1answer
5k views

Sending serial data in an interrupt

An ATMEGA328-P chip is used with a toggle switch attached to pin 8 and a momentary switch attached to pin 9. My objective is to send the following information over serial: The status of pin 8, every ...
3
votes
2answers
5k views

IR Receiver interrupt and arduino sleep mode

I need to put my arduino into the sleep mode in order to consume less power. My arduino receives IR data and do some work with it, but I need to make it sleep until there is no data. If the data has ...
3
votes
1answer
11k views

Interrupts for analog inputs

I have an Arduino Uno. I've been reading about pin change interrupts, and one vector covers the analog pins. However, is it possible to trigger interrupts using analog pins as analog inputs (not ...
3
votes
1answer
643 views

How to delay properly inside ISR

I am currently working on a little code which needs to react fast. Here is what I am trying to accomplish: Using a sine wave phase detector I am detecting every zero crossing and feeding that pulse ...
3
votes
3answers
1k views

How to properly use interruptions with twi (I2C)

I would like to reprogram Wire.h, or a part, to use interruptions, in order to not waste time to wait. I'm using an Arduino Mega with an Adafruit motor shield v2.3. In the datasheet, page 262, 24.9.2,...
3
votes
1answer
5k views

How to generate hardware interrupt in mpu6050 to wakeup arduino from SLEEP_MODE_PWR_DOWN mode?

I am using Arduino UNO and has kept in SLEEP_MODE_PWR_DOWN mode & want it to wakeup using MPU6050 hardware INT pin (which should send a signal when MPU is in motion). I have used the article https:...
3
votes
1answer
127 views

Two outputs: which one “leads” the other?

I have a problem with my Arduino Uno and my AS5311 position sensor I am trying to get incremental output as described in Section 7 but I don't really know how to do it. It says that there are three ...
3
votes
1answer
3k views

How can I replace pulseIn with interrupts?

I have an HC-SR04 sensor and I need to get the distance from it. I use this code: digitalWrite(trig, LOW); delayMicroseconds(2); digitalWrite(trig, HIGH); delayMicroseconds(10); digitalWrite(trig, ...
3
votes
1answer
669 views

Setting the frequency of a timer interrupt

The concept: Play a sine wave saved as a character array in PROGMEM through an 8-bit DAC connected to the PORTC pins on the Arduino Mega. This works: // File just defines an array and a size #...
3
votes
2answers
2k views

Arduino Hardware timer and interrupts issue

I recently started programming with Arduino and and currently I'm making a project to read RPM and Speed of my car using Arduino Uno. So far I got everything working but the speed value does not show ...
3
votes
3answers
9k views

Using TIMER0_COMPB_vect

I'm trying to understand how to fully use the COMPB vector ISR of Timer0 on the ATMega328 (standard Arduino core). I realize it will make delay() and millis() not work but that's ok by me. I've setup ...
3
votes
1answer
86 views

Timer interrupt triggers too often

The following question is based on the Arduino Pro Mini (8MHz, 3.3V) I'm in process of developing (yet another) LED strip driver shield. For that I wrote a simple control loop, that adjusts the ...
3
votes
1answer
81 views

How can you check how long a timer interrupt really is?

I'm trying to set a 33 ms interrupt on my Arduino Mega and I'm not sure if I a in fact getting that kind of delay time. Is there a way to check? I've calculated that that I need 515.6 ticks to achive ...
3
votes
3answers
2k views

Breaking a switch case from an ISR

I'm struggling with something. My CPU sits in a switch case state machine like this: switch(expression) { case constant-expression_1 : statement(s); break; /* optional */ case ...
3
votes
1answer
1k views

Accelerometer Interrupt Meaning - Wakeup Function

I am working with an LSM9DS1 IMU, and now specifically trying to program a wakeup feature into the system. My idea is to set the accelerometer at the lowest possible read rate, then when the ...
3
votes
2answers
678 views

Trouble with sleep mode and interrupts

Context I am building a small battery powered counting device. As with many other projects like this, saving power is critical. I am therefore trying to utilise the sleep mode wherever possible. This ...
3
votes
2answers
315 views

Serial data affected by interrupt

In my recent project, I have done everything means capture serial data and split it out in proper form. Until now everything is fine. But when I add another portion of code which contains Interrupt. ...
3
votes
3answers
6k views

Using rotary encoders with pin change interrupts

I'm using an Arduino Uno and two (3-pin) rotary encoders for a project. Since the loop takes a bit long and accuracy is important, I'd like to use interrupts to read the values from the rotary ...