A noob asks about serial interrupt

Hi y’all,

I am new to the forum, new with the arduino and new in programming. So i’m a noob3.

I am trying to build an arduino based quadcopter which will be controlled by the pc through serial. So I need your help with one simple (I hope) question.

I know that to check for incoming bytes on the serial you can use sth like that:

void loop()
{
if (Serial.available() > 0) {
    
    incomingByte = Serial.read(); 
.
.
.
}

But as far as I understand this means that the program checks in every loop to see if you have received anything. Is there a way to do it using some kind of interrupt? ie don’t check constantly with the Serial.available() function, instead whenever I receive a serial, trigger an interrupt which will do the rest (ex Serial.read()).

But then you still have to pole (that’s what it is called when you constantly look at things) to see that you have read data. In fact that is what the Arduino does already, the serial input triggers an interrupt and the interrupt service routine reads it an puts it in a buffer. Asking it Serial.available() is saying is there anything in the buffer, at that point the data has already been read into the processor.
You need to keep all the interrupt service routines very short because that blocks out any other interrupts being looked after, so it is the best situation.
If you actually did stuff in the ISR (Interrupt service routine) then it could block other data being received and queued up.

Sorry to post a spelling nit-pick, but it’s “poll”. The process of checking for available inputs is called “polling”. Though I’d better point that out in case the OP tries a search or something.

Thanks for the reply. I think you are right.
All the codes in other projects I checked so far do it in the same way. So, I just wanted to see if there is a better way of doing this but apparently there is not.

Thanks again.

www.arduino.cc[Test/url]

I’m still interested in the original question. Is there a way to interrupt off of Serial.available()'s data? In other words. I want a subroutine called every time the serial data is available. I will be handling other tasks and don’t have the spare cycles to keep calling Serial.available(). I want to stop doing whatever I’m doing if there is data available.

Does that make sense??