Problem with ServoTimer2 and Wire libraries

If the solution to my problem is glaringly obvious, I apologize in advance. I’m new to this stuff.
I have a Mega with a Waveshield, modified (butchered) as shown here:
In my main loop I play a few sounds and call a method which at present simply rotates a servo (on pin 6) from 0 to 180 and back again. To control the servo I have had to use the ServoTimer2 library because the Waveshield uses Timer1, which is also used by the standard Arduino Servo library.
Anyway, the Waveshield and ServoTimer2 play nicely together.
The problem arises when I add into the loop a call to the following method, which acquires data from an Omron D6T-8L thermal sensor connected to pins 20 (SDA) and 21 (SCL):

void readTemperatures(){
    int  i = 0 ;

      int writeStatus = Wire.endTransmission(); 
      if(writeStatus != 0){
        //Serial.println("Writing failed");
    Wire.requestFrom(0x0A, 18); 
    for  (i  =  0 ;  i  <  35 ;  i++)  {
      rbuf [i]  =;
     T_PTAT  =  (rbuf[0]+(rbuf[1] << 8)); 
     for  (i  =  0 ;  i  <  8 ;  i++)  {
        TDATA [i] = (rbuf [(i * 2 + 2)] + ( rbuf [(i * 2 + 3)] << 8 ));//offset by 2 because T_PTAT occupies the first 2 bytes


(rbuf, T_PTAT and TDATA are defined earlier)
That just stops the servo dead. To summarize: Waveshield + ServoTimer2 = OK. Waveshield + reading the temperature sensor = OK. All three together = servo stops when readTemperature is called.

Any ideas?

No idea if its significant, but you request 18 bytes then read 35 bytes from the TWI.

You're right, MarkT! I was originally reading from a 4x4 sensor and am now using a 8 x 1. I'll update the code and see if it helps. Thanks.

That seems to have solved the problem. Thank you. Incredible that I’ve been writing code for years (though not C++) and can still make such a daft mistake.
Thank you for your time and effort. I hope that one day I’ll have learnt enough also to help the generous souls in this arduino community.

Hi wittgenstein,

Which Arduino board are you using? I am trying to get my Arduino Due to take in the data from the sensor but to no avail.
Is it possible to post the code that you use. Only the temperature reading would be fine.

Hello, ECUni

I posted the relevant code in another thread a while ago. You can find it in reply #8 here: Tracking a person's motion with a thermal sensor? - #9 by system - Sensors - Arduino Forum

I was using a Mega. I initially used a UNO and at first had problems getting any output at all on the Mega because I had overlooked the fact that the I2C pins were in a different location.

There's a thread here which refers specifically to I2C on the Due: How to use second I2C? - Arduino Due - Arduino Forum

I hope that helps.