I tried to make a sketch with attachInterrupt and tone methods.
void setup() {
Serial.begin(57600);
Serial.println("Start");
attachInterrupt(0, changed, CHANGE);
tone(6, 1000);
}
This sketch outputted no tone unless I removed the attachinterrupt. I thought that external interrupts were completely separate from timer interrupts. What is happening?
orangeLearner:
I thought that external interrupts were completely separate from timer interrupts.
They are.
What is happening?
You forgot to post your code. You also forgot to include a description of the interrupt rate.
I apologize. Here is my full code:
/* Prints the time in ms between interrupts. */
volatile unsigned long lastInterrupt = 0;
void setup() {
Serial.begin(57600);
Serial.println("Start");
attachInterrupt(0, changed, CHANGE);
}
void loop() {
tone(6, 1000);
delay(2000);
noTone(6);
delay(2000);
}
void changed(){
Serial.print(!digitalRead(2));
Serial.print(": ");
Serial.println(micros() - lastInterrupt);
lastInterrupt = micros();
}
And here is the circuit. Originally pin 6 was connected to the data in of this RF transmitter and pin 2 was connected to the data out of the data out of this receiver, but when that failed to produce any interrupts at all, I switched to this circuit:

When the yellow wire is disconnected, it will output a tone for two seconds, delay, then repeat like expected. When I connect the yellow wire, at the next tone output, the TX light blinks and the sketch stops even if I disconnect the yellow wire again. What could be happening?
It's a mistake to do Serial.print in an interrupt routine. That relies on interrupts, which are disabled.
Is there any sound output? Ticking noise?
The sequence of events...
The tone timer interrupt fires. The timer interrupt service routine adjusts the tone output pin (pin 6) and returns.
Pin 2 was toggled (because tone toggle it) so the INT0 interrupt fires ultimately resulting in your function (changed) being called. Your function does several things that use a moderate amount of CPU time (digitalRead, micros twice, converting an unsigned long to text, buffer data for serial output).
In order to generate a 1000 Hz tone, the tone timer interrupt service routine has to run every 1/(2*1000)*1000000 = 500 microseconds. Your function (changed) is very likely taking much longer than 500 microseconds to run. The "overrun" prevents tone from working correctly.
Originally pin 6 was connected to the data in of this RF transmitter and pin 2 was connected to the data out of the data out of this receiver,
Why? SoftwareSerial (NewSoftSerial) should work reasonably well.