Skip to content

Added comments to the examples files. #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 9 commits into from
Jun 19, 2018
Merged
Show file tree
Hide file tree
Changes from 8 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
9 changes: 6 additions & 3 deletions adafruit_l3gd20.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@

_L3GD20_REGISTER_CTRL_REG1 = const(0x20)
_L3GD20_REGISTER_CTRL_REG4 = const(0x23)
_L3GD20_REGISTER_OUT_X_L = const(0x28)

# _L3GD20_REGISTER_OUT_X_L = const(0x28)
_L3GD20_REGISTER_OUT_X_L_X80 = const(0xA8)
_L3GD20_REGISTER_OUT_X_L_X40 = const(0x68)

_ID_REGISTER = const(0x0F)

Expand Down Expand Up @@ -196,7 +199,7 @@ class L3GD20_I2C(L3GD20):
:param address: the optional device address, 0x68 is the default address
"""

acceleration_raw = Struct((_L3GD20_REGISTER_OUT_X_L | 0x80), '<hhh')
acceleration_raw = Struct(_L3GD20_REGISTER_OUT_X_L_X80, '<hhh')
"""Gives the raw acceleration readings, in units of the scaled mdps."""

def __init__(self, i2c, rng=L3DS20_RANGE_250DPS, address=0x6B):
Expand Down Expand Up @@ -288,5 +291,5 @@ def read_bytes(self, register, buffer):
def acceleration_raw(self):
"""Gives the raw acceleration readings, in units of the scaled mdps."""
buffer = self._spi_bytearray6
self.read_bytes((_L3GD20_REGISTER_OUT_X_L | 0x40), buffer)
self.read_bytes(_L3GD20_REGISTER_OUT_X_L_X40, buffer)
return unpack('<hhh', buffer)
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
# Uncomment the below if you use native CircuitPython modules such as
# digitalio, micropython and busio. List the modules you use. Without it, the
# autodoc module docs will fail to generate with a warning.
# autodoc_mock_imports = ["digitalio", "busio"]
autodoc_mock_imports = ["digitalio", "busio", "micropython", "adafruit_register",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only needs ["micropython", "adafruit_register"] since that is all that you import. struct/ustruct isn't needed (my mistake earlier; forgot struct is in CPython so Sphinx will import it without issue).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"struct", "ustruct"]


intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'Register': ('https://circuitpython.readthedocs.io/projects/register/en/latest/', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
Expand Down
8 changes: 7 additions & 1 deletion docs/examples.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
Simple test
------------

Ensure your device works with this simple test.
For I2C communications, ensure your device works with this simple test.

.. literalinclude:: ../examples/l3gd20_simpletest.py
:caption: examples/l3gd20_simpletest.py
:linenos:

For SPI communications, ensure your device works with this simple test.

.. literalinclude:: ../examples/l3gd20_spi_simpletest.py
:caption: examples/l3gd20_spi_simpletest.py
:linenos:
6 changes: 1 addition & 5 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,11 @@ 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 Triple Axis Gyro Breakout <https://learn.adafruit.com/adafruit-triple-axis-gyro-breakout>

.. toctree::
:caption: Related Products

Copy link
Collaborator

@sommersoft sommersoft Jun 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the related product. It is already in the .py file; grabbed this from there: L3GD20H Triple-Axis Gyro Breakout Board <https://www.adafruit.com/product/1032>

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

.. todo:: Add any product links here. If there are none, then simply delete this todo and leave
the toctree above for use later.

.. toctree::
:caption: Other Links

Expand Down
2 changes: 2 additions & 0 deletions examples/l3gd20_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import busio
import adafruit_l3gd20

# define the I2C wires
I2C = busio.I2C(SCL, SDA)
# initialize the device
SENSOR = adafruit_l3gd20.L3GD20_I2C(I2C)

while True:
Expand Down
3 changes: 3 additions & 0 deletions examples/l3gd20_spi_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import adafruit_l3gd20
import digitalio

# define the spi conneciton
CS = digitalio.DigitalInOut(D5) # select pin is 5
SPIB = busio.SPI(SCK, MOSI, MISO)
# now initialize the device
SENSOR = adafruit_l3gd20.L3GD20_SPI(SPIB, CS)

while True:
Expand All @@ -14,4 +16,5 @@

print()

#sleep for 1 second
time.sleep(1)