Voltage when generating a tone

I'm trying to generate some tones on a piezo speaker via one of the digital output pins. The problem is that I can only get 2.5V output from the digital pin. I've tried several pins and get the same result. Is there some trick to getting the full 5V out?

Here's my code. What is curious is that I can get 5V via digitalWrite() but not via tone().

const int PIEZO_PIN = 11;

void setup() { 
  pinMode(PIEZO_PIN, OUTPUT);

  tone(PIEZO_PIN, 1568, 1000);
  delay(1000);

  tone(PIEZO_PIN, 2048, 1000);
  delay(3000); 

  digitalWrite(PIEZO_PIN, HIGH);
  delay(5000);
  digitalWrite(PIEZO_PIN, LOW);
}

void loop() {
  // no need to repeat.
}

How are you measuring the voltage?

You'll need to use an oscilloscope to measure it properly.

If you are using a DMM, then you will surely see 2.5V.

b

Yes, I am using a DMM. Is it essentially averaging out the highs and lows of the square wave?

Bingo! The wave is 5V at 50% duty cycle (i.e. square wave) and the meter will average that out to 2.5V.

b

Thanks. That does make perfect sense. I know just enough about electronics to be dangerous, so I still have much to learn.