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

    I2C accelerometer model MMA7455

    Scheduled Pinned Locked Moved Getting Started
    lopyi2csensormma7455i2c bus error
    25 Posts 4 Posters 10.6k Views 4 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.
    • L Offline
      livius @pablocaviglia
      last edited by

      @pablocaviglia
      try this instead

      data = i2c.readfrom_mem(SlaveAddress, 0x00, 1)
      

      think about people first, then computers

      P 1 Reply Last reply Reply Quote 0
      • P Offline
        pablocaviglia @livius
        last edited by

        @livius said in I2C accelerometer model MMA7455:

        data = i2c.readfrom_mem(SlaveAddress, 0x00, 1)

        Well... at least something changed!

        0_1494434698826_upload-1a5aab5e-1c1b-4e15-ac31-447f2d581053

        The 0000000 at the end is the way i found to show the byte in binary string. Btw is this way correct to do that ?

        def byteToBitArrayString(rcv):
        bitArrayStr = "1" if rcv&0 != 0 else "0"
        bitArrayStr += "1" if rcv&1 != 0 else "0"
        bitArrayStr += "1" if rcv&2 != 0 else "0"
        bitArrayStr += "1" if rcv&3 != 0 else "0"
        bitArrayStr += "1" if rcv&4 != 0 else "0"
        bitArrayStr += "1" if rcv&5 != 0 else "0"
        bitArrayStr += "1" if rcv&6 != 0 else "0"
        bitArrayStr += "1" if rcv&7 != 0 else "0"
        return bitArrayStr

        L 1 Reply Last reply Reply Quote 0
        • L Offline
          livius @pablocaviglia
          last edited by

          @pablocaviglia
          for bin formatthing use:

          >>> bin(5)
          '0b101'
          >>> "{0:b}".format(5)
          '101'
          >>>
          

          to see more in memory

          data = i2c.readfrom_mem(SlaveAddress, 0x00, 5) #increase value to 5 bytes from memory
          

          and look what you get

          think about people first, then computers

          P 1 Reply Last reply Reply Quote 1
          • P Offline
            pablocaviglia @livius
            last edited by

            @livius said in I2C accelerometer model MMA7455:

            "{0:b}".format(5)

            Uhhh good, looks much better than my awful function :D jajaja, sorry for breaking your eyes but didnt know that

            1 Reply Last reply Reply Quote 0
            • P Offline
              pablocaviglia
              last edited by

              @jmarcelino @livius @robert-hh
              Hey all, thx a lot for helping me this last days with this driver. This is the code i have until now... it's a shame that i didn't make it, but i think that i could have broken the sensor when i plugged CS to 5v instead of 3V3.
              I think i will buy another one, that will take some weeks until it gets to Uruguay :P

              Anyway, this is the code we've made until now, maybe it's useful for someone else. It's not throwing the ugly i2c bus error anymore, but the device id registry is returning always zero, and that's bad... not sure if the device is broken or what, but comparing this code with the implementation @livius has referenced, and with other implementations i found on google for other languages, it looks like the retrieval of the device id is the first action almost everyone does, so... i dont know.


              from machine import I2C
              from machine import Pin
              from machine import Timer
              import time

              def DelayUs(us):
              Timer.sleep_us(us)

              #i2c slave address
              SLAVE_ADDRESS = 0x1D

              #registers
              REG_POWER_CTL = 0x2D
              REG_BW_RATE = 0x2C

              #connected to SDO and CS of MMA7455
              CS = Pin("P23", mode=Pin.OUT)
              CS.value(1)
              CS.hold()

              DelayUs(1000)

              #main
              i2c = I2C(0, I2C.MASTER, baudrate=100000)
              print(i2c.scan())

              def setPowerCtrl(measure, wake_up=0, sleep=0, auto_sleep=0, link=0):
              power_ctl = wake_up & 0x03
              if sleep:
              power_ctl |= 0x04
              if measure:
              power_ctl |= 0x08
              if auto_sleep:
              power_ctl |= 0x10
              if link:
              power_ctl |= 0x20
              i2c.writeto_mem(SLAVE_ADDRESS, REG_POWER_CTL, bytes([power_ctl]))

              #*****************************
              #******* main logic **********
              #*****************************
              data = i2c.readfrom_mem(SLAVE_ADDRESS, 0x00, 1)
              print("DEVID: " + str(bin(data[0])))

              #set power characteristics
              setPowerCtrl(1, wake_up=0, sleep=0, auto_sleep=0, link=0)


              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
              • 2
              • 2 / 2
              • First post
                Last post

              Pycom on Twitter

              Pycom