Skip to content

Commit bbf7e0d

Browse files
authored
Merge pull request #1 from mrmcwethy/initial
Thanks @mrmcwethy!
2 parents b7a1853 + 2c30637 commit bbf7e0d

File tree

6 files changed

+30
-12
lines changed

6 files changed

+30
-12
lines changed

adafruit_l3gd20.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@
6868

6969
_L3GD20_REGISTER_CTRL_REG1 = const(0x20)
7070
_L3GD20_REGISTER_CTRL_REG4 = const(0x23)
71-
_L3GD20_REGISTER_OUT_X_L = const(0x28)
71+
72+
# _L3GD20_REGISTER_OUT_X_L = const(0x28)
73+
_L3GD20_REGISTER_OUT_X_L_X80 = const(0xA8)
74+
_L3GD20_REGISTER_OUT_X_L_X40 = const(0x68)
7275

7376
_ID_REGISTER = const(0x0F)
7477

@@ -84,16 +87,22 @@ class L3GD20: # pylint: disable=no-member
8487
"""
8588
Driver for the L3GD20 3-axis Gyroscope sensor.
8689
87-
:param int rng: a range value one of L3DS20_RANGE_250DPS, L3DS20_RANGE_500DPS, or
90+
:param int rng: a range value one of L3DS20_RANGE_250DPS (default), L3DS20_RANGE_500DPS, or
8891
L3DS20_RANGE_2000DPS
8992
"""
9093

91-
def __init__(self, rng):
94+
def __init__(self, rng=L3DS20_RANGE_250DPS):
9295
chip_id = self.read_register(_ID_REGISTER)
9396
if chip_id != _L3GD20_CHIP_ID and chip_id != _L3GD20H_CHIP_ID:
9497
raise RuntimeError("bad chip id (%x != %x or %x)" %
9598
(chip_id, _L3GD20_CHIP_ID, _L3GD20H_CHIP_ID))
9699

100+
if rng != L3DS20_RANGE_250DPS and \
101+
rng != L3DS20_RANGE_500DPS and \
102+
rng != L3DS20_RANGE_2000DPS:
103+
raise ValueError("Range value must be one of L3DS20_RANGE_250DPS, "
104+
"L3DS20_RANGE_500DPS, or L3DS20_RANGE_2000DPS")
105+
97106
# Set CTRL_REG1 (0x20)
98107
# ====================================================================
99108
# BIT Symbol Description Default
@@ -196,7 +205,7 @@ class L3GD20_I2C(L3GD20):
196205
:param address: the optional device address, 0x68 is the default address
197206
"""
198207

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

202211
def __init__(self, i2c, rng=L3DS20_RANGE_250DPS, address=0x6B):
@@ -219,7 +228,7 @@ def write_register(self, register, value):
219228

220229
def read_register(self, register):
221230
"""
222-
Get a byte value from a register
231+
Returns a byte value from a register
223232
224233
:param register: the register to read a byte
225234
"""
@@ -288,5 +297,5 @@ def read_bytes(self, register, buffer):
288297
def acceleration_raw(self):
289298
"""Gives the raw acceleration readings, in units of the scaled mdps."""
290299
buffer = self._spi_bytearray6
291-
self.read_bytes((_L3GD20_REGISTER_OUT_X_L | 0x40), buffer)
300+
self.read_bytes(_L3GD20_REGISTER_OUT_X_L_X40, buffer)
292301
return unpack('<hhh', buffer)

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# Uncomment the below if you use native CircuitPython modules such as
2121
# digitalio, micropython and busio. List the modules you use. Without it, the
2222
# autodoc module docs will fail to generate with a warning.
23-
# autodoc_mock_imports = ["digitalio", "busio"]
23+
autodoc_mock_imports = ["micropython", "adafruit_register"]
2424

2525

2626
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)}

docs/examples.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
Simple test
22
------------
33

4-
Ensure your device works with this simple test.
4+
For I2C communications, ensure your device works with this simple test.
55

66
.. literalinclude:: ../examples/l3gd20_simpletest.py
77
:caption: examples/l3gd20_simpletest.py
88
:linenos:
9+
10+
For SPI communications, ensure your device works with this simple test.
11+
12+
.. literalinclude:: ../examples/l3gd20_spi_simpletest.py
13+
:caption: examples/l3gd20_spi_simpletest.py
14+
:linenos:

docs/index.rst

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

26-
.. todo:: Add any Learn guide links here. If there are none, then simply delete this todo and leave
27-
the toctree above for use later.
26+
Adafruit Triple Axis Gyro Breakout <https://learn.adafruit.com/adafruit-triple-axis-gyro-breakout>
2827

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

32-
.. todo:: Add any product links here. If there are none, then simply delete this todo and leave
33-
the toctree above for use later.
31+
L3GD20H Triple-Axis Gyro Breakout Board <https://www.adafruit.com/product/1032>
3432

3533
.. toctree::
3634
:caption: Other Links

examples/l3gd20_simpletest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import busio
44
import adafruit_l3gd20
55

6+
# define the I2C wires
67
I2C = busio.I2C(SCL, SDA)
8+
# initialize the device
79
SENSOR = adafruit_l3gd20.L3GD20_I2C(I2C)
810

911
while True:

examples/l3gd20_spi_simpletest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import adafruit_l3gd20
55
import digitalio
66

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

1113
while True:
@@ -14,4 +16,5 @@
1416

1517
print()
1618

19+
#sleep for 1 second
1720
time.sleep(1)

0 commit comments

Comments
 (0)