Reading Value With I2C From Magnetoscope

Hey Guys,.

Im pretty new still to all this. So please excuse me if there is something obvious.

So here is my question, I have been struggling with the included datasheet for an magnetoscope.
For some reason it seam like everything is working but, when i wave a magnet at it, Im not really getting the real response in the serial console.

So here is some information.

#include <Wire.h>

 void setup() {
  Wire.begin();                // join i2c bus (address optional for master)
  Serial.begin(9600);          // start serial communication at 9600bps
 }

 void loop() {
  int reading = 0;
  int Address = 30;
  Wire.beginTransmission(Address);
  Wire.write(byte(0x03));
  Wire.write(byte(0x04));
  Wire.endTransmission();

  Wire.requestFrom(Address, 2);
  delay(10);
  if (2 <= Wire.available()) {
    reading = Wire.read();
    reading = reading << 8;
    reading |= Wire.read();
    Serial.println(int(reading));
  }

  delay(250);
 }

with this response I get in the serial console

-5637
-5637
-5637
-5637
-5637

But then if I remove the following line “Wire.write(byte(0x03));” My output does not change.
Value from device are supposed to be expressed as two’s complement.

So at first I tought it was me that didnt know how to send multple bytes to the device, but after some research i found that i was doing it right ( i think )

Then if I only put “Wire.write(byte(0x03));” I receive “0” as response.
Reading the Datasheet I see that response 0 mean that the command was invalid.

I included the datasheet to this post.
Can someone point me in the right dirrection?
The IC im using is LSM303DLHC and im using it from this “sheild”

Here is the datasheet

the following picture is a picture of the comunication of the bus. If it helps anyway helping me :slight_smile:

Thanks for the picture and the links and information.

When you show code, please show the complete code between code tags. The button for code tags is the upper-left button above the text field, the “< / >” button.
Some say: The problem is in the part that you didn’t show or are not telling us.

In the Arduino IDE via de menu “Sketch”, you can find the Library Manager.
Type ‘lsm303’ (without quotes) in the search field.
There are 4 libraries.

The Pololu version is the most simple, despite a bug.
I think that the Adafruit and Sparkfun version require additional libraries.

After installing one of those libraries, find in the menu the examples. Try for example the Pololu LSM303 “Serial” example.
If that is working, then you are okay. That is the moment to start reading the datasheet.
If it is not working, take a step back and run a I2C scanner.

In the Arduino world, the I2C address is often written as a shifted 7-bits address in hexadecimal notation. For the LSM303 that is 0x1D or 0x1E (I think).

Hey @Koepel thanks for the reply, I updated the OP with the complete code, thanks I didn’t see the button.

I will give this a try right now and report back here. :slight_smile:
Thanks for your time