Adding a speaker to 3pi

Hi all,

I’d just like some guidance as to how you think I could go about adding a speaker (that will be used to play musical notes) to the 3pi. I am currently using the P0 and P1 pins for a master slave connection with an arduino board, so can’t really wire the speaker to that.

The reason why I am opting not to use the buzzer is due to the fact that the notes played via the buzzer don’t work well with my tone analysis system running on the Arduino.

I have the speaker running great on the arduino, but realised that I can’t analyse the sound and play it at the same time.

So hoping the 3pi can play the notes and the Arduino can analyse it through a microphone.

Any help would be much appreciated :slight_smile:


[Or is it really just a matter of connecting the grounds, the power to vcc and the signal to pc5. Then in Arduino writing the audio output to pin 19?] <—solved

And if attached to the 3pi is there anyway to control the volume?


I don’t understand from your post what you are doing, does “solved” mean your latest wiring working? You can control the volume of a speaker by changing the duty cycle of the PWM that you are driving the speaker with. Our AVR library has buzzer control functions that let you change the volume.

- Ryan

I have attached a speaker to PC5 and ground, but have found that when I run the default line follower code on the 3pi it writes to the PC5 pin and thus plays this high pitched tone. Is there anyway to stop this so that the line follower code does not write to PC5?

EDIT I am using the Arduino IDE and therefore can’t make much sense out of:

static unsigned char Pololu3pi::init(unsigned int line_sensor_timeout = 1000, unsigned char disable_emitter_pin = 0)

unsigned char pololu_3pi_init(unsigned int line_sensor_timeout)

unsigned char pololu_3pi_init_disable_emitter_pin(unsigned int line_sensor_timeout)


From the link you posted:

When you initialize the 3pi code, you can use the disable_emitter parameter to tell the library to not use the emitter pin at all. Does this make sense?

- Ben

Hi Ben,

Thanks for the reply. Where about should I write that in my code? in the setup() I assume.

And do I just write : disable_emitter_pin(1);

because that is hwat I am having problems with. The right syntax to use in Arduino

or perhaps this?

robot.init(line_sensor_timeout = 1000, disable_emitter_pin = 1);

That isn’t valid C/C++. It’s just a function call, so you would do what you would for any other function call:

robot.init(1000, 1);

The syntax you are copying from the command reference is how the methods are declared, and the “= 1000” part means that the associated variable will get the default value of 1000 if it is not specified. For example, if the method is declared:

void init(unsigned char line_sensor_timeout = 1000, unsigned char disable_emitter_pin = 0);



has the same effect as calling:

init(1000, 0);

If you want different values from the defaults, you should call the functions with those parameters.

- Ben

Thanks Ben, :slight_smile: your explanation was awesome.

And it works great. Can’t wait to show you guys what I have been working on for the better part of a year. fingers crossed everything else works out.