Skip to content

Commit 1cb3e85

Browse files
authored
Merge pull request #1 from kattni/initial
Initial working code!
2 parents 27270c7 + d7d6560 commit 1cb3e85

File tree

6 files changed

+104
-35
lines changed

6 files changed

+104
-35
lines changed

README.rst

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Introduction
2121
:target: https://github.com/psf/black
2222
:alt: Code Style: Black
2323

24-
A CircuitPython driver for the ADXL37x family of accelerometers
24+
A CircuitPython I2C driver for the ADXL37x family of accelerometers
2525

2626

2727
Dependencies
@@ -30,26 +30,21 @@ This driver depends on:
3030

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

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

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

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

4545

4646
Installing from PyPI
4747
=====================
48-
.. note:: This library is not available on PyPI yet. Install documentation is included
49-
as a standard element. Stay tuned for PyPI availability!
50-
51-
.. todo:: Remove the above note if PyPI version is/will be available at time of release.
52-
5348
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
5449
PyPI <https://pypi.org/project/adafruit-circuitpython-adxl37x/>`_.
5550
To install for current user:
@@ -101,19 +96,30 @@ Or the following command to update an existing version:
10196
Usage Example
10297
=============
10398

104-
.. todo:: Add a quick, simple example. It and other examples should live in the
105-
examples folder and be included in docs/examples.rst.
99+
.. code-block:: python
106100
107-
Contributing
108-
============
101+
import time
102+
import board
103+
import adafruit_adxl37x
104+
105+
i2c = board.I2C()
106+
accelerometer = adafruit_adxl37x.ADXL375(i2c)
107+
108+
while True:
109+
print("%f %f %f" % accelerometer.acceleration)
110+
time.sleep(0.2)
109111
110-
Contributions are welcome! Please read our `Code of Conduct
111-
<https://github.com/adafruit/Adafruit_CircuitPython_ADXL37x/blob/HEAD/CODE_OF_CONDUCT.md>`_
112-
before contributing to help this project stay welcoming.
113112
114113
Documentation
115114
=============
116115
API documentation for this library can be found on `Read the Docs <https://docs.circuitpython.org/projects/adxl37x/en/latest/>`_.
117116

118117
For information on building library documentation, please check out
119118
`this guide <https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs#sphinx-5-1>`_.
119+
120+
Contributing
121+
============
122+
123+
Contributions are welcome! Please read our `Code of Conduct
124+
<https://github.com/adafruit/Adafruit_CircuitPython_ADXL37x/blob/HEAD/CODE_OF_CONDUCT.md>`_
125+
before contributing to help this project stay welcoming.

adafruit_adxl37x.py

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,80 @@
1616
1717
**Hardware:**
1818
19-
.. todo:: Add links to any specific hardware product page(s), or category page(s).
20-
Use unordered list & hyperlink rST inline format: "* `Link Text <url>`_"
19+
* `ADXL375 - High G Accelerometer (+-200g) <https://www.adafruit.com/product/5374>`_
2120
2221
**Software and Dependencies:**
2322
2423
* Adafruit CircuitPython firmware for the supported boards:
25-
https://github.com/adafruit/circuitpython/releases
24+
https://circuitpython.org/downloads
2625
27-
.. todo:: Uncomment or remove the Bus Device and/or the Register library dependencies
28-
based on the library's use of either.
26+
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
27+
* Adafruit CircuitPython ADXL34x: https://github.com/adafruit/Adafruit_CircuitPython_ADXL34x
2928
30-
# * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
31-
# * Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
3229
"""
3330

34-
# imports
31+
from micropython import const
32+
import adafruit_adxl34x
3533

3634
__version__ = "0.0.0-auto.0"
3735
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ADXL37x.git"
36+
37+
_ADXL375_DEFAULT_ADDRESS = const(0x53)
38+
39+
40+
class DataRate(adafruit_adxl34x.DataRate): # pylint: disable=too-few-public-methods
41+
"""Stub class for data rate."""
42+
43+
44+
class Range(adafruit_adxl34x.Range): # pylint: disable=too-few-public-methods
45+
"""Stub class for range."""
46+
47+
48+
class ADXL375(adafruit_adxl34x.ADXL345):
49+
"""
50+
Driver for the ADXL375 accelerometer
51+
52+
:param ~busio.I2C i2c: The I2C bus the ADXL375 is connected to.
53+
:param address: The I2C device address for the sensor. Default is :const:`0x53`.
54+
55+
**Quickstart: Importing and using the device**
56+
57+
Here is an example of using the :class:`ADXL375` class.
58+
First you will need to import the libraries to use the sensor.
59+
60+
.. code-block:: python
61+
62+
import board
63+
import adafruit_adxl37x
64+
65+
Once this is done you can define your `board.I2C` object and define your sensor object.
66+
If using the STEMMA QT connector built into your microcontroller,
67+
use ``board.STEMMA_I2C()``.
68+
69+
.. code-block:: python
70+
71+
i2c = board.I2C() # uses board.SCL and board.SDA
72+
accelerometer = adafruit_adxl37x.ADXL375(i2c)
73+
74+
Now you have access to the :attr:`acceleration` attribute.
75+
76+
.. code-block:: python
77+
78+
acceleration = accelerometer.acceleration
79+
80+
"""
81+
82+
def __init__(self, i2c, address=None):
83+
super().__init__(
84+
i2c, address if address is not None else _ADXL375_DEFAULT_ADDRESS
85+
)
86+
87+
@property
88+
def range(self):
89+
"""Range is fixed. Updating the range is not implemented."""
90+
return
91+
92+
@range.setter
93+
def range(self, val):
94+
"""Range is fixed. Updating the range is not implemented."""
95+
raise NotImplementedError("Range not implemented. ADXL375 is fixed at 200G.")

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929

3030

3131
intersphinx_mapping = {
32-
"python": ("https://docs.python.org/3", None),"BusDevice": ("https://docs.circuitpython.org/projects/busdevice/en/latest/", None),
33-
32+
"python": ("https://docs.python.org/3", None),
33+
"BusDevice": ("https://docs.circuitpython.org/projects/busdevice/en/latest/", None),
3434
"CircuitPython": ("https://docs.circuitpython.org/en/latest/", None),
3535
}
3636

docs/index.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@ Table of Contents
2424
.. toctree::
2525
:caption: Tutorials
2626

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

3029
.. toctree::
3130
:caption: Related Products
3231

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

3634
.. toctree::
3735
:caption: Other Links

examples/adxl37x_simpletest.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
21
# SPDX-FileCopyrightText: Copyright (c) 2022 Kattni Rembor for Adafruit Industries
32
#
43
# SPDX-License-Identifier: Unlicense
4+
import time
5+
import board
6+
import adafruit_adxl37x
7+
8+
i2c = board.I2C() # uses board.SCL and board.SDA
9+
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
10+
accelerometer = adafruit_adxl37x.ADXL375(i2c)
11+
12+
while True:
13+
print("%f %f %f" % accelerometer.acceleration)
14+
time.sleep(0.2)

setup.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
https://github.com/pypa/sampleproject
1111
"""
1212

13-
from setuptools import setup, find_packages
13+
from setuptools import setup
1414

1515
# To use a consistent encoding
1616
from codecs import open
@@ -57,11 +57,8 @@
5757
],
5858
# What does your project relate to?
5959
keywords="adafruit blinka circuitpython micropython adxl37x adxl375 motion acceleration "
60-
"i2c spi triple axis",
61-
60+
"i2c spi triple axis",
6261
# You can just specify the packages manually here if your project is
6362
# simple. Or you can use find_packages().
64-
# TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER,
65-
# CHANGE `py_modules=['...']` TO `packages=['...']`
6663
py_modules=["adafruit_adxl37x"],
6764
)

0 commit comments

Comments
 (0)