"Unit Scales" example in github doesn't work

  • 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

  • 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);


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

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


  • Thank you very much . work like a charm!!

  • Hello @pop-k

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

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