Hello, I'm trying to make an antenna tracking system using m8n gps and mpu6050 imu to track my Fpv drone. Initially, the code was too slow because while the stepper motors move the calculated position the Fpv drone is too fast and it's already in a new location so for that I want to use interrupts on the data the GPS sends to the Arduino update variables as new data is received.
The problem is that I do not know how to use interrupts and I want to use interrupt on tx and rx pin that when data is available from GPS(on serial port 0,1 using softwareserial) an interupt is generated then it should stop code and receive data from GPS into serial populate data into variables subsequently helping Arduino to be updated on the new position of drone.
if there is an example of how to use interrupts with data received in serial port that would be helpful.
Basically i undestand that the serial port is interrrupt driven meaning as data comes in rx pin , it will add it to buffer but what i want is to use it as a function so i can populate my global variables....
Interrupts are not the answer. Either your code is poorly structured or you are using a stepper library that blocks execution while it's moving the motor. Either way, post your complete code to get useful help.
I cannot send code right now becuase its on my laptop at home however i will send it when i get home. But the problem is that the im not just using gps data, im also using two i2c inputs(1 from compas and 1 from gyroscope) so there is no way fro me to downsize code anyway.
Its basically a monster quad people use to record dslr videos. With the size of the battery i can fly upto 15 mins meaning i can record longer distances but fpv video breaks up unless im pointing the direction of my fpv goggles towards the drone which gives me a headache everytime i move from the postion im in.
thats why i opted for using ats
Is there a way to use the data coming in from serial port as interrupt as function like the Timerone library which generates an interrupt with given interval to run sepcific commands like read and updating variables etc.
Yes, Intially i opted for servos but they dont move 360 so went for stepper motors. Dont get confused, its gonna be heavy but its small and reliable with stepper.
Nothing you've said changes my position that using interrupts will not be useful here. I might change my mind after seeing your code, but I highly doubt it.
OK will send you when i get home.
In the mean time one quick question, does void serialEvent() act like an interrupt?
I read a faq in which someone sad it acts like a serial interrupt but it doesnt make sense to me, isnt this a fucntion?
Question. What use is it to have an interrupt tell you a character is arriving on any pin, when that character is simply the first, small portion of the complete string being received? What you really need(and will never get) for the purpose you've described is an interrupt when the last character is almost completely received.
What you need, and can get help with here, is a serial reception code that is non-blocking, responsive, and also not blocked by other code fragments, such as motor control, etc.
Showing us your code will be the first step; once your need is better understood(the code will help), and any deficiency in your code explored(a necessary, but sometimes painful, step), then suggestions will likely be made about how to fix, or replace, your code.
Please understand that the serial port interrupt is ALREADY BEING USED by the very code you are using to read bytes form that port. The interrupt occurs when all the bits for the current byte have been received and the interrupt occurs to tell the code to move that byte to the buffer that your code is looking at.
So, unless you are prepared to write and test code to replace what you get with the Arduino IDE, you will have to do without an interrupt.
It would be possible to assign another pin an interrupt, attach it to the RX pin, and thus have an interrupt that fired when an incoming character started the process.
However, what one would do with that interrupt, and how it would be better or faster than working with the hardware and software combination already built into the processor, is beyond me.
Methinks the OP needs to expose his code for inspection, because it's very likely the source of the problem.
Since the program could not know in advance exactly how many 1 bits the character has that would be futile! Or could be 0 bits. There would be no interrupts for multiple identical bits.
@Paul_KD7HB Did I suggest somehow that it made sense to do so? No, I did not. It's one of those "things" that people get in their heads - "Oh, I need an interrupt to tell me...", not understanding that the process is already far more complicated and sophisticated than their concept allows for, as you've detailed.
Meh. Yet again, you strike up a fire where none existed.