Add support for reading and writing to I2C devices from lua #934
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is essentially just a wrapper for the exisiting C functions.
Writing is currently set to require PERM_MEMORY
I have tested this a bit, and it seems to work ok
The syntax is
i2c.read(device_id, register, length)andi2c.write(device_id, register, data_table)Reading returns a table of values, while writing returns a bool True on success or errors on a fail.
(Should this return a false and a string instead of error?)
Test script
Volume slider reads fine, voltage reads back 3.68 (seems ok), I don't see any LED stuff, but when reading back the same register I see the changes. The final test is reading and writing multiple registers, this also seems to work ok.