vsergeev / lua-periphery

A Lua library for peripheral I/O (GPIO, LED, PWM, SPI, I2C, MMIO, Serial) in Linux.
MIT License
186 stars 39 forks source link

i2c:transfer exception #29

Open guachong133 opened 11 months ago

guachong133 commented 11 months ago

hi its really a wonderful tool but I meet the following error when running i2c test:


local I2C = require('periphery').I2C
-- Open i2c-0 controller
local i2c = I2C("/dev/i2c-0")

-- Read byte at address 0x100 of EEPROM at 0x50
-- local msgs = { {0xac,0x33,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,flags = I2C.I2C_M_RD} }
 local msgs = { {0x01, 0x00}, {0x00, flags = I2C.I2C_M_RD} }
i2c:transfer(0x38, msgs)
print(string.format("0x100: 0x%02x", msgs[2][1]))
i2c:close()

when run ,it returns

$ lua ./api_iic.lua
lua: Error: I2C transfer: Invalid argument [errno 22]

my version is

$ lua -v
Lua 5.3.3  Copyright (C) 1994-2016 Lua.org, PUC-Rio

it will be great thansk if you would help to provide more guide to location the problem thanks~