Skip to content

Commit f37ba1d

Browse files
Merge pull request #23 from sparkfun/feature/packaging
Feature/packaging
2 parents 4513cf8 + 3c6168d commit f37ba1d

File tree

9 files changed

+124
-170
lines changed

9 files changed

+124
-170
lines changed

README.md

Lines changed: 51 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
1-
Qwiic_I2C_Py
2-
==============
1+
![Qwiic I2C Python Package](docs/images/i2c-gh-banner-py.png "qwiic IC Python Package" )
32

4-
<p align="center">
5-
<img src="https://cdn.sparkfun.com/assets/custom_pages/2/7/2/qwiic-logo-registered.jpg" width=200>
6-
<img src="https://www.python.org/static/community_logos/python-logo-master-v3-TM.png" width=240>
7-
</p>
8-
<p align="center">
9-
<a href="https://pypi.org/project/sparkfun-qwiic-i2c/" alt="Package">
10-
<img src="https://img.shields.io/pypi/pyversions/sparkfun_qwiic_i2c.svg" /></a>
11-
<a href="https://github.com/sparkfun/Qwiic_I2C_Py/issues" alt="Issues">
12-
<img src="https://img.shields.io/github/issues/sparkfun/Qwiic_I2C_Py.svg" /></a>
13-
<a href="https://qwiic-i2c-py.readthedocs.io/en/latest/index.html" alt="Documentation">
14-
<img src="https://readthedocs.org/projects/qwiic-i2c-py/badge/?version=latest&style=flat" /></a>
15-
<a href="https://github.com/sparkfun/Qwiic_Proximity_Py/blob/master/LICENSE" alt="License">
16-
<img src="https://img.shields.io/badge/license-MIT-blue.svg" /></a>
17-
<a href="https://twitter.com/intent/follow?screen_name=sparkfun">
18-
<img src="https://img.shields.io/twitter/follow/sparkfun.svg?style=social&logo=twitter"
19-
alt="follow on Twitter"></a>
20-
21-
</p>
3+
Sparkfun Qwiic I2C - Python Package
4+
==============
225

23-
<img src="https://cdn.sparkfun.com/assets/custom_pages/2/7/2/qwiic-products-hooked-up.jpg" align="right" width=340>
6+
![PyPi Version](https://img.shields.io/pypi/v/sparkfun_qwiic_i2c)
7+
![GitHub issues](https://img.shields.io/github/issues/sparkfun/qwiic_i2c_py)
8+
![License](https://img.shields.io/github/license/sparkfun/qwiic_i2c_py)
9+
![X](https://img.shields.io/twitter/follow/sparkfun)
2410

2511
Python package to support multi platform I2C bus integrations for the SparkFun [qwiic ecosystem](https://www.sparkfun.com/qwiic)
2612

@@ -35,12 +21,16 @@ New to qwiic? Take a look at the entire [SparkFun qwiic ecosystem](https://www.s
3521
* [Documentation](#documentation)
3622
* [Installation](#installation)
3723

38-
Supported Platforms
39-
--------------------
40-
The qwiic I2C Python package current supports the following platforms:
41-
* [Raspberry Pi](https://www.sparkfun.com/search/results?term=raspberry+pi) (Single Board Computers)
42-
* [NVidia Jetson Nano](https://www.sparkfun.com/products/15297)
43-
* [Google Coral Development Board](https://www.sparkfun.com/products/15318)
24+
### Supported Platforms
25+
See the [MicroPython Downloads Page](https://micropython.org/download/?vendor=Sparkfun) for more boards compatible with MicroPython.
26+
| Python | Platform | Boards |
27+
|--|--|--|
28+
| Python | Linux | [Raspberry Pi](https://www.sparkfun.com/raspberry-pi-5-8gb.html) , [NVIDIA Jetson Orin Nano](https://www.sparkfun.com/nvidia-jetson-orin-nano-developer-kit.html) via the [SparkFun Qwiic SHIM](https://www.sparkfun.com/sparkfun-qwiic-shim-for-raspberry-pi.html) |
29+
| MicroPython | Raspberry Pi - RP2, ESP32 | [SparkFun RP2040 Thing+](https://www.sparkfun.com/sparkfun-thing-plus-rp2040.html), [SparkFun RP2350 Thing+](https://www.sparkfun.com/sparkfun-thing-plus-rp2350.html), [SparkFun ESP32 Thing+](https://www.sparkfun.com/sparkfun-thing-plus-esp32-wroom-usb-c.html)
30+
|CircuitPython | Raspberry Pi - RP2, ESP32 | [SparkFun RP2040 Thing+](https://www.sparkfun.com/sparkfun-thing-plus-rp2040.html), [SparkFun RP2350 Thing+](https://www.sparkfun.com/sparkfun-thing-plus-rp2350.html), [SparkFun ESP32 Thing+](https://www.sparkfun.com/sparkfun-thing-plus-esp32-wroom-usb-c.html)
31+
32+
> [!NOTE]
33+
> The listed supported platforms and boards are the primary platform targets tested. It is fully expected that this package will work across a wide variety of Python enabled systems.
4434
4535
Dependencies
4636
---------------
@@ -51,42 +41,57 @@ Documentation
5141
-------------
5242
The SparkFun qwiic I2C module documentation is hosted at [ReadTheDocs](https://qwiic-i2c-py.readthedocs.io/en/latest/index.html)
5343

54-
Installation
55-
---------------
44+
# Installation
45+
46+
The first step to using this package is installing it on your system. The install method depends on the python platform. The following sections outline installation on Python, MicroPython and CircuitPython.
5647

57-
### PyPi Installation
58-
This repository is hosted on PyPi as the [sparkfun-qwiic-i2c](https://pypi.org/project/sparkfun-qwiic-i2c/) package. On systems that support PyPi installation via pip, this library is installed using the following commands
48+
### Python
5949

60-
For all users (note: the user must have sudo privileges):
50+
#### PyPi Installation
51+
52+
The package is primarily installed using the `pip3` command, downloading the package from the Python Index - "PyPi".
53+
54+
Note - the below instructions outline installation on a Linux-based (Raspberry Pi) system.
55+
56+
First, setup a virtual environment from a specific directory using venv:
6157
```sh
62-
sudo pip install sparkfun-qwiic-i2c
58+
python3 -m venv ~/sparkfun_venv
6359
```
64-
For the current user:
60+
You can pass any path instead of ~/sparkfun_venv, just make sure you use the same one for all future steps. For more information on venv [click here](https://docs.python.org/3/library/venv.html).
6561

62+
Next, install the qwiic package with:
63+
```sh
64+
~/sparkfun_venv/bin/pip3 install sparkfun-qwiic-i2c
65+
```
66+
Now you should be able to run any example or custom python scripts that have `import qwiic_i2c` by running e.g.:
6667
```sh
67-
pip install sparkfun-qwiic-i2c
68+
~/sparkfun_venv/bin/python3 example_script.py
6869
```
69-
## Local Installation
70-
To install, make sure the setuptools package is installed on the system.
7170

72-
Direct installation at the command line:
71+
### MicroPython Installation
72+
If not already installed, follow the [instructions here](https://docs.micropython.org/en/latest/reference/mpremote.html) to install mpremote on your computer.
73+
74+
Connect a device with MicroPython installed to your computer and then install the package directly to your device with mpremote mip.
7375
```sh
74-
python setup.py install
76+
mpremote mip install github:sparkfun/qwiic_i2c_py
7577
```
7678

77-
To build a package for use with pip:
79+
### CircuitPython Installation
80+
If not already installed, follow the [instructions here](https://docs.circuitpython.org/projects/circup/en/latest/#installation) to install CircUp on your computer.
81+
82+
Ensure that you have the latest version of the SparkFun Qwiic CircuitPython bundle.
7883
```sh
79-
python setup.py sdist
80-
```
81-
A package file is built and placed in a subdirectory called dist. This package file can be installed using pip.
84+
circup bundle-add sparkfun/qwiic_py
85+
```
86+
87+
Finally, connect a device with CircuitPython installed to your computer and then install the package directly to your device with circup.
8288
```sh
83-
cd dist
84-
pip install sparkfun_qwiic_i2c-<version>.tar.gz
89+
circup install --py qwiic_i2c
8590
```
8691

8792
Examples
8893
---------------
89-
This package is used extensively by the python modules for the SparkFun qwiic ecosystem. References to the modules can be found in the [qwiic python package](https://github.com/sparkfun/Qwiic_Py/tree/main/qwiic/drivers)
94+
This package is used extensively by the python modules for the SparkFun qwiic ecosystem. References to the modules can be found in the [sparkfun-python github topic](https://github.com/topics/sparkfun-python) or in the [drivers directories of Qwiic Py](https://github.com/sparkfun/Qwiic_Py/tree/main/qwiic/drivers).
9095

9196
General package use examples:
9297

docs/images/i2c-gh-banner-py.png

544 KB
Loading

pyproject.toml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
[build-system]
2+
requires = ["setuptools"]
3+
4+
[project]
5+
name = "sparkfun_qwiic_i2c"
6+
version = "1.0.0"
7+
description = "SparkFun Electronics Qwiic I2C library"
8+
readme = "DESCRIPTION.rst"
9+
10+
authors = [{name="SparkFun Electronics", email="info@sparkfun.com"}]
11+
dependencies = ["smbus2"]
12+
13+
classifiers=[
14+
# How mature is this project? Common values are
15+
# 3 - Alpha
16+
# 4 - Beta
17+
# 5 - Production/Stable
18+
"Development Status :: 5 - Production/Stable",
19+
20+
# Indicate who your project is intended for
21+
"Intended Audience :: Developers",
22+
"Topic :: Software Development :: Build Tools",
23+
24+
# Pick your license as you wish (should match "license" above)
25+
"License :: OSI Approved :: MIT License",
26+
27+
# Specify the Python versions you support here. In particular, ensure
28+
# that you indicate whether you support Python 2, Python 3 or both.
29+
"Programming Language :: Python :: 3.5",
30+
"Programming Language :: Python :: 3.6",
31+
"Programming Language :: Python :: 3.7",
32+
"Programming Language :: Python :: 3.8",
33+
"Programming Language :: Python :: 3.9",
34+
"Programming Language :: Python :: 3.10",
35+
"Programming Language :: Python :: 3.11",
36+
"Programming Language :: Python :: 3.12",
37+
"Programming Language :: Python :: 3.13",
38+
"Programming Language :: Python :: 3.14",
39+
"Programming Language :: Python :: Implementation :: MicroPython",
40+
# NOTE: CircuitPython is also supported, but no classifier exists for it
41+
]
42+
43+
keywords = ["electronics, maker"]
44+
45+
[project.urls]
46+
homepage = "http://www.sparkfun.com/qwiic"
47+
48+
[tool.setuptools]
49+
packages = ["qwiic_i2c"]

qwiic_i2c/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
# All supported platform module and class names
6969
_supported_platforms = {
7070
"linux_i2c": "LinuxI2C",
71-
"circuitpy_i2c": "CircuitPythonI2C",
71+
"circuitpython_i2c": "CircuitPythonI2C",
7272
"micropython_i2c": "MicroPythonI2C"
7373
}
7474

File renamed without changes.

qwiic_i2c/linux_i2c.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,13 @@ def __setattr__(self, name, value):
152152
# read Data Command
153153

154154
# Performs a general read of <nBytes> from the device at <address> without a command/register code
155-
# Linux doesn't support this directly like CircuitPython and MicroPython, so we have to read byte by byte
156155
def _read_no_command(self, address, nBytes):
157-
data = [0] * nBytes
158-
for i in range(nBytes):
159-
data = self._i2cbus.read_byte(address)
160-
data[i] = data
161-
return data
156+
from smbus2 import i2c_msg
157+
158+
full_read_msg = i2c_msg.read(address, nBytes)
159+
self._i2cbus.i2c_rdwr(full_read_msg)
160+
161+
return list(full_read_msg)
162162

163163
def readWord(self, address, commandCode):
164164

qwiic_i2c/micropython_i2c.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,27 @@
4040
_PLATFORM_NAME = "MicroPython"
4141

4242
# used internally in this file to get i2c class object
43-
def _connectToI2CBus(sda=18, scl=19, freq=100000, *args, **argk):
43+
def _connectToI2CBus(sda=None, scl=None, freq=100000, *args, **argk):
4444
try:
4545
from machine import I2C, Pin
4646
if sys.platform == 'rp2':
47-
# I2C busses follow every other pair of pins
48-
scl_id = (scl // 2) % 2
49-
sda_id = (sda // 2) % 2
50-
# Check if both pins are on the same bus
51-
if scl_id != sda_id:
52-
raise Exception("I2C SCL and SDA pins must be on same ports")
53-
return I2C(id=scl_id, scl=Pin(scl), sda=Pin(sda), freq=freq)
47+
if sda is not None and scl is not None:
48+
# I2C busses follow every other pair of pins
49+
scl_id = (scl // 2) % 2
50+
sda_id = (sda // 2) % 2
51+
# Check if both pins are on the same bus
52+
if scl_id != sda_id:
53+
raise Exception("I2C SCL and SDA pins must be on same ports")
54+
return I2C(id=scl_id, scl=Pin(scl), sda=Pin(sda), freq=freq)
55+
else:
56+
return I2C()
5457
elif 'xbee' in sys.platform:
5558
return I2C(id=1, freq=freq)
59+
elif 'esp32' in sys.platform:
60+
if sda is not None and scl is not None:
61+
return I2C(scl=Pin(scl), sda=Pin(sda), freq=freq)
62+
else:
63+
return I2C()
5664
else:
5765
raise Exception("Unknown MicroPython platform: " + sys.platform)
5866
except Exception as e:
@@ -69,7 +77,7 @@ class MicroPythonI2C(I2CDriver):
6977
name = _PLATFORM_NAME
7078
_i2cbus = None
7179

72-
def __init__(self, sda=18, scl=19, freq=100000, *args, **argk):
80+
def __init__(self, sda=None, scl=None, freq=100000, *args, **argk):
7381
I2CDriver.__init__(self) # init super
7482

7583
self._sda = sda

setup.cfg

Lines changed: 0 additions & 2 deletions
This file was deleted.

setup.py

Lines changed: 0 additions & 106 deletions
This file was deleted.

0 commit comments

Comments
 (0)