Compare commits

...

31 commits

Author SHA1 Message Date
dherrada
f653030744 Fixed discord invite link 2020-07-08 16:49:04 -04:00
Kattni
d55c69299b
Merge pull request #25 from FoamyGuy/fix_readme
Fix readme example
2020-06-22 12:17:03 -04:00
FoamyGuy
22c7dcfad1 remove pylint disables from readme example 2020-06-20 12:58:41 -05:00
FoamyGuy
6035c11350 remove pylint ignores from simpletest 2020-06-19 13:51:16 -05:00
FoamyGuy
0f9db6967d run black on simpletest 2020-06-18 17:18:34 -05:00
FoamyGuy
f026861d20 update readme example to use code from simpletest. Fix a few pylint issues in simpletest. 2020-06-18 17:13:50 -05:00
Scott Shawcroft
0add342f10
Merge pull request #22 from adafruit/black-update
Black reformatting with Python 3 target.
2020-04-09 09:41:05 -07:00
Kattni Rembor
0f8a9f0f10 Black reformatting with Python 3 target. 2020-04-08 13:11:08 -04:00
sommersoft
aa057068dc build.yml: add black formatting check
Signed-off-by: sommersoft <sommersoft@gmail.com>
2020-04-07 16:09:27 -05:00
Kattni
6c88ecae18
Merge pull request #20 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2020-03-17 13:44:48 -04:00
dherrada
7000a21f17 Ran black, updated to pylint 2.x 2020-03-16 14:48:58 -04:00
sommersoft
a6e7b80514 update code of coduct: discord moderation contact section
Signed-off-by: sommersoft <sommersoft@gmail.com>
2020-03-15 18:21:55 -05:00
Kattni
ad7b512267
Merge pull request #19 from sommersoft/patch_coc
Update Code of Conduct
2020-03-13 15:09:00 -04:00
sommersoft
ae5a652b59 update code of conduct 2020-03-13 13:23:44 -05:00
sommersoft
c0fa277de1 update pylintrc for black
Signed-off-by: sommersoft <sommersoft@gmail.com>
2020-03-08 19:01:38 -05:00
sommersoft
9cdab4602e build.yml: move pylint, black, and Sphinx installs to each repo; add description to 'actions-ci/install.sh'
Signed-off-by: sommersoft <sommersoft@gmail.com>
2020-03-05 10:00:17 -06:00
sommersoft
e84a5c47ad update pylint examples directive
Signed-off-by: sommersoft <sommersoft@gmail.com>
2020-01-14 17:07:14 -06:00
Limor "Ladyada" Fried
c64b75bef1
Merge pull request #18 from adafruit/dherrada-patch-1
Moved repository from Travis to GitHub Actions
2019-12-27 22:41:42 -05:00
dherrada
07611a05a6 Moved repository from Travis to GitHub Actions 2019-12-27 22:24:14 -05:00
Kattni
a6c48ee687
Merge pull request #17 from adafruit/dherrada-patch-1
Removed building locally section from README, replaced with documenta…
2019-10-21 19:56:17 -04:00
dherrada
e8d145a1ae
Removed building locally section from README, replaced with documentation section 2019-10-17 18:16:56 -04:00
Melissa LeBlanc-Williams
98fa538629
Merge pull request #15 from makermelissa/master
Removed frozenset so it works on a Trinket M0
2019-05-21 18:59:02 -07:00
Melissa LeBlanc-Williams
3cdc3b164d Linted 2019-05-21 18:56:27 -07:00
Melissa LeBlanc-Williams
a68c991fc0 Changed frozenset to list to work on Trinket 2019-05-21 18:55:09 -07:00
Melissa LeBlanc-Williams
bccab5488e
Merge pull request #13 from jraber/master
Adopt changes from the BME280 library
2019-05-02 19:15:56 -07:00
Jeff Raber
b9e41db49e s/bme/bmp in examples/bmp280_normal_mode.py 2019-05-02 00:54:05 -05:00
Jeff Raber
921d4f07d1 Remove unnecessary 'if' and 'else' in the pressure property
This causes a change in behavior when var1 == 0.  Previously, the property
would return 0.  Now it returns _BMP280_PRESSURE_MIN_HPA.  The
new behavior is the same as in the Bosch C driver.

This also makes pylint happy by remove the 'return after else'
2019-04-03 21:39:16 -05:00
Jeff Raber
e3bc8af436 Adopt changes from the BME280 library
Add Normal mode for continuous reading
2019-04-03 21:38:33 -05:00
Kattni
82792ef4eb
Merge pull request #11 from sommersoft/readme_fix_travis
Update README Travis Badge
2018-12-21 13:23:22 -06:00
sommersoft
471bdd5acb change 'travis-ci.org' to 'travis-ci.com' 2018-12-21 13:15:22 -06:00
Brennen Bearnes
54a85599a7
Merge pull request #10 from adafruit/pypi-readme-update
PyPI readme update
2018-10-31 17:56:46 -06:00
12 changed files with 677 additions and 269 deletions

57
.github/workflows/build.yml vendored Normal file
View file

@ -0,0 +1,57 @@
name: Build CI
on: [pull_request, push]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Translate Repo Name For Build Tools filename_prefix
id: repo-name
run: |
echo ::set-output name=repo-name::$(
echo ${{ github.repository }} |
awk -F '\/' '{ print tolower($2) }' |
tr '_' '-'
)
- name: Set up Python 3.6
uses: actions/setup-python@v1
with:
python-version: 3.6
- name: Versions
run: |
python3 --version
- name: Checkout Current Repo
uses: actions/checkout@v1
with:
submodules: true
- name: Checkout tools repo
uses: actions/checkout@v2
with:
repository: adafruit/actions-ci-circuitpython-libs
path: actions-ci
- name: Install dependencies
# (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.)
run: |
source actions-ci/install.sh
- name: Pip install pylint, black, & Sphinx
run: |
pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
- name: Library version
run: git describe --dirty --always --tags
- name: Check formatting
run: |
black --check --target-version=py35 .
- name: PyLint
run: |
pylint $( find . -path './adafruit*.py' )
([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace $( find . -path "./examples/*.py" ))
- name: Build assets
run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location .
- name: Build docs
working-directory: docs
run: sphinx-build -E -W -b html . _build/html

81
.github/workflows/release.yml vendored Normal file
View file

@ -0,0 +1,81 @@
name: Release Actions
on:
release:
types: [published]
jobs:
upload-release-assets:
runs-on: ubuntu-latest
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Translate Repo Name For Build Tools filename_prefix
id: repo-name
run: |
echo ::set-output name=repo-name::$(
echo ${{ github.repository }} |
awk -F '\/' '{ print tolower($2) }' |
tr '_' '-'
)
- name: Set up Python 3.6
uses: actions/setup-python@v1
with:
python-version: 3.6
- name: Versions
run: |
python3 --version
- name: Checkout Current Repo
uses: actions/checkout@v1
with:
submodules: true
- name: Checkout tools repo
uses: actions/checkout@v2
with:
repository: adafruit/actions-ci-circuitpython-libs
path: actions-ci
- name: Install deps
run: |
source actions-ci/install.sh
- name: Build assets
run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location .
- name: Upload Release Assets
# the 'official' actions version does not yet support dynamically
# supplying asset names to upload. @csexton's version chosen based on
# discussion in the issue below, as its the simplest to implement and
# allows for selecting files with a pattern.
# https://github.com/actions/upload-release-asset/issues/4
#uses: actions/upload-release-asset@v1.0.1
uses: csexton/release-asset-action@master
with:
pattern: "bundles/*"
github-token: ${{ secrets.GITHUB_TOKEN }}
upload-pypi:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Check For setup.py
id: need-pypi
run: |
echo ::set-output name=setup-py::$( find . -wholename './setup.py' )
- name: Set up Python
if: contains(steps.need-pypi.outputs.setup-py, 'setup.py')
uses: actions/setup-python@v1
with:
python-version: '3.x'
- name: Install dependencies
if: contains(steps.need-pypi.outputs.setup-py, 'setup.py')
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
if: contains(steps.need-pypi.outputs.setup-py, 'setup.py')
env:
TWINE_USERNAME: ${{ secrets.pypi_username }}
TWINE_PASSWORD: ${{ secrets.pypi_password }}
run: |
python setup.py sdist
twine upload dist/*

1
.gitignore vendored
View file

@ -4,7 +4,6 @@ __pycache__
_build _build
*.pyc *.pyc
.env .env
build*
bundles bundles
*.DS_Store *.DS_Store
.eggs .eggs

View file

@ -52,7 +52,7 @@ confidence=
# no Warning level messages displayed, use"--disable=all --enable=classes # no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W" # --disable=W"
# disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call # disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call
disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation
# Enable the message, report, category or checker with the given id(s). You can # Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option # either give multiple identifier separated by comma (,) or put this option
@ -119,7 +119,8 @@ spelling-store-unknown-words=no
[MISCELLANEOUS] [MISCELLANEOUS]
# List of note tags to take in consideration, separated by a comma. # List of note tags to take in consideration, separated by a comma.
notes=FIXME,XXX,TODO # notes=FIXME,XXX,TODO
notes=FIXME,XXX
[TYPECHECK] [TYPECHECK]

View file

@ -1,31 +0,0 @@
dist: trusty
sudo: false
language: python
python:
- '3.6'
cache:
pip: true
deploy:
- provider: releases
api_key: "$GITHUB_TOKEN"
file_glob: true
file: "$TRAVIS_BUILD_DIR/bundles/*"
skip_cleanup: true
overwrite: true
on:
tags: true
- provider: pypi
user: adafruit-travis
on:
tags: true
password:
secure: cWI6Vmsiauq17r4eKeJWyIJkKi//J5aBcwZB76Dx099overDtUAl352Keg4tfsw9k9C8G2jWMhYTiR0vzv85k5th6aFw/5M1HHz5N/rDcAIQwCGwkwkiBbdRXk4UNKx1PNep1cUZl9oiO/34mowDnESYMOqQ8bEL9loRK61IjwKsUbx5uaivuISw9haFu1yhRs7GR4/9vF5rkn7Jof/rDfE2P52sopdim2sU6U49jvgl3XS1f4hPbHaEEkZi5bKVR81UV45oI/KnOXpRo4beR+1fts4GtkzEYDrJU/jBglVdqDcDfafs3jp20+6l2ngUfIZTg718JSs7F4MqjV/aATFlNiWYLxCEpdS/Y4k3SaaljzI1IznjPTUvrpYkCpSwMuzxDFpXUVXVUfYX7CqIF+UYa1gmPW44ieahCz7C7BBs6FA6CwVH64uQ57mNJLxrFXbQByQ+S1dGeGgdbF5juxGVr6P+nCkc7lwumixkeJULnC7AMyI7nP9yxj22u+UYuvL6VQncix+b/bNJzesFXpOfM9laSBhrjQEKDt9zQDk6dN+kFbZhCQfouYXf1/P5K+UxiYPOqqPpHfxkhCux15uMcnpFgjK40ACMOnSOU0dLVc7X6vK1kNeKBWQvuZcXAzXSvVTlCFs4ftxofnmoxzfFEySKLICCPZpc6ZjilDM=
install:
- pip install -r requirements.txt
- pip install pylint circuitpython-build-tools Sphinx sphinx-rtd-theme
- pip install --force-reinstall pylint==1.9.2
script:
- pylint adafruit_bmp280.py
- ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name examples/*.py)
- circuitpython-build-bundles --filename_prefix adafruit-circuitpython-bmp280 --library_location .
- cd docs && sphinx-build -E -W -b html . _build/html && cd ..

View file

@ -1,74 +1,129 @@
# Contributor Covenant Code of Conduct # Adafruit Community Code of Conduct
## Our Pledge ## Our Pledge
In the interest of fostering an open and welcoming environment, we as In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and contributors and leaders pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience, size, disability, ethnicity, gender identity and expression, level or type of
nationality, personal appearance, race, religion, or sexual identity and experience, education, socio-economic status, nationality, personal appearance,
orientation. race, religion, or sexual identity and orientation.
## Our Standards ## Our Standards
We are committed to providing a friendly, safe and welcoming environment for
all.
Examples of behavior that contributes to creating a positive environment Examples of behavior that contributes to creating a positive environment
include: include:
* Be kind and courteous to others
* Using welcoming and inclusive language * Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences * Being respectful of differing viewpoints and experiences
* Collaborating with other community members
* Gracefully accepting constructive criticism * Gracefully accepting constructive criticism
* Focusing on what is best for the community * Focusing on what is best for the community
* Showing empathy towards other community members * Showing empathy towards other community members
Examples of unacceptable behavior by participants include: Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or * The use of sexualized language or imagery and sexual attention or advances
advances * The use of inappropriate images, including in a community member's avatar
* The use of inappropriate language, including in a community member's nickname
* Any spamming, flaming, baiting or other attention-stealing behavior
* Excessive or unwelcome helping; answering outside the scope of the question
asked
* Trolling, insulting/derogatory comments, and personal or political attacks * Trolling, insulting/derogatory comments, and personal or political attacks
* Promoting or spreading disinformation, lies, or conspiracy theories against
a person, group, organisation, project, or community
* Public or private harassment * Public or private harassment
* Publishing others' private information, such as a physical or electronic * Publishing others' private information, such as a physical or electronic
address, without explicit permission address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a * Other conduct which could reasonably be considered inappropriate
professional setting
The goal of the standards and moderation guidelines outlined here is to build
and maintain a respectful community. We ask that you dont just aim to be
"technically unimpeachable", but rather try to be your best self.
We value many things beyond technical expertise, including collaboration and
supporting others within our community. Providing a positive experience for
other community members can have a much more significant impact than simply
providing the correct answer.
## Our Responsibilities ## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable Project leaders are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior. response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or Project leaders have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions reject messages, comments, commits, code, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate, permanently any community member for other behaviors that they deem
threatening, offensive, or harmful. inappropriate, threatening, offensive, or harmful.
## Moderation
Instances of behaviors that violate the Adafruit Community Code of Conduct
may be reported by any member of the community. Community members are
encouraged to report these situations, including situations they witness
involving other community members.
You may report in the following ways:
In any situation, you may send an email to <support@adafruit.com>.
On the Adafruit Discord, you may send an open message from any channel
to all Community Moderators by tagging @community moderators. You may
also send an open message from any channel, or a direct message to
@kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442,
@sommersoft#0222, @Mr. Certainly#0472 or @Andon#8175.
Email and direct message reports will be kept confidential.
In situations on Discord where the issue is particularly egregious, possibly
illegal, requires immediate action, or violates the Discord terms of service,
you should also report the message directly to Discord.
These are the steps for upholding our communitys standards of conduct.
1. Any member of the community may report any situation that violates the
Adafruit Community Code of Conduct. All reports will be reviewed and
investigated.
2. If the behavior is an egregious violation, the community member who
committed the violation may be banned immediately, without warning.
3. Otherwise, moderators will first respond to such behavior with a warning.
4. Moderators follow a soft "three strikes" policy - the community member may
be given another chance, if they are receptive to the warning and change their
behavior.
5. If the community member is unreceptive or unreasonable when warned by a
moderator, or the warning goes unheeded, they may be banned for a first or
second offense. Repeated offenses will result in the community member being
banned.
## Scope ## Scope
This Code of Conduct and the enforcement policies listed above apply to all
Adafruit Community venues. This includes but is not limited to any community
spaces (both public and private), the entire Adafruit Discord server, and
Adafruit GitHub repositories. Examples of Adafruit Community spaces include
but are not limited to meet-ups, audio chats on the Adafruit Discord, or
interaction at a conference.
This Code of Conduct applies both within project spaces and in public spaces This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of when an individual is representing the project or its community. As a community
representing a project or community include using an official project e-mail member, you are representing our community, and are expected to behave
address, posting via an official social media account, or acting as an appointed accordingly.
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at support@adafruit.com. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution ## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, This Code of Conduct is adapted from the [Contributor Covenant][homepage],
available at [http://contributor-covenant.org/version/1/4][version] version 1.4, available at
<https://www.contributor-covenant.org/version/1/4/code-of-conduct.html>,
and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html).
[homepage]: http://contributor-covenant.org For other projects adopting the Adafruit Community Code of
[version]: http://contributor-covenant.org/version/1/4/ Conduct, please contact the maintainers of those projects for enforcement.
If you wish to use this code of conduct for your own project, consider
explicitly mentioning your moderation policy or making a copy with your
own moderation policy so as to avoid confusion.

View file

@ -6,11 +6,11 @@ Introduction
:alt: Documentation Status :alt: Documentation Status
.. image :: https://img.shields.io/discord/327254708534116352.svg .. image :: https://img.shields.io/discord/327254708534116352.svg
:target: https://discord.gg/nBQh6qu :target: https://adafru.it/discord
:alt: Discord :alt: Discord
.. image:: https://travis-ci.org/adafruit/Adafruit_CircuitPython_BMP280.svg?branch=master .. image:: https://github.com/adafruit/Adafruit_CircuitPython_BMP280/workflows/Build%20CI/badge.svg
:target: https://travis-ci.org/adafruit/Adafruit_CircuitPython_BMP280 :target: https://github.com/adafruit/Adafruit_CircuitPython_BMP280/actions/
:alt: Build Status :alt: Build Status
CircuitPython driver from BMP280 Temperature and Barometic Pressure sensor CircuitPython driver from BMP280 Temperature and Barometic Pressure sensor
@ -58,23 +58,23 @@ Usage Example
.. code-block:: python .. code-block:: python
import board
import digitalio
import busio
import time import time
from adafruit_bmp280 import adafruit_bmp280 import board
# import digitalio # For use with SPI
import busio
import adafruit_bmp280
# Create library object using our Bus I2C port # Create library object using our Bus I2C port
i2c = busio.I2C(board.SCL, board.SDA) i2c = busio.I2C(board.SCL, board.SDA)
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c) bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)
# OR create library object using our Bus SPI port # OR create library object using our Bus SPI port
#spi = busio.SPI(board.SCK, board.MOSI, board.MISO) # spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
#bmp_cs = digitalio.DigitalInOut(board.D10) # bmp_cs = digitalio.DigitalInOut(board.D10)
#bmp280 = adafruit_bmp280.Adafruit_BMP280_SPI(spi, bmp_cs) # bmp280 = adafruit_bmp280.Adafruit_BMP280_SPI(spi, bmp_cs)
# change this to match the location's pressure (hPa) at sea level # change this to match the location's pressure (hPa) at sea level
bmp280.seaLevelhPa = 1013.25 bmp280.sea_level_pressure = 1013.25
while True: while True:
print("\nTemperature: %0.1f C" % bmp280.temperature) print("\nTemperature: %0.1f C" % bmp280.temperature)
@ -89,49 +89,8 @@ Contributions are welcome! Please read our `Code of Conduct
<https://github.com/adafruit/Adafruit_CircuitPython_bmp280/blob/master/CODE_OF_CONDUCT.md>`_ <https://github.com/adafruit/Adafruit_CircuitPython_bmp280/blob/master/CODE_OF_CONDUCT.md>`_
before contributing to help this project stay welcoming. before contributing to help this project stay welcoming.
Building locally Documentation
================ =============
To build this library locally you'll need to install the For information on building library documentation, please check out `this guide <https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs#sphinx-5-1>`_.Travis will. This is a good way to
`circuitpython-build-tools <https://github.com/adafruit/circuitpython-build-tools>`_ package.
.. code-block:: shell
python3 -m venv .env
source .env/bin/activate
pip install circuitpython-build-tools
Once installed, make sure you are in the virtual environment:
.. code-block:: shell
source .env/bin/activate
Then run the build:
.. code-block:: shell
circuitpython-build-bundles --filename_prefix adafruit-circuitpython-bmp280 --library_location .
Sphinx documentation
-----------------------
Sphinx is used to build the documentation based on rST files and comments in the code. First,
install dependencies (feel free to reuse the virtual environment from above):
.. code-block:: shell
python3 -m venv .env
source .env/bin/activate
pip install Sphinx sphinx-rtd-theme
Now, once you have the virtual environment activated:
.. code-block:: shell
cd docs
sphinx-build -E -W -b html . _build/html
This will output the documentation to ``docs/_build/html``. Open the index.html in your browser to
view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to
locally verify it will pass. locally verify it will pass.

View file

@ -20,20 +20,20 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
""" """
`adafruit_bmp280` `adafruit_bmp280` - Adafruit BMP280 - Temperature & Barometic Pressure Sensor
==================================================== ===============================================================================
CircuitPython driver from BMP280 Temperature and Barometic Pressure sensor CircuitPython driver from BMP280 Temperature and Barometic Pressure sensor
* Author(s): ladyada * Author(s): ladyada
""" """
import math import math
import time from time import sleep
try: try:
import struct import struct
except ImportError: except ImportError:
import ustruct as struct import ustruct as struct
from micropython import const from micropython import const
__version__ = "0.0.0-auto.0" __version__ = "0.0.0-auto.0"
@ -45,96 +45,324 @@ _CHIP_ID = const(0x58)
_REGISTER_CHIPID = const(0xD0) _REGISTER_CHIPID = const(0xD0)
_REGISTER_DIG_T1 = const(0x88) _REGISTER_DIG_T1 = const(0x88)
# _REGISTER_DIG_T2 = const(0x8A)
# _REGISTER_DIG_T3 = const(0x8C)
# _REGISTER_DIG_P1 = const(0x8E)
# _REGISTER_DIG_P2 = const(0x90)
# _REGISTER_DIG_P3 = const(0x92)
# _REGISTER_DIG_P4 = const(0x94)
# _REGISTER_DIG_P5 = const(0x96)
# _REGISTER_DIG_P6 = const(0x98)
# _REGISTER_DIG_P7 = const(0x9A)
# _REGISTER_DIG_P8 = const(0x9C)
# _REGISTER_DIG_P9 = const(0x9E)
_REGISTER_SOFTRESET = const(0xE0) _REGISTER_SOFTRESET = const(0xE0)
_REGISTER_STATUS = const(0xF3) _REGISTER_STATUS = const(0xF3)
_REGISTER_CONTROL = const(0xF4) _REGISTER_CTRL_MEAS = const(0xF4)
_REGISTER_CONFIG = const(0xF5) _REGISTER_CONFIG = const(0xF5)
_REGISTER_PRESSUREDATA = const(0xF7) _REGISTER_PRESSUREDATA = const(0xF7)
_REGISTER_TEMPDATA = const(0xFA) _REGISTER_TEMPDATA = const(0xFA)
class Adafruit_BMP280: # pylint: disable=invalid-name _BMP280_PRESSURE_MIN_HPA = const(300)
_BMP280_PRESSURE_MAX_HPA = const(1100)
"""iir_filter values"""
IIR_FILTER_DISABLE = const(0)
IIR_FILTER_X2 = const(0x01)
IIR_FILTER_X4 = const(0x02)
IIR_FILTER_X8 = const(0x03)
IIR_FILTER_X16 = const(0x04)
_BMP280_IIR_FILTERS = (
IIR_FILTER_DISABLE,
IIR_FILTER_X2,
IIR_FILTER_X4,
IIR_FILTER_X8,
IIR_FILTER_X16,
)
"""overscan values for temperature, pressure, and humidity"""
OVERSCAN_DISABLE = const(0x00)
OVERSCAN_X1 = const(0x01)
OVERSCAN_X2 = const(0x02)
OVERSCAN_X4 = const(0x03)
OVERSCAN_X8 = const(0x04)
OVERSCAN_X16 = const(0x05)
_BMP280_OVERSCANS = {
OVERSCAN_DISABLE: 0,
OVERSCAN_X1: 1,
OVERSCAN_X2: 2,
OVERSCAN_X4: 4,
OVERSCAN_X8: 8,
OVERSCAN_X16: 16,
}
"""mode values"""
MODE_SLEEP = const(0x00)
MODE_FORCE = const(0x01)
MODE_NORMAL = const(0x03)
_BMP280_MODES = (MODE_SLEEP, MODE_FORCE, MODE_NORMAL)
"""
standby timeconstant values
TC_X[_Y] where X=milliseconds and Y=tenths of a millisecond
"""
STANDBY_TC_0_5 = const(0x00) # 0.5ms
STANDBY_TC_10 = const(0x06) # 10ms
STANDBY_TC_20 = const(0x07) # 20ms
STANDBY_TC_62_5 = const(0x01) # 62.5ms
STANDBY_TC_125 = const(0x02) # 125ms
STANDBY_TC_250 = const(0x03) # 250ms
STANDBY_TC_500 = const(0x04) # 500ms
STANDBY_TC_1000 = const(0x05) # 1000ms
_BMP280_STANDBY_TCS = (
STANDBY_TC_0_5,
STANDBY_TC_10,
STANDBY_TC_20,
STANDBY_TC_62_5,
STANDBY_TC_125,
STANDBY_TC_250,
STANDBY_TC_500,
STANDBY_TC_1000,
)
class Adafruit_BMP280: # pylint: disable=invalid-name
"""Base BMP280 object. Use `Adafruit_BMP280_I2C` or `Adafruit_BMP280_SPI` instead of this. This """Base BMP280 object. Use `Adafruit_BMP280_I2C` or `Adafruit_BMP280_SPI` instead of this. This
checks the BMP280 was found, reads the coefficients and enables the sensor for continuous checks the BMP280 was found, reads the coefficients and enables the sensor for continuous
reads""" reads"""
def __init__(self): def __init__(self):
# Check device ID. # Check device ID.
chip_id = self._read_byte(_REGISTER_CHIPID) chip_id = self._read_byte(_REGISTER_CHIPID)
if _CHIP_ID != chip_id: if _CHIP_ID != chip_id:
raise RuntimeError('Failed to find BMP280! Chip ID 0x%x' % chip_id) raise RuntimeError("Failed to find BMP280! Chip ID 0x%x" % chip_id)
# Set some reasonable defaults.
self._iir_filter = IIR_FILTER_DISABLE
self._overscan_temperature = OVERSCAN_X2
self._overscan_pressure = OVERSCAN_X16
self._t_standby = STANDBY_TC_0_5
self._mode = MODE_SLEEP
self._reset()
self._read_coefficients() self._read_coefficients()
self._write_ctrl_meas()
self._write_config()
self.sea_level_pressure = 1013.25 self.sea_level_pressure = 1013.25
"""Pressure in hectoPascals at sea level. Used to calibrate `altitude`.""" """Pressure in hectoPascals at sea level. Used to calibrate `altitude`."""
self._t_fine = None
def _read(self): def _read_temperature(self):
"""Returns a tuple for temperature and pressure.""" # perform one measurement
# perform one measurement in high res, forced mode if self.mode != MODE_NORMAL:
self._write_register_byte(_REGISTER_CONTROL, 0xFE) self.mode = MODE_FORCE
# Wait for conversion to complete
while self._get_status() & 0x08:
sleep(0.002)
raw_temperature = (
self._read24(_REGISTER_TEMPDATA) / 16
) # lowest 4 bits get dropped
# print("raw temp: ", UT)
var1 = (
raw_temperature / 16384.0 - self._temp_calib[0] / 1024.0
) * self._temp_calib[1]
# print(var1)
var2 = (
(raw_temperature / 131072.0 - self._temp_calib[0] / 8192.0)
* (raw_temperature / 131072.0 - self._temp_calib[0] / 8192.0)
) * self._temp_calib[2]
# print(var2)
# Wait for conversion to complete self._t_fine = int(var1 + var2)
while self._read_byte(_REGISTER_STATUS) & 0x08: # print("t_fine: ", self.t_fine)
time.sleep(0.002)
# lowest 4 bits get dropped
UT = self._read24(_REGISTER_TEMPDATA) / 16
#print("raw temp: ", UT)
var1 = (UT / 16384.0 - self._temp_calib[0] / 1024.0) * self._temp_calib[1] def _reset(self):
var2 = ((UT / 131072.0 - self._temp_calib[0] / 8192.0) * ( """Soft reset the sensor"""
UT / 131072.0 - self._temp_calib[0] / 8192.0)) * self._temp_calib[2] self._write_register_byte(_REGISTER_SOFTRESET, 0xB6)
#print("t_fine: ", self.t_fine) sleep(0.004) # Datasheet says 2ms. Using 4ms just to be safe
t_fine = int(var1 + var2)
temperature = t_fine / 5120.0
adc = self._read24(_REGISTER_PRESSUREDATA) / 16 def _write_ctrl_meas(self):
var1 = float(t_fine) / 2.0 - 64000.0 """
var2 = var1 * var1 * self._pressure_calib[5] / 32768.0 Write the values to the ctrl_meas register in the device
var2 = var2 + var1 * self._pressure_calib[4] * 2.0 ctrl_meas sets the pressure and temperature data acquistion options
var2 = var2 / 4.0 + self._pressure_calib[3] * 65536.0 """
var1 = (self._pressure_calib[2] * var1 * var1 / 524288.0 + self._write_register_byte(_REGISTER_CTRL_MEAS, self._ctrl_meas)
self._pressure_calib[1] * var1) / 524288.0
var1 = (1.0 + var1 / 32768.0) * self._pressure_calib[0] def _get_status(self):
if var1 == 0: """Get the value from the status register in the device """
return 0 return self._read_byte(_REGISTER_STATUS)
p = 1048576.0 - adc
p = ((p - var2 / 4096.0) * 6250.0) / var1 def _read_config(self):
var1 = self._pressure_calib[8] * p * p / 2147483648.0 """Read the value from the config register in the device """
var2 = p * self._pressure_calib[7] / 32768.0 return self._read_byte(_REGISTER_CONFIG)
p = p + (var1 + var2 + self._pressure_calib[6]) / 16.0
pressure = p / 100 def _write_config(self):
return (temperature, pressure) """Write the value to the config register in the device """
normal_flag = False
if self._mode == MODE_NORMAL:
# Writes to the config register may be ignored while in Normal mode
normal_flag = True
self.mode = MODE_SLEEP # So we switch to Sleep mode first
self._write_register_byte(_REGISTER_CONFIG, self._config)
if normal_flag:
self.mode = MODE_NORMAL
@property
def mode(self):
"""
Operation mode
Allowed values are set in the MODE enum class
"""
return self._mode
@mode.setter
def mode(self, value):
if not value in _BMP280_MODES:
raise ValueError("Mode '%s' not supported" % (value))
self._mode = value
self._write_ctrl_meas()
@property
def standby_period(self):
"""
Control the inactive period when in Normal mode
Allowed standby periods are set the STANDBY enum class
"""
return self._t_standby
@standby_period.setter
def standby_period(self, value):
if not value in _BMP280_STANDBY_TCS:
raise ValueError("Standby Period '%s' not supported" % (value))
if self._t_standby == value:
return
self._t_standby = value
self._write_config()
@property
def overscan_temperature(self):
"""
Temperature Oversampling
Allowed values are set in the OVERSCAN enum class
"""
return self._overscan_temperature
@overscan_temperature.setter
def overscan_temperature(self, value):
if not value in _BMP280_OVERSCANS:
raise ValueError("Overscan value '%s' not supported" % (value))
self._overscan_temperature = value
self._write_ctrl_meas()
@property
def overscan_pressure(self):
"""
Pressure Oversampling
Allowed values are set in the OVERSCAN enum class
"""
return self._overscan_pressure
@overscan_pressure.setter
def overscan_pressure(self, value):
if not value in _BMP280_OVERSCANS:
raise ValueError("Overscan value '%s' not supported" % (value))
self._overscan_pressure = value
self._write_ctrl_meas()
@property
def iir_filter(self):
"""
Controls the time constant of the IIR filter
Allowed values are set in the IIR_FILTER enum class
"""
return self._iir_filter
@iir_filter.setter
def iir_filter(self, value):
if not value in _BMP280_IIR_FILTERS:
raise ValueError("IIR Filter '%s' not supported" % (value))
self._iir_filter = value
self._write_config()
@property
def _config(self):
"""Value to be written to the device's config register """
config = 0
if self.mode == MODE_NORMAL:
config += self._t_standby << 5
if self._iir_filter:
config += self._iir_filter << 2
return config
@property
def _ctrl_meas(self):
"""Value to be written to the device's ctrl_meas register """
ctrl_meas = self.overscan_temperature << 5
ctrl_meas += self.overscan_pressure << 2
ctrl_meas += self.mode
return ctrl_meas
@property
def measurement_time_typical(self):
"""Typical time in milliseconds required to complete a measurement in normal mode"""
meas_time_ms = 1
if self.overscan_temperature != OVERSCAN_DISABLE:
meas_time_ms += 2 * _BMP280_OVERSCANS.get(self.overscan_temperature)
if self.overscan_pressure != OVERSCAN_DISABLE:
meas_time_ms += 2 * _BMP280_OVERSCANS.get(self.overscan_pressure) + 0.5
return meas_time_ms
@property
def measurement_time_max(self):
"""Maximum time in milliseconds required to complete a measurement in normal mode"""
meas_time_ms = 1.25
if self.overscan_temperature != OVERSCAN_DISABLE:
meas_time_ms += 2.3 * _BMP280_OVERSCANS.get(self.overscan_temperature)
if self.overscan_pressure != OVERSCAN_DISABLE:
meas_time_ms += 2.3 * _BMP280_OVERSCANS.get(self.overscan_pressure) + 0.575
return meas_time_ms
@property @property
def temperature(self): def temperature(self):
"""The compensated temperature in degrees celsius.""" """The compensated temperature in degrees celsius."""
return self._read()[0] self._read_temperature()
return self._t_fine / 5120.0
@property @property
def pressure(self): def pressure(self):
"""The compensated pressure in hectoPascals.""" """
return self._read()[1] The compensated pressure in hectoPascals.
returns None if pressure measurement is disabled
"""
self._read_temperature()
# Algorithm from the BMP280 driver
# https://github.com/BoschSensortec/BMP280_driver/blob/master/bmp280.c
adc = self._read24(_REGISTER_PRESSUREDATA) / 16 # lowest 4 bits get dropped
var1 = float(self._t_fine) / 2.0 - 64000.0
var2 = var1 * var1 * self._pressure_calib[5] / 32768.0
var2 = var2 + var1 * self._pressure_calib[4] * 2.0
var2 = var2 / 4.0 + self._pressure_calib[3] * 65536.0
var3 = self._pressure_calib[2] * var1 * var1 / 524288.0
var1 = (var3 + self._pressure_calib[1] * var1) / 524288.0
var1 = (1.0 + var1 / 32768.0) * self._pressure_calib[0]
if not var1:
return _BMP280_PRESSURE_MIN_HPA
pressure = 1048576.0 - adc
pressure = ((pressure - var2 / 4096.0) * 6250.0) / var1
var1 = self._pressure_calib[8] * pressure * pressure / 2147483648.0
var2 = pressure * self._pressure_calib[7] / 32768.0
pressure = pressure + (var1 + var2 + self._pressure_calib[6]) / 16.0
pressure /= 100
if pressure < _BMP280_PRESSURE_MIN_HPA:
return _BMP280_PRESSURE_MIN_HPA
if pressure > _BMP280_PRESSURE_MAX_HPA:
return _BMP280_PRESSURE_MAX_HPA
return pressure
@property @property
def altitude(self): def altitude(self):
"""The altitude based on the sea level pressure (`sea_level_pressure`) - which you must """The altitude based on the sea level pressure (`sea_level_pressure`) - which you must
enter ahead of time)""" enter ahead of time)"""
p = self.pressure # in Si units for hPascal p = self.pressure # in Si units for hPascal
return 44330 * (1.0 - math.pow(p / self.sea_level_pressure, 0.1903)) return 44330 * (1.0 - math.pow(p / self.sea_level_pressure, 0.1903))
####################### Internal helpers ################################ ####################### Internal helpers ################################
def _read_coefficients(self): def _read_coefficients(self):
"""Read & save the calibration coefficients""" """Read & save the calibration coefficients"""
coeff = self._read_register(_REGISTER_DIG_T1, 24) coeff = self._read_register(_REGISTER_DIG_T1, 24)
coeff = list(struct.unpack('<HhhHhhhhhhhh', bytes(coeff))) coeff = list(struct.unpack("<HhhHhhhhhhhh", bytes(coeff)))
coeff = [float(i) for i in coeff] coeff = [float(i) for i in coeff]
# The temp_calib lines up with DIG_T# registers. # The temp_calib lines up with DIG_T# registers.
self._temp_calib = coeff[:3] self._temp_calib = coeff[:3]
@ -167,11 +395,14 @@ class Adafruit_BMP280: # pylint: disable=invalid-name
"""Low level register writing, not implemented in base class""" """Low level register writing, not implemented in base class"""
raise NotImplementedError() raise NotImplementedError()
class Adafruit_BMP280_I2C(Adafruit_BMP280): # pylint: disable=invalid-name
class Adafruit_BMP280_I2C(Adafruit_BMP280): # pylint: disable=invalid-name
"""Driver for I2C connected BMP280. Default address is 0x77 but another address can be passed """Driver for I2C connected BMP280. Default address is 0x77 but another address can be passed
in as an argument""" in as an argument"""
def __init__(self, i2c, address=0x77): def __init__(self, i2c, address=0x77):
import adafruit_bus_device.i2c_device as i2c_device import adafruit_bus_device.i2c_device as i2c_device # pylint: disable=import-outside-toplevel
self._i2c = i2c_device.I2CDevice(i2c, address) self._i2c = i2c_device.I2CDevice(i2c, address)
super().__init__() super().__init__()
@ -181,20 +412,23 @@ class Adafruit_BMP280_I2C(Adafruit_BMP280): # pylint: disable=invalid-name
i2c.write(bytes([register & 0xFF])) i2c.write(bytes([register & 0xFF]))
result = bytearray(length) result = bytearray(length)
i2c.readinto(result) i2c.readinto(result)
#print("$%02X => %s" % (register, [hex(i) for i in result])) # print("$%02X => %s" % (register, [hex(i) for i in result]))
return result return result
def _write_register_byte(self, register, value): def _write_register_byte(self, register, value):
"""Low level register writing over I2C, writes one 8-bit value""" """Low level register writing over I2C, writes one 8-bit value"""
with self._i2c as i2c: with self._i2c as i2c:
i2c.write(bytes([register & 0xFF, value & 0xFF])) i2c.write(bytes([register & 0xFF, value & 0xFF]))
#print("$%02X <= 0x%02X" % (register, value)) # print("$%02X <= 0x%02X" % (register, value))
class Adafruit_BMP280_SPI(Adafruit_BMP280): class Adafruit_BMP280_SPI(Adafruit_BMP280):
"""Driver for SPI connected BMP280. Default clock rate is 100000 but can be changed with """Driver for SPI connected BMP280. Default clock rate is 100000 but can be changed with
'baudrate'""" 'baudrate'"""
def __init__(self, spi, cs, baudrate=100000): def __init__(self, spi, cs, baudrate=100000):
import adafruit_bus_device.spi_device as spi_device import adafruit_bus_device.spi_device as spi_device # pylint: disable=import-outside-toplevel
self._spi = spi_device.SPIDevice(spi, cs, baudrate=baudrate) self._spi = spi_device.SPIDevice(spi, cs, baudrate=baudrate)
super().__init__() super().__init__()
@ -206,7 +440,7 @@ class Adafruit_BMP280_SPI(Adafruit_BMP280):
spi.write(bytearray([register])) spi.write(bytearray([register]))
result = bytearray(length) result = bytearray(length)
spi.readinto(result) spi.readinto(result)
#print("$%02X => %s" % (register, [hex(i) for i in result])) # print("$%02X => %s" % (register, [hex(i) for i in result]))
return result return result
def _write_register_byte(self, register, value): def _write_register_byte(self, register, value):

View file

@ -2,7 +2,8 @@
import os import os
import sys import sys
sys.path.insert(0, os.path.abspath('..'))
sys.path.insert(0, os.path.abspath(".."))
# -- General configuration ------------------------------------------------ # -- General configuration ------------------------------------------------
@ -10,34 +11,45 @@ sys.path.insert(0, os.path.abspath('..'))
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones. # ones.
extensions = [ extensions = [
'sphinx.ext.autodoc', "sphinx.ext.autodoc",
'sphinx.ext.intersphinx', "sphinx.ext.intersphinx",
'sphinx.ext.viewcode', "sphinx.ext.viewcode",
] ]
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None),'Register': ('https://circuitpython.readthedocs.io/projects/register/en/latest/', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} intersphinx_mapping = {
"python": ("https://docs.python.org/3.4", None),
"BusDevice": (
"https://circuitpython.readthedocs.io/projects/busdevice/en/latest/",
None,
),
"Register": (
"https://circuitpython.readthedocs.io/projects/register/en/latest/",
None,
),
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
}
# Add any paths that contain templates here, relative to this directory. # Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates'] templates_path = ["_templates"]
source_suffix = '.rst' source_suffix = ".rst"
# The master toctree document. # The master toctree document.
master_doc = 'index' master_doc = "index"
# General information about the project. # General information about the project.
project = u'Adafruit BMP280 Library' project = "Adafruit BMP280 Library"
copyright = u'2017 ladyada' copyright = "2017 ladyada"
author = u'ladyada' author = "ladyada"
# The version info for the project you're documenting, acts as replacement for # The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the # |version| and |release|, also used in various other places throughout the
# built documents. # built documents.
# #
# The short X.Y version. # The short X.Y version.
version = u'1.0' version = "1.0"
# The full version, including alpha/beta/rc tags. # The full version, including alpha/beta/rc tags.
release = u'1.0' release = "1.0"
# The language for content autogenerated by Sphinx. Refer to documentation # The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages. # for a list of supported languages.
@ -49,7 +61,7 @@ language = None
# List of patterns, relative to source directory, that match files and # List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files. # directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path # This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md'] exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"]
# The reST default role (used for this markup: `text`) to use for all # The reST default role (used for this markup: `text`) to use for all
# documents. # documents.
@ -61,7 +73,7 @@ default_role = "any"
add_function_parentheses = True add_function_parentheses = True
# The name of the Pygments (syntax highlighting) style to use. # The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx' pygments_style = "sphinx"
# If true, `todo` and `todoList` produce output, else they produce nothing. # If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False todo_include_todos = False
@ -70,65 +82,67 @@ todo_include_todos = False
todo_emit_warnings = True todo_emit_warnings = True
# -- Options for HTML output ---------------------------------------------- # -- Options for HTML output ----------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for # The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes. # a list of builtin themes.
# #
on_rtd = os.environ.get('READTHEDOCS', None) == 'True' on_rtd = os.environ.get("READTHEDOCS", None) == "True"
if not on_rtd: # only import and set the theme if we're building docs locally if not on_rtd: # only import and set the theme if we're building docs locally
try: try:
import sphinx_rtd_theme import sphinx_rtd_theme
html_theme = 'sphinx_rtd_theme'
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.'] html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."]
except: except:
html_theme = 'default' html_theme = "default"
html_theme_path = ['.'] html_theme_path = ["."]
else: else:
html_theme_path = ['.'] html_theme_path = ["."]
# Add any paths that contain custom static files (such as style sheets) here, # Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files, # relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css". # so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static'] html_static_path = ["_static"]
# The name of an image file (relative to this directory) to use as a favicon of # The name of an image file (relative to this directory) to use as a favicon of
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large. # pixels large.
# #
html_favicon = '_static/favicon.ico' html_favicon = "_static/favicon.ico"
# Output file base name for HTML help builder. # Output file base name for HTML help builder.
htmlhelp_basename = 'AdafruitBMP280Librarydoc' htmlhelp_basename = "AdafruitBMP280Librarydoc"
# -- Options for LaTeX output --------------------------------------------- # -- Options for LaTeX output ---------------------------------------------
latex_elements = { latex_elements = {
# The paper size ('letterpaper' or 'a4paper'). # The paper size ('letterpaper' or 'a4paper').
# #
# 'papersize': 'letterpaper', # 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
# The font size ('10pt', '11pt' or '12pt'). #
# # 'pointsize': '10pt',
# 'pointsize': '10pt', # Additional stuff for the LaTeX preamble.
#
# Additional stuff for the LaTeX preamble. # 'preamble': '',
# # Latex figure (float) alignment
# 'preamble': '', #
# 'figure_align': 'htbp',
# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
} }
# Grouping the document tree into LaTeX files. List of tuples # Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, # (source start file, target name, title,
# author, documentclass [howto, manual, or own class]). # author, documentclass [howto, manual, or own class]).
latex_documents = [ latex_documents = [
(master_doc, 'AdafruitBMP280Library.tex', u'Adafruit BMP280 Library Documentation', (
author, 'manual'), master_doc,
"AdafruitBMP280Library.tex",
"Adafruit BMP280 Library Documentation",
author,
"manual",
),
] ]
# -- Options for manual page output --------------------------------------- # -- Options for manual page output ---------------------------------------
@ -136,8 +150,13 @@ latex_documents = [
# One entry per manual page. List of tuples # One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section). # (source start file, name, description, authors, manual section).
man_pages = [ man_pages = [
(master_doc, 'adafruitBMP280library', u'Adafruit BMP280 Library Documentation', (
[author], 1) master_doc,
"adafruitBMP280library",
"Adafruit BMP280 Library Documentation",
[author],
1,
)
] ]
# -- Options for Texinfo output ------------------------------------------- # -- Options for Texinfo output -------------------------------------------
@ -146,10 +165,16 @@ man_pages = [
# (source start file, target name, title, author, # (source start file, target name, title, author,
# dir menu entry, description, category) # dir menu entry, description, category)
texinfo_documents = [ texinfo_documents = [
(master_doc, 'AdafruitBMP280Library', u'Adafruit BMP280 Library Documentation', (
author, 'AdafruitBMP280Library', 'One line description of project.', master_doc,
'Miscellaneous'), "AdafruitBMP280Library",
"Adafruit BMP280 Library Documentation",
author,
"AdafruitBMP280Library",
"One line description of project.",
"Miscellaneous",
),
] ]
# API docs fix # API docs fix
autodoc_mock_imports = ['micropython'] autodoc_mock_imports = ["micropython"]

View file

@ -0,0 +1,35 @@
"""
Example showing how the BMP280 library can be used to set the various
parameters supported by the sensor.
Refer to the BMP280 datasheet to understand what these parameters do
"""
import time
import board
import busio
import adafruit_bmp280
# Create library object using our Bus I2C port
i2c = busio.I2C(board.SCL, board.SDA)
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)
# OR create library object using our Bus SPI port
# spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
# bmp_cs = digitalio.DigitalInOut(board.D10)
# bmp280 = adafruit_bmp280.Adafruit_BMP280_SPI(spi, bmp_cs)
# change this to match the location's pressure (hPa) at sea level
bmp280.sea_level_pressure = 1013.25
bmp280.mode = adafruit_bmp280.MODE_NORMAL
bmp280.standby_period = adafruit_bmp280.STANDBY_TC_500
bmp280.iir_filter = adafruit_bmp280.IIR_FILTER_X16
bmp280.overscan_pressure = adafruit_bmp280.OVERSCAN_X16
bmp280.overscan_temperature = adafruit_bmp280.OVERSCAN_X2
# The sensor will need a moment to gather inital readings
time.sleep(1)
while True:
print("\nTemperature: %0.1f C" % bmp280.temperature)
print("Pressure: %0.1f hPa" % bmp280.pressure)
print("Altitude = %0.2f meters" % bmp280.altitude)
time.sleep(2)

View file

@ -1,9 +1,10 @@
"""Simpletest Example that shows how to get temperature,
pressure, and altitude readings from a BMP280"""
import time import time
import board import board
# import digitalio # For use with SPI # import digitalio # For use with SPI
import busio import busio
import adafruit_bmp280 import adafruit_bmp280
# Create library object using our Bus I2C port # Create library object using our Bus I2C port
@ -11,9 +12,9 @@ i2c = busio.I2C(board.SCL, board.SDA)
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c) bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)
# OR create library object using our Bus SPI port # OR create library object using our Bus SPI port
#spi = busio.SPI(board.SCK, board.MOSI, board.MISO) # spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
#bmp_cs = digitalio.DigitalInOut(board.D10) # bmp_cs = digitalio.DigitalInOut(board.D10)
#bmp280 = adafruit_bmp280.Adafruit_BMP280_SPI(spi, bmp_cs) # bmp280 = adafruit_bmp280.Adafruit_BMP280_SPI(spi, bmp_cs)
# change this to match the location's pressure (hPa) at sea level # change this to match the location's pressure (hPa) at sea level
bmp280.sea_level_pressure = 1013.25 bmp280.sea_level_pressure = 1013.25

View file

@ -7,6 +7,7 @@ https://github.com/pypa/sampleproject
# Always prefer setuptools over distutils # Always prefer setuptools over distutils
from setuptools import setup, find_packages from setuptools import setup, find_packages
# To use a consistent encoding # To use a consistent encoding
from codecs import open from codecs import open
from os import path from os import path
@ -14,47 +15,38 @@ from os import path
here = path.abspath(path.dirname(__file__)) here = path.abspath(path.dirname(__file__))
# Get the long description from the README file # Get the long description from the README file
with open(path.join(here, 'README.rst'), encoding='utf-8') as f: with open(path.join(here, "README.rst"), encoding="utf-8") as f:
long_description = f.read() long_description = f.read()
setup( setup(
name='adafruit-circuitpython-bmp280', name="adafruit-circuitpython-bmp280",
use_scm_version=True, use_scm_version=True,
setup_requires=['setuptools_scm'], setup_requires=["setuptools_scm"],
description="CircuitPython driver for the BMP280.",
description='CircuitPython driver for the BMP280.',
long_description=long_description, long_description=long_description,
long_description_content_type='text/x-rst', long_description_content_type="text/x-rst",
# The project's main homepage. # The project's main homepage.
url='https://github.com/adafruit/Adafruit_CircuitPython_BMP280', url="https://github.com/adafruit/Adafruit_CircuitPython_BMP280",
# Author details # Author details
author='Adafruit Industries', author="Adafruit Industries",
author_email='circuitpython@adafruit.com', author_email="circuitpython@adafruit.com",
install_requires=["Adafruit-Blinka", "adafruit-circuitpython-busdevice"],
install_requires=['Adafruit-Blinka', 'adafruit-circuitpython-busdevice'],
# Choose your license # Choose your license
license='MIT', license="MIT",
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers # See https://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[ classifiers=[
'Development Status :: 3 - Alpha', "Development Status :: 3 - Alpha",
'Intended Audience :: Developers', "Intended Audience :: Developers",
'Topic :: Software Development :: Libraries', "Topic :: Software Development :: Libraries",
'Topic :: System :: Hardware', "Topic :: System :: Hardware",
'License :: OSI Approved :: MIT License', "License :: OSI Approved :: MIT License",
'Programming Language :: Python :: 3', "Programming Language :: Python :: 3",
'Programming Language :: Python :: 3.4', "Programming Language :: Python :: 3.4",
'Programming Language :: Python :: 3.5', "Programming Language :: Python :: 3.5",
], ],
# What does your project relate to? # What does your project relate to?
keywords='adafruit bmp280 barometric pressure temperature hardware sensor micropython circuitpython', keywords="adafruit bmp280 barometric pressure temperature hardware sensor micropython circuitpython",
# You can just specify the packages manually here if your project is # You can just specify the packages manually here if your project is
# simple. Or you can use find_packages(). # simple. Or you can use find_packages().
py_modules=['adafruit_bmp280'], py_modules=["adafruit_bmp280"],
) )