title: TimerOne and Serial Libraries
body: <p>I'm working using <a href="http://playground.arduino.cc/code/timer1" rel="nofollow">TimerOne library</a>, the code is shown below:</p>
  
  <pre><code>#include &lt;TimerOne.h&gt;
  
  void setup() {
      Serial.begin(9600);
      pinMode(13, OUTPUT);    
      Serial.println();
      Timer1.initialize(1000000); // set a timer of length 1000000 microseconds
      Timer1.attachInterrupt(timerIsr); // attach the service routine here
  }
  
  void loop() {
      Serial.println(millis());
  }
  
  void timerIsr() {
      Serial.print("FROM Time1: ");
      Serial.println(millis());
  }
  </code></pre>
  
  <p>The problem is, after some loops (when millis of loop() returns 930), the arduino stop</p>
  
  <p>I think that the problem is, when the arduino is running the loop, and write in Serial port, the ISR Routine is writing too. How can I solve this problem?</p>
  
  <p>I try change:</p>
  
  <pre><code>Serial.print("FROM Time1: ");
  Serial.println(millis());
  </code></pre>
  
  <p>by:</p>
  
  <pre><code>digitalWrite(13, !digitalRead(13));
  </code></pre>
  
  <p>And work fine, I think that the Serial library of arduino has some problem when use interrupts, It's possible?</p>
  
  <p>There's any way to block arduino in some block of code, I try use <a href="http://www.nongnu.org/avr-libc/user-manual/group__util__atomic.html" rel="nofollow">atomic</a> and didn't work.</p>
  
  <p>I'm using Arduino UNO (ATmega328)</p>