├── docs ├── requirements.txt ├── apiref.rst ├── _static │ └── favicon.ico ├── index.rst └── conf.py ├── requirements.txt ├── DESCRIPTION.rst ├── .readthedocs.yml ├── README.txt ├── .github └── workflows │ ├── build.yml │ └── release.yml ├── LICENSE ├── update-submodules.sh ├── install_requirements.txt ├── pyproject.toml ├── README.md ├── .gitmodules └── qwiic └── __init__.py /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | m2r 2 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | circuitpython-build-tools 2 | setuptools 3 | -------------------------------------------------------------------------------- /docs/apiref.rst: -------------------------------------------------------------------------------- 1 | API Reference 2 | ============== 3 | 4 | .. automodule:: qwiic 5 | :members: -------------------------------------------------------------------------------- /docs/_static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sparkfun/Qwiic_Py/HEAD/docs/_static/favicon.ico -------------------------------------------------------------------------------- /DESCRIPTION.rst: -------------------------------------------------------------------------------- 1 | Qwiic Package 2 | ========================== 3 | 4 | This package provides an overall python support for the qwiic system. -------------------------------------------------------------------------------- /.readthedocs.yml: -------------------------------------------------------------------------------- 1 | python: 2 | version: 3 3 | install: 4 | - requirements: docs/requirements.txt 5 | setup_py_install: true 6 | 7 | submodules: 8 | exclude: all 9 | recursive: false 10 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | This README pertains to the CircuitPython bundle generated by the SparkFun Qwiic_Py repository. 2 | 3 | README.txt is a required file for Circup/CircuitPython bundle generation. 4 | 5 | To add the bundle to your computer, execute "circup bundle-add sparkfun/Qwiic_Py". 6 | 7 | Afterwards, to install individual drivers from the bundle to a device, execute "circup install --py ". 8 | 9 | See the README for each supported driver for more information. -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build CI 2 | 3 | on: [pull_request, push] 4 | 5 | jobs: 6 | test: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - name: Set up Python 3 10 | uses: actions/setup-python@v4 11 | with: 12 | python-version: 3.x 13 | - name: Versions 14 | run: | 15 | python3 --version 16 | - uses: actions/checkout@v3 17 | with: 18 | submodules: true 19 | - name: Fetch correct submodule shas 20 | run: git submodule foreach 'git fetch --tags --depth 1 origin $sha1 && git checkout -q $sha1' 21 | - name: Install deps 22 | run: | 23 | sudo apt-get install -y gettext gawk 24 | pip install -r requirements.txt 25 | - name: Library version 26 | run: git describe --dirty --always --tags 27 | - name: Build assets 28 | run: ./build.sh 29 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. sparkfun_qwiic documentation master file, created by 2 | sphinx-quickstart on Tue Jul 2 11:01:40 2019. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | .. mdinclude:: ../README.md 7 | 8 | Table of Contents 9 | ================= 10 | 11 | .. toctree:: 12 | :maxdepth: 4 13 | :caption: Contents: 14 | 15 | self 16 | 17 | 18 | .. toctree:: 19 | :caption: API Reference 20 | :maxdepth: 3 21 | 22 | apiref 23 | 24 | .. toctree:: 25 | :caption: Other Links 26 | 27 | SparkFun 28 | GitHub 29 | SparkFun qwiic 30 | 31 | 32 | Indices and tables 33 | ================== 34 | 35 | * :ref:`genindex` 36 | * :ref:`modindex` 37 | * :ref:`search` 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2019 SparkFun Electronics 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /update-submodules.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | # The MIT License (MIT) 4 | # 5 | # Copyright (c) 2016 Scott Shawcroft for Adafruit Industries 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy 8 | # of this software and associated documentation files (the "Software"), to deal 9 | # in the Software without restriction, including without limitation the rights 10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | # copies of the Software, and to permit persons to whom the Software is 12 | # furnished to do so, subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in 15 | # all copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | # THE SOFTWARE. 24 | 25 | # This script updates all submodules to the latest tag (hopefully release). 26 | git submodule update 27 | git submodule foreach git fetch 28 | git submodule foreach "tag=\$(git rev-list --tags --max-count=1); git checkout -q \$tag" 29 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release Actions 2 | 3 | on: 4 | release: 5 | types: [published] 6 | 7 | jobs: 8 | upload-release-assets: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Translate Repo Name For Build Tools filename_prefix 12 | id: repo-name 13 | run: | 14 | echo "repo-name=$( 15 | echo ${{ github.repository }} | 16 | awk -F '\/' '{ print tolower($2) }' | 17 | tr '_' '-' 18 | )" >> $GITHUB_OUTPUT 19 | - name: Set up Python 3 20 | uses: actions/setup-python@v4 21 | with: 22 | python-version: 3.x 23 | - name: Versions 24 | run: | 25 | python3 --version 26 | - uses: actions/checkout@v3 27 | with: 28 | submodules: true 29 | - name: Fetch correct submodule shas 30 | run: git submodule foreach 'git fetch --tags --depth 1 origin $sha1 && git checkout -q $sha1' 31 | - name: Install deps 32 | run: | 33 | sudo apt-get install -y gettext gawk 34 | pip install -r requirements.txt 35 | - name: Build assets 36 | run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location qwiic/drivers --library_depth 1 --package_folder_prefix "Qwiic, qwiic, Pi" 37 | - name: Upload Release Assets 38 | uses: shogo82148/actions-upload-release-asset@v1 39 | with: 40 | asset_path: "bundles/*" 41 | github_token: ${{ secrets.GITHUB_TOKEN }} 42 | upload_url: ${{ github.event.release.upload_url }} -------------------------------------------------------------------------------- /install_requirements.txt: -------------------------------------------------------------------------------- 1 | sparkfun-qwiic-serlcd 2 | sparkfun-qwiic-i2c 3 | sparkfun-qwiic-bme280 4 | sparkfun-qwiic-lsm6dso 5 | sparkfun-qwiic-keypad 6 | sparkfun-qwiic-sgp40 7 | sparkfun-qwiic-veml6030 8 | sparkfun-qwiic-soil-moisture-sensor 9 | sparkfun-qwiic-cap1203 10 | sparkfun-qwiic-ultrasonic 11 | sparkfun-qwiic-joystick 12 | sparkfun-qwiic-nau7802 13 | sparkfun-qwiic-alphanumeric 14 | sparkfun-qwiic-relay 15 | sparkfun-qwiic-button 16 | sparkfun-qwiic-mmc5983ma 17 | sparkfun-qwiic-max3010x 18 | sparkfun-qwiic-rfid 19 | sparkfun-qwiic-led-stick 20 | sparkfun-qwiic-twist 21 | sparkfun-qwiic-otos 22 | sparkfun-qwiic-kx13x 23 | sparkfun-qwiic-icm20948 24 | sparkfun-qwiic-scmd 25 | sparkfun-qwiic-pca9685 26 | sparkfun-qwiic-gpio 27 | sparkfun-qwiic-fs3000 28 | sparkfun-qwiic-micropressure 29 | sparkfun-qwiic-as7265x 30 | sparkfun-qwiic-as726x 31 | sparkfun-qwiic-vl53l5cx 32 | sparkfun-qwiic-rv8803 33 | sparkfun-qwiic-scd4x 34 | sparkfun-qwiic-ads1015 35 | sparkfun-qwiic-bmp581 36 | sparkfun-qwiic-mcp4725 37 | sparkfun-qwiic-mcp9600 38 | sparkfun-qwiic-tmp102 39 | sparkfun-qwiic-tmp117 40 | sparkfun-qwiic-max1704x 41 | sparkfun-qwiic-ens160 42 | sparkfun-qwiic-titan-gps 43 | sparkfun-qwiic-oled-base 44 | sparkfun-qwiic-ism330dhcx 45 | sparkfun-qwiic-vl53l1x 46 | sparkfun-qwiic-tca9548a 47 | sparkfun-qwiic-huskylens 48 | sparkfun-pi-servo-hat 49 | sparkfun-qwiic-adxl313 50 | sparkfun-qwiic-as6212 51 | sparkfun-qwiic-ccs811 52 | sparkfun-qwiic-dual-encoder-reader 53 | sparkfun-qwiic-eeprom 54 | sparkfun-opt4048-tristimulus-color-sensor 55 | sparkfun-qwiic-pir 56 | sparkfun-qwiic-proximity 57 | sparkfun-top-phat-button 58 | sparkfun-ublox-gps -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools"] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [project] 6 | name = "sparkfun_qwiic" 7 | version='2.0.0' 8 | description="SparkFun Electronics qwiic library" 9 | authors = [{name = "SparkFun Electronics", email = "info@sparkfun.com"}] 10 | readme = "DESCRIPTION.rst" # could also have the readme itself if we prefer... 11 | dynamic = ["dependencies"] 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 | ] 33 | 34 | keywords = ["electronics", "maker"] 35 | 36 | [project.urls] 37 | homepage = "http://www.sparkfun.com/qwiic" 38 | 39 | [tool.setuptools] 40 | packages = ["qwiic"] 41 | 42 | [tool.setuptools.package-data] 43 | qwiic = ["drivers/**/*", "drivers_linux_only/**/*"] 44 | 45 | [tool.setuptools.exclude-package-data] 46 | qwiic = ["*/docs/*"] 47 | 48 | [tool.setuptools.dynamic] 49 | dependencies = {file = "install_requirements.txt"} 50 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # Configuration file for the Sphinx documentation builder. 2 | # 3 | # This file only contains a selection of the most common options. For a full 4 | # list see the documentation: 5 | # http://www.sphinx-doc.org/en/master/config 6 | 7 | # -- Path setup -------------------------------------------------------------- 8 | 9 | # If extensions (or modules to document with autodoc) are in another directory, 10 | # add these directories to sys.path here. If the directory is relative to the 11 | # documentation root, use os.path.abspath to make it absolute, like shown here. 12 | # 13 | import os 14 | import sys 15 | sys.path.insert(0, os.path.abspath('.')) 16 | 17 | 18 | # -- Project information ----------------------------------------------------- 19 | 20 | project = 'sparkfun_qwiic' 21 | copyright = '2019, SparkFun Electronics' 22 | author = 'SparkFun Electronics' 23 | 24 | # The full version, including alpha/beta/rc tags 25 | release = '0.9.1' 26 | 27 | 28 | # -- General configuration --------------------------------------------------- 29 | 30 | # Add any Sphinx extension module names here, as strings. They can be 31 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 32 | # ones. 33 | extensions = [ 34 | 'sphinx.ext.autodoc', 35 | 'sphinx.ext.intersphinx', 36 | 'sphinx.ext.viewcode', 37 | 'm2r' 38 | ] 39 | 40 | source_suffix = ['.rst', '.md'] 41 | # Add any paths that contain templates here, relative to this directory. 42 | templates_path = ['_templates'] 43 | 44 | master_doc = 'index' 45 | # List of patterns, relative to source directory, that match files and 46 | # directories to ignore when looking for source files. 47 | # This pattern also affects html_static_path and html_extra_path. 48 | exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] 49 | 50 | 51 | # -- Options for HTML output ------------------------------------------------- 52 | 53 | # The theme to use for HTML and HTML Help pages. See the documentation for 54 | # a list of builtin themes. 55 | # 56 | import sphinx_rtd_theme 57 | html_theme = 'sphinx_rtd_theme' 58 | html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.'] 59 | 60 | # Add any paths that contain custom static files (such as style sheets) here, 61 | # relative to this directory. They are copied after the builtin static files, 62 | # so a file named "default.css" will overwrite the builtin "default.css". 63 | html_static_path = ['_static'] 64 | 65 | html_favicon = '_static/favicon.ico' 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Qwiic_Py 2 | ======== 3 | 4 |

5 | 6 | 7 |

8 |

9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | follow on Twitter 20 | 21 |

22 | 23 | 24 | 25 | The SparkFun qwiic python package aggregates all python qwiic drivers/modules to provide a single entity for qwiic within a python environment. The qwiic package delivers the high-level functionality needed to dynamically discover connected qwiic devices and construct their associated driver object. 26 | 27 | New to qwiic? Take a look at the entire [SparkFun qwiic ecosystem](https://www.sparkfun.com/qwiic). 28 | 29 | ## Contents 30 | 31 | * [Supported Platforms](#supported-platforms) 32 | * [Structure](#structure) 33 | * [Dependent Modules](#dependent-modules) 34 | * [MicroPython and CircuitPython](#micropython-and-circuitpython) 35 | * [Checkout Commands](#checkout-commands) 36 | * [Installation](#installation) 37 | * [Documentation](#documentation) 38 | 39 | Supported Platforms 40 | -------------------- 41 | The qwiic Python package current supports the following platforms: 42 | * [Raspberry Pi](https://www.sparkfun.com/search/results?term=raspberry+pi) 43 | * [NVidia Jetson Nano](https://www.sparkfun.com/products/15297) 44 | * [Google Coral Development Board](https://www.sparkfun.com/products/15318) 45 | 46 | 47 | Structure 48 | ------------- 49 | Each qwiic board has an independent driver library that implements the required logic for the specific board. This driver implementation is structured as a python package that supports standard python package management operations and tools. Additionally, each driver is deployed in a distinct GitHub repository which provides a central area for package management and development. 50 | 51 | To provide dynamic discovery and instantiation capabilities, the qwiic package imports all the underlying qwiic driver packages at runtime. As such the qwiic driver packages must be installed prior to using this package. These packages can be installed manually, or the overall package will install them automatically when using a PyPi based package manger (aka pip). 52 | 53 | Dependent Modules 54 | ------------------ 55 | To make development and evaluation easer, the modules this package is dependent on are included in this repository as git submodules. This allows rapid checkout and access to the entire qwiic python ecosystem if needed. 56 | 57 | This structure has the following layout: 58 | ``` 59 | Qwiic_Py/ 60 | | 61 | +--- qwiic_i2c/ --> Link to the qwiic_i2c submodule repository 62 | | |--- __index__.py 63 | | `--- ... The cross platform I2C bus access driver 64 | | 65 | +--- qwiic/ 66 | | |--- __index__.py 67 | | +--- ... Package Implementation 68 | | `--- drivers/ 69 | | |--- qwiic_bme280 --> The qwiic_bme280 submodule 70 | | |--- qwiic_micro_oled --> The qwiic_micro_oled submodule 71 | | `--- ... links to qwiic driver submodule repositories 72 | | 73 | +--- README.md 74 | +--- setup.py 75 | `--- ...etc 76 | 77 | ``` 78 | 79 | Micropython and CircuitPython 80 | ------------------ 81 | The drivers in the [drivers directory](https://github.com/sparkfun/Qwiic_Py/tree/master/qwiic/drivers) are supported on Linux, MicroPython and CircuitPython. The drivers in the [drivers_linux_only directory](https://github.com/sparkfun/Qwiic_Py/tree/master/qwiic/drivers_linux_only) are currently only supported for Linux. To learn more about MicroPython and CircuitPython, and for install instructions for your specific driver, see the README file of each supported driver. 82 | 83 | Dependencies 84 | ------------- 85 | The qwiic package depends on the qwiic I2C driver: 86 | [Qwiic_I2C_Py](https://github.com/sparkfun/Qwiic_I2C_Py) 87 | 88 | This package is also dependent on the driver packages contained in the [drivers directory](https://github.com/sparkfun/Qwiic_Py/tree/master/qwiic/drivers). 89 | 90 | Documentation 91 | -------------- 92 | The SparkFun qwiic package documentation is hosted at [ReadTheDocs](https://qwiic-py.readthedocs.io/en/latest/index.html) 93 | 94 | 95 | Checkout Commands 96 | ------------------ 97 | To clone this repository, a standard git clone command will create a local copy of this repository: 98 | ```sh 99 | git clone https://github.com/sparkfun/Qwiic_Py 100 | ``` 101 | 102 | This will create a local version of this repository, but the submodule directories (drivers/*, and qwiic_i2c/ ) will be empty. To clone the git repository and include the submodule contents, use the following command: 103 | ```sh 104 | git clone --recurse-submodules https://github.com/sparkfun/Qwiic_Py.git 105 | ``` 106 | 107 | Installation 108 | ------------- 109 | ### PyPi Installation 110 | This repository is hosted on PyPi as the [sparkfun-qwiic](https://pypi.org/project/sparkfun-qwiic/) package. 111 | 112 | Note - the below instructions outline installation on a Linux-based (Raspberry Pi) system and will install all the drivers in this package. **To install for MicroPython or CircuitPython, see the instructions in each driver's README.** 113 | 114 | First, setup a virtual environment from a specific directory using venv: 115 | ```sh 116 | python3 -m venv ~/sparkfun_venv 117 | ``` 118 | 119 | 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). 120 | 121 | Next, install the qwiic package with: 122 | ```sh 123 | ~/sparkfun_venv/bin/pip3 install sparkfun-qwiic 124 | ``` 125 | Now you should be able to run any example or custom python scripts that have `import qwiic` by running e.g.: 126 | ```sh 127 | ~/sparkfun_venv/bin/python3 example_script.py 128 | ``` 129 | 130 | This process will install all drivers and modules the qwiic package requires for operation. If you are only working with one driver, it is recommended to download that driver directly (see instructions in each driver's README) rather than from this large meta-package. 131 | 132 |

133 | SparkFun - Start Something 134 |

135 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "drivers/qwiic_bme280"] 2 | path = qwiic/drivers/qwiic_bme280 3 | url = https://github.com/sparkfun/Qwiic_BME280_Py.git 4 | [submodule "drivers/qwiic_ccs811"] 5 | path = qwiic/drivers_linux_only/qwiic_ccs811 6 | url = https://github.com/sparkfun/Qwiic_CCS811_Py.git 7 | [submodule "drivers/qwiic_proximity"] 8 | path = qwiic/drivers_linux_only/qwiic_proximity 9 | url = https://github.com/sparkfun/Qwiic_Proximity_Py.git 10 | [submodule "drivers/qwiic_scmd"] 11 | path = qwiic/drivers/qwiic_scmd 12 | url = https://github.com/sparkfun/Qwiic_SCMD_Py.git 13 | [submodule "qwiic_i2c"] 14 | path = qwiic/drivers/qwiic_i2c 15 | url = https://github.com/sparkfun/Qwiic_I2C_Py.git 16 | [submodule "drivers/qwiic_keypad"] 17 | path = qwiic/drivers/qwiic_keypad 18 | url = https://github.com/sparkfun/Qwiic_Keypad_Py.git 19 | [submodule "drivers/qwiic_joystick"] 20 | path = qwiic/drivers/qwiic_joystick 21 | url = https://github.com/sparkfun/Qwiic_Joystick_Py.git 22 | [submodule "drivers/qwiic_twist"] 23 | path = qwiic/drivers/qwiic_twist 24 | url = https://github.com/sparkfun/Qwiic_Twist_Py.git 25 | [submodule "qwiic/drivers/qwiic_vl53l1x"] 26 | path = qwiic/drivers/qwiic_vl53l1x 27 | url = https://github.com/sparkfun/Qwiic_VL53L1X_Py 28 | [submodule "qwiic/drivers/qwiic_pca9685"] 29 | path = qwiic/drivers/qwiic_pca9685 30 | url = https://github.com/sparkfun/Qwiic_PCA9685_Py 31 | [submodule "qwiic/drivers/pi_servo_hat"] 32 | path = qwiic/drivers/pi_servo_hat 33 | url = https://github.com/sparkfun/PiServoHat_Py 34 | [submodule "qwiic/drivers/qwiic_ublox_gps"] 35 | path = qwiic/drivers/qwiic_ublox_gps 36 | url = https://github.com/sparkfun/Qwiic_Ublox_Gps_Py 37 | [submodule "qwiic/drivers/qwiic_titan_gps"] 38 | path = qwiic/drivers/qwiic_titan_gps 39 | url = https://github.com/sparkfun/Qwiic_Titan_Gps_Py 40 | [submodule "qwiic/drivers/qwiic_tca9548a"] 41 | path = qwiic/drivers/qwiic_tca9548a 42 | url = https://github.com/sparkfun/Qwiic_TCA9548A_Py.git 43 | [submodule "qwiic/drivers/qwiic_dual_encoder_reader"] 44 | path = qwiic/drivers_linux_only/qwiic_dual_encoder_reader 45 | url = https://github.com/sparkfun/Qwiic_Dual_Encoder_Reader_Py.git 46 | [submodule "qwiic/drivers/top_phat_button"] 47 | path = qwiic/drivers_linux_only/top_phat_button 48 | url = https://github.com/sparkfun/Top_pHAT_Button_Py 49 | [submodule "qwiic/drivers/qwiic_icm20948"] 50 | path = qwiic/drivers/qwiic_icm20948 51 | url = https://github.com/sparkfun/Qwiic_9DoF_IMU_ICM20948_Py.git 52 | [submodule "qwiic/drivers/qwiic_max3010x"] 53 | path = qwiic/drivers/qwiic_max3010x 54 | url = https://github.com/sparkfun/Qwiic_MAX3010x_Py.git 55 | [submodule "qwiic/drivers/qwiic_relay"] 56 | path = qwiic/drivers/qwiic_relay 57 | url = https://github.com/sparkfun/Qwiic_Relay_Py.git 58 | [submodule "qwiic/drivers/ublox_gps"] 59 | path = qwiic/drivers_linux_only/ublox_gps 60 | url = https://github.com/sparkfun/qwiic_ublox_gps_py 61 | [submodule "qwiic/drivers/qwiic_serlcd"] 62 | path = qwiic/drivers/qwiic_serlcd 63 | url = https://github.com/sparkfun/Qwiic_SerLCD_Py 64 | [submodule "qwiic/drivers/qwiic_gpio"] 65 | path = qwiic/drivers/qwiic_gpio 66 | url = https://github.com/sparkfun/Qwiic_GPIO_Py.git 67 | [submodule "qwiic/drivers/qwiic_adxl313"] 68 | path = qwiic/drivers_linux_only/qwiic_adxl313 69 | url = https://github.com/sparkfun/Qwiic_ADXL313_Py 70 | [submodule "qwiic/drivers/qwiic_button"] 71 | path = qwiic/drivers/qwiic_button 72 | url = https://github.com/sparkfun/Qwiic_Button_Py.git 73 | [submodule "qwiic/drivers/qwiic_rfid"] 74 | path = qwiic/drivers/qwiic_rfid 75 | url = https://github.com/sparkfun/Qwiic_RFID_Py 76 | [submodule "qwiic/drivers/qwiic_soil_moisture_sensor"] 77 | path = qwiic/drivers/qwiic_soil_moisture_sensor 78 | url = https://github.com/sparkfun/Qwiic_Soil_Moisture_Sensor_Py 79 | [submodule "qwiic/drivers/qwiic_pir"] 80 | path = qwiic/drivers_linux_only/qwiic_pir 81 | url = https://github.com/sparkfun/Qwiic_PIR_Py 82 | [submodule "qwiic/drivers/qwiic_sgp40"] 83 | path = qwiic/drivers/qwiic_sgp40 84 | url = https://github.com/sparkfun/Qwiic_SGP40_Py 85 | [submodule "qwiic/drivers/qwiic_kx13x"] 86 | path = qwiic/drivers/qwiic_kx13x 87 | url = https://github.com/sparkfun/Qwiic_KX13X_Py 88 | [submodule "qwiic/drivers/qwiic_led_stick"] 89 | path = qwiic/drivers/qwiic_led_stick 90 | url = https://github.com/sparkfun/Qwiic_LED_Stick_Py 91 | [submodule "qwiic/drivers/qwiic_eeprom"] 92 | path = qwiic/drivers_linux_only/qwiic_eeprom 93 | url = https://github.com/sparkfun/Qwiic_EEPROM_Py 94 | [submodule "qwiic/drivers/qwiic_as6212"] 95 | path = qwiic/drivers_linux_only/qwiic_as6212 96 | url = https://github.com/sparkfun/Qwiic_AS6212_Py 97 | [submodule "qwiic/drivers/qwiic_alphanumeric"] 98 | path = qwiic/drivers/qwiic_alphanumeric 99 | url = https://github.com/sparkfun/Qwiic_Alphanumeric_Py 100 | [submodule "qwiic/drivers/qwiic_otos"] 101 | path = qwiic/drivers/qwiic_otos 102 | url = https://github.com/sparkfun/Qwiic_OTOS_Py 103 | 104 | [submodule "qwiic/drivers/qwiic_tmp102"] 105 | path = qwiic/drivers/qwiic_tmp102 106 | url = https://github.com/sparkfun/Qwiic_TMP102_Py.git 107 | [submodule "qwiic/drivers/qwiic_cap1203"] 108 | path = qwiic/drivers/qwiic_cap1203 109 | url = https://github.com/sparkfun/Qwiic_CAP1203_Py.git 110 | [submodule "qwiic/drivers/qwiic_lsm6dso"] 111 | path = qwiic/drivers/qwiic_lsm6dso 112 | url = https://github.com/sparkfun/Qwiic_LSM6DSO_Py.git 113 | [submodule "qwiic/drivers/qwiic_mmc5983ma"] 114 | path = qwiic/drivers/qwiic_mmc5983ma 115 | url = https://github.com/sparkfun/Qwiic_MMC5983MA_Py.git 116 | [submodule "qwiic/drivers/qwiic_nau7802"] 117 | path = qwiic/drivers/qwiic_nau7802 118 | url = https://github.com/sparkfun/Qwiic_NAU7802_Py.git 119 | [submodule "qwiic/drivers/qwiic_ultrasonic"] 120 | path = qwiic/drivers/qwiic_ultrasonic 121 | url = https://github.com/sparkfun/Qwiic_Ultrasonic_Py.git 122 | [submodule "qwiic/drivers/qwiic_veml6030"] 123 | path = qwiic/drivers/qwiic_veml6030 124 | url = https://github.com/sparkfun/Qwiic_VEML6030_Py.git 125 | [submodule "qwiic/drivers/qwiic_micropressure"] 126 | path = qwiic/drivers/qwiic_micropressure 127 | url = https://github.com/sparkfun/qwiic_micropressure_py.git 128 | [submodule "qwiic/drivers/qwiic_as7265x"] 129 | path = qwiic/drivers/qwiic_as7265x 130 | url = https://github.com/sparkfun/qwiic_as7265x_py.git 131 | [submodule "qwiic/drivers/qwiic_as726x"] 132 | path = qwiic/drivers/qwiic_as726x 133 | url = https://github.com/sparkfun/qwiic_as726x_py.git 134 | [submodule "qwiic/drivers/qwiic_vl53l5cx"] 135 | path = qwiic/drivers/qwiic_vl53l5cx 136 | url = https://github.com/sparkfun/qwiic_vl53l5cx_py.git 137 | [submodule "qwiic/drivers/qwiic_rv8803"] 138 | path = qwiic/drivers/qwiic_rv8803 139 | url = https://github.com/sparkfun/qwiic_rv-8803_py.git 140 | [submodule "qwiic/drivers/qwiic_scd4x"] 141 | path = qwiic/drivers/qwiic_scd4x 142 | url = https://github.com/sparkfun/qwiic_scd4x_py.git 143 | [submodule "qwiic/drivers/qwiic_ads1015"] 144 | path = qwiic/drivers/qwiic_ads1015 145 | url = https://github.com/sparkfun/qwiic_ads1015_py.git 146 | [submodule "qwiic/drivers/qwiic_bmp581"] 147 | path = qwiic/drivers/qwiic_bmp581 148 | url = https://github.com/sparkfun/qwiic_bmp581_py.git 149 | [submodule "qwiic/drivers/qwiic_mcp4725"] 150 | path = qwiic/drivers/qwiic_mcp4725 151 | url = https://github.com/sparkfun/qwiic_mcp4725_py.git 152 | [submodule "qwiic/drivers/qwiic_mcp9600"] 153 | path = qwiic/drivers/qwiic_mcp9600 154 | url = https://github.com/sparkfun/qwiic_mcp9600_py.git 155 | [submodule "qwiic/drivers/qwiic_tmp117"] 156 | path = qwiic/drivers/qwiic_tmp117 157 | url = https://github.com/sparkfun/qwiic_tmp117_py.git 158 | [submodule "qwiic/drivers/qwiic_max1704x"] 159 | path = qwiic/drivers/qwiic_max1704x 160 | url = https://github.com/sparkfun/qwiic_max1704x_py.git 161 | [submodule "qwiic/drivers/qwiic_ens160"] 162 | path = qwiic/drivers/qwiic_ens160 163 | url = https://github.com/sparkfun/qwiic_ens160_py.git 164 | [submodule "qwiic/drivers/qwiic_fs3000"] 165 | path = qwiic/drivers/qwiic_fs3000 166 | url = https://github.com/sparkfun/qwiic_fs3000_py.git 167 | [submodule "qwiic/drivers/qwiic_oled"] 168 | path = qwiic/drivers/qwiic_oled 169 | url = https://github.com/sparkfun/qwiic_oled_base_py.git 170 | [submodule "qwiic/drivers/qwiic_ism330dhcx"] 171 | path = qwiic/drivers/qwiic_ism330dhcx 172 | url = https://github.com/sparkfun/qwiic_ism330dhcx_py.git 173 | [submodule "qwiic/drivers/qwiic_huskylens"] 174 | path = qwiic/drivers/qwiic_huskylens 175 | url = https://github.com/sparkfun/qwiic_huskylens_py.git 176 | [submodule "qwiic/drivers/qwiic_as7343"] 177 | path = qwiic/drivers/qwiic_as7343 178 | url = https://github.com/sparkfun/qwiic_as7343_py.git 179 | -------------------------------------------------------------------------------- /qwiic/__init__.py: -------------------------------------------------------------------------------- 1 | #----------------------------------------------------------------------------- 2 | # __init__.py 3 | # 4 | #------------------------------------------------------------------------ 5 | # 6 | # 7 | # Written by SparkFun Electronics, May 2021 8 | # 9 | # This python library supports the SparkFun Electroncis qwiic 10 | # qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single 11 | # board computers. 12 | # 13 | # More information on qwiic is at https://www.sparkfun.com/qwiic 14 | # 15 | # Do you like this library? Help support SparkFun. Buy a board! 16 | # 17 | #================================================================================== 18 | # Copyright (c) 2021 SparkFun Electronics 19 | # 20 | # Permission is hereby granted, free of charge, to any person obtaining a copy 21 | # of this software and associated documentation files (the "Software"), to deal 22 | # in the Software without restriction, including without limitation the rights 23 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | # copies of the Software, and to permit persons to whom the Software is 25 | # furnished to do so, subject to the following conditions: 26 | # 27 | # The above copyright notice and this permission notice shall be included in all 28 | # copies or substantial portions of the Software. 29 | # 30 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 36 | # SOFTWARE. 37 | #================================================================================== 38 | # 39 | # pylint: disable=old-style-class, missing-docstring, wrong-import-position 40 | # 41 | #----------------------------------------------------------------------------- 42 | # Usage 43 | # 44 | # The package provides a wrapper/overview of classes that encapsulate a specific 45 | # object that represnets a qwiic enabled device. 46 | # 47 | # Use of the pacakge is as follows: 48 | # 49 | # Option 1 - import the package, create the specific class 50 | # 51 | # import qwiic 52 | # myDevice = qwiic.MyDevice() 53 | # 54 | # Option 2 - Create the device object using the device address, classname or 55 | # human readable name 56 | # 57 | # import qwiic 58 | # myDevice = qwiic.create_device("My Device Name") 59 | # 60 | # 61 | # 62 | """ 63 | qwiic 64 | ======== 65 | 66 | The SparkFun qwiic python package aggregates all python qwiic 67 | drivers/modules to provide a single entity for qwiic within a 68 | python environment. The qwiic package delivers the high-level 69 | functionality needed to dynamically discover connected qwiic 70 | devices and construct their associated driver object. 71 | 72 | New to qwiic? Take a look at the entire 73 | [SparkFun qwiic ecosystem](https://www.sparkfun.com/qwiic). 74 | 75 | """ 76 | #----------------------------------------------------------------------------- 77 | from __future__ import print_function 78 | import sys 79 | import os 80 | 81 | import qwiic_i2c 82 | 83 | #----------------------------------------------------------------------------- 84 | # Define a class to store content, etc using class scoped methods and variables 85 | # 86 | # Simple method to encapsulate information, and create a simple 87 | # store that doesnt' required the use of 'global' 88 | 89 | class _QwiicInternal: 90 | qwiic_devices = [] 91 | available_devices = {} 92 | i2c_driver = None 93 | 94 | def __init__(self): 95 | pass 96 | 97 | @classmethod 98 | def add_qwiic_device(cls, new_device): 99 | cls.qwiic_devices.append(new_device) 100 | 101 | @classmethod 102 | def get_qwiic_devices(cls): 103 | return cls.qwiic_devices 104 | 105 | @classmethod 106 | def get_i2c_driver(cls): 107 | 108 | if cls.i2c_driver is None: 109 | 110 | cls.i2c_driver = qwiic_i2c.getI2CDriver() 111 | 112 | if cls.i2c_driver is None: 113 | print("Unable to get the plaform I2C driver for QWIIC.") 114 | 115 | return cls.i2c_driver 116 | 117 | #----------------------------------------------------------------------- 118 | # _getAvailableDevices() 119 | # 120 | # Return a dictionary that defines the available qwiic devices in the 121 | # package as a list. The key is the I2C address. 122 | # 123 | # Devices with multiple possible addresses have mulitple entries. 124 | @classmethod 125 | def get_available_devices(cls): 126 | 127 | # do we already have these 128 | if not cls.available_devices: 129 | 130 | # Loop through the device lists and add the class to the 131 | # dict - address is the key. 132 | 133 | for device_class in cls.qwiic_devices: 134 | 135 | # loop over the device addresses - add list of device name 136 | for addr in device_class.available_addresses: 137 | cls.available_devices.setdefault(addr,[]).append(device_class) 138 | 139 | # return cls.available_devices 140 | 141 | # return cls.available_devices, sorted by the I2C addresses 142 | return dict(sorted(cls.available_devices.items())) 143 | 144 | 145 | 146 | #---------------------------------------------------- 147 | # _load_driver_classes() 148 | # 149 | # Method to load the qwiic driver Classes AND expose them as 150 | # attributes to this package. 151 | # 152 | # Use the driver sub directory of this package to determine the names 153 | # and drivers of these pacakges . 154 | # 155 | 156 | def _load_driver_classes(): 157 | 158 | driver_dir = __file__.rsplit(os.sep, 1)[0] + os.sep + "drivers" 159 | driver_dir_linux = __file__.rsplit(os.sep, 1)[0] + os.sep + "drivers_linux_only" 160 | 161 | try: 162 | driver_packages = os.listdir(driver_dir) 163 | driver_packages += os.listdir(driver_dir_linux) 164 | if "qwiic_i2c" in driver_packages: 165 | driver_packages.remove("qwiic_i2c") 166 | except IOError: 167 | print("The qwiic drivers are not installed - please check your installation") 168 | return 169 | 170 | for driver in driver_packages: 171 | # The driver objects are just the driver pacakge names in camelcase 172 | 173 | tmp_parts = driver.split('_') 174 | 175 | class_name = tmp_parts[0].title() + ''.join(x.title() for x in tmp_parts[1:]) 176 | 177 | try: 178 | module = __import__(driver) 179 | 180 | # by default we look for a class name of QwiicName, where name is camel cased 181 | # Camel case is sometimes missed by the driver implementors, so we try to 182 | # catch this here.. Adds a little to startup, but it's a one time event. 183 | 184 | if not hasattr(module, class_name): 185 | moduleItems = dir(module) 186 | i =0 187 | lname = class_name.lower() 188 | for tmp in moduleItems: 189 | if lname == tmp.lower(): 190 | break 191 | elif tmp.lower().startswith(lname): 192 | break 193 | i = i + 1 194 | 195 | if i >= len(moduleItems): 196 | print("Invalid driver class name. Unable to locate %s" % class_name) 197 | continue 198 | 199 | class_name = moduleItems[i] 200 | 201 | cls_driver = getattr(module, class_name) 202 | 203 | setattr(sys.modules[__name__], class_name, cls_driver) 204 | 205 | _QwiicInternal.add_qwiic_device(cls_driver) 206 | except Exception as err: 207 | print("Error loading module `%s`: %s" % (driver, err)) 208 | continue 209 | 210 | 211 | 212 | # load the driver modules... 213 | _load_driver_classes() 214 | 215 | #----------------------------------------------------------------------- 216 | # I2C Bus / Device methods 217 | #----------------------------------------------------------------------- 218 | # 219 | # Cache for QWIIC device classes - determined at runtime 220 | 221 | #----------------------------------------------------------------------- 222 | # scan() 223 | # 224 | # Scans the I2C bus and returns a list of addresses that have a devices connected 225 | # 226 | def scan(): 227 | """ 228 | Used to scan the I2C bus, returning a list of I2C address attached to the computer. 229 | 230 | :return: A list of I2C addresses. If no devices are attached, an empty list is returned. 231 | :rtype: list 232 | 233 | :example: 234 | 235 | >>> import qwiic 236 | >>> [2]: qwiic.scan() 237 | [61, 91, 96, 119] 238 | """ 239 | 240 | i2c_driver = _QwiicInternal.get_i2c_driver() 241 | 242 | if i2c_driver is None: 243 | return [] 244 | 245 | return i2c_driver.scan() 246 | 247 | 248 | #----------------------------------------------------------------------- 249 | # list_devices() 250 | # 251 | # Return a list of tuples that define the qwiic devices connected to the I2C bus. 252 | # 253 | def list_devices(): 254 | """ 255 | Returns a list of known qwiic driver/packages for I2c address(es) of device(s) connected to the I2C bus. 256 | 257 | :return: A list of the qwiic devices associated with the I2C address(es) 258 | scanned from the I2C bus. Each element of the list a tuple that 259 | contains the following values (Device I2C Address, Device Name, 260 | Device Driver Class Name) 261 | If no devices are attached, an empty list is returned. 262 | :rtype: list 263 | 264 | :example: 265 | 266 | >>> import qwiic 267 | >>> qwiic.list_devices() 268 | [(61, 'Qwiic Micro OLED', 'QwiicMicroOled'), 269 | (61, 'Qwiic 4m Distance Sensor (ToF)', 'QwiicVL53L1X'), 270 | (91, 'Qwiic PCA9685', 'QwiicPCA9685'), 271 | (91, 'Qwiic 4m Distance Sensor (ToF)', 'QwiicVL53L1X'), 272 | (91, 'Qwiic CCS811', 'QwiicCcs811'), 273 | (96, 'Qwiic PCA9685', 'QwiicPCA9685'), 274 | (96, 'Qwiic 4m Distance Sensor (ToF)', 'QwiicVL53L1X'), 275 | (96, 'Qwiic Proximity Sensor', 'QwiicProximity'), 276 | (119, 'Qwiic PCA9685', 'QwiicPCA9685'), 277 | (119, 'Qwiic 4m Distance Sensor (ToF)', 'QwiicVL53L1X'), 278 | (119, 'Qwiic Mux', 'QwiicTCA9548A'), 279 | (119, 'Qwiic BME280', 'QwiicBme280')] 280 | 281 | """ 282 | 283 | # Scan the bus 284 | device_address = scan() 285 | if not device_address: 286 | return [] 287 | 288 | 289 | # What QWIIC devices do we know about -- what's defined in the package 290 | qwiic_devs = _QwiicInternal.get_available_devices() 291 | if not qwiic_devs: 292 | return [] 293 | 294 | found_qwiic = [] 295 | # match scan, with definition 296 | for address in device_address: 297 | 298 | if address in qwiic_devs.keys(): 299 | 300 | # make list of devices at address 301 | device_list = list(qwiic_devs[address]) 302 | 303 | for dev in device_list: 304 | # make the return tuple 305 | found_qwiic.append((address, dev.device_name, \ 306 | dev.__name__)) 307 | 308 | 309 | return found_qwiic 310 | 311 | #----------------------------------------------------------------------- 312 | # list_available_drivers() 313 | # 314 | # Return a list of tuples that define the available qwiic drivers/packages. 315 | # 316 | def list_available_drivers(device_address=None): 317 | """ 318 | Returns a list of known drivers/packages for qwiic devices. 319 | 320 | :param device_address: A list with an I2C address or addresses. If no value 321 | was given, the I2C bus will be scanned and the address(es) of the 322 | connected qwiic devices will be used. 323 | 324 | :return: A list of qwiic drivers/packages associated with the address(es) in the 325 | list. Each element of the list a tuple that contains the following values 326 | (Device I2C Address, Device Name, Device Driver Class Name) 327 | :rtype: list 328 | 329 | 330 | :example: 331 | 332 | >>> import qwiic 333 | >>> qwiic.list_available_drivers([32]) 334 | [(32, 'Qwiic GPIO', 'QwiicGPIO'), 335 | (32, 'Qwiic 4m Distance Sensor (ToF)', 'QwiicVL53L1X'), 336 | (32, 'SparkFun Qwiic Joystick', 'QwiicJoystick')] 337 | >>> qwiic.list_available_drivers([61,91]) 338 | [(61, 'Qwiic Micro OLED', 'QwiicMicroOled'), 339 | (61, 'Qwiic 4m Distance Sensor (ToF)', 'QwiicVL53L1X'), 340 | (91, 'Qwiic PCA9685', 'QwiicPCA9685'), 341 | (91, 'Qwiic 4m Distance Sensor (ToF)', 'QwiicVL53L1X'), 342 | (91, 'Qwiic CCS811', 'QwiicCcs811')] 343 | 344 | """ 345 | 346 | if device_address is None: 347 | device_address = list(range(0x08,0x77+1)) 348 | 349 | 350 | # What QWIIC devices do we know about -- what's defined in the package 351 | qwiic_devs = _QwiicInternal.get_available_devices() 352 | if not qwiic_devs: 353 | return [] 354 | 355 | found_qwiic = [] 356 | 357 | # Match scan, with definition 358 | for address in device_address: 359 | 360 | # Make list of devices at address 361 | if address in qwiic_devs.keys(): 362 | device_list = list(qwiic_devs[address]) 363 | 364 | # List all devices from address 365 | for dev in device_list: 366 | # make the return tuple 367 | found_qwiic.append((address, dev.device_name, \ 368 | dev.__name__)) 369 | 370 | 371 | return found_qwiic 372 | 373 | #------------------- 374 | # get_devices() 375 | # 376 | # Returns a list of objects that define the qwiic devices attached to the 377 | # I2C bus. 378 | # 379 | def get_devices(): 380 | """ 381 | Used to create device objects for all qwiic devices attached to the computer. 382 | 383 | :return: A list of qwiic device objects. 384 | If no qwiic devices are an empty list is returned. 385 | :rtype: list 386 | 387 | :example: 388 | 389 | >>> import qwiic 390 | 391 | >>> qwiic.get_devices() 392 | [, 393 | , 394 | , 395 | ] 396 | 397 | """ 398 | 399 | # Scan the bus 400 | found_devices = scan() 401 | if not found_devices: 402 | return [] 403 | 404 | # What QWIIC devices do we know about -- what's defined in the package 405 | qwiic_devs = _QwiicInternal.get_available_devices() 406 | if not qwiic_devs: 407 | return [] 408 | 409 | 410 | found_qwiic = [] 411 | # match scan, with definition 412 | for address in found_devices: 413 | 414 | if address in qwiic_devs.keys(): 415 | 416 | # make list of devices at address 417 | device_list = list(qwiic_devs[address]) 418 | 419 | for dev in device_list: 420 | # Create an object and append to our found list 421 | # note: class defs are stored in the defs dictionary.. 422 | found_qwiic.append(dev(address)) 423 | 424 | 425 | return found_qwiic 426 | 427 | #------------------- 428 | # create_device() 429 | # 430 | # Given the Address, Name or Clasname of a qwiic device, create the 431 | # assocaited device object and return it to the caller. 432 | # 433 | # The intent is for the user to call list_devices() (connected devices only), 434 | # find a device they like AND use this method to create the device at the 435 | # connected address 436 | # 437 | def create_device(device=None): 438 | """ 439 | Used to create a device object for a specific qwiic device 440 | 441 | :param device: The I2C address (int), Name or Class name (str) of the device to created, 442 | or selection from listed connected devices (tuple). 443 | The device address should be an integer value, of the hex value. For 444 | an example, for an `0x60` (hex) address enter `qwiic.create_device(60)`. 445 | :return: A qwiic device object for the specified qwiic device, using the I2C address 446 | that the device is connected at. 447 | If the specified device isn't found, None is returned. 448 | :rtype: Object 449 | 450 | :example: 451 | 452 | >>> import qwiic 453 | >>> results = qwiic.list_devices() 454 | >>> print(results) 455 | [(16, 'Qwiic 4m Distance Sensor (ToF)', 'QwiicVL53L1X'), (16, 'Qwiic Titan GPS', 'QwiicTitanGps'), (41, 'Qwiic 4m Distance Sensor (ToF)', 'QwiicVL53L1X'), (60, 'Qwiic Micro OLED (64x48)', 'QwiicMicroOled'), (60, 'Qwiic 4m Distance Sensor (ToF)', 'QwiicVL53L1X'), (60, 'SSD1306 Display Driver', 'QwiicSSD1306Driver'), (60, 'Qwiic OLED Display (128x32)', 'QwiicOledDisplay'), (61, 'Qwiic Micro OLED (64x48)', 'QwiicMicroOled'), (61, 'Qwiic 4m Distance Sensor (ToF)', 'QwiicVL53L1X'), (61, 'SSD1306 Display Driver', 'QwiicSSD1306Driver'), (61, 'Qwiic OLED Display (128x32)', 'QwiicOledDisplay')] 456 | >>> mydevice1 = qwiic.create_device(results[47]) 457 | >>> print(mydevice1) 458 | 459 | >>> mydevice2 = qwiic.create_device(41) 460 | >>> print(mydevice2) 461 | 462 | >>> mydevice3 = qwiic.create_device("QwiicTitanGps") 463 | ============================================================================ 464 | Message about Titan GPS package... 465 | ============================================================================ 466 | >>> print(mydevice3) 467 | 468 | 469 | """ 470 | 471 | if device is None: 472 | print("No device provided.") 473 | return None 474 | 475 | conn_devices = list_devices() 476 | 477 | 478 | # The entries in the connDevices list are tuples, with the values: 479 | # (I2C address, Device Name, Class Name) 480 | # For the provided value (device), if a match is found in the current 481 | # device tuple, a list is created from the tuple 482 | if type(device) is tuple: 483 | dev_match = [curr_dev for curr_dev in conn_devices if device == curr_dev] 484 | else: 485 | dev_match = [curr_dev for curr_dev in conn_devices if device in curr_dev] 486 | 487 | 488 | # If there are no matching entries for the inputted device descriptor 489 | if len(dev_match) == 0: 490 | print("Error: No matching connected devices\n") 491 | 492 | return None 493 | 494 | # If there are mulitple entries for the inputted device descriptor 495 | elif len(dev_match) > 1: 496 | # Print out matched devices 497 | print("Error: Multiple matches found for input: \n") 498 | print(dev_match, "\n") 499 | 500 | return None 501 | 502 | # If there is a match 503 | else: 504 | # we need the class definition 505 | qwiic_defs = _QwiicInternal.get_available_devices() 506 | 507 | 508 | if type(device) is int: 509 | return qwiic_defs[device][0](int) 510 | else: 511 | # Match classes that are indexed at dev_address, to the dev_name 512 | for dev_class in qwiic_defs[dev_match[0][0]]: 513 | if dev_class.device_name == dev_match[0][1]: 514 | # Create a device using cless at the connected address 515 | return dev_class(dev_match[0][0]) 516 | 517 | 518 | # if we are here, we have an issue 519 | print("Unabled to create requested device - is the device connected?") 520 | 521 | return None 522 | --------------------------------------------------------------------------------