You are reading a single comment by @luwar and its replies. Click here to read the full conversation.
  • Hi, I'm using an adapted version of i2cdetect for my own i2c experiments. Maybe it is useful for somebody else:

    function scanI2c( i2c, first, last ) {
       if (typeof first === "undefined") {
            first = 0x03;
        }
        if (typeof (last) === "undefined") {
            last = 0x77;
        }
        print( "     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f" );
        for (var upper = 0; upper < 8; ++upper) {
            var line = upper + "0: ";
    
            for (var lower = 0; lower < 16; ++lower) {
                var address = (upper << 4) + lower;
    
                // Skip unwanted addresses
                if ((address < first) || (address > last)) {
                    line += "   ";
                    continue;
                }
    
                try {
                    i2c.readFrom( address, 1 );
                    line += (address + 0x100).toString( 16 ).substr( -2 );
                    line += " ";
                } catch (err) {
                    line += "-- ";
                }
            }
            print( line );
        }
    }
    
    // Usage
    I2C1.setup( {scl: B8, sda: B9} );
    scanI2c( I2C1, 0x03, 0x2f );
    

    Output - first line is not aligned correctly.

         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
    00:          03 04 05 06 07 -- -- -- -- -- -- -- --
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    

    What would be the right place for such a code snippet?

    1. Too special → don't share
    2. Own module: require("i2cdetect").scan()
    3. https://gist.github.com/
    4. ???

    It takes quite a long time to scan all addresses. Is it possible to decrease the timeout somehow?

About

Avatar for luwar @luwar started