I'm having troubles with the tone() statement.
My circuit is just connecting a speaker to an I/O pin, and then through a resistor to ground:


(Sorry about the flipped image, not sure why the forum software wants to put it upside-down.)
When I upload the sketch (I hate that term, when I upload the program), I get no sound:
Code: Select all
//A sketch to demonstrate the tone() function
//Specify digital pin on the Arduino to which the positive lead of the speaker is attached.
int SpkrPin = 0;
void setup() {
pinMode(SpkrPin, OUTPUT);
} //close setup
void loop() {
tone(SpkrPin, 2000);
// digitalWrite(SpkrPin, HIGH);
// delay(2);
// digitalWrite(SpkrPin, LOW);
// delay(2);
}
I have tried with and without the pinMode() statement, and have also added a digitalWrite() statement to initially set the pin high (and low) - I saw someone somewhere say that you needed that.
When I uncomment the digitalWrite() statements to toggle the I/O pin, and comment out the tone() statement, I get a tone. Changing the delay() statements works as expected. The scope (connected to the green line on the schematic) shows: (BTW, thanks for the 'scope Jason, it has come in handy.)

In addition, I have tried all 6 of the I/O pins, none of them give a tone (all show 0V on my scope, except for P5, which shows constant high.)
.bmp)
When I switch to an Arduino Uno, I get the tone from the speaker, using either the digitalWrite, or the tone() statements.
Does anyone have any ideas where I am going wrong?