Skip to content

Initial working code! #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Introduction
:target: https://github.com/psf/black
:alt: Code Style: Black

A CircuitPython driver for the ADXL37x family of accelerometers
A CircuitPython I2C driver for the ADXL37x family of accelerometers


Dependencies
Expand All @@ -30,26 +30,21 @@ This driver depends on:

* `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_
* `Bus Device <https://github.com/adafruit/Adafruit_CircuitPython_BusDevice>`_
* `ADXL34x <https://github.com/adafruit/Adafruit_CircuitPython_ADXL34x>`_

Please ensure all dependencies are available on the CircuitPython filesystem.
This is easily achieved by downloading
`the Adafruit library and driver bundle <https://circuitpython.org/libraries>`_
or individual libraries can be installed using
`circup <https://github.com/adafruit/circup>`_.

.. todo:: Describe the Adafruit product this library works with. For PCBs, you can also add the
image from the assets folder in the PCB's GitHub repo.
This library works with the ADXL375 accelerometer breakout over I2C.

`Purchase one from the Adafruit shop <http://www.adafruit.com/products/5374>`_


Installing from PyPI
=====================
.. note:: This library is not available on PyPI yet. Install documentation is included
as a standard element. Stay tuned for PyPI availability!

.. todo:: Remove the above note if PyPI version is/will be available at time of release.

On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
PyPI <https://pypi.org/project/adafruit-circuitpython-adxl37x/>`_.
To install for current user:
Expand Down Expand Up @@ -101,19 +96,30 @@ Or the following command to update an existing version:
Usage Example
=============

.. todo:: Add a quick, simple example. It and other examples should live in the
examples folder and be included in docs/examples.rst.
.. code-block:: python

Contributing
============
import time
import board
import adafruit_adxl37x

i2c = board.I2C()
accelerometer = adafruit_adxl37x.ADXL375(i2c)

while True:
print("%f %f %f" % accelerometer.acceleration)
time.sleep(0.2)

Contributions are welcome! Please read our `Code of Conduct
<https://github.com/adafruit/Adafruit_CircuitPython_ADXL37x/blob/HEAD/CODE_OF_CONDUCT.md>`_
before contributing to help this project stay welcoming.

Documentation
=============
API documentation for this library can be found on `Read the Docs <https://docs.circuitpython.org/projects/adxl37x/en/latest/>`_.

For information on building library documentation, please check out
`this guide <https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs#sphinx-5-1>`_.

Contributing
============

Contributions are welcome! Please read our `Code of Conduct
<https://github.com/adafruit/Adafruit_CircuitPython_ADXL37x/blob/HEAD/CODE_OF_CONDUCT.md>`_
before contributing to help this project stay welcoming.
74 changes: 66 additions & 8 deletions adafruit_adxl37x.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,80 @@

**Hardware:**

.. todo:: Add links to any specific hardware product page(s), or category page(s).
Use unordered list & hyperlink rST inline format: "* `Link Text <url>`_"
* `ADXL375 - High G Accelerometer (+-200g) <https://www.adafruit.com/product/5374>`_

**Software and Dependencies:**

* Adafruit CircuitPython firmware for the supported boards:
https://github.com/adafruit/circuitpython/releases
https://circuitpython.org/downloads

.. todo:: Uncomment or remove the Bus Device and/or the Register library dependencies
based on the library's use of either.
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
* Adafruit CircuitPython ADXL34x: https://github.com/adafruit/Adafruit_CircuitPython_ADXL34x

# * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
# * Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
"""

# imports
from micropython import const
import adafruit_adxl34x

__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ADXL37x.git"

_ADXL375_DEFAULT_ADDRESS = const(0x53)


class DataRate(adafruit_adxl34x.DataRate): # pylint: disable=too-few-public-methods
"""Stub class for data rate."""


class Range(adafruit_adxl34x.Range): # pylint: disable=too-few-public-methods
"""Stub class for range."""


class ADXL375(adafruit_adxl34x.ADXL345):
"""
Driver for the ADXL375 accelerometer

:param ~busio.I2C i2c: The I2C bus the ADXL375 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:`ADXL375` class.
First you will need to import the libraries to use the sensor.

.. code-block:: python

import board
import adafruit_adxl37x

Once this is done you can define your `board.I2C` object and define your sensor object.
If using the STEMMA QT connector built into your microcontroller,
use ``board.STEMMA_I2C()``.

.. code-block:: python

i2c = board.I2C() # uses board.SCL and board.SDA
accelerometer = adafruit_adxl37x.ADXL375(i2c)

Now you have access to the :attr:`acceleration` attribute.

.. code-block:: python

acceleration = accelerometer.acceleration

"""

def __init__(self, i2c, address=None):
super().__init__(
i2c, address if address is not None else _ADXL375_DEFAULT_ADDRESS
)

@property
def range(self):
"""Range is fixed. Updating the range is not implemented."""
return

@range.setter
def range(self, val):
"""Range is fixed. Updating the range is not implemented."""
raise NotImplementedError("Range not implemented. ADXL375 is fixed at 200G.")
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@


intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),"BusDevice": ("https://docs.circuitpython.org/projects/busdevice/en/latest/", None),

"python": ("https://docs.python.org/3", None),
"BusDevice": ("https://docs.circuitpython.org/projects/busdevice/en/latest/", None),
"CircuitPython": ("https://docs.circuitpython.org/en/latest/", None),
}

Expand Down
6 changes: 2 additions & 4 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ Table of Contents
.. toctree::
:caption: Tutorials

.. todo:: Add any Learn guide links here. If there are none, then simply delete this todo and leave
the toctree above for use later.
Adafruit ADXL375 <https://learn.adafruit.com/adafruit-adxl375>

.. toctree::
:caption: Related Products

.. todo:: Add any product links here. If there are none, then simply delete this todo and leave
the toctree above for use later.
ADXL375 - High G Accelerometer with I2C - STEMMA QT <https://www.adafruit.com/product/5374>

.. toctree::
:caption: Other Links
Expand Down
12 changes: 11 additions & 1 deletion examples/adxl37x_simpletest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
# SPDX-FileCopyrightText: Copyright (c) 2022 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense
import time
import board
import adafruit_adxl37x

i2c = board.I2C() # uses board.SCL and board.SDA
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
accelerometer = adafruit_adxl37x.ADXL375(i2c)

while True:
print("%f %f %f" % accelerometer.acceleration)
time.sleep(0.2)
7 changes: 2 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
https://github.com/pypa/sampleproject
"""

from setuptools import setup, find_packages
from setuptools import setup

# To use a consistent encoding
from codecs import open
Expand Down Expand Up @@ -57,11 +57,8 @@
],
# What does your project relate to?
keywords="adafruit blinka circuitpython micropython adxl37x adxl375 motion acceleration "
"i2c spi triple axis",

"i2c spi triple axis",
# You can just specify the packages manually here if your project is
# simple. Or you can use find_packages().
# TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER,
# CHANGE `py_modules=['...']` TO `packages=['...']`
py_modules=["adafruit_adxl37x"],
)