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

    MCP3428 I2C Data Errors

    Scheduled Pinned Locked Moved MicroPython
    4 Posts 3 Posters 294 Views 3 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.
    • J Offline
      jmpratt
      last edited by

      I'm using an MCP3428 for ADC on the I2C bus with an address of 104. I'm able to get data from the sensor, but sometimes the format seems to be corrupted. After sending
      i2c.readfrom(104, 3)
      the device should return 3 bytes: MSB, LSB, and configuration byte. Sometimes it returns three bytes correctly:
      b'\x00\x00\x10'
      If I change the configuration byte from 0x10 to 0xD0, the i2c.readfrom(104, 3) command yeilds:
      b'\x00\x00P'

      How is it possible to have "P" appear in a hexadecimal number? It'll send other impossible hexadecimal values, too. Are the binary bytes getting translated incorrectly?

      robert-hhR 1 Reply Last reply Reply Quote 0
      • E Offline
        Eric73
        last edited by

        It's not an I2C trouble, but it a display misunderstand.
        It's because 'P' as ascii code 0x50 and the print methodes show ascii when it can.
        To have always an hexadecimal display use ubinascii.hexlify(i2c.readfrom(104, 3))

        1 Reply Last reply Reply Quote 0
        • robert-hhR Offline
          robert-hh @jmpratt
          last edited by

          @jmpratt Nothing is wrong. What you see is just the way print() display byte strings. If a byte is printable, it is shown as ASCII character. So 'P' is just 0x50. If you want to see all bytes as hex, you have to convert it, e.g. with ubinascii.hexlify(). That is standard Python behavior.

          1 Reply Last reply Reply Quote 0
          • J Offline
            jmpratt
            last edited by

            Great! Thanks for the explanation. It all makes sense now!

            1 Reply Last reply Reply Quote 0

            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