I am working on an autonomous car based on an Arduino Uno with a GPS shield (GPS Shield Retail Kit - RTL-10709 - SparkFun Electronics). For guidance, I am using a compass (LSM303DLM Pololu - LSM303DLM 3D Compass and Accelerometer Carrier with Voltage Regulators) to read the heading. I have followed the wiring and code instructions in the guide (GitHub - pololu/lsm303-arduino: Arduino library for Pololu LSM303 boards). However, when I try to read data from it, all I get is a blank Serial Monitor window.

In trying to fix the problem, I first made sure that the baud rate in Serial.begin matches that in the Serial monitor window, which it did.
I then poked around in the compass example and lsm303.cpp and found that the line that was causing it to fail was:
while (Wire.available() < 6);
For this line in context, see the selection of lsm303.cpp below.
When I comment out this line, it prints, but without sensor data:

Do you know why this line of code is broken? Might it be that the compass is incompatible with the GPS shield (e.g., because the GPS draws too much power)? Do you think I have a bad compass?
Serial.pde (https://github.com/pololu/LSM303/blob/master/LSM303/examples/Serial/Serial.pde)
#include <Wire.h>
#include <LSM303.h>
LSM303 compass;
void setup() {
Serial.begin(9600);
Wire.begin();
compass.init();
compass.enableDefault();
}
void loop() {
compass.read();
Serial.print("A ");
Serial.print("X: ");
Serial.print((int)compass.a.x);
Serial.print(" Y: ");
Serial.print((int)compass.a.y);
Serial.print(" Z: ");
Serial.print((int)compass.a.z);
Serial.print(" M ");
Serial.print("X: ");
Serial.print((int)compass.m.x);
Serial.print(" Y: ");
Serial.print((int)compass.m.y);
Serial.print(" Z: ");
Serial.println((int)compass.m.z);
delay(100);
}
lsm303.cpp (https://github.com/pololu/LSM303/blob/master/LSM303/LSM303.cpp)
....
// Reads the 3 accelerometer channels and stores them in vector a
void LSM303::readAcc(void)
{
Wire.beginTransmission(acc_address);
// assert the MSB of the address to get the accelerometer
// to do slave-transmit subaddress updating.
Wire.write(LSM303_OUT_X_L_A | (1 << 7));
Wire.endTransmission();
Wire.requestFrom(acc_address, (byte)6);
while (Wire.available() < 6); // ***** fails here *****
byte xla = Wire.read();
byte xha = Wire.read();
byte yla = Wire.read();
byte yha = Wire.read();
byte zla = Wire.read();
byte zha = Wire.read();
a.x = (xha << 8 | xla) >> 4;
a.y = (yha << 8 | yla) >> 4;
a.z = (zha << 8 | zla) >> 4;
}
// Reads the 3 magnetometer channels and stores them in vector m
void LSM303::readMag(void)
{
Wire.beginTransmission(MAG_ADDRESS);
Wire.write(LSM303_OUT_X_H_M);
Wire.endTransmission();
Wire.requestFrom(MAG_ADDRESS, 6);
while (Wire.available() < 6); // ***** fails here *****
byte xhm = Wire.read();
byte xlm = Wire.read();
byte yhm, ylm, zhm, zlm;
if (_device == LSM303DLH_DEVICE)
{
// DLH: register address for Y comes before Z
yhm = Wire.read();
ylm = Wire.read();
zhm = Wire.read();
zlm = Wire.read();
}
else
{
// DLM, DLHC: register address for Z comes before Y
zhm = Wire.read();
zlm = Wire.read();
yhm = Wire.read();
ylm = Wire.read();
}
m.x = (xhm << 8 | xlm);
m.y = (yhm << 8 | ylm);
m.z = (zhm << 8 | zlm);
}
// Reads all 6 channels of the LSM303 and stores them in the object variables
void LSM303::read(void)
{
readAcc();
readMag();
}
...
