🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    "Unit Scales" example in github doesn't work

    SOFTWARE
    2
    4
    3.4k
    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.
    • P
      pop-k
      last edited by

      I use m5stack grey with "Unit Scale" link. after using arduino sketch compile and upload code , it shows "scales not connect".
      but i use easyloader to burn firmware it works fine.
      so what is the difference between them.
      and i use i2c to scan it shows 0x26

      1 Reply Last reply Reply Quote 0
      • felmueF
        felmue
        last edited by felmue

        Hello @pop-k

        it looks like newer ESP32 Arduino libraries added an overloaded begin() function to also allow to setup an I2C slave. Whether the begin() for an I2C master or slave is called is determined by the linker by looking at the parameter types.

        I2C master: parameter types are int, int, uint32_t

        bool TwoWire::begin(int sda = -1, int scl = -1, uint32_t frequency = 0U)
        

        I2C slave: parameter types are uint8_t, int, int, uint32_t

        bool TwoWire::begin(uint8_t slaveAddr, int sda = -1, int scl = -1, uint32_t frequency = 0U)
        

        Now some unit libraries (including the one for unit scales) are calling the begin() like this:

        _wire->begin(_sda, _scl, 400000UL);
        

        where _sda and _scl are defined as uint8_t.

        So the first parameter _sda is an uint8_t and the first parameter of the begin() for an I2C slave also is an uint8_t (whereas the first parameter for an I2C master is an int) therefore the linker calls the begin() of the I2C slave. But we need it to call the begin() of an I2C master.

        In short, try to modify below line in file M5Unit-Scales/src/M5_Scales.cpp from:

        _wire->begin(_sda, _scl, 400000UL);
        

        to

        _wire->begin((int)_sda, (int)_scl, 400000UL);
        

        to force the linker to call the I2C master begin().

        Thanks
        Felix

        GPIO translation table M5Stack / M5Core2
        Information about various M5Stack products.
        Code examples

        1 Reply Last reply Reply Quote 2
        • P
          pop-k
          last edited by

          Thank you very much . work like a charm!!

          1 Reply Last reply Reply Quote 0
          • felmueF
            felmue
            last edited by felmue

            Hello @pop-k

            I am glad to hear that. Thank you for reporting back.

            @m5stack : please check this pull-request. Thank you.

            Thanks
            Felix

            GPIO translation table M5Stack / M5Core2
            Information about various M5Stack products.
            Code examples

            1 Reply Last reply Reply Quote 1
            • First post
              Last post