Problem combining Servo library with LCD and Wire Library.

For my project I am using four libraries that I believe conflict with each other.

?#?include? <BitVoicer11.h> //Imports the BitVoicer library to the sketch
#include <Servo.h> //Includes the instance of servo library
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

When running my code. My servos are experiencing a lot of twitching and jittering.
I have no problem with my code when I don’t include my LCD screen communicated via i2c code.

After doing some trouble shooting, the problem doesn’t occur until I specifically include the lcd.print(“String”) command for the lcd screen. Once I include that in my code, but servos become jittery when they should be stationary.

Is this a problem with conflicting timer usage and interrupts? How would I go about fixing this. Any help is appreciated.

After doing some trouble shooting, the problem doesn't occur until I specifically include the lcd.print("String") command for the lcd screen. Once I include that in my code, but servos become jittery when they should be stationary.

LCDs, especially those run via I2C, use lots of time delays. Depending on how those delays are implemented in the library they very well could be having an influence on the operation of the servos.

Don

Does anyone have an idea for a work around for this problem?

The servo library is interrupt driven. The core library functions delayMicroseconds() does not mask interrupts so its use will not affect the servo library interrupts. delay() does not mask interrupts but only briefly while it fetches some counter values, then it unmasks interrupts so I woldnt' think its use would affect the servo library interrupts.

The wire (i2c) library on the other hand does do some polling in its ISR that can delay interrupts. I've never liked the Wire library code. It is pretty ugly, it is split between C and C++ and has five (yes 5) 32 byte buffers.

What may be affecting the Servo library is that the i2c state machine is run by s/w in the i2c ISR and when it issues a STOP to end transmission (which is normal) it then polls in the ISR for the STOP to complete. The STOP will be around 10us and then there is the ISR function overhead on top of that. This will create jitter in the servo ISR processing as it has to potentially wait until the i2C ISR finishes.

The only way to know for sure would be to dig deeper and look at the pulses on a scope or logic analyzer to see what is really happening.

--- bill