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?
It takes quite a long time to scan all addresses. Is it possible to decrease the timeout somehow?
@luwar started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hi, I'm using an adapted version of i2cdetect for my own i2c experiments. Maybe it is useful for somebody else:
Output - first line is not aligned correctly.
What would be the right place for such a code snippet?
It takes quite a long time to scan all addresses. Is it possible to decrease the timeout somehow?