Lost with this compass?

We have a costume pcb with HMC5883, the circuit is the same as this one :

All the capacitors in place, and if I check with an IC2 connection test program from here, He find the device at 0x48 (data sheet says 0x1E).

When I am taking measurements, I always get the same values no matter what,

  3769  4004  3533
  3769  4004  3533
  3769  4004  3533
  3769  4004  3533
  3769  4004  3533
  3769  4004  3533

and angle is 49.5 constant .

This is the program :

    #include <Wire.h>  

    #define DEVICE (0x1E)  //1E
     #define TO_READ (6) 
     byte buff[TO_READ] ; 

      const float xOffset = 0;//103.0;      // Offset required to adjust x coordinate to zero origin
      const float yOffset =0;//  -165.0;       // Offset required to adjust y coordinate to zero origin
      const float declination = 70.1;    // Enter magnetic declination mrads here (local to your geo area) 

     void setup()
             while (!Serial) 



           //measurment mode
            writeTo(DEVICE, 0x02, 0x00); //set measuring mode
            writeTo(DEVICE, 0x01, 0x20); // set scaling to +1.3Ga


            void loop()
                      int x=0, y=0, z=0,xs=0,ys=0,zs=0;
                      uint8_t x_msb;   // X-axis most significant byte
                       uint8_t x_lsb;   // X-axis least significant byte
                       uint8_t y_msb;   // Y-axis most significant byte
                       uint8_t y_lsb;   // Y-axis least significant byte
                       uint8_t z_msb;   // Z-axis most significant byte
                       uint8_t z_lsb;   // Z-axis least significant byte
                       // Get the value from the sensor
                            readFrom(DEVICE, 0x3,(uint8_t)1, &x_msb)  ;
                            readFrom(DEVICE, 0x4,(uint8_t)1, &x_lsb)  ;
                            readFrom(DEVICE, 0x5,(uint8_t)1, &z_msb)  ;
                            readFrom(DEVICE, 0x6,(uint8_t)1, &z_lsb)  ;
                            readFrom(DEVICE, 0x7,(uint8_t)1, &y_msb)  ;
                            readFrom(DEVICE, 0x8,(uint8_t)1, &y_lsb) ;
                        x = x_msb << 8 | x_lsb;
                        y = y_msb << 8 | y_lsb;
                        z = z_msb << 8 | z_lsb;

                        float gScale = .92;  // Scale factor for +1.3Ga setting
                        float adjx = x - xOffset;
                        float adjy = y - yOffset;
                        xs = adjx * gScale; 
                        ys = adjy * gScale;
                        zs = z * gScale;    

                        Serial.print("  ");
                        Serial.print("  ");
                        Serial.print("  ");

                        float heading = atan2(ys, xs);
                        heading += declination / 1000; // Declination for geo area
                           if (heading < 0);
                             heading += 2*PI;
                           if (heading > 2*PI)
                             heading -= 2*PI;
                          float angle = heading * 180/M_PI;
                                  //Serial.print("   A: ");


            void writeTo(int device, byte address, byte val)
               Wire.beginTransmission(device); //start transmission to device 
               Wire.write(address);        // send register address
               Wire.write(val);        // send value to write
               Wire.endTransmission(); //end transmission
            void readFrom(int device, byte address, int num, byte buff[]) 
              Wire.beginTransmission(device); //start transmission to device 
              Wire.write(address);        //sends address to read from
              Wire.endTransmission(); //end transmission
               Wire.requestFrom(device, num);    // request 6 bytes from device
              int i = 0;
              while(Wire.available())    //device may send less than requested (abnormal)
                buff[i] = Wire.read(); // receive a byte

How can we debug this? How can i know that i do get data from the chip and this is not just garbage? what could go wrong ?

Thanks .

+1 karma for title.

Other than that, are these values related to any error codes for the device?

Datasheet recommend 6 ms delay after configuration register setup and 67 ms between the reads of values, should be simple to start trying this.

Ciao, Ale.

He find the device at 0x48 (data sheet says 0x1E).

That is a problem.

Try the Adafruit library & sample program.

Be sure to calibrate the compass. It is nearly useless until you do so.

I configured my UNO with a HMC5883L and loaded your sketch, seems to work just fine. I move the compass around and get a wide range of numbers on the output.
Does your HMC5883 provide pull up resistors? Mine has 10K on SCL and SDA tied to its onboard 3.3 Volts.