Skip to main content

This Python module allows SMBus access through the I2C /dev interface on Linux hosts. The host kernel must have I2C support, I2C device interface support, and a bus adapter driver.

Project description

This Python module allows SMBus access through the I2C /dev interface on Linux hosts. The host kernel must have I2C support, I2C device interface support, and a bus adapter driver.

This module is a cffi-based python reimplementation of the python-smbus C-extension (http://www.lm-sensors.org/browser/i2c-tools/trunk/py-smbus/) and works on PyPy and CPython 2.7.

Notes

Currently cffi, the module used for the bindings to the smbus library, is rather slow loading a module. It might take a moment to load smbus, in particular on slow devices like a Raspeberry Pi. This behaviour will change in future releases of cffi.

The SMBus methods read_block_data and block_process_call are not fully tested, and might not work correctly, see note below.

Note of caution for Raspberry Pi users: when calling read_block_data and block_process_call the underlying i2c/smbus library/driver causes a kernel panic on the Raspberry Pi. Testing these features on other hardware would be a great way to contribute.

Example

Assuming you have a device connected at address 4 on the bus

>>> from smbus import SMBus

>>> bus = SMBus(4)

>>> bus.write_quick()

>>> some_reg = 123

>>> bus.write_i2c_block_data(4, some_reg, [1, 4, 7])

Installation

There are several methods to install the package. Note: unfortunately when installing using pip or setup.py on CPython you first need to make sure that the cffi package is installed.

1. pip install from PyPi

pip install smbus-cffi

2. pip install from git

pip install git+https://github.com/bivab/smbus-cffi.git

3. Clone the repository and run setup.py

git clone https://github.com/bivab/smbus-cffi.git
python setup.py install

Bug Reporting

To submit a bugreport use the GitHub bugtracker for the project:

https://github.com/bivab/smbus-cffi/issues

Development

You can get the latest version from the repository hosted at GitHub https://github.com/bivab/smbus-cffi The file requirements.txt contains the list of dependencies needed to work with smbus-cffi.

The project uses py.test for testing and tox to test on pypy and python 2.7.

The file test/test_smbus_integration.py contains a set of integration tests for the smbus wrapper. To run the integrations tests you need an Arduino board flashed with the sketch provided in test/test_sketch. The serial port and the i2c pins of the Arduino board need to be connected to the machine running the tests. The sketch implements the counterpart of the smbus protocol that reads and writes data for each test using smbus and the serial port.

Dependencies

To install smbus-cffi you will need:

  • A C compiler

  • i2c development headers

  • PyPy or CPython development headers

Authors

  • David Schneider

Author of the original smbus C extension:

  • Mark M. Hoffman

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

smbus-cffi-0.1.tar.gz (20.6 kB view details)

Uploaded Source

File details

Details for the file smbus-cffi-0.1.tar.gz.

File metadata

  • Download URL: smbus-cffi-0.1.tar.gz
  • Upload date:
  • Size: 20.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for smbus-cffi-0.1.tar.gz
Algorithm Hash digest
SHA256 0368388980e86be75ae0256c40bae571fa0d955396d17e92ac31b65ee8842fea
MD5 28381467c2cbd8c2e978a4acb96512d5
BLAKE2b-256 13a1af1afaf90bca1f7e489ba05383c4839790fda459002caf3b9b4835ea2941

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page