Multiple sensors with interrupts

I'm working on a project to connect a Gyro + Accel sensor (MDU 6050), a GPS (Adafruit MDK3339) and a SD card reader to an Arduino Uno to record the data. Both gyro and GPS sensors can use an interrupts to get their values (preferred method).
I don't know how to make them work together and sync the 2 interrupts or if I should use just the interrupt from one sensor and code the second sensor in the loop function.
Since I'm new at this, any feedback or advice is welcome.

It depends on how you want to record your data.
Do you want it to be recorded everytime the unit moves, or read data every minute and store it on the SD?

You can have one interrupt for each sensor, but it could cause troubles if not coded correctly.

Please explain why interrupts are the 'preferred method'?

How do you want to use your application. If the MCU causes an interrupt, record MCU and GPS information. Or if GPS causes an interrupt, record MCU and GPS information. Or only record information if both have caused an interrupt? Or something completely different.

Interrupts can not be synced; they are asynchronous by nature. You can record that an interrupt on the GPS occurred and record that the interrupt on the MCU occurred (it can be hours later :wink: ). In your main loop() you can check those recorded events.

I'd like the unit to record to the SD card at a predefined interval (set at 1 second for now) the current GPS location and gyro / accel data at that location/time so that the data can be analyzed later.

I read somewhere that the GPS sensor is more "accurate" when using an interrupt. If using the loop function it may have not picked up the "latest" reading yet and report an old reading. However I'm not an expert, and I could use the regular loop if I can make it work. The problem is that when I tried to use the loop function for all sensors (gyro+GPS+SD) the unit became unresponsive after a few seconds (it worked for about 20 seconds then stopped - crash?).

Could you please post the code you tried? remember to put it in code tags

makymax:
I'd like the unit to record to the SD card at a predefined interval (set at 1 second for now) the current GPS location and gyro / accel data at that location/time so that the data can be analyzed later.

I read somewhere that the GPS sensor is more "accurate" when using an interrupt. If using the loop function it may have not picked up the "latest" reading yet and report an old reading.

If you only need a reading every second there is absolutely no need to use interrupts.

Have a look at how millis() is used to manage timing without blocking in several things at a time

...R

makymax:
I read somewhere that the GPS sensor is more "accurate" when using an interrupt. ... However I'm not an expert,

Nor is seems, was whoever wrote that.

You do have to be careful what you read on the Internet! :roll_eyes:

Robin2:
If you only need a reading every second there is absolutely no need to use interrupts.

Have a look at how millis() is used to manage timing without blocking in several things at a time

...R

I'll take a look at the sample code....

If you are timing nanoseconds or microseconds then interrupts are 'more accurate.' But if you only need to get all these readings within the same millisecond then don't use interrupts.

Also, with chips like the MPU6050, you often busy-wait on the output that they call 'interrupt.' The chip doesn't force you to use an interrupt. It's just a convenient name for that wire.