I have an arduino duemilanove being used as an I2C slave device. My code is overall working great - no problems whatsoever with functionality. The problem is when using I2C, the servos will twitch around 1-5 degrees in a random direction every other second. It appears to be random. As soon as I disable Wire.onRequest(slavewrite), the twitching stops entirely. If I disable Wire.onReceive(slaveread), there's still twitching but it is barely noticeable.
I'm positive my code has nothing to do with the twitching, because it will happen even if I fixate the servos at 1500 and eliminate all other unrelated code. Also, if I disconnect the master arduino (on I2C), the twitching stops. I have a feeling this has something to do with timers but I'm not sure what to do about it. I tried the Servo2 library but it doesn't do anything at all.
I thought maybe adding a delay at the end of the loop would help but it doesn't do anything.
I have exactly the same issue with my hexapod. I'm using 2 self made PCB's with ATmega328's (with duemilanove bootloader), connected to each other over I2C. You can see the servos twitch in this video: Bajdupod 9G with RGB leds on Vimeo
Yup that's pretty much the same symptom as mine, except mine is more distinct because it's a pedestal instead of a leg so it shakes around a lot more. Hah cool hexapod though, kinda has a beat to it when it walks.
So I tried softwareservo, which surprisingly acts almost exactly the same. It twitches slightly less often but the twitches are stronger. I am only using 2 servos so I MIGHT be able to get away with the really old servo library (that I think only worked on pins 9 and 10) but I'd prefer to avoid that if possible.
I now tried the old PWMServo library (the one that only uses pins 9 and 10) and surprisingly my problem went away entirely. This library is apparently hardware driven, whereas both other libraries I used were largely software based. The problem is I may end up needing more servos, and if that's the case then I can't keep using this library. PWMServo clearly isn't an option for Bajdi.
Why do you want two 12-channel servo controllers in a master-slave .... the servos also twitch rather than move to the required position.Image processing
I never said I wanted two 12-channel controllers, the master actually isn't the one driving the servos. But even if I did, how does that change the situation? I'm still getting a problem with twitching when they're supposed to be stationary.
I hooked up my oscilloscope to a couple of pins and can clearly see the servo pulse change even when the hexapod is at a standstill and I'm sending the same pulse width. This happens irregularly and only for a fraction of a second. I know there is an issue with the servo library and the pulseln function but the I2C wire library doesn't use this function. Anyone know of other issues with the servo or wire libraries? Both libraries use interrupts maybe there is a conflict there?
As I said before, it is likely a timer problem. I think maybe having the servo library use timer2 might fix this but I don't know how to make it do that.