-->
Page 1 of 2

i2c device discovery

PostPosted: Mon Dec 08, 2014 8:03 am
by sancho
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 ;)

Re: i2c device discovery

PostPosted: Fri Dec 12, 2014 1:15 pm
by vincent1971
If I am running this script I discover something strange. If I connect a ds1307 I see that the esp8266 a ds1307 recognize it. If I connect an other ds1307 it doesn't. I look in the datasheet and shaw that it is a 5v device. But thanks for this script a ds3231 works very good. Also a tmp101.

Re: i2c device discovery

PostPosted: Fri Dec 12, 2014 2:07 pm
by sancho
vincent1971 wrote:If I am running this script I discover something strange. If I connect a ds1307 I see that the esp8266 a ds1307 recognize it. If I connect an other ds1307 it doesn't. I look in the datasheet and shaw that it is a 5v device. But thanks for this script a ds3231 works very good. Also a tmp101.

Don't mean no offense, but are you sure you changed the address of the second DS1307? If not... :)
Not like that did not happen to me - that's exactly why I used similar script long time ago with Arduino ;)

Re: i2c device discovery

PostPosted: Sat Dec 13, 2014 4:49 pm
by vincent1971
I connected just one ds1307. One of them is always recognized. The others not..very strand behavior