Tone and Servo libraries

The documentation of the Tone lbrary ( states that "Using this library will affect usage of the PWM outputs, so be aware" Does that mean that I have to expect negative effects also with the Servo library?

Depends on what else you are doing. Pins 9 and 10 are affected, on the Duemilanove by the servo library, whether you use them, or not.

Or is there a better/easier way to generate a 34kHz master clock signal for an Intersema MS5534C pressure sensor? (

Using the tone library seemed the easiest, and it works well so far. But now I want to use it in conjunction with other sensors and servos.

So, if I use pin's 9 and 10 only for non-time-critical stuff, I should be fine?

I couldn't really tell from the datasheet, but does the device have to be driven at the same rate as the microcontroller interfacing to it?

I would think you could simply use a separate crystal oscillator (as specified in the spec of 32.768 kHz), along with appropriate decoupling caps (basically a similar arrangement to the Arduino's resonator, except with a crystal).

That would probably be the most reliable solution, albeit not the simplest (or cheapest).

From what I read in the data sheet, I'm pretty sure, it would work with the external oscillator. But I don't have the suitable components, and I wouldn't know how to fit them together. So, unless you can convince me, that it's really easy, I prefer to stick with the digital pins.

Well, nothing is easy when it comes to making clock circuits work.

Check this app note (for a completely different chip with a completely different clock rate):

There's a schematic that shows a sample implementation, with an external clock; its not much different from the hookup for the external resonator on the Arduino (a few extra parts).

Here's one on how a Rabbit ( system uses a 32.768 kHz clock - with schematics:

Once again, some extra parts involved. Here's another clock circuit - it has the least extra parts:

Just the crystal (taken from an old wall clock), a couple of capacitors, and a resistor (you could probably drop the resistor, and only use the singular upper output from the oscillator crystal; the other side of the crystal I think is the "inverse" output). This is basically as many parts as what is running the Arduino...

The only real gotcha to all of this is that it is one of those unlikely plug-n-go projects; it is more likely you would hook it up, and nothing would work because the clock won't run (for whatever myriad reason) - to troubleshoot you would need an oscilloscope and a frequency counter; not every hobbyist owns such tools (I more or less have the o-scope covered, but not by much - and I don't have a freq counter, either; unless you count my dog when she barks out the front window - that's a joke, son).


Thanks for the links. The clock circuit scared me a bit off. I might nevertheless try it some day. But for the moment, I prefer to stick with the digital pins.

I found out that the Tone and the Servo library are incompatible. By including both into my project, I got a compiler error. Don't remember what it was. But I found the tone() function in the core Arduino language reference ( Tried with the sensor, and it works as well. (only tested in isolation so far) The documentation of the tone() function says : "Use of the tone() function will interfere with PWM output on pins 3 and 11"

So, if I use pin3 for the pressure sensor's master clock and pin 11 only for reading or switching non-time-critical stuff, am I on the safe side?

I found out that the Tone and the Servo library are incompatible.

What error did you get and what version are you using?

The tone function from 0018 works fine with the Arduino servo library.

It's the Tone library, not the tone() function, that caused problems. The error ist: ..."arduino-0018/hardware/arduino/cores/arduino/Tone.cpp:206: multiple definition of `timer1_toggle_count'" At the indicated location there is indeed another tone library, but the location doesn't seem to be in the standard search path. The Tone library that I used was downloaded from the internet. Anyway, with the tone() free function, I don't have these problems.

So, if I use pin3 for the pressure sensor's master clock and pin 11 only for reading or switching non-time-critical stuff, am I on the safe side?

The tone function is based on the code in that tone library. So in linking the library the compiler is telling you that there are conflicting definitions. This has nothing to do with the servo library and the solution, as you have found, is to use the tone function directly and skip the tone library.

Yes, you should be able to use pin 11 for digital input and output that does not involve the timer used by the tone library (timer2)

Have fun!