Here a Simple set of I2C-Tools: I2C-Scanner, I2C-Read, i2C-Write for Tests with I2C-Drives.
Done..
For ESPBASIC < 3.0
[clear]
cls
print "I2C-Tool: "
button "Clear Screen" [clear]
button "Scan for Drives" [scan]
button "Read from Drive" [read]
button "Write to Drive" [write]
button "Programm Exit" [exit]
print ""
wait
'
[write]
wprint "Adresse (dec): "
let addr = 73
textbox addr
wprint " Write Register: "
let reg = 0
textbox reg
wprint "Bytes (48 4f):"
let bytes = "ff"
textbox bytes
button "Run" [wrun]
print ""
wait
'
[wrun]
i2c.begin(addr)
i2c.write(reg)
i2c.write(bytes)
i2c.end
wprint "Write "
wprint bytes
wprint " to "
wprint reg
print ""
wait
'
[read]
wprint "Adresse (dec): "
let addr = 73
textbox addr
wprint " Read Register: "
let reg = 0
textbox reg
wprint " Read Bytes: "
let byte = 1
textbox byte
button "Run" [rrun]
print ""
wait
'
[rrun]
byte = int(byte)
let data = ""
i2c.begin(addr)
i2c.write(reg)
i2c.end()
i2c.requestfrom(addr,byte)
for x = 1 to byte
data = data & "["
data = data & int(x)
data = data & "]"
data = data & i2c.read()
next x
wprint "Read:"
wprint data
print ""
wait
'
[scan]
wprint "Found: "
for addr = 1 to 119
i2c.begin(addr)
i2c.write(0)
i2c.end()
i2c.requestfrom(addr,1)
data = i2c.read()
if data <> "-1" then wprint hex(addr)
if data <> "-1" then wprint "/"
if data <> "-1" then wprint int(addr)
if data <> "-1" then wprint " "
next addr
print ""
wait
'
[exit]
end
For ESPBASIC > 3.0
[Setup]
i2c.setup(5, 4)
'
[clear]
cls
print "I2C-Tool: "
button "Clear Screen", [clear]
button "Scan for Drives", [scan]
button "Read from Drive", [read]
button "Write to Drive", [write]
button "Programm Exit", [exit]
print ""
wait
'
[write]
wprint "Adresse (dec): "
let addr = 73
textbox addr
wprint " Write Register: "
let reg = 0
textbox reg
wprint "Bytes (48 4f):"
let bytes = "ff"
textbox bytes
button "Run", [wrun]
print ""
wait
'
[wrun]
i2c.begin(addr)
i2c.write(reg)
i2c.write(bytes)
i2c.end
wprint "Write "
wprint bytes
wprint " to "
wprint reg
print ""
wait
'
[read]
wprint "Adresse (dec): "
let addr = 72
textbox addr
wprint " Read Register: "
let reg = 0
textbox reg
wprint " Read Bytes: "
let byte = 1
textbox byte
button "Run", [rrun]
print ""
wait
'
[rrun]
byte = int(byte)
let data = ""
i2c.begin(addr)
i2c.write(reg)
i2c.end()
i2c.requestfrom(addr,byte)
for x = 1 to byte
data = data & "["
data = data & int(x)
data = data & "]"
data = data & i2c.read()
next x
wprint "Read:"
wprint data
print ""
wait
'
[scan]
wprint "Found: "
for addr = 1 to 119
i2c.begin(addr)
i2c.write(0)
i2c.end()
i2c.requestfrom(addr,1)
data = i2c.read()
if data <> "-1" then wprint hex(addr)
if data <> "-1" then wprint "/"
if data <> "-1" then wprint int(addr)
if data <> "-1" then wprint " "
next addr
print ""
wait
'
[exit]
end