Post your best Lua script examples here

User avatar
By sancho
#4278 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 ;)
User avatar
By vincent1971
#4691 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.
User avatar
By sancho
#4693
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 ;)