Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pi i2c HMC5843 magnetometer sequence of write/reads #57

Open
mdsousa opened this issue Dec 10, 2014 · 0 comments
Open

Pi i2c HMC5843 magnetometer sequence of write/reads #57

mdsousa opened this issue Dec 10, 2014 · 0 comments

Comments

@mdsousa
Copy link

mdsousa commented Dec 10, 2014

Hi

I'm trying to use quick2wire to communicate between my Pi (rev B) and an HMC5843 magnetometer.
When I run sudo i2cdetect -y 1 it shows the 5843 is assigned i2c address 1e. I've created a script to get some data from the 5843. Everytime I run my script, it returns some bytes showing empty [](as you can see, the example here shows the second and fourth are empty):
[b'\x10']
[b' ']
[b'\x10']
[b' ']
[b'\x10']
[b'\x01']

Sometimes I get an I/O error:
File "/usr/local/lib/python3.2/dist-packages/quick2wire_api-0.0.0.2-py3.2.egg/quick2wire/i2c.py", line 78, in transaction
ioctl(self.fd, I2C_RDWR, ioctl_arg)
IOError: [Errno 5] Input/output error

Sometimes I get both errors (empty brackets along withthe I/O error.

Here's is my code:

from quick2wire.i2c import I2CMaster, writing_bytes,reading
import time
address = 0x1e
with I2CMaster() as bus:
    # Get data from hmc5843 register
    # for continuous measurement mode, send bytes 0x3C 0x02 0x00
    bus.transaction(writing_bytes(address,0x3C))
    bus.transaction(writing_bytes(address,0x02))
    bus.transaction(writing_bytes(address,0x00))
    time.sleep(0.01) # allow to settle
    # want to start reading from address 0x03
    bus.transaction(writing_bytes(address,0x03))
    xLSB = bus.transaction(reading(address,1))
    xMSB = bus.transaction(reading(address,1))
    yLSB = bus.transaction(reading(address,1))
    yMSB = bus.transaction(reading(address,1))
    zMSB = bus.transaction(reading(address,1))
    zLSB = bus.transaction(reading(address,1))
    print(xLSB)
    print(xMSB)
    print(yLSB)
    print(yMSB)
    print(zLSB)
    print(zMSB)

Any idea what I am doing wrong? Thanks for your help...

@mdsousa mdsousa changed the title Pi <-> HMC5843 magnetometer sequence of write/reads Pi i2c HMC5843 magnetometer sequence of write/reads Dec 10, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant