Qwiic_KX13X_Py  packaging_test1
Python for SFE Qwiic KX13X
Loading...
Searching...
No Matches
Qwiic_KX13X_Py

SparkFun Qwiic KX13X - Python Package

PyPi Version GitHub issues License X API

The SparkFun Qwiic Accelerometer KX13X Module provides a simple and cost effective solution for adding Accelerometer capabilities to your project. Implementing a SparkFun Qwiic I2C interface, these sensors can be rapidly added to any project with boards that are part of the SparkFun Qwiic ecosystem.

This repository implements a Python package for the SparkFun Qwiic KX13X. This package works with Python, MicroPython and CircuitPython.

Contents

  • About
  • Getting Started
  • Installation
  • Supported Platforms
  • Documentation
  • Examples

About the Package

This python package enables the user to access the features of the KX13X via a single Qwiic cable. This includes <reading 3-axis acceleration, managing interrupts> and more. The capabilities of the KX13X are each demonstrated in the included examples.

New to qwiic? Take a look at the entire SparkFun qwiic ecosystem.

Supported SparkFun Products

This Python package supports the following SparkFun qwiic products on Python, MicroPython and Circuit python.

Supported Platforms

Python Platform Boards
Python Linux Raspberry Pi , NVIDIA Jetson Orin Nano via the SparkFun Qwiic SHIM
MicroPython Raspberry Pi - RP2, ESP32 SparkFun RP2040 Thing+, SparkFun RP2350 Thing+, SparkFun ESP32 Thing+
CircuitPython Raspberry Pi - RP2, ESP32 SparkFun RP2040 Thing+, SparkFun RP2350 Thing+, SparkFun ESP32 Thing+

‍[!NOTE] 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.

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. For more information on venv click here.

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:

mprmeote mip install 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 (i.e. "/" vs. "\"). See the <a href="https://learn.adafruit.com/keep-your-circuitpython-libraries-on-devices-up-to-date-with-circup/example-command" >CircUp \"example\" command documentation</a> for more information) @icode{sh} circup example qwiic_kx13x\qwiic_kx13x_ex1 circup example qwiic_kx13x\qwiic_kx13x_ex3 circup example qwiic_kx13x\qwiic_kx13x_ex4 @endicode @subsection autotoc_md10 Example Use Below is a quickstart program to print readings from the KX13X. See the examples directory for more detailed use examples and <a href="https://github.com/sparkfun/qwiic_kx13x_py/blob/main/examples/README.md" >examples/README.md</a> for a summary of the available examples. @icode{python} import qwiic_kx13x import time import sys def runExample(): print("\nSparkFun KX13X Accelerometer Example 1
") myKx = qwiic_kx13x.QwiicKX132() if myKx.connected == False: print("The Qwiic KX13X Accelerometer device isn't connected to the system. Please check your connection", \ file=sys.stderr) return if myKx.begin(): print("Ready.") else: print("Make sure you're using the KX132 and not the KX134") if (myKx.software_reset()): print("Reset") myKx.enable_accel(False) myKx.set_range(myKx.KX132_RANGE16G) myKx.enable_data_engine() myKx.enable_accel() while True: if myKx.data_ready(): myKx.get_accel_data() print("X: {0} Y: {1} Z: {2}".format(myKx.kx132_accel.x, myKx.kx132_accel.y, myKx.kx132_accel.z)) time.sleep(.02) #Set delay to 1/Output Data Rate which is by default 50Hz 1/50 = .02 if __name__ == '__main__': try: runExample() except (KeyboardInterrupt, SystemExit) as exErr: print("\nEnding Example 1") sys.exit(0) @endicode <p align="center"> <img src="https://cdn.sparkfun.com/assets/custom_pages/3/3/4/dark-logo-red-flame.png" alt="SparkFun - Start Something">