diff --git a/README.rst b/README.rst index 6f299ae..7336d5f 100644 --- a/README.rst +++ b/README.rst @@ -53,14 +53,15 @@ To install in a virtual environment in your current project: Usage Example ============= -:: +.. code:: python3 import time import board - import busio import adafruit_adxl34x - i2c = busio.I2C(board.SCL, board.SDA) + + i2c = board.I2C() # uses board.SCL and board.SDA accelerometer = adafruit_adxl34x.ADXL345(i2c) + while True: print("%f %f %f"%accelerometer.acceleration) time.sleep(1) diff --git a/adafruit_adxl34x.py b/adafruit_adxl34x.py index c9739cb..9b753a5 100755 --- a/adafruit_adxl34x.py +++ b/adafruit_adxl34x.py @@ -12,16 +12,19 @@ Based on drivers by K. Townsend and Tony DiCola + Implementation Notes -------------------- **Hardware:** -https://www.adafruit.com/product/1231 + +* Adafruit `ADXL345 Digital Accelerometer + `_ (Product ID: 1231) **Software and Dependencies:** * Adafruit CircuitPython firmware for the supported boards: - https://github.com/adafruit/circuitpython/releases + https://circuitpython.org/downloads * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice """ @@ -140,8 +143,32 @@ class Range: # pylint: disable=too-few-public-methods class ADXL345: """Driver for the ADXL345 3 axis accelerometer - :param ~busio.I2C i2c_bus: The I2C bus the ADXL345 is connected to. - :param address: The I2C device address for the sensor. Default is ``0x53``. + :param ~busio.I2C i2c: The I2C bus the ADXL345 is connected to. + :param address: The I2C device address for the sensor. Default is :const:`0x53`. + + **Quickstart: Importing and using the device** + + Here is an example of using the :class:`ADXL345` class. + First you will need to import the libraries to use the sensor + + .. code-block:: python + + import board + import adafruit_adxl34x + + Once this is done you can define your `board.I2C` object and define your sensor object + + .. code-block:: python + + i2c = board.I2C() # uses board.SCL and board.SDA + accelerometer = adafruit_adxl34x.ADXL343(i2c) + + + Now you have access to the :attr:`acceleration` attribute + + .. code-block:: python + + acceleration = accelerometer.acceleration """ @@ -158,7 +185,7 @@ def __init__(self, i2c, address=_ADXL345_DEFAULT_ADDRESS): @property def acceleration(self): - """The x, y, z acceleration values returned in a 3-tuple in m / s ^ 2.""" + """The x, y, z acceleration values returned in a 3-tuple in :math:`m / s ^ 2`""" x, y, z = unpack(" + .. toctree:: :caption: Related Products -.. https://www.adafruit.com/product/1231 + ADXL345 - Triple-Axis Accelerometer (+-2g/4g/8g/16g) w/ I2C/SPI .. toctree:: diff --git a/examples/adxl34x_freefall_detection_test.py b/examples/adxl34x_freefall_detection_test.py index 83a2a0e..689aa23 100644 --- a/examples/adxl34x_freefall_detection_test.py +++ b/examples/adxl34x_freefall_detection_test.py @@ -3,10 +3,9 @@ import time import board -import busio import adafruit_adxl34x -i2c = busio.I2C(board.SCL, board.SDA) +i2c = board.I2C() # uses board.SCL and board.SDA # For ADXL343 accelerometer = adafruit_adxl34x.ADXL343(i2c) diff --git a/examples/adxl34x_motion_detection_test.py b/examples/adxl34x_motion_detection_test.py index 70f4882..4367dd5 100644 --- a/examples/adxl34x_motion_detection_test.py +++ b/examples/adxl34x_motion_detection_test.py @@ -3,10 +3,9 @@ import time import board -import busio import adafruit_adxl34x -i2c = busio.I2C(board.SCL, board.SDA) +i2c = board.I2C() # uses board.SCL and board.SDA # For ADXL343 accelerometer = adafruit_adxl34x.ADXL343(i2c) diff --git a/examples/adxl34x_simpletest.py b/examples/adxl34x_simpletest.py index f1a18f8..f44d681 100644 --- a/examples/adxl34x_simpletest.py +++ b/examples/adxl34x_simpletest.py @@ -3,10 +3,9 @@ import time import board -import busio import adafruit_adxl34x -i2c = busio.I2C(board.SCL, board.SDA) +i2c = board.I2C() # uses board.SCL and board.SDA # For ADXL343 accelerometer = adafruit_adxl34x.ADXL343(i2c) diff --git a/examples/adxl34x_tap_detection_test.py b/examples/adxl34x_tap_detection_test.py index ed71338..9d3eabd 100644 --- a/examples/adxl34x_tap_detection_test.py +++ b/examples/adxl34x_tap_detection_test.py @@ -3,10 +3,9 @@ import time import board -import busio import adafruit_adxl34x -i2c = busio.I2C(board.SCL, board.SDA) +i2c = board.I2C() # uses board.SCL and board.SDA # For ADXL343 accelerometer = adafruit_adxl34x.ADXL343(i2c)