user20786: The sample rate of an accelerometer, like an MPU6050, is much faster than the GPS log rate, different technology, different issues. 
A common GPS Reciver has, approximatly, one second log rate.
In my specific case the accelerometer has a 100hz log rate.
With a previous code the gps log rate was slowing down the accelerometer log rate so i thought to introduce two counters:

one for the gps 
one for the accelerometer

What i tried to do was: 
  if ((lastLogGPS + LOG_RATE_GPS) <= micros()) {
  //Log accelerometer and gps data
  } else ((  if ((lastLog + LOG_RATE) <= micros()) {
  //Log only Accelerometer data
  }


1. Is that a speed and memory efficient solution? Or better way exist*?
2. During a 60 seconds test the board return me only the accelerometer value, never the satellites informations, i think there are some dumb errors in my code 

Thanks for your help :) 
This is the void loop section 
void loop()
  {
    Wire.beginTransmission(MPU);
    Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
    Wire.endTransmission(false);
    Wire.requestFrom(MPU,14,true);   // request a total of 14 registers
    AcX=Wire.read()<<8;
    AcX|= Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)     
    AcY=Wire.read()<<8;
    AcY|=Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
    AcZ=Wire.read()<<8;
    AcZ|=Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
    GyX=Wire.read()<<8;
    GyX|=Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
    GyY=Wire.read()<<8 ;
    GyY|=Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
    GyZ=Wire.read()<<8;
    GyZ|=Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
    if ((lastLogGPS + LOG_RATE_GPS) <= micros()) {
    while (gps.available( gpsPort )) {
    fix = gps.read();  // get the entire fix structure, once per second

    if (logGPSData()) { // Log the GPS data
    SerialMonitor.println( F("GPS logged.") ); // Print a debug message
    } else {// If we failed to log GPS
    // Print an error, don't update lastLog
    SerialMonitor.println( F("Failed to log new GPS data.") );
      }
    }
   lastLogGPS=micros();
  }
  else{ 
    if ((lastLog + LOG_RATE) <= micros()) {

      printImuData(dataFile,lastLog, AcX, AcY, AcZ, GyX, GyY, GyZ);
      dataFile.flush(); 
      }
    lastLog=micros(); 
    }
  } 

This the function that print only the accelerometer informations:
static void printImuData(Print &printer, unsigned long lastLog,
        int16_t AcX, int16_t AcY, int16_t AcZ,
        int16_t GyX, int16_t GyY, int16_t GyZ)
{//Printing the mpu6050 information 

  printer.print("0");   printer.print(",");   //0 longitude
  printer.print("0");   printer.print(",");   //0 latitude
  printer.print("0");   printer.print(",");   //0 altitude
  printer.print("0");   printer.print(",");   //0 speed
  printer.print("0");   printer.print(",");   //0 course
  printer.print("0");   printer.print(",");   //0 date
  printer.print("0");   printer.print(",");   //0 time 
  printer.print("0");   printer.print(",");   //0 satellites
  printer.print(lastLog); printer.print(",");   
  printer.print(AcX);     printer.print(",");
  printer.print(AcY);     printer.print(",");
  printer.print(AcZ);     printer.print(",");
  printer.print(GyX);     printer.print(",");
  printer.print(GyY);     printer.print(",");        
  printer.println(GyZ);  

}

And this is the part for the GPS informations:
byte logGPSData()
{
  if (dataFile.isOpen())
  { // Print longitude, latitude, altitude (in feet), speed (in mph), course
    // in (degrees), date, time, and number of satellites.

    if (fix.valid.location)
      dataFile.print(fix.longitude(), 6);
    dataFile.print(',');
    if (fix.valid.location)
      dataFile.print(fix.latitude(), 6);
    dataFile.print(',');
    if (fix.valid.altitude)
      dataFile.print(fix.altitude() * 3.2808, 1);
    dataFile.print(',');
    if (fix.valid.speed)
      dataFile.print(fix.speed_mph(), 1);
    dataFile.print(',');
    if (fix.valid.heading)
      dataFile.print(fix.heading(), 1);
    dataFile.print(',');

    if (fix.valid.date) {
      dataFile.print( fix.dateTime.full_year() );
      if (fix.dateTime.month < 10)
        dataFile.print( '0' );
      dataFile.print( fix.dateTime.month );
      if (fix.dateTime.date < 10)
        dataFile.print( '0' );
      dataFile.print( fix.dateTime.date );
    }
    dataFile.print(',');

    if (fix.valid.time) {
      if (fix.dateTime.hours < 10)
        dataFile.print( '0' );
      dataFile.print( fix.dateTime.hours );
      if (fix.dateTime.minutes < 10)
        dataFile.print( '0' );
      dataFile.print( fix.dateTime.minutes );
      if (fix.dateTime.seconds < 10)
        dataFile.print( '0' );
      dataFile.print( fix.dateTime.seconds );
    }
    dataFile.print(',');

    if (fix.valid.satellites)
      dataFile.print(fix.satellites);
  dataFile.print(',');  
  dataFile.print(lastLogGPS);  
    dataFile.print(',');
    dataFile.print(AcX);
    dataFile.print(',');
    dataFile.print(AcY);
    dataFile.print(',');
    dataFile.print(AcZ);
    dataFile.print(',');
    dataFile.print(GyX);
    dataFile.print(',');
    dataFile.print(GyY);
    dataFile.print(',');
    dataFile.print(GyZ);

    dataFile.println();
    dataFile.flush(); // make sure the file contains at least this much

    return 1; // Return success
  }

  return 0; // If we failed to open the file, return fail
}

Here a pic of some data returned by Arduino

*I need to load easily the *.csv whith the recorded data on matlab so i have some constraints. 

user27157: Ok, I won't recreate your whole code, but here is a logic snippet that you can use.
Let's suppose that you have 2 sensors, sensor1 and sensor2.
sensor1 is read every 10 milliseconds and sensor2 is read every 16 milliseconds.
Here is what you would do:
Make 2 global variables for your timers :
unsigned long timer1 = 0;
unsigned long timer2 = 0;

Then make 2 constants for the frequency, this example will set the frequency in milliseconds.
const int frequency1 = 10;
cosnt int frequency2 = 16;

Then in your void loop, you would do something like this:
void loop () {
    if (timer1 + frequency1 >= millis()
        read(sensor1);
        timer1 = millis();
    }

    if (timer2 + frequency2 >= millis()
        read(sensor2);
        timer2 = millis();
    }
}

This method makes sure that your code isn't going to get stuck anywhere. I would also suggest to remove any while loops because of that danger that it might freeze& your code.

20786: <p>The sample rate of an accelerometer, like an MPU6050, is much faster than the GPS log rate, different technology, different issues. 
A common GPS Reciver has, approximatly, one second log rate.
In my specific case the accelerometer has a 100hz log rate.</p>

<p>With a previous code the gps log rate was slowing down the accelerometer log rate so i thought to introduce two counters:</p>

<ul>
<li>one for the gps </li>
<li>one for the accelerometer</li>
</ul>

<p>What i tried to do was: </p>

<pre><code>  if ((lastLogGPS + LOG_RATE_GPS) &lt;= micros()) {
  //Log accelerometer and gps data
  } else ((  if ((lastLog + LOG_RATE) &lt;= micros()) {
  //Log only Accelerometer data
  }
</code></pre>

<hr>

<p><strong>1. Is that a speed and memory efficient solution? Or better way exist*?</strong></p>

<p><strong>2. During a 60 seconds test the board return me only the accelerometer value, never the satellites informations, i think there are some dumb errors in my code</strong> </p>

<hr>

<p>Thanks for your help :) </p>

<p>This is the void loop section </p>

<pre><code>void loop()
  {
    Wire.beginTransmission(MPU);
    Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
    Wire.endTransmission(false);
    Wire.requestFrom(MPU,14,true);   // request a total of 14 registers
    AcX=Wire.read()&lt;&lt;8;
    AcX|= Wire.read(); // 0x3B (ACCEL_XOUT_H) &amp; 0x3C (ACCEL_XOUT_L)     
    AcY=Wire.read()&lt;&lt;8;
    AcY|=Wire.read();  // 0x3D (ACCEL_YOUT_H) &amp; 0x3E (ACCEL_YOUT_L)
    AcZ=Wire.read()&lt;&lt;8;
    AcZ|=Wire.read();  // 0x3F (ACCEL_ZOUT_H) &amp; 0x40 (ACCEL_ZOUT_L)
    GyX=Wire.read()&lt;&lt;8;
    GyX|=Wire.read();  // 0x43 (GYRO_XOUT_H) &amp; 0x44 (GYRO_XOUT_L)
    GyY=Wire.read()&lt;&lt;8 ;
    GyY|=Wire.read();  // 0x45 (GYRO_YOUT_H) &amp; 0x46 (GYRO_YOUT_L)
    GyZ=Wire.read()&lt;&lt;8;
    GyZ|=Wire.read();  // 0x47 (GYRO_ZOUT_H) &amp; 0x48 (GYRO_ZOUT_L)
    if ((lastLogGPS + LOG_RATE_GPS) &lt;= micros()) {
    while (gps.available( gpsPort )) {
    fix = gps.read();  // get the entire fix structure, once per second

    if (logGPSData()) { // Log the GPS data
    SerialMonitor.println( F("GPS logged.") ); // Print a debug message
    } else {// If we failed to log GPS
    // Print an error, don't update lastLog
    SerialMonitor.println( F("Failed to log new GPS data.") );
      }
    }
   lastLogGPS=micros();
  }
  else{ 
    if ((lastLog + LOG_RATE) &lt;= micros()) {

      printImuData(dataFile,lastLog, AcX, AcY, AcZ, GyX, GyY, GyZ);
      dataFile.flush(); 
      }
    lastLog=micros(); 
    }
  } 
</code></pre>

<p>This the function that print only the accelerometer informations:</p>

<pre><code>static void printImuData(Print &amp;printer, unsigned long lastLog,
        int16_t AcX, int16_t AcY, int16_t AcZ,
        int16_t GyX, int16_t GyY, int16_t GyZ)
{//Printing the mpu6050 information 

  printer.print("0");   printer.print(",");   //0 longitude
  printer.print("0");   printer.print(",");   //0 latitude
  printer.print("0");   printer.print(",");   //0 altitude
  printer.print("0");   printer.print(",");   //0 speed
  printer.print("0");   printer.print(",");   //0 course
  printer.print("0");   printer.print(",");   //0 date
  printer.print("0");   printer.print(",");   //0 time 
  printer.print("0");   printer.print(",");   //0 satellites
  printer.print(lastLog); printer.print(",");   
  printer.print(AcX);     printer.print(",");
  printer.print(AcY);     printer.print(",");
  printer.print(AcZ);     printer.print(",");
  printer.print(GyX);     printer.print(",");
  printer.print(GyY);     printer.print(",");        
  printer.println(GyZ);  

}
</code></pre>

<p>And this is the part for the GPS informations:</p>

<pre><code>byte logGPSData()
{
  if (dataFile.isOpen())
  { // Print longitude, latitude, altitude (in feet), speed (in mph), course
    // in (degrees), date, time, and number of satellites.

    if (fix.valid.location)
      dataFile.print(fix.longitude(), 6);
    dataFile.print(',');
    if (fix.valid.location)
      dataFile.print(fix.latitude(), 6);
    dataFile.print(',');
    if (fix.valid.altitude)
      dataFile.print(fix.altitude() * 3.2808, 1);
    dataFile.print(',');
    if (fix.valid.speed)
      dataFile.print(fix.speed_mph(), 1);
    dataFile.print(',');
    if (fix.valid.heading)
      dataFile.print(fix.heading(), 1);
    dataFile.print(',');

    if (fix.valid.date) {
      dataFile.print( fix.dateTime.full_year() );
      if (fix.dateTime.month &lt; 10)
        dataFile.print( '0' );
      dataFile.print( fix.dateTime.month );
      if (fix.dateTime.date &lt; 10)
        dataFile.print( '0' );
      dataFile.print( fix.dateTime.date );
    }
    dataFile.print(',');

    if (fix.valid.time) {
      if (fix.dateTime.hours &lt; 10)
        dataFile.print( '0' );
      dataFile.print( fix.dateTime.hours );
      if (fix.dateTime.minutes &lt; 10)
        dataFile.print( '0' );
      dataFile.print( fix.dateTime.minutes );
      if (fix.dateTime.seconds &lt; 10)
        dataFile.print( '0' );
      dataFile.print( fix.dateTime.seconds );
    }
    dataFile.print(',');

    if (fix.valid.satellites)
      dataFile.print(fix.satellites);
  dataFile.print(',');  
  dataFile.print(lastLogGPS);  
    dataFile.print(',');
    dataFile.print(AcX);
    dataFile.print(',');
    dataFile.print(AcY);
    dataFile.print(',');
    dataFile.print(AcZ);
    dataFile.print(',');
    dataFile.print(GyX);
    dataFile.print(',');
    dataFile.print(GyY);
    dataFile.print(',');
    dataFile.print(GyZ);

    dataFile.println();
    dataFile.flush(); // make sure the file contains at least this much

    return 1; // Return success
  }

  return 0; // If we failed to open the file, return fail
}
</code></pre>

<p>Here a pic of some data returned by Arduino
<a href="https://i.stack.imgur.com/vTfCU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vTfCU.png" alt="enter image description here"></a></p>

<p>*I need to load easily the *.csv whith the recorded data on matlab so i have some constraints. </p>
 27157: <p>Ok, I won't recreate your whole code, but here is a logic snippet that you can use.</p>

<p>Let's suppose that you have 2 sensors, <code>sensor1</code> and <code>sensor2</code>.</p>

<p><code>sensor1</code> is read every 10 milliseconds and <code>sensor2</code> is read every 16 milliseconds.</p>

<p>Here is what you would do:</p>

<p>Make 2 global variables for your timers :</p>

<pre><code>unsigned long timer1 = 0;
unsigned long timer2 = 0;
</code></pre>

<p>Then make 2 constants for the frequency, this example will set the frequency in milliseconds.</p>

<pre><code>const int frequency1 = 10;
cosnt int frequency2 = 16;
</code></pre>

<p>Then in your void loop, you would do something like this:</p>

<pre><code>void loop () {
    if (timer1 + frequency1 &gt;= millis()
        read(sensor1);
        timer1 = millis();
    }

    if (timer2 + frequency2 &gt;= millis()
        read(sensor2);
        timer2 = millis();
    }
}
</code></pre>

<p>This method makes sure that your code isn't going to get <em>stuck</em> anywhere. I would also suggest to remove any <code>while</code> loops because of that danger that it might <em>freeze&amp;</em> your code.</p>
