Skip to content
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
34 changes: 34 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,40 @@ specific conventions and guidelines for micropython-lib:
packages](README.md#installing-packages-from-forks) in your Pull Request
description.

### Module documentation

Each package in micropython-lib is encouraged to include documentation in
the form of docstrings in the code itself. The top-level docstring in the main
module or package should provide an overview of the package's functionality,
usage examples, and any important notes or caveats.

Note that the docstrings should be concise and relevant, even though they will
not be included in the cross-compiled bytecode and will not impact the size of
the module when installed via `mip`.

When writing docstrings, please follow these guidelines:
* Use triple double quotes (`"""`) for docstrings.
* Multi-line docstrings should place the starting and ending triple quotes on
their own lines.
* Start with a brief summary of the module's purpose.
* Include usage examples where appropriate (indent examplecode blocks with 4
spaces).
* Use proper indentation for multi-line docstrings to align with the code block.

### Module versioning

Each package in micropython-lib should include a `manifest.py` file that
specifies metadata about the package, including its version. The version
management is intentionally manual to ensure package stability and prevent
accidental version bumps. When making changes to a package that affect its
functionality or API, please update the version in `manifest.py`. The
`tools/build.py` script will detect new versions and add them to the index, but
won't increment versions automatically

> [!NOTE]
> Changes to docstrings or comments that do not change the generated bytecode
> should not change the version.

### Publishing packages from forks

You can easily publish the packages from your micropython-lib
Expand Down
2 changes: 1 addition & 1 deletion micropython/bluetooth/aioble/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async with aioble.scan(duration_ms=5000, interval_us=30000, window_us=30000, act
# Either from scan result
device = result.device
# Or with known address
device = aioble.Device(aioble.PUBLIC, "aa:bb:cc:dd:ee:ff")
device = aioble.Device(aioble.ADDR_PUBLIC, "aa:bb:cc:dd:ee:ff")

try:
connection = await device.connect(timeout_ms=2000)
Expand Down
4 changes: 2 additions & 2 deletions micropython/bluetooth/aioble/examples/temp_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
_ADV_APPEARANCE_GENERIC_THERMOMETER = const(768)

# How frequently to send advertising beacons.
_ADV_INTERVAL_MS = 250_000
_ADV_INTERVAL_US = 250_000


# Register GATT server.
Expand Down Expand Up @@ -50,7 +50,7 @@ async def sensor_task():
async def peripheral_task():
while True:
async with await aioble.advertise(
_ADV_INTERVAL_MS,
_ADV_INTERVAL_US,
name="mpy-temp",
services=[_ENV_SENSE_UUID],
appearance=_ADV_APPEARANCE_GENERIC_THERMOMETER,
Expand Down
38 changes: 20 additions & 18 deletions micropython/drivers/imu/bmi270/bmi270.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,31 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Basic example usage:
Basic example usage::

import time
from bmi270 import BMI270
from machine import Pin, SPI, I2C

# Init in I2C mode.
imu = BMI270(I2C(1, scl=Pin(15), sda=Pin(14)))

# Or init in SPI mode.
# TODO: Not supported yet.
# imu = BMI270(SPI(5), cs=Pin(10))

while (True):
print('Accelerometer: x:{:>6.3f} y:{:>6.3f} z:{:>6.3f}'.format(*imu.accel()))
print('Gyroscope: x:{:>6.3f} y:{:>6.3f} z:{:>6.3f}'.format(*imu.gyro()))
print('Magnetometer: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*imu.magnet()))
print("")
time.sleep_ms(100)

import time
from bmi270 import BMI270
from machine import Pin, SPI, I2C

# Init in I2C mode.
imu = BMI270(I2C(1, scl=Pin(15), sda=Pin(14)))

# Or init in SPI mode.
# TODO: Not supported yet.
# imu = BMI270(SPI(5), cs=Pin(10))

while (True):
print('Accelerometer: x:{:>6.3f} y:{:>6.3f} z:{:>6.3f}'.format(*imu.accel()))
print('Gyroscope: x:{:>6.3f} y:{:>6.3f} z:{:>6.3f}'.format(*imu.gyro()))
print('Magnetometer: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*imu.magnet()))
print("")
time.sleep_ms(100)
"""

import array
import time

from micropython import const

_DEFAULT_ADDR = const(0x68)
Expand Down
24 changes: 12 additions & 12 deletions micropython/drivers/imu/bmm150/bmm150.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Basic example usage:
Basic example usage::

import time
from bmm150 import BMM150
from machine import Pin, SPI, I2C
import time
from bmm150 import BMM150
from machine import Pin, SPI, I2C

# Init in I2C mode.
imu = BMM150(I2C(1, scl=Pin(15), sda=Pin(14)))
# Init in I2C mode.
imu = BMM150(I2C(1, scl=Pin(15), sda=Pin(14)))

# Or init in SPI mode.
# TODO: Not supported yet.
# imu = BMM150(SPI(5), cs=Pin(10))
# Or init in SPI mode.
# TODO: Not supported yet.
# imu = BMM150(SPI(5), cs=Pin(10))

while (True):
print('magnetometer: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*imu.magnet()))
time.sleep_ms(100)
while (True):
print('magnetometer: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*imu.magnet()))
time.sleep_ms(100)
"""

import array
Expand Down
27 changes: 14 additions & 13 deletions micropython/drivers/imu/lsm6dsox/lsm6dsox.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,24 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Basic example usage:
Basic example usage::

import time
from lsm6dsox import LSM6DSOX
import time
from lsm6dsox import LSM6DSOX

from machine import Pin, SPI, I2C
# Init in I2C mode.
lsm = LSM6DSOX(I2C(0, scl=Pin(13), sda=Pin(12)))

from machine import Pin, SPI, I2C
# Init in I2C mode.
lsm = LSM6DSOX(I2C(0, scl=Pin(13), sda=Pin(12)))
# Or init in SPI mode.
#lsm = LSM6DSOX(SPI(5), cs=Pin(10))

# Or init in SPI mode.
#lsm = LSM6DSOX(SPI(5), cs=Pin(10))
while (True):
print('Accelerometer: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*lsm.accel()))
print('Gyroscope: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*lsm.gyro()))
print("")
time.sleep_ms(100)

while (True):
print('Accelerometer: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*lsm.accel()))
print('Gyroscope: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*lsm.gyro()))
print("")
time.sleep_ms(100)
"""

import array
Expand Down
24 changes: 12 additions & 12 deletions micropython/drivers/imu/lsm9ds1/lsm9ds1.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@
The sensor contains an accelerometer / gyroscope / magnetometer
Uses the internal FIFO to store up to 16 gyro/accel data, use the iter_accel_gyro generator to access it.
Example usage:
Example usage::
import time
from lsm9ds1 import LSM9DS1
from machine import Pin, I2C
import time
from lsm9ds1 import LSM9DS1
from machine import Pin, I2C
imu = LSM9DS1(I2C(1, scl=Pin(15), sda=Pin(14)))
imu = LSM9DS1(I2C(1, scl=Pin(15), sda=Pin(14)))
while (True):
#for g,a in imu.iter_accel_gyro(): print(g,a) # using fifo
print('Accelerometer: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*imu.accel()))
print('Magnetometer: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*imu.magnet()))
print('Gyroscope: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*imu.gyro()))
print("")
time.sleep_ms(100)
while (True):
#for g,a in imu.iter_accel_gyro(): print(g,a) # using fifo
print('Accelerometer: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*imu.accel()))
print('Magnetometer: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*imu.magnet()))
print('Gyroscope: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*imu.gyro()))
print("")
time.sleep_ms(100)
"""

import array
Expand Down
7 changes: 5 additions & 2 deletions micropython/drivers/sensor/ds18x20/ds18x20.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# DS18x20 temperature sensor driver for MicroPython.
# MIT license; Copyright (c) 2016 Damien P. George
"""
DS18x20 temperature sensor driver for MicroPython.

MIT license; Copyright (c) 2016 Damien P. George
"""

from micropython import const

Expand Down
22 changes: 12 additions & 10 deletions micropython/drivers/sensor/hs3003/hs3003.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,23 @@
THE SOFTWARE.

HS3003 driver for MicroPython.
------------------------------

Example usage:

import time
from hs3003 import HS3003
from machine import Pin, I2C
import time
from hs3003 import HS3003
from machine import Pin, I2C

bus = I2C(1, scl=Pin(15), sda=Pin(14))
hts = HS3003(bus)
bus = I2C(1, scl=Pin(15), sda=Pin(14))
hts = HS3003(bus)

while True:
rH = hts.humidity()
temp = hts.temperature()
print ("rH: %.2f%% T: %.2fC" %(rH, temp))
time.sleep_ms(100)

while True:
rH = hts.humidity()
temp = hts.temperature()
print ("rH: %.2f%% T: %.2fC" %(rH, temp))
time.sleep_ms(100)
"""

import struct
Expand Down
22 changes: 12 additions & 10 deletions micropython/drivers/sensor/hts221/hts221.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,24 @@
THE SOFTWARE.

HTS221 driver driver for MicroPython.
-------------------------------------

Original source: https://github.com/ControlEverythingCommunity/HTS221/blob/master/Python/HTS221.py

Example usage:

import time
import hts221
from machine import Pin, I2C
import time
import hts221
from machine import Pin, I2C

bus = I2C(1, scl=Pin(15), sda=Pin(14))
hts = hts221.HTS221(bus)
bus = I2C(1, scl=Pin(15), sda=Pin(14))
hts = hts221.HTS221(bus)

while (True):
rH = hts.humidity()
temp = hts.temperature()
print ("rH: %.2f%% T: %.2fC" %(rH, temp))
time.sleep_ms(100)
while (True):
rH = hts.humidity()
temp = hts.temperature()
print ("rH: %.2f%% T: %.2fC" %(rH, temp))
time.sleep_ms(100)
"""

import struct
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import requests

r = requests.get("http://api.xively.com/")
r = requests.get("https://dummyjson.com/quotes/1")
print(r)
print(r.content)
print(r.text)
Expand Down
29 changes: 15 additions & 14 deletions python-stdlib/cmd/cmd.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
"""A generic class to build line-oriented command interpreters.
"""
A generic class to build line-oriented command interpreters.

Interpreters constructed with this class obey the following conventions:

1. End of file on input is processed as the command 'EOF'.
2. A command is parsed out of each line by collecting the prefix composed
of characters in the identchars member.
3. A command `foo' is dispatched to a method 'do_foo()'; the do_ method
3. A command 'foo' is dispatched to a method 'do_foo()'; the do_ method
is passed a single argument consisting of the remainder of the line.
4. Typing an empty line repeats the last command. (Actually, it calls the
method `emptyline', which may be overridden in a subclass.)
5. There is a predefined `help' method. Given an argument `topic', it
calls the command `help_topic'. With no arguments, it lists all topics
method 'emptyline', which may be overridden in a subclass.)
5. There is a predefined 'help' method. Given an argument 'topic', it
calls the command 'help_topic'. With no arguments, it lists all topics
with defined help_ functions, broken into up to three topics; documented
commands, miscellaneous help topics, and undocumented commands.
6. The command '?' is a synonym for `help'. The command '!' is a synonym
for `shell', if a do_shell method exists.
6. The command '?' is a synonym for 'help'. The command '!' is a synonym
for 'shell', if a do_shell method exists.
7. If completion is enabled, completing commands will be done automatically,
and completing of commands args is done by calling complete_foo() with
arguments text, line, begidx, endidx. text is string we are matching
Expand All @@ -23,21 +24,21 @@
indexes of the text being matched, which could be used to provide
different completion depending upon which position the argument is in.

The `default' method may be overridden to intercept commands for which there
The 'default' method may be overridden to intercept commands for which there
is no do_ method.

The `completedefault' method may be overridden to intercept completions for
The 'completedefault' method may be overridden to intercept completions for
commands that have no complete_ method.

The data member `self.ruler' sets the character used to draw separator lines
The data member 'self.ruler' sets the character used to draw separator lines
in the help messages. If empty, no ruler line is drawn. It defaults to "=".

If the value of `self.intro' is nonempty when the cmdloop method is called,
If the value of 'self.intro' is nonempty when the cmdloop method is called,
it is printed out on interpreter startup. This value may be overridden
via an optional argument to the cmdloop() method.

The data members `self.doc_header', `self.misc_header', and
`self.undoc_header' set the headers used for the help function's
The data members 'self.doc_header', 'self.misc_header', and
'self.undoc_header' set the headers used for the help function's
listings of documented functions, miscellaneous topics, and undocumented
functions respectively.

Expand All @@ -48,7 +49,7 @@
One of the notable deviations is that since MicroPython strips doc strings,
this means that that help by doc string feature doesn't work.

completions have also been stripped out.
Completions have also been stripped out.
"""

import sys
Expand Down
Loading
Loading