Questions about Magnetometer, HMC5883L

Hi, guys.

I am currently trying to build a program that can read the output from a Honeywell Magnetometer.

I believe I wire up the chip correctly. However, I am getting 255 for all 6 x,y,z (technically 3) outputs.

Can someone explain to me why this happens? Do I need to send message to initialize the chip, instead of just reading from it?

Someone help please, thanks.

Sincerely

P.S. I don't know how to post codes, but if you guys want it, I can definitely try it.

Please read and follow the directions in the "How to use this forum" post.

Here is my unfinished code.

#include <Wire.h>

void Convertion(byte val)
{
  int n;


  
}




 byte Useless1;
 byte Useless2;
 byte Useless3;
 byte X_MSB;
 byte X_LSB;
 byte Z_MSB;
 byte Z_LSB;
 byte Y_MSB;
 byte Y_LSB;

 int X, x1, x2;
 int Y, y1, y2;
 int Z, z1, z2;


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Wire.begin();
  
}

void loop() {
  // put your main code here, to run repeatedly:
  Wire.beginTransmission(0x3d);
  Wire.write(0);
  Wire.endTransmission();

  Wire.requestFrom(0x3d,9);

  Useless1 = Wire.read();
  Useless2 = Wire.read();
  Useless3 = Wire.read();
  X_MSB = Wire.read();
  X_LSB = Wire.read();
  
  
  
  Z_MSB = Wire.read();
  Z_LSB = Wire.read();
  Y_MSB = Wire.read();
  Y_LSB = Wire.read();

  byte gg = B111;

  x1 = (int)X_MSB;
  x2 = (int)X_LSB;
  X = x1 * pow(2,8) + x2;

 
  Serial.println(X);

  Serial.println(X_MSB, DEC);
  Serial.println(X_LSB);
  Serial.println(Z_MSB);
  Serial.println(Z_LSB);
  Serial.println(Y_MSB);
  Serial.println(Y_LSB);
  Serial.print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n");

    
  delay(1000);

}

Google “arduino hmc5883l” for lots of example code.