sancho wrote:This small script scans i2c bus and returns address of any device responding.Code: Select allid=0
sda=8
scl=9
-- initialize i2c, set pin1 as sda, set pin0 as scl
i2c.setup(id,sda,scl,i2c.SLOW)
for i=0,127 do
i2c.start(id)
resCode = i2c.address(id, i, i2c.TRANSMITTER)
i2c.stop(id)
if resCode == true then print("We have a device on address 0x" .. string.format("%02x", i) .. " (" .. i ..")") end
end
Enjoy
when i run the script to detect i2c device, rescode always gets 1, whether or not device is connected.
I am using latest firmware.
and return 1 in below function seems problem?
static int i2c_address( lua_State *L )
{
unsigned id = luaL_checkinteger( L, 1 );
int address = luaL_checkinteger( L, 2 );
int direction = luaL_checkinteger( L, 3 );
MOD_CHECK_ID( i2c, id );
if ( address < 0 || address > 127 )
return luaL_error( L, "wrong arg range" );
lua_pushboolean( L, platform_i2c_send_address( id, (u16)address, direction ) );
return 1;
}