Binho Host Adapter
raw JSON → 0.1.6 verified Mon Apr 27 auth: no python
Python library for controlling Binho multi-protocol USB host adapters (I2C, SPI, UART, GPIO, etc.). Current version 0.1.6. Release cadence: sporadic.
pip install binho-host-adapter Common errors
error ImportError: cannot import name 'BinhoHostAdapter' from 'binho' ↓
cause Installed version too old (pre-0.1.0) or incomplete install.
fix
Upgrade:
pip install --upgrade binho-host-adapter. error AttributeError: 'BinhoHostAdapter' object has no attribute 'i2c' ↓
cause Adapter mode not set to I2C before accessing i2c sub-object.
fix
Call
adapter.setOperationMode(BINHO_I2C) before using adapter.i2c. error serial.serialutil.SerialException: could not open port /dev/ttyACM0: [Errno 13] Permission denied: '/dev/ttyACM0' ↓
cause User does not have permission to access the USB serial device.
fix
Add user to dialout group:
sudo usermod -a -G dialout $USER && logout. Warnings
gotcha Adapter must be opened before any operation. Forgetting `adapter.open()` causes `AttributeError` or silent failures. ↓
fix Always call `adapter.open()` after instantiation.
gotcha The library uses `pyserial` for serial communication. On Windows, missing or misconfigured serial drivers can cause `SerialException`. Ensure proper FTDI drivers are installed. ↓
fix Install FTDI VCP drivers from ftdichip.com.
deprecated Older examples use `adapter.i2c_write()` method which was replaced by `adapter.i2c.write()`. The old method may be removed. ↓
fix Use the new I2C object methods: `adapter.i2c.write()`, `adapter.i2c.read()`.
Imports
- BinhoHostAdapter wrong
import binho; adapter = binho.BinhoHostAdapter()correctfrom binho import BinhoHostAdapter - BINHO_I2C wrong
from binho import BINHO_I2Ccorrectfrom binho.defines import BINHO_I2C
Quickstart
from binho import BinhoHostAdapter
from binho.defines import BINHO_I2C
adapter = BinhoHostAdapter()
adapter.open()
adapter.setOperationMode(BINHO_I2C)
adapter.i2c.setBitRate(400000)
adapter.i2c.begin()
# Write to device 0x50
adapter.i2c.write(0x50, [0x00, 0x01])
# Read 2 bytes
data = adapter.i2c.read(0x50, 2)
print(data)
adapter.close()