Below are the X,Y,Z registers for HMC5883L.
while this is the Arduino code for HMC5883L to acquire X,Y,Z reading. If you look at this code, we do not mention the X, Y, Z address specifically.
Wire.beginTransmission(0x1E);
Wire.write(0x02);
Wire.write(0b00000001);
Wire.endTransmission();
delay(10);
Wire.requestFrom(0x1E,6);
if (Wire.available() > 5)
{
x = readValue();
y = readValue();
z = readValue();
}
else
{
Serial.println("No data found");
}
int readValue()
{
int val = Wire.read()<<8;
val |= Wire.read();
return val;
}
We only write Wire.request()
and do not mention X,Y,Z addresses specifically for HMC5883L.
While in the case of ADXL345 we mention every register of X,Y,Z separately to acquire data. Which is exactly my question like why not simply use Wire.requestFrom()
for ADXL345 too. When will we access each X,Y,Z register separately? and when will we do not?
Below is Arduino ADXL345 code for reading X axis data.
Wire.beginTransmission(0x53);
//Ask the particular registers for data
Wire.write(0x32);
Wire.write(0x33);
Wire.endTransmission();
Wire.requestFrom(0x53,2);
if(Wire.available()<=2) {
X0 = Wire.read();
X1 = Wire.read();
X1=X1<<8;
X_out =X0+X1;
Xa=X_out/256.0;
}
Datasheets for both sensors are available on the link.
The code above is not mine. https://drive.google.com/open?id=1AswNTdBz55Rfg3nu4-YsLFj4ANrsCL5I