Serial.println inside ISR = bad idea?

I'm using attachInterrupt() to catch pulses on a rotary encoder. I want to send those pulses back to my desktop application via the serial message system I'm using for this project, but it's locking up my Arduino. Here's what I've got:

volatile int rotaryPulses; //count pulses from the rotary encoder

void setup(){
   inputString.Reserve(400); // for incoming serial messages from desktop

   attachInterrupt(0, rotaryPulseCounter, LOW);

void loop(){
   //doing stuff...

void rotaryPulseCounter(){
   Serial.print("STATUS|ROTARY PULSE: ");

When I run the program, things function as expected, the motor turns and things are moving the way I want them to. Once the rotary encoder makes a revolution, I get the following via serial:


...So I know that testing for LOW here is correct and it's happening when I would expect it to. However, at this point, the Arduino has locked up.

I thought maybe the problem is that by looking for the encoder's pulse to go to LOW, I might be getting "stuck" in the LOW state. I changed this to "FALLING" (also tried "RISING") and the pulse count is never incremented, even after several revolutions.

CHANGE doesn't seem like the right choice either, because I don't want to trigger the interrupt when it goes from HIGH to LOW and then again from LOW to HIGH.

Any thoughts? Am I doing something wrong here? Is the problem with Serial printing inside the interrupt routine, or is it something else?


Yes it's bad. Serial uses interrupts to work. Depending on a few other things, it can't interrupt an interrupt so it gets stuck.

Use the interrupt to set a volatile flag which the main loop() looks at and decides when to print.

Thanks. I had a feeling that might be the case.