A client and server for I2C control over TCP
Project description
Remote I2C
A SMBus class-compatible TCP proxy allowing you to host or connect to a Remote I2C session with minimal effort.
My use case for writing this module is to allow me to work with I2C on a Raspberry Pi that is on my network, without having to install anything that takes up too much memory or processing power. I serve this thin SMBus server module on the Pi, then I can develop as I please on my computer and interact with the I2C bus as if it was on my own machine.
Important Notes
This module was developed:
- quickly
- without tests
- for the purpose of development
It is NOT:
- a replacement for an actual local I2C connection (particularly for real-time comms)
- guaranteed to be free of bugs
- suitable for production use (unless you're happy to take your chances)
Install
Install with pip:
pip install remote-i2c
Example
On the I2C Host (e.g., Raspberry Pi)
- Ensure that I2C is enabled! (
sudo raspi-config
) - Ensure that the user you're operating under has permission to access the I2C hardware! (e.g., part of the i2c group)
- Run the remote-i2c module directly with the python interpreter from the command line:
python3 -m remote_i2c
- Alternatively, run the module from a python script:
#!/usr/bin/env python3 # Import the RemoteI2CServer class from remote_i2c import RemoteI2CServer # Create the server (see docstring for additional args) server = RemoteI2CServer() # Start the server (blocks forever!) server.serve()
On the I2C Client (e.g., Desktop/Laptop)
#!/usr/bin/env python3
# Import the RemoteI2CClient class
from remote_i2c import RemoteI2CClient
# Connect to the I2C Host (see docstring for additional args)
remote_i2c_host = '192.168.1.2'
bus = RemoteI2CClient(remote_i2c_host)
bus.connect()
# Perform I2C operations as you normally would with SMBus2
addr = 0x67
reg = 0xf2
value = bus.read_byte_data(addr, reg)
bus.write_byte_data(addr, reg, value + 1 % 0xff)
# Disconnect when you're done, if you feel the need
bus.disconnect()
Author
Daniel 'Vector' Kerr (vector@vector.id.au | https://vector.id.au)
License
Copyright © 2019 Daniel 'Vector' Kerr (vector@vector.id.au)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file remote-i2c-0.0.9.tar.gz
.
File metadata
- Download URL: remote-i2c-0.0.9.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6290311217866c29526120cc5477e062f8ee6ba35aa5e83e6df4edb00a9bf12 |
|
MD5 | f3760254aa8d999869b3521e37322dfe |
|
BLAKE2b-256 | 9e9ac20e85dfb55e6034362cbe03075c1f29001598041c40e9111c5a3073b046 |