A useful i2c package for Pi
Project description
A useful i2c Python3 package for Pi
It is a simple I2C interface based on smbus2.
1. Installation
Via pip
pip3 install pyi2c
2. How to use I2C? (Example)
2.1 Write
from pyi2c import I2C
# Create i2c
BUS_N = 0 # 0 or 1 or 2. Change this to yours
i2c = I2C(BUS_N)
# Write
ADDR = 0x38 # Change this to yours
WRITE1 = 0x00 # Change this to yours
i2c.write(ADDR, WRITE)
# or write multi bytes, up to 64 bytes
WRITE0 = 0x01 # Change this to yours
i2c.write(ADDR, [WRITE0, WRITE1])
2.2 Read
from pyi2c import I2C
# Create i2c
BUS_N = 0 # 0 or 1 or 2. Change this to yours
i2c = I2C(BUS_N)
# Read
read_data = i2c.read(ADDR)
# or set length of reading bytes
bytes_n = 2
read_data = i2c.read(ADDR, byte_n)
2.3 Write and read
from pyi2c import I2C
# Create i2c
BUS_N = 0 # 0 or 1 or 2. Change this to yours
i2c = I2C(BUS_N)
# First write and read rapidly
read_data = i2c.writeread(ADDR, WRITE0)
# These also work
read_data = i2c.writeread(ADDR, [WRITE0, WRITE1])
read_data = i2c.writeread(ADDR, [WRITE0, WRITE1], bytes_n)
3. How to use useful functions? (Example)
3.1 getBit
from pyi2c import getBit
byte = 0x5a
print( bin(byte) )
# Will return '0b1011010'
print( getBit(byte, 0) )
# Will return 0 from #0 bit
print( getBit(byte, 1) )
# Will return 1 from #1 bit
if getBit(byte, 4) == 1:
print('hoge')
# Will return 'hoge'
4. API
4.1 I2C
writereadwriteread
4.2 Useful functions
getBit(byte, bit_n)
For developers
Build
python3 -m build
Upload
python3 -m twine upload dist/*
Reference
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyi2c-0.0.2.tar.gz
(3.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
pyi2c-0.0.2-py3-none-any.whl
(3.7 kB
view details)
File details
Details for the file pyi2c-0.0.2.tar.gz.
File metadata
- Download URL: pyi2c-0.0.2.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79c63b3a780989ecb78efe3640bf6d74f5f347b9daed4496e29ec738b2ccfee9
|
|
| MD5 |
2de5e0772c5718ebea27a9f92bd826b7
|
|
| BLAKE2b-256 |
fe004f6d3fc4276df33ff02f226ca4c24ee0577fa8a874089328ef277b958ef0
|
File details
Details for the file pyi2c-0.0.2-py3-none-any.whl.
File metadata
- Download URL: pyi2c-0.0.2-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
999ea8a0567ce4807c369d813417ef006dd61985d49512feab896d35e758b0a4
|
|
| MD5 |
ff5ebd3375002bbe7302fddb41e7370c
|
|
| BLAKE2b-256 |
c3b367350fbfdb687f5bc695da29396d1d35ce36da4e32d4a3b1b6fffa3c1006
|