Closed drauschenbach closed 4 weeks ago
My mistake, I was using the pcall incorrectly. This works:
local I2C = require('periphery').I2C
local device = '/dev/i2c-1'
function find_components(device)
io.stderr:write(' 0 1 2 3 4 5 6 7 8 9 a b c d e f\n')
for i = 0, 127, 16 do
io.stderr:write(string.format('%02x: ', i))
for j = 0, 15 do
local addr = i + j
if addr < 0x03 or addr > 0x77 then
io.stderr:write(' ')
else
local i2c = I2C(device, addr)
local message = { 0, flags = I2C.I2C_M_RD }
local ok = pcall(I2C.transfer, i2c, addr, { message })
if ok then
io.stderr:write(string.format('%02x ', addr))
else
io.stderr:write('-- ')
end
end
end
io.stderr:write('\n')
end
end
find_components(device)
I'm trying to figure out how to use the I2C error reporting in a
pcall
.My test script attempts to perform the equivalent of:
System Info
Raspberry Pi 5.