Skip to content

Commit 2a25e0c

Browse files
authored
Merge pull request #16 from jposada202020/improving_docs
improving_docs
2 parents 0f4c519 + 74747e4 commit 2a25e0c

8 files changed

+78
-44
lines changed

README.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,13 @@ To install in a virtual environment in your current project:
5555
Usage Example
5656
=============
5757

58-
.. code-block:: python
58+
.. code-block:: python3
5959
6060
import time
6161
import board
62-
import busio
6362
import adafruit_mpu6050
6463
65-
i2c = busio.I2C(board.SCL, board.SDA)
64+
i2c = board.I2C() # uses board.SCL and board.SDA
6665
mpu = adafruit_mpu6050.MPU6050(i2c)
6766
6867
while True:

adafruit_mpu6050.py

Lines changed: 59 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@
1515
--------------------
1616
1717
**Hardware:**
18-
* Adafruit's MPU6050 Breakout: https://adafruit.com/products/3886
18+
19+
* Adafruit `MPU-6050 6-DoF Accel and Gyro Sensor
20+
<https://www.adafruit.com/product/3886>`_
1921
2022
**Software and Dependencies:**
2123
2224
* Adafruit CircuitPython firmware for the supported boards:
23-
https://github.com/adafruit/circuitpython/releases
24-
25-
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
26-
* Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
25+
https://circuitpython.org/downloads
26+
* Adafruit's Bus Device library:
27+
https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
28+
* Adafruit's Register library:
29+
https://github.com/adafruit/Adafruit_CircuitPython_Register
2730
"""
2831

2932
# imports
@@ -65,10 +68,10 @@
6568
class Range: # pylint: disable=too-few-public-methods
6669
"""Allowed values for `accelerometer_range`.
6770
68-
- ``Range.RANGE_2_G``
69-
- ``Range.RANGE_4_G``
70-
- ``Range.RANGE_8_G``
71-
- ``Range.RANGE_16_G``
71+
- :attr:`Range.RANGE_2_G`
72+
- :attr:`Range.RANGE_4_G`
73+
- :attr:`Range.RANGE_8_G`
74+
- :attr:`Range.RANGE_16_G`
7275
7376
"""
7477

@@ -81,10 +84,10 @@ class Range: # pylint: disable=too-few-public-methods
8184
class GyroRange: # pylint: disable=too-few-public-methods
8285
"""Allowed values for `gyro_range`.
8386
84-
- ``GyroRange.RANGE_250_DPS``
85-
- ``GyroRange.RANGE_500_DPS``
86-
- ``GyroRange.RANGE_1000_DPS``
87-
- ``GyroRange.RANGE_2000_DPS``
87+
- :attr:`GyroRange.RANGE_250_DPS`
88+
- :attr:`GyroRange.RANGE_500_DPS`
89+
- :attr:`GyroRange.RANGE_1000_DPS`
90+
- :attr:`GyroRange.RANGE_2000_DPS`
8891
8992
"""
9093

@@ -97,13 +100,13 @@ class GyroRange: # pylint: disable=too-few-public-methods
97100
class Bandwidth: # pylint: disable=too-few-public-methods
98101
"""Allowed values for `filter_bandwidth`.
99102
100-
- ``Bandwidth.BAND_260_HZ``
101-
- ``Bandwidth.BAND_184_HZ``
102-
- ``Bandwidth.BAND_94_HZ``
103-
- ``Bandwidth.BAND_44_HZ``
104-
- ``Bandwidth.BAND_21_HZ``
105-
- ``Bandwidth.BAND_10_HZ``
106-
- ``Bandwidth.BAND_5_HZ``
103+
- :attr:`Bandwidth.BAND_260_HZ`
104+
- :attr:`Bandwidth.BAND_184_HZ`
105+
- :attr:`Bandwidth.BAND_94_HZ`
106+
- :attr:`Bandwidth.BAND_44_HZ`
107+
- :attr:`Bandwidth.BAND_21_HZ`
108+
- :attr:`Bandwidth.BAND_10_HZ`
109+
- :attr:`Bandwidth.BAND_5_HZ`
107110
108111
"""
109112

@@ -119,10 +122,10 @@ class Bandwidth: # pylint: disable=too-few-public-methods
119122
class Rate: # pylint: disable=too-few-public-methods
120123
"""Allowed values for `cycle_rate`.
121124
122-
- ``Rate.CYCLE_1_25_HZ``
123-
- ``Rate.CYCLE_5_HZ``
124-
- ``Rate.CYCLE_20_HZ``
125-
- ``Rate.CYCLE_40_HZ``
125+
- :attr:`Rate.CYCLE_1_25_HZ`
126+
- :attr:`Rate.CYCLE_5_HZ`
127+
- :attr:`Rate.CYCLE_20_HZ`
128+
- :attr:`Rate.CYCLE_40_HZ`
126129
127130
"""
128131

@@ -135,8 +138,34 @@ class Rate: # pylint: disable=too-few-public-methods
135138
class MPU6050:
136139
"""Driver for the MPU6050 6-DoF accelerometer and gyroscope.
137140
138-
:param ~busio.I2C i2c_bus: The I2C bus the MPU6050 is connected to.
139-
:param address: The I2C slave address of the sensor
141+
:param ~busio.I2C i2c_bus: The I2C bus the device is connected to
142+
:param int address: The I2C device address. Defaults to :const:`0x68`
143+
144+
**Quickstart: Importing and using the device**
145+
146+
Here is an example of using the :class:`MPU6050` class.
147+
First you will need to import the libraries to use the sensor
148+
149+
.. code-block:: python
150+
151+
import board
152+
import adafruit_mpu6050
153+
154+
Once this is done you can define your `board.I2C` object and define your sensor object
155+
156+
.. code-block:: python
157+
158+
i2c = board.I2C() # uses board.SCL and board.SDA
159+
mpu = adafruit_mpu6050.MPU6050(i2c)
160+
161+
Now you have access to the :attr:`acceleration`, :attr:`gyro`
162+
and :attr:`temperature` attributes
163+
164+
.. code-block:: python
165+
166+
acc_x, acc_y, acc_z = sensor.acceleration
167+
gyro_x, gyro_y, gyro_z = sensor.gyro
168+
temperature = sensor.temperature
140169
141170
"""
142171

@@ -194,14 +223,14 @@ def reset(self):
194223

195224
@property
196225
def temperature(self):
197-
"""The current temperature in º C"""
226+
"""The current temperature in º Celsius"""
198227
raw_temperature = self._raw_temp_data
199228
temp = (raw_temperature / 340.0) + 36.53
200229
return temp
201230

202231
@property
203232
def acceleration(self):
204-
"""Acceleration X, Y, and Z axis data in m/s^2"""
233+
"""Acceleration X, Y, and Z axis data in :math:`m/s^2` """
205234
raw_data = self._raw_accel_data
206235
raw_x = raw_data[0][0]
207236
raw_y = raw_data[1][0]
@@ -227,7 +256,7 @@ def acceleration(self):
227256

228257
@property
229258
def gyro(self):
230-
"""Gyroscope X, Y, and Z axis data in º/s"""
259+
"""Gyroscope X, Y, and Z axis data in :math:`º/s` """
231260
raw_data = self._raw_gyro_data
232261
raw_x = raw_data[0][0]
233262
raw_y = raw_data[1][0]
@@ -253,7 +282,7 @@ def gyro(self):
253282

254283
@property
255284
def cycle(self):
256-
"""Enable or disable perodic measurement at a rate set by `cycle_rate`.
285+
"""Enable or disable periodic measurement at a rate set by :meth:`cycle_rate`.
257286
If the sensor was in sleep mode, it will be waken up to cycle"""
258287
return self._cycle
259288

docs/examples.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,12 @@ by viewing the data in a serial plotter
2626
.. literalinclude:: ../examples/mpu6050_sleep_example.py
2727
:caption: examples/mpu6050_sleep_example.py
2828
:linenos:
29+
30+
Inclinometer Example
31+
--------------------
32+
33+
Provides an example on how to use the sensor as an inclinometer
34+
35+
.. literalinclude:: ../examples/mpu6050_inclinometer.py
36+
:caption: examples/mpu6050_inclinometer.py
37+
:linenos:

docs/index.rst

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

26-
26+
Adafruit MPU-6050 6-DoF Accel and Gyro Sensor Learning Guide <https://learn.adafruit.com/mpu6050-6-dof-accelerometer-and-gyro>
2727

2828
.. toctree::
2929
:caption: Related Products
3030

31-
* Adafruit's MPU6050 Breakout: https://adafruit.com/products/3886
31+
Adafruit MPU-6050 6-DoF Accel and Gyro Sensor <https://adafruit.com/products/3886>
3232

3333

3434

examples/mpu6050_inclinometer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
import time
1010
from math import atan2, degrees
1111
import board
12-
import busio
1312
import adafruit_mpu6050
1413

15-
i2c = busio.I2C(board.SCL, board.SDA)
14+
i2c = board.I2C() # uses board.SCL and board.SDA
1615
sensor = adafruit_mpu6050.MPU6050(i2c)
1716

1817

examples/mpu6050_plotter_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
import time
55
import board
6-
import busio
76
import adafruit_mpu6050
87

9-
i2c = busio.I2C(board.SCL, board.SDA)
8+
i2c = board.I2C() # uses board.SCL and board.SDA
109
mpu = adafruit_mpu6050.MPU6050(i2c)
1110
mpu.accelerometer_range = adafruit_mpu6050.Range.RANGE_2_G
1211
mpu.gyro_range = adafruit_mpu6050.GyroRange.RANGE_250_DPS
12+
1313
while True:
1414
# this prints out all the values like a tuple which Mu's plotter prefer
1515
print("(%.2f, %.2f, %.2f " % (mpu.acceleration), end=", ")

examples/mpu6050_simpletest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33

44
import time
55
import board
6-
import busio
76
import adafruit_mpu6050
87

9-
i2c = busio.I2C(board.SCL, board.SDA)
8+
i2c = board.I2C() # uses board.SCL and board.SDA
109
mpu = adafruit_mpu6050.MPU6050(i2c)
1110

1211
while True:

examples/mpu6050_sleep_example.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33

44
import time
55
import board
6-
import busio
76
import adafruit_mpu6050
87

9-
i2c = busio.I2C(board.SCL, board.SDA)
8+
i2c = board.I2C() # uses board.SCL and board.SDA
109
mpu = adafruit_mpu6050.MPU6050(i2c)
1110

1211
# This example is meant to be used with the serial plotter which makes
1312
# it easier to see how the readings change with different settings.
1413
# Make sure to poke and prod the sensor while the demo is running to
15-
# generate some intersting data!
14+
# generate some interesting data!
1615

1716
while True:
1817
# first show some 'normal' readings

0 commit comments

Comments
 (0)