Skip to main content

Python Setup

Note: This package and the included examples assume you are using the latest version of Python 3. If this is your first time using Python or I²C hardware on a Raspberry Pi, these tutorials can help you get started:

We've written a Python package to control the KX13x Breakouts for users who prefer a Raspberry Pi or other Python-specific development environment. You can install the sparkfun-qwiic-kx13x Python package hosted by PyPi through a command interface. If you prefer to manually download and build the libraries from the GitHub repository.

*Please be aware of any package dependencies. You can also check out the repository documentation page, hosted on Read the Docs.

Installation

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.

Python

PyPi Installation

The package is primarily installed using the pip3 command, downloading the package from the Python Index - "PyPi".

Note - the below instructions outline installation on a Linux-based (Raspberry Pi) system.

First, setup a virtual environment from a specific directory using venv:

python3 -m venv path/to/venv

You can pass any path as path/to/venv, just make sure you use the same one for all future steps. Visit this link for more information on venv.

Next, install the qwiic package with:

path/to/venv/bin/pip3 install sparkfun-qwiic-kx13x

Now you should be able to run any example or custom python scripts that have import qwiic_kx13x by running e.g.:

path/to/venv/bin/python3 example_script.py

MicroPython Installation

If not already installed, follow the instructions here to install mpremote on your computer.

Connect a device with MicroPython installed to your computer and then install the package directly to your device with mpremote mip.

mpremote mip install github:sparkfun/qwiic_kx13x_py

If you would also like to install the examples for this repository, issue the following mip command as well:

mpremote mip install --target "" github:sparkfun/qwiic_kx13x_py@examples

CircuitPython Installation

If not already installed, follow the instructions here to install CircUp on your computer.

Ensure that you have the latest version of the SparkFun Qwiic CircuitPython bundle.

circup bundle-add sparkfun/Qwiic_Py

Finally, connect a device with CircuitPython installed to your computer and then install the package directly to your device with circup.

circup install --py qwiic_kx13x

If you would like to install any of the examples from this repository, issue the corresponding circup command from below. (NOTE: The below syntax assumes you are using CircUp on Windows. Linux and Mac will have different path seperators. See the CircUp "example" command documentation for more information)

circup example qwiic_kx13x\qwiic_kx13x_ex1
circup example qwiic_kx13x\qwiic_kx13x_ex3
circup example qwiic_kx13x\qwiic_kx13x_ex4