Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Problem getting MAG data from Adafruit LSM303

    Scheduled Pinned Locked Moved LoPy
    adafruitlopymagnetometer
    4 Posts 2 Posters 721 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • O Offline
      oldGuyDave
      last edited by

      I have an Adafruit LSM303 board connected to a PyCOM LoPY (ESP32 cpu) and I can communicate to the LSM303HDLC chip over I2C.
      I am getting what appears to be reasonable data from the accelerometer.
      I can read, write, modify and verify i2c changes to the 3 config magnetometer registers. For some reason (maybe I missed something in the LSM303 data sheet) the mag data registers, temperature registers and the status register always read 0x00.
      My config registers currently contain:
      CRA_REG_M = 0x98
      CRB_REG_M = 0x20
      MR_REG_M = 0x00

      Any ideas?

      “Life is trying things to see if they work.” ~Ray Bradbury

      1 Reply Last reply Reply Quote 0
      • rcolisteteR Offline
        rcolistete
        last edited by

        Are you using your own code or a LSM303HDLC MicroPython driver ?

        My "MicroPython Samples". My "MicroPython Firmwares" with many options (double precision, ulab, etc).

        O 1 Reply Last reply Reply Quote 0
        • O Offline
          oldGuyDave
          last edited by

          The code is my own, albeit copied in content and structure from what I believe is a working adafruit project. My modifications include such changes as...
          adafruit project code:
          self._mag.write8(LSM303_REGISTER_MAG_MR_REG_M, 0x00)
          mag_raw = self._mag.readList(LSM303_REGISTER_MAG_OUT_X_H_M, 6)
          vs.
          my code:
          self.i2c.writeto_mem(LSM303_ADDRESS_MAG,LSM303_REGISTER_MAG_CRA_REG_M, 0x98)
          self.i2c.writeto_mem(LSM303_ADDRESS_MAG,LSM303_REGISTER_MAG_CRB_REG_M, 0x20)
          self.i2c.writeto_mem(LSM303_ADDRESS_MAG,LSM303_REGISTER_MAG_MR_REG_M, 0x00)

          MAG=self.i2c.readfrom_mem(LSM303_ADDRESS_MAG,LSM303_REGISTER_MAG_OUT_X_H_M | 0x80, 6)

          Please keep in mind the accelerometer part of the chip seems to be working fine.

          “Life is trying things to see if they work.” ~Ray Bradbury

          1 Reply Last reply Reply Quote 1
          • O Offline
            oldGuyDave @rcolistete
            last edited by

            @rcolistete Maybe I misunderstood your question. The code I was referring to above is my own library that calls the 'built-in' machine.I2C micropython driver supplied in the LoPy firmware binary rev. 1.18.1.r1.
            Example:

            def __init__(self):
                            self.i2c = I2C(0, mode=I2C.MASTER, pins=(sda, scl), baudrate=100000);
                    magEnable = [0x10, 0x20, 0x00]
                    self.i2c.writeto_mem(MAG_DEV_ADDR, MAG_CONFIG_REG_A, bytearray(magEnable));
            
            

            “Life is trying things to see if they work.” ~Ray Bradbury

            1 Reply Last reply Reply Quote 1

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • 1 / 1
            • First post
              Last post

            Pycom on Twitter

            Pycom