Qwiic_ADXL313_Py

follow on Twitter

SparkFun 3-Axis Digital Accelerometer Breakout - ADXL313 (Qwiic)

Python module for the SparkFun 3-Axis Digital Accelerometer Breakout - ADXL313 (Qwiic)

This python package is a port of the existing SparkFun ADXL313 Arduino Library

This package can be used in conjunction with the overall SparkFun qwiic Python Package

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

Dependencies

This driver package depends on the qwiic I2C driver: Qwiic_I2C_Py

Documentation

The SparkFun qwiic Adxl313 module documentation is hosted at ReadTheDocs

Installation

PyPi Installation

This repository is hosted on PyPi as the sparkfun-qwiic-adxl313 package. On systems that support PyPi installation via pip, this library is installed using the following commands

For all users (note: the user must have sudo privileges):

sudo pip install sparkfun-qwiic-adxl313

For the current user:

pip install sparkfun-qwiic-adxl313

Local Installation

To install, make sure the setuptools package is installed on the system.

Direct installation at the command line:

python setup.py install

To build a package for use with pip:

python setup.py sdist

A package file is built and placed in a subdirectory called dist. This package file can be installed using pip.

cd dist
pip install sparkfun_qwiic_adxl313-<version>.tar.gz

Example Use

See the examples directory for more detailed use examples.

from __future__ import print_function
import qwiic_adxl313
import time
import sys

def runExample():

    print("\nSparkFun Adxl313  Example 1 - Basic Readings\n")
    myAdxl = qwiic_adxl313.QwiicAdxl313()

    if myAdxl.connected == False:
        print("The Qwiic ADXL313 device isn't connected to the system. Please check your connection", \
            file=sys.stderr)
        return
    else:
        print("Device connected successfully.")

    myAdxl.measureModeOn()

    while True:
        if myAdxl.dataReady():
            myAdxl.readAccel() # read all axis from sensor, note this also updates all instance variables
            print(\
             '{: 06d}'.format(myAdxl.x)\
            , '\t', '{: 06d}'.format(myAdxl.y)\
            , '\t', '{: 06d}'.format(myAdxl.z)\
            )
            time.sleep(0.03)
        else:
            print("Waiting for data")
            time.sleep(0.5)

if __name__ == '__main__':
    try:
        runExample()
    except (KeyboardInterrupt, SystemExit) as exErr:
        print("\nEnding Example 1")
        sys.exit(0)

SparkFun - Start Something

Indices and tables