Magnetometer gives strange results

I get the results from the magnetometer in thousands and not 0-360 as should be .
Here is example from spark fun:
https://www.sparkfun.com/tutorials/301

Here is my code :

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

 
     void setup()
      
      {
             Serial.begin(9600); 
             while (!Serial) 
             {;} 

              Serial.println("Started");

              
              Wire.begin();  


            
           
           //measurment mode
           writeTo(DEVICE, 0x02, 0x00);

      }


        
            void loop()
            {
        
                     int x, y, z;

                     readFrom(DEVICE, 0x03, TO_READ, buff);    
                
                     x = (((int)buff[1]) << 8) | buff[0];   
                     y = (((int)buff[3])<< 8) | buff[2];
                     z = (((int)buff[5]) << 8) | buff[4];
                     String all=String(x)+" | "+String(y)+"| "+String(z);
                      Serial.println(all);
                      
                     delay(250);

        
            }

to read and write , the usual functions :

             //READ WRITE FUNCTIONS TO AX
            
            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.beginTransmission(device); //start transmission to device (initiate again)
              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
                i++;
              }
             // Wire.endTransmission(); //end transmission
              
            }

I get the results from the magnetometer in thousands and not 0-360 as should be .

You're going to have to explain your reasoning there - what makes you think a magnetometer should return numbers arbitrarily scaled to 0 - 360?

(It would be polite to format your code before posting it, but thanks at least are due for not posting mere snippets this time)

The first thing to try is to run the code as-is from the sparkfun site. If that works, then the problem is in your code. If not, then the problem is in your wiring/soldering/etc.

I didn't expect you to be kind, its always comes with some unexplained anger.

Well i expected 0-360 because :

  1. I did exactly what done in spark fun and they show 0-360 values .(did you open the link? )
  2. It should show the xyz degrees- like what a compass does .

Now, increase your unexplained anger with a new respond, showing me how idiot i am.

  1. I did exactly what done in spark fun and they show 0-360 values .(did you open the link? )

I did open the link. One of the first things that struck me was the number 384 and the number 392.

What don't you understand about the difference between a device that measures magnetic fields, and a device that can be calibrated to point to the planet's magnetic North Pole?

  1. It should show the xyz degrees- like what a compass does .

I should have a 100 metre yacht moored off Monte Carlo, crewed entirely by Miss World contestants. But, like you, I'm just going to have to keep working at understanding more things, instead of going off like a bull in a china shop.

Some light reading

I didn't expect you to be kind, its always comes with some unexplained anger.

Anger? You've got to be kidding!

The people around me are staring wondering why I'm continuously chuckling :D

Ok. Thanks very much.

You're very welcome.

It would be a good idea for you to read through the data sheet for the magnetometer, so that you have some idea what the numbers mean, and how they are related to the local magnetic field. Sparkfun has a link to it.

You can also read about how to use a magnetometer to create a digital compass. The theory is described in this application note from Freescale.

However, for good results (in some cases, even for sensible results) it is necessary to calibrate the magnetometer. The most reliable procedure is described in this blog article: http://sailboatinstruments.blogspot.com/2011/08/improved-magnetometer-calibration.html