Skip to content

Pi i2c HMC5843 magnetometer sequence of write/reads #57

Description

@mdsousa

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...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions