Wire and Servo libraries together

Hi Folks,

Recently I got Duemilanove and experimenting with servo and I2C SRF08 sonar. I just want to rotate the servo to certain angle depending on the distance measured by sonar. So there are basically two steps: a) read value from sonar and b) map the value and rotate the servo.

Each separate step (as a different sketches) works just fine. Rotating servo with Servo library works as expected. I am also able to read distance from sonar. However, if I am trying to merge two sketches (essentially merging sweep and srf08 examples) I stop getting response from sonar and sketch hangs up waiting for the data from i2c bus.

I've got a feeling that there is some kind of conflict between these libraries which prevents them from being used together. Another reason I can imagine is the interference between i2c and servo because they are using common +5v power source.

I would appreciate if someone can comment on this issue and share experience (if any) on how to marry Servo and Wire libraries.

Thank you,
Andrey.

It could be a power problem. Try running your sketch with the servo disconnected – if it no longer hangs then the cause is likely to be insufficient power (try powering the servo using an external supply) or decoupling (a search of Arduino and decoupling should turn up advice on that)

I don't think it is a conflict in the library. I have a sonar sensor mounted on a servo and am using I2C to pass the distance data to a second Arduino.

Everything is working.

Thank you guys for the comments and suggestions!