If there is no way to accomplish this with programming tricks...
The fundamental problem is that I2C read and SD write both block: they sit in a while loop until the operation is complete. Interrupts are enabled during these operations, because, well, the libraries use interrupts to know when to read/write the next byte (among other things). But the Arduino can only do one of those operations at a time, from start to completion.
In your case, the pressure sensor I2C read time (10ms) is longer than the gyro cycle time (I2C? SPI? read time?). Should I mention the occasional 100ms delay from an SD write? (Depends on your specific card.)
This same problem just cropped up over here. The gist is that the IMU read time was ~6ms and the SD write time was occasionally ~10ms (it may be more). The cycle time is only 10ms. The only way to do both in 10ms is to make the operations concurrent, not sequential.
Part One of The Trick is to modify the I2C library so that it will do a read in several non-blocking steps:
- start the read (this actually writes 3 bytes to the device);
- check the read state (like Serial.available()); and
- finish the read (like Serial.read() this returns bytes that were saved during an I2C interrupt).
Part Two of The Trick is to modify the SD library so that it will call a helper function while it's waiting for the a write to complete (actually, the previous write must complete before the current write can begin). There were murmurings of calling the
yield function, but all the versions I have seen do not.
With both Parts of The Trick, you can start an I2C transfer, go do other work, watch for the I2C transfer to complete, and start writing data to the SD card (described here, code here). Provide a
yield function that does all of those things except writing to the SD card (recursion!). As long as you have sufficient buffers to span the SD write time, it will work because
yield is called from the SD write method while it's blocked.
You must also be careful to keep the write data rate below the SD card speed. 200KB/s to 300KB/s is easily doable.
Oh, and don't try to write all this to Serial @ 9600 baud, because the prints will block while those character trickle out, 1 character per ms.