2

I using a HMC5883L with the i2c library. I am using this code to get the direction it is facing

from i2clibraries import i2c_hmc5883l

hmc5883l = i2c_hmc5883l.i2c_hmc5883l(1)
hmc5883l.setContinuousMode()
hmc5883l.setDeclination(0,6)
print(hmc5883l)

But this prints all of the axises and I just want the x-axis but I do not know how just get the x-axis alone so I can compare x values. If anyone knows how to do this your help would be greatly appreciated.

1
  • This isn't a Pi specific question. Assign hmc58831 to a variable and use standard Python functions to extract the information you want. Search for Python tutorials.
    – joan
    Commented Sep 17, 2016 at 20:00

1 Answer 1

2

you can find sample code for HMC5883 over here.

here you will find c,java,python and micro python code. just to get X axis look at this section.

xMag = data[0] * 256 + data[1] if xMag > 32767 : xMag -= 65536

zMag = data[2] * 256 + data[3] if zMag > 32767 : zMag -= 65536

yMag = data[4] * 256 + data[5] if yMag > 32767 : yMag -= 65536

So all you need to do is, read the first 16bit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.