Hello,
I have a project that reads data from a TPA81 thermopile using I2C and it moves a servo based on the readings. When the Wire commands are in the code the servos don't respond to Servo.write() commands. If I remove the Wire commands then the servos will responds as expected.
I'm using an Uno and compiling on a verion 1.0.1.
Am I missing something or do the Wire.h and Servo.h libraries not work together? The code is below:
#include <Servo.h>
#include <Wire.h>
#define TPA81ADDR (0xd0>>1)
int pixel[9] = {0};
Servo panservo;
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
Serial.print("starting TPA81 test\n");
panservo.attach(9); //attach servo to pin 9
panservo.write(90); //set the inital servo position to 90 degrees
}
void loop()
{
byte b; // used to store data from TPA81
int i; //used for counting in for loops
for (i=1; i<=9; i++)
{
Wire.beginTransmission(TPA81ADDR); //Begin Communication with TPA81
Wire.write(i); //Send reg to TPA81
Wire.endTransmission();
Wire.requestFrom(TPA81ADDR, (int) 1); //Request 1 byte
//while(Wire.available() < 1); //wait for byte to arrive
while(Wire.available())
b = Wire.read(); // receive a byte as character
pixel[i] = b; //create an array of the pixels
}
panservo.write(45);
delay(1000);
panservo.write(135);
delay(1000);
} //end main loop