Zumo buzzer

Dear Pololu’s support,

I have a functionnal Zumo now, but I’d like to add the buzzer and accelerometer features. From now, I’m playing with the buzzer.
But, I can not compile the code because of this error :
<
ZumoBuzzer/ZumoBuzzer.cpp.o: In function ZumoBuzzer::playMode(unsigned char)': /usr/share/arduino/libraries/ZumoBuzzer/ZumoBuzzer.cpp:722: multiple definition of__vector_9’
ServoTimer2/ServoTimer2.cpp.o:/usr/share/arduino/libraries/ServoTimer2/ServoTimer2.cpp:94: first defined here
collect2: ld returned 1 exit status

What should I do ?
Thank you.

Alb.

Hi, Alb.

It looks like your code isn’t compiling because there are multiple conflicting definitions of the Timer2 overflow interrupt. The ZumoBuzzer library uses Timer2 to control the buzzer, so unfortunately, you won’t be able to use it along with any other library that uses Timer2.

-Derrill

ok fair enough, thank you for this answer.

So, I presumed that I can put the jumper and directly use a digitalWrite() on pin3 to play a note. But the zumo is still very quiet…
Do you have an idea on how should I fix it ?

Albatros

Hello.

You need to drive the buzzer pin at the frequency of the sound you want it to make. Just driving it steadily high could just burn it out. So, for example, if you want to play a 1 kHz note, you would drive the buzzer pin high for 500 us, low for 500 us, high for 500 us, low for 500 us, etc.

- Ben

do you have a code sample ?

because I think it’s what I did :

analogWrite(3, 128);
delay(500);
analogWrite(3, 128);
delay(500);
analogWrite(3, 128);

but 128 it’s like medium right ?

so I should do :

analogWrite(3, 255);
delay(500);
analogWrite(3, 0);
delay(500);

and this code have no effetct :

analogWrite(3, HIGH);
delay(500);
analogWrite(3, LOW);
delay(500);
analogWrite(3, HIGH);
delay(500);
analogWrite(3, LOW);

analogWrite() only works on pins that are hardware PWM outputs. delay(500) is delaying for 500 ms, not 500 us. You need to use delayMicroseconds().

- Ben

Ok Ben, Thx…

I understood this one, but the following is not working :

analogWrite(buzzer_PIN, HIGH); // pin 3
delayMicroseconds(500);
analogWrite(buzzer_PIN, LOW);
delayMicroseconds(500);
analogWrite(buzzer_PIN, HIGH);
delayMicroseconds(500);
analogWrite(buzzer_PIN, LOW);

As I said, analogWrite() is only valid on hardware PWM pins. You should be using digitalWrite().

- Ben

yes indeed, now it’s working. But how come the sound is so weak ?

Are you making the pin an output? Can you post your full program (it should only be a few lines long)?

- Ben