GPS breaking when adding lots of sensors

Hi, for a bit of context im designing a GPS, datalogger and simple roll stabilisation for a UAV. I don't really know etiquette for posting here so just let me know if its too much. My problem comes from the GPS saying that it isn't receiving a GPS fix when really i think it should. Im using the NEOGPS library and the GPS itself works perfectly within all the examples, similarly for each of the functions I need to code, they work, the problem comes when combining them together.

The sensors i'm using are: Gyro, accel+magnometer, pressure sensor, GPS.
The data im trying to gather: roll, pitch, date, time, lat, long, alt, speed, heading.
On an arduino Mega with adafruit ultimate GPS logging Shield.

the Gyro, accel, pressure and SD logging work perfectly in their sketch.
the GPS and SD logging work perfectly in their own sketch.

When i simply tried to directly copy paste them over everything went wrong as it normally does. So i built the sketch up line by line until i found the problem. I can have GPS, gyro and accel with datalogging working more or less as intended. But only just. as soon as i add even a 100ms delay, the GPS stops satisfying its if(gps.available(gpsport)){} criteria and i get no GPS data to log.

The same thing happens if i try to add pressure(altitude) sensing or Heading into the mix. I considered that perhaps the GPS buffer was too full and that slowing down the code any further was causing it to overflow and lose data. But i find this unlikely as i log roll and pitch ~20 times for every one log containing GPS data.

The code is below but its almost 400 lines long so i don't expect anyone to read it line by line! id just like to see of anyone knows why adding a small delay or additional sensor could break the gps of an otherwise reasonably functional piece of code.

if you would rather i post it directly i can do that too.

this version of the code uses all the functions that work, but even adding something like a delay(100); makes the GPS data stop being spat out, either into serial or SD despite compiling.

Again, this is a rather broad question so i understand if you guys can't advise much.

I'd appreciate any help.

what microcontroller are you running the code on?
could you be running out of memory? what does memory usage does the linker report?
how do you power the devices ? could the combination of GPS, sensors, etc be overloading the power?

arduino Mega, im at storage 14% and memory 24% if i remember right.

powered through USB printer cable from my laptop.

i don't believe the devices are particularly power intensive

oh and even when the gps isnt giving out data the other functions still work

Of course the GPS fails. For valid data you must capture a complete NMEA sentence, with not a single character missing (and with valid checksum). For a GPS with serial Baud rate 9600, you must process at least 1000 characters per second on average. A significant delay can make that impossible.

There is no reason to have any delays.

Read the forum guidelines to see some information on making a good post.

hm, that makes sense but to my knowledge the library im using parses the whole sentence without any delay between them and i have my delay after the sentence is complete. would that still cause a problem?

The NeoGPS library processes characters one at a time, as fast as you feed them in. The library does not block, and merely informs you when an entire valid sentence has been received and processed.

Post your code, using code tags, and we can explain where the problem is (but that is already clear).

i see, so does that mean there is only so much code i can write before a loop takes too long and the gps fails? cos every step adds on a bit of time, does that mean i am at that limit?

Correct. But you don't have to read every sensor, every pass through the loop. You do have to keep up with the GPS unit.

would this still be helpful? ive put a git hub link but i can post the full thing here if you like

You are the one asking for help, so it is up to you whether to provide the requested information.

As far as I'm concerned, the problem is understood and very easily solved.

I get what your saying im just not sure how to would skip over some sensors

Please follow the forum guidelines when posting code. Post ALL of it, using code tags.

As for reading sensors at specific intervals, check out the "blink without delay" code example in the Arduino IDE.

perfect thanks for ur help, ill try to make use of the blink without delay

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.