From f4916281f240f0fe8e3654b35d9dfb9b9cc596a4 Mon Sep 17 00:00:00 2001 From: Karl-Petter Lindegaard <5760583+kplindegaard@users.noreply.github.com> Date: Sun, 5 Jun 2022 09:06:40 +0200 Subject: [PATCH] Prepare v0.4.2 (#83) --- CHANGELOG.md | 9 ++- README.md | 169 +++++++++++++++++++++++++-------------------- doc/index.rst | 5 +- smbus2/__init__.py | 2 +- 4 files changed, 107 insertions(+), 78 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b175dc..e28fd31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ Notable changes to the smbus2 project are recorded here. ## [Unreleased] No unreleased updates. +## [0.4.2] - 2022-06-05 +### General +- Explicitly export from top level of package [#69](https://github.com/kplindegaard/smbus2/pull/69). +- Transitioned pipelines from Travis-CI to GitHub Actions. + - Python 3.10 added. + ## [0.4.1] - 2021-01-17 ### General - SonarCloud quality checks. @@ -86,7 +92,8 @@ with SMBus(1) as bus: First published version. -[Unreleased]: https://github.com/kplindegaard/smbus2/compare/0.4.1...HEAD +[Unreleased]: https://github.com/kplindegaard/smbus2/compare/0.4.2...HEAD +[0.4.2]: https://github.com/kplindegaard/smbus2/compare/0.4.1...0.4.2 [0.4.1]: https://github.com/kplindegaard/smbus2/compare/0.4.0...0.4.1 [0.4.0]: https://github.com/kplindegaard/smbus2/compare/0.3.0...0.4.0 [0.3.0]: https://github.com/kplindegaard/smbus2/compare/0.2.3...0.3.0 diff --git a/README.md b/README.md index 2e0dbf8..02f497d 100644 --- a/README.md +++ b/README.md @@ -47,66 +47,78 @@ smbus2 installs next to smbus as the package, so it's not really a 100% replacem ## Example 1a: Read a byte - from smbus2 import SMBus +```python +from smbus2 import SMBus + +# Open i2c bus 1 and read one byte from address 80, offset 0 +bus = SMBus(1) +b = bus.read_byte_data(80, 0) +print(b) +bus.close() +``` - # Open i2c bus 1 and read one byte from address 80, offset 0 - bus = SMBus(1) - b = bus.read_byte_data(80, 0) - print(b) - bus.close() - ## Example 1b: Read a byte using 'with' This is the very same example but safer to use since the smbus will be closed automatically when exiting the with block. - from smbus2 import SMBus - - with SMBus(1) as bus: - b = bus.read_byte_data(80, 0) - print(b) +```python +from smbus2 import SMBus + +with SMBus(1) as bus: + b = bus.read_byte_data(80, 0) + print(b) +``` ## Example 1c: Read a byte with PEC enabled Same example with Packet Error Checking enabled. - from smbus2 import SMBus +```python +from smbus2 import SMBus - with SMBus(1) as bus: - bus.pec = 1 # Enable PEC - b = bus.read_byte_data(80, 0) - print(b) +with SMBus(1) as bus: + bus.pec = 1 # Enable PEC + b = bus.read_byte_data(80, 0) + print(b) +``` ## Example 2: Read a block of data You can read up to 32 bytes at once. - from smbus2 import SMBus - - with SMBus(1) as bus: - # Read a block of 16 bytes from address 80, offset 0 - block = bus.read_i2c_block_data(80, 0, 16) - # Returned value is a list of 16 bytes - print(block) +```python +from smbus2 import SMBus + +with SMBus(1) as bus: + # Read a block of 16 bytes from address 80, offset 0 + block = bus.read_i2c_block_data(80, 0, 16) + # Returned value is a list of 16 bytes + print(block) +``` ## Example 3: Write a byte - from smbus2 import SMBus - - with SMBus(1) as bus: - # Write a byte to address 80, offset 0 - data = 45 - bus.write_byte_data(80, 0, data) +```python +from smbus2 import SMBus + +with SMBus(1) as bus: + # Write a byte to address 80, offset 0 + data = 45 + bus.write_byte_data(80, 0, data) +``` ## Example 4: Write a block of data It is possible to write 32 bytes at the time, but I have found that error-prone. Write less and add a delay in between if you run into trouble. - from smbus2 import SMBus - - with SMBus(1) as bus: - # Write a block of 8 bytes to address 80 from offset 0 - data = [1, 2, 3, 4, 5, 6, 7, 8] - bus.write_i2c_block_data(80, 0, data) +```python +from smbus2 import SMBus + +with SMBus(1) as bus: + # Write a block of 8 bytes to address 80 from offset 0 + data = [1, 2, 3, 4, 5, 6, 7, 8] + bus.write_i2c_block_data(80, 0, data) +``` # I2C @@ -120,61 +132,72 @@ Each operation is represented by a *i2c_msg* message object. ## Example 5: Single i2c_rdwr - from smbus2 import SMBus, i2c_msg +```python +from smbus2 import SMBus, i2c_msg + +with SMBus(1) as bus: + # Read 64 bytes from address 80 + msg = i2c_msg.read(80, 64) + bus.i2c_rdwr(msg) + + # Write a single byte to address 80 + msg = i2c_msg.write(80, [65]) + bus.i2c_rdwr(msg) - with SMBus(1) as bus: - # Read 64 bytes from address 80 - msg = i2c_msg.read(80, 64) - bus.i2c_rdwr(msg) - - # Write a single byte to address 80 - msg = i2c_msg.write(80, [65]) - bus.i2c_rdwr(msg) - - # Write some bytes to address 80 - msg = i2c_msg.write(80, [65, 66, 67, 68]) - bus.i2c_rdwr(msg) + # Write some bytes to address 80 + msg = i2c_msg.write(80, [65, 66, 67, 68]) + bus.i2c_rdwr(msg) +``` ## Example 6: Dual i2c_rdwr To perform dual operations just add more i2c_msg instances to the bus call: - from smbus2 import SMBus, i2c_msg - - # Single transaction writing two bytes then read two at address 80 - write = i2c_msg.write(80, [40, 50]) - read = i2c_msg.read(80, 2) - with SMBus(1) as bus: - bus.i2c_rdwr(write, read) +```python +from smbus2 import SMBus, i2c_msg + +# Single transaction writing two bytes then read two at address 80 +write = i2c_msg.write(80, [40, 50]) +read = i2c_msg.read(80, 2) +with SMBus(1) as bus: + bus.i2c_rdwr(write, read) +``` ## Example 7: Access i2c_msg data All data is contained in the i2c_msg instances. Here are some data access alternatives. - # 1: Convert message content to list - msg = i2c_msg.write(60, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) - data = list(msg) # data = [1, 2, 3, ...] - print(len(data)) # => 10 - - # 2: i2c_msg is iterable - for value in msg: - print(value) - - # 3: Through i2c_msg properties - for k in range(msg.len): - print(msg.buf[k]) +```python +# 1: Convert message content to list +msg = i2c_msg.write(60, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) +data = list(msg) # data = [1, 2, 3, ...] +print(len(data)) # => 10 + +# 2: i2c_msg is iterable +for value in msg: + print(value) +# 3: Through i2c_msg properties +for k in range(msg.len): + print(msg.buf[k]) +``` # Installation instructions -From PyPi with `pip`: +From [PyPi](https://pypi.org/) with `pip`: - pip install smbus2 +``` +pip install smbus2 +``` -From conda-forge using `conda`: +From [conda-forge](https://anaconda.org/conda-forge) using `conda`: - conda install -c conda-forge smbus2 +``` +conda install -c conda-forge smbus2 +``` Installation from source code is straight forward: - python setup.py install +``` +python setup.py install +``` diff --git a/doc/index.rst b/doc/index.rst index c9314ae..801a63c 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -1,7 +1,7 @@ smbus2 ====== -.. image:: https://travis-ci.org/kplindegaard/smbus2.svg?branch=master - :target: https://travis-ci.org/kplindegaard/smbus2 +.. image:: https://github.com/kplindegaard/smbus2/actions/workflows/python-build-test.yml/badge.svg?branch=master + :target: https://github.com/kplindegaard/smbus2/actions/workflows/python-build-test.yml .. image:: https://img.shields.io/pypi/pyversions/smbus2.svg :target: https://pypi.python.org/pypi/smbus2 @@ -12,4 +12,3 @@ smbus2 .. automodule:: smbus2 :members: SMBus, i2c_msg :undoc-members: - diff --git a/smbus2/__init__.py b/smbus2/__init__.py index 38a5f03..2db6218 100644 --- a/smbus2/__init__.py +++ b/smbus2/__init__.py @@ -22,5 +22,5 @@ from .smbus2 import SMBus, i2c_msg, I2cFunc # noqa: F401 -__version__ = "0.4.1" +__version__ = "0.4.2" __all__ = ["SMBus", "i2c_msg", "I2cFunc"]