Go Down

Topic: Piezo is making a soft sound after having played a tone() - how can I stop it? (Read 1 time) previous topic - next topic

local_dani_21

Hi

I connected a piezo speaker to a ATMEGA32U4 (pin 9). The other piezo-pin goes to ground

When I power up the board, the piezo is completely quiet. I then play a tone using tone(9,500,1000);. After having played the tone (and also after having executed noTone(9)), there is a soft hissing noise coming from the speaker.

Does anyone have any idea how to stop the noise?

Thank you,
Dani

robtillaart

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Jiggy-Ninja

Post your sketch.

I suspect this. When the sketch first powers up, all pins are in INPUT mode. This high Z input impedance causes there to be no current flow through the speaker, causing absolutely no noise.

When tone() is run, the pin is forced to OUTPUT. After noTone(), the pin is still OUTPUT, but written LOW. This is a low impedance output that can cause some currents and noise to flow.

After noTone(), try setting the pin to INPUT and see what happens.

Grumpy_Mike

Quote
After noTone(), try setting the pin to INPUT and see what happens.

Yes, or write a logic LOW to the pin after the noTone.

Jiggy-Ninja


Quote
After noTone(), try setting the pin to INPUT and see what happens.

Yes, or write a logic LOW to the pin after the noTone.

noTone() already does that.
Code: [Select]
void noTone(uint8_t _pin)
{
  int8_t _timer = -1;
 
  for (int i = 0; i < AVAILABLE_TONE_PINS; i++) {
    if (tone_pins[i] == _pin) {
      _timer = pgm_read_byte(tone_pin_to_timer_PGM + i);
      tone_pins[i] = 255;
    }
  }
 
  disableTimer(_timer);

  digitalWrite(_pin, 0);
}

Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:

shortcuts: alt+s submit/post or alt+p preview