title: Serial print slowing down execution of code. Arduino Due
body: <p>We are using an Arduino Due to send serial data via usb to a piece of software produced in visual studio.</p>
  
  <p>The problem we are having lies with the Due. We have a section of code that is time critical </p>
  
  <pre><code>      PumpCycleTime = millis();
        // Loop this until the pumpHIGH duration has expired
        do
        {
          digitalWrite(Pump, HIGH);
          SendSerialData();
        }
        while (millis() - PumpCycleTime &lt; PumpHIGH);
  
  
        // Record the pump cycle LOW start time
        PumpCycleTime = millis();
        // Loop this until the pumpLOW duration has expired
        do
        {
          digitalWrite(Pump, LOW);
          SendSerialData();
        }
        while (millis() - PumpCycleTime &lt; 1);
  </code></pre>
  
  <p>Initially we were controlling the frequency of the pump using delays. Which gave us reliable frequencies when measure on an oscilloscope. However this of course compromised the plotting of the graphs as there was gaps in the data. </p>
  
  <p>With millis() we are unable to produce the same frequency. Obviously we could compensate to achieve a single frequency however we need to be able to use a range frequencies reliably. </p>
  
  <p>It seems the SendSerialData(), which is a function with around 15 serial.print's, is effecting the timings as without it the frequency is as expected. </p>
  
  <p>Does anyone know of any solutions? Data logging and plotting to a graph in real time is essential and cannot be compromised.</p>
  
  <p>Thanks in advance</p>