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 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
21 changes: 15 additions & 6 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 All @@ -84,16 +87,22 @@ class L3GD20: # pylint: disable=no-member
"""
Driver for the L3GD20 3-axis Gyroscope sensor.

:param int rng: a range value one of L3DS20_RANGE_250DPS, L3DS20_RANGE_500DPS, or
:param int rng: a range value one of L3DS20_RANGE_250DPS (default), L3DS20_RANGE_500DPS, or
L3DS20_RANGE_2000DPS
"""

def __init__(self, rng):
def __init__(self, rng=L3DS20_RANGE_250DPS):
chip_id = self.read_register(_ID_REGISTER)
if chip_id != _L3GD20_CHIP_ID and chip_id != _L3GD20H_CHIP_ID:
raise RuntimeError("bad chip id (%x != %x or %x)" %
(chip_id, _L3GD20_CHIP_ID, _L3GD20H_CHIP_ID))

if rng != L3DS20_RANGE_250DPS and \
rng != L3DS20_RANGE_500DPS and \
rng != L3DS20_RANGE_2000DPS:
raise ValueError("Range value must be one of L3DS20_RANGE_250DPS, "
"L3DS20_RANGE_500DPS, or L3DS20_RANGE_2000DPS")

# Set CTRL_REG1 (0x20)
# ====================================================================
# BIT Symbol Description Default
Expand Down Expand Up @@ -196,7 +205,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 All @@ -219,7 +228,7 @@ def write_register(self, register, value):

def read_register(self, register):
"""
Get a byte value from a register
Returns a byte value from a register

:param register: the register to read a byte
"""
Expand Down Expand Up @@ -288,5 +297,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)
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# 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 = ["micropython", "adafruit_register"]


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: 2 additions & 4 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,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 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.
L3GD20H Triple-Axis Gyro Breakout Board <https://www.adafruit.com/product/1032>

.. 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)