hi guys
i was wondering if its possible to generate interrupts when a character is send to the board through serial, for example i want the board to keep an led on until it receives a string like "OFF" through serial using interrupts.
Is there a special reason why you want to use interrupys for this?
It could easyli be achived without resorting to interrupts, but something else might be going on at the same time that could justify using an interrupt. I'm not sure taht i is possible to connect an interrupt to the serial port though.
There is an internal interrupt (in wiring_serial.c) that is raised when a character is received on the serial hardware but its not a good idea for sketch code to handle incoming serial data in this way. You could miss incoming characters if the code that responds to the interrupt is still running when new characters come in. Although lighting an LED would probably be quick enough for this not to happen, if you wanted to add functionality later on your code would break.
And modifying interrupt handlers is something that can result in bugs that are difficult to find and fix.
I agree with mikmo's advice, If you can, try to structure your sketch so that you can check in your loop code to see if characters are available using Serial.available.
i will have a lot of code running on my program and i need the interrupts to stop the main code and call another function depending on the serial input so i kinda need interrupts. p.s i want to know more abut the interrupts on arduino so it would be nice if some one could share their knowledge about arduino interrupts and how they can be modified
My experience is that it is usually better to implement complex arduino code (i.e. easier to write, maintain and share) without modifying the low level interrupt handlers, so I am not the right person to take you down that path.
But if you want, I can try and help you structure your sketch so that your application works as you need without interrupts. If you post your sketch with a brief overview of what functionality you want to have then there may be a simple way to add the capability you need without resorting to modifying arduino hardware interrupt handlers.
There are some applications that modifying the UART interrupt may be a good choice, but it may not be necessary just because there is lots of code doing lots of tasks. My first arduino sketch monitored the serial port while: reading a pot value and switch setting, updating an LCD display, driving a servo, reading the signal from a Radio control transmitter and monitor battery voltage. This was implemented by coding all the services as a separate function which are polled in the main loop. I also wrote my own simple delay function so that the serial port could be constantly monitored even when the sketch was waiting for a long delay.
Let me know if you want to consider doing something like this in your sketch.
Have fun!
im going to try something like that but the problem is that i will have image processing running on the side on a pc and all of the data will be send to the robot to get analysed and that takes a bit of time that's why i want to0 have interrupts, anyway ill send you a copy of my code when its done for you to have a look at it and see if its possible to make it more efficient tnx for you help;)
If you post a fragment of your analysis code you can get some early suggestions on how this could be structured to minimize delays in responding to the serial messages.
I was curious, what is the longest acceptable delay between a serial message coming in and your sketch responding to it.
i haven't wrote it yet right now i'm having trouble uploading my sketches to my arduino bt :-/