├── .gitattributes ├── .github ├── PULL_REQUEST_TEMPLATE │ └── adafruit_circuitpython_pr.md └── workflows │ ├── build.yml │ ├── failure-help-text.yml │ ├── release_gh.yml │ └── release_pypi.yml ├── .gitignore ├── .pre-commit-config.yaml ├── .readthedocs.yaml ├── CODE_OF_CONDUCT.md ├── LICENSE ├── LICENSES ├── CC-BY-4.0.txt ├── MIT.txt └── Unlicense.txt ├── README.rst ├── README.rst.license ├── adafruit_bmp280.py ├── docs ├── _static │ ├── favicon.ico │ └── favicon.ico.license ├── api.rst ├── api.rst.license ├── conf.py ├── examples.rst ├── examples.rst.license ├── index.rst ├── index.rst.license └── requirements.txt ├── examples ├── bmp280_displayio_simpletest.py ├── bmp280_normal_mode.py └── bmp280_simpletest.py ├── optional_requirements.txt ├── pyproject.toml ├── requirements.txt └── ruff.toml /.gitattributes: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | .py text eol=lf 6 | .rst text eol=lf 7 | .txt text eol=lf 8 | .yaml text eol=lf 9 | .toml text eol=lf 10 | .license text eol=lf 11 | .md text eol=lf 12 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | Thank you for contributing! Before you submit a pull request, please read the following. 6 | 7 | Make sure any changes you're submitting are in line with the CircuitPython Design Guide, available here: https://docs.circuitpython.org/en/latest/docs/design_guide.html 8 | 9 | If your changes are to documentation, please verify that the documentation builds locally by following the steps found here: https://adafru.it/build-docs 10 | 11 | Before submitting the pull request, make sure you've run Pylint and Black locally on your code. You can do this manually or using pre-commit. Instructions are available here: https://adafru.it/check-your-code 12 | 13 | Please remove all of this text before submitting. Include an explanation or list of changes included in your PR, as well as, if applicable, a link to any related issues. 14 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: Build CI 6 | 7 | on: [pull_request, push] 8 | 9 | jobs: 10 | test: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Run Build CI workflow 14 | uses: adafruit/workflows-circuitpython-libs/build@main 15 | -------------------------------------------------------------------------------- /.github/workflows/failure-help-text.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Scott Shawcroft for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: Failure help text 6 | 7 | on: 8 | workflow_run: 9 | workflows: ["Build CI"] 10 | types: 11 | - completed 12 | 13 | jobs: 14 | post-help: 15 | runs-on: ubuntu-latest 16 | if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.event == 'pull_request' }} 17 | steps: 18 | - name: Post comment to help 19 | uses: adafruit/circuitpython-action-library-ci-failed@v1 20 | -------------------------------------------------------------------------------- /.github/workflows/release_gh.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: GitHub Release Actions 6 | 7 | on: 8 | release: 9 | types: [published] 10 | 11 | jobs: 12 | upload-release-assets: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Run GitHub Release CI workflow 16 | uses: adafruit/workflows-circuitpython-libs/release-gh@main 17 | with: 18 | github-token: ${{ secrets.GITHUB_TOKEN }} 19 | upload-url: ${{ github.event.release.upload_url }} 20 | -------------------------------------------------------------------------------- /.github/workflows/release_pypi.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: PyPI Release Actions 6 | 7 | on: 8 | release: 9 | types: [published] 10 | 11 | jobs: 12 | upload-release-assets: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Run PyPI Release CI workflow 16 | uses: adafruit/workflows-circuitpython-libs/release-pypi@main 17 | with: 18 | pypi-username: ${{ secrets.pypi_username }} 19 | pypi-password: ${{ secrets.pypi_password }} 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Kattni Rembor, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | # Do not include files and directories created by your personal work environment, such as the IDE 6 | # you use, except for those already listed here. Pull requests including changes to this file will 7 | # not be accepted. 8 | 9 | # This .gitignore file contains rules for files generated by working with CircuitPython libraries, 10 | # including building Sphinx, testing with pip, and creating a virual environment, as well as the 11 | # MacOS and IDE-specific files generated by using MacOS in general, or the PyCharm or VSCode IDEs. 12 | 13 | # If you find that there are files being generated on your machine that should not be included in 14 | # your git commit, you should create a .gitignore_global file on your computer to include the 15 | # files created by your personal setup. To do so, follow the two steps below. 16 | 17 | # First, create a file called .gitignore_global somewhere convenient for you, and add rules for 18 | # the files you want to exclude from git commits. 19 | 20 | # Second, configure Git to use the exclude file for all Git repositories by running the 21 | # following via commandline, replacing "path/to/your/" with the actual path to your newly created 22 | # .gitignore_global file: 23 | # git config --global core.excludesfile path/to/your/.gitignore_global 24 | 25 | # CircuitPython-specific files 26 | *.mpy 27 | 28 | # Python-specific files 29 | __pycache__ 30 | *.pyc 31 | 32 | # Sphinx build-specific files 33 | _build 34 | 35 | # This file results from running `pip -e install .` in a local repository 36 | *.egg-info 37 | 38 | # Virtual environment-specific files 39 | .env 40 | .venv 41 | 42 | # MacOS-specific files 43 | *.DS_Store 44 | 45 | # IDE-specific files 46 | .idea 47 | .vscode 48 | *~ 49 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | repos: 6 | - repo: https://github.com/pre-commit/pre-commit-hooks 7 | rev: v4.5.0 8 | hooks: 9 | - id: check-yaml 10 | - id: end-of-file-fixer 11 | - id: trailing-whitespace 12 | - repo: https://github.com/astral-sh/ruff-pre-commit 13 | rev: v0.3.4 14 | hooks: 15 | - id: ruff-format 16 | - id: ruff 17 | args: ["--fix"] 18 | - repo: https://github.com/fsfe/reuse-tool 19 | rev: v3.0.1 20 | hooks: 21 | - id: reuse 22 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | # Read the Docs configuration file 6 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 7 | 8 | # Required 9 | version: 2 10 | 11 | sphinx: 12 | configuration: docs/conf.py 13 | 14 | build: 15 | os: ubuntu-20.04 16 | tools: 17 | python: "3" 18 | 19 | python: 20 | install: 21 | - requirements: docs/requirements.txt 22 | - requirements: requirements.txt 23 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 6 | 7 | # Adafruit Community Code of Conduct 8 | 9 | ## Our Pledge 10 | 11 | In the interest of fostering an open and welcoming environment, we as 12 | contributors and leaders pledge to making participation in our project and 13 | our community a harassment-free experience for everyone, regardless of age, body 14 | size, disability, ethnicity, gender identity and expression, level or type of 15 | experience, education, socio-economic status, nationality, personal appearance, 16 | race, religion, or sexual identity and orientation. 17 | 18 | ## Our Standards 19 | 20 | We are committed to providing a friendly, safe and welcoming environment for 21 | all. 22 | 23 | Examples of behavior that contributes to creating a positive environment 24 | include: 25 | 26 | * Be kind and courteous to others 27 | * Using welcoming and inclusive language 28 | * Being respectful of differing viewpoints and experiences 29 | * Collaborating with other community members 30 | * Gracefully accepting constructive criticism 31 | * Focusing on what is best for the community 32 | * Showing empathy towards other community members 33 | 34 | Examples of unacceptable behavior by participants include: 35 | 36 | * The use of sexualized language or imagery and sexual attention or advances 37 | * The use of inappropriate images, including in a community member's avatar 38 | * The use of inappropriate language, including in a community member's nickname 39 | * Any spamming, flaming, baiting or other attention-stealing behavior 40 | * Excessive or unwelcome helping; answering outside the scope of the question 41 | asked 42 | * Trolling, insulting/derogatory comments, and personal or political attacks 43 | * Promoting or spreading disinformation, lies, or conspiracy theories against 44 | a person, group, organisation, project, or community 45 | * Public or private harassment 46 | * Publishing others' private information, such as a physical or electronic 47 | address, without explicit permission 48 | * Other conduct which could reasonably be considered inappropriate 49 | 50 | The goal of the standards and moderation guidelines outlined here is to build 51 | and maintain a respectful community. We ask that you don’t just aim to be 52 | "technically unimpeachable", but rather try to be your best self. 53 | 54 | We value many things beyond technical expertise, including collaboration and 55 | supporting others within our community. Providing a positive experience for 56 | other community members can have a much more significant impact than simply 57 | providing the correct answer. 58 | 59 | ## Our Responsibilities 60 | 61 | Project leaders are responsible for clarifying the standards of acceptable 62 | behavior and are expected to take appropriate and fair corrective action in 63 | response to any instances of unacceptable behavior. 64 | 65 | Project leaders have the right and responsibility to remove, edit, or 66 | reject messages, comments, commits, code, issues, and other contributions 67 | that are not aligned to this Code of Conduct, or to ban temporarily or 68 | permanently any community member for other behaviors that they deem 69 | inappropriate, threatening, offensive, or harmful. 70 | 71 | ## Moderation 72 | 73 | Instances of behaviors that violate the Adafruit Community Code of Conduct 74 | may be reported by any member of the community. Community members are 75 | encouraged to report these situations, including situations they witness 76 | involving other community members. 77 | 78 | You may report in the following ways: 79 | 80 | In any situation, you may send an email to . 81 | 82 | On the Adafruit Discord, you may send an open message from any channel 83 | to all Community Moderators by tagging @community moderators. You may 84 | also send an open message from any channel, or a direct message to 85 | @kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442, 86 | @sommersoft#0222, @Mr. Certainly#0472 or @Andon#8175. 87 | 88 | Email and direct message reports will be kept confidential. 89 | 90 | In situations on Discord where the issue is particularly egregious, possibly 91 | illegal, requires immediate action, or violates the Discord terms of service, 92 | you should also report the message directly to Discord. 93 | 94 | These are the steps for upholding our community’s standards of conduct. 95 | 96 | 1. Any member of the community may report any situation that violates the 97 | Adafruit Community Code of Conduct. All reports will be reviewed and 98 | investigated. 99 | 2. If the behavior is an egregious violation, the community member who 100 | committed the violation may be banned immediately, without warning. 101 | 3. Otherwise, moderators will first respond to such behavior with a warning. 102 | 4. Moderators follow a soft "three strikes" policy - the community member may 103 | be given another chance, if they are receptive to the warning and change their 104 | behavior. 105 | 5. If the community member is unreceptive or unreasonable when warned by a 106 | moderator, or the warning goes unheeded, they may be banned for a first or 107 | second offense. Repeated offenses will result in the community member being 108 | banned. 109 | 110 | ## Scope 111 | 112 | This Code of Conduct and the enforcement policies listed above apply to all 113 | Adafruit Community venues. This includes but is not limited to any community 114 | spaces (both public and private), the entire Adafruit Discord server, and 115 | Adafruit GitHub repositories. Examples of Adafruit Community spaces include 116 | but are not limited to meet-ups, audio chats on the Adafruit Discord, or 117 | interaction at a conference. 118 | 119 | This Code of Conduct applies both within project spaces and in public spaces 120 | when an individual is representing the project or its community. As a community 121 | member, you are representing our community, and are expected to behave 122 | accordingly. 123 | 124 | ## Attribution 125 | 126 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 127 | version 1.4, available at 128 | , 129 | and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html). 130 | 131 | For other projects adopting the Adafruit Community Code of 132 | Conduct, please contact the maintainers of those projects for enforcement. 133 | If you wish to use this code of conduct for your own project, consider 134 | explicitly mentioning your moderation policy or making a copy with your 135 | own moderation policy so as to avoid confusion. 136 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 ladyada for Adafruit Industries 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LICENSES/CC-BY-4.0.txt: -------------------------------------------------------------------------------- 1 | Creative Commons Attribution 4.0 International Creative Commons Corporation 2 | ("Creative Commons") is not a law firm and does not provide legal services 3 | or legal advice. Distribution of Creative Commons public licenses does not 4 | create a lawyer-client or other relationship. Creative Commons makes its licenses 5 | and related information available on an "as-is" basis. Creative Commons gives 6 | no warranties regarding its licenses, any material licensed under their terms 7 | and conditions, or any related information. Creative Commons disclaims all 8 | liability for damages resulting from their use to the fullest extent possible. 9 | 10 | Using Creative Commons Public Licenses 11 | 12 | Creative Commons public licenses provide a standard set of terms and conditions 13 | that creators and other rights holders may use to share original works of 14 | authorship and other material subject to copyright and certain other rights 15 | specified in the public license below. The following considerations are for 16 | informational purposes only, are not exhaustive, and do not form part of our 17 | licenses. 18 | 19 | Considerations for licensors: Our public licenses are intended for use by 20 | those authorized to give the public permission to use material in ways otherwise 21 | restricted by copyright and certain other rights. Our licenses are irrevocable. 22 | Licensors should read and understand the terms and conditions of the license 23 | they choose before applying it. Licensors should also secure all rights necessary 24 | before applying our licenses so that the public can reuse the material as 25 | expected. Licensors should clearly mark any material not subject to the license. 26 | This includes other CC-licensed material, or material used under an exception 27 | or limitation to copyright. More considerations for licensors : wiki.creativecommons.org/Considerations_for_licensors 28 | 29 | Considerations for the public: By using one of our public licenses, a licensor 30 | grants the public permission to use the licensed material under specified 31 | terms and conditions. If the licensor's permission is not necessary for any 32 | reason–for example, because of any applicable exception or limitation to copyright–then 33 | that use is not regulated by the license. Our licenses grant only permissions 34 | under copyright and certain other rights that a licensor has authority to 35 | grant. Use of the licensed material may still be restricted for other reasons, 36 | including because others have copyright or other rights in the material. A 37 | licensor may make special requests, such as asking that all changes be marked 38 | or described. Although not required by our licenses, you are encouraged to 39 | respect those requests where reasonable. More considerations for the public 40 | : wiki.creativecommons.org/Considerations_for_licensees Creative Commons Attribution 41 | 4.0 International Public License 42 | 43 | By exercising the Licensed Rights (defined below), You accept and agree to 44 | be bound by the terms and conditions of this Creative Commons Attribution 45 | 4.0 International Public License ("Public License"). To the extent this Public 46 | License may be interpreted as a contract, You are granted the Licensed Rights 47 | in consideration of Your acceptance of these terms and conditions, and the 48 | Licensor grants You such rights in consideration of benefits the Licensor 49 | receives from making the Licensed Material available under these terms and 50 | conditions. 51 | 52 | Section 1 – Definitions. 53 | 54 | a. Adapted Material means material subject to Copyright and Similar Rights 55 | that is derived from or based upon the Licensed Material and in which the 56 | Licensed Material is translated, altered, arranged, transformed, or otherwise 57 | modified in a manner requiring permission under the Copyright and Similar 58 | Rights held by the Licensor. For purposes of this Public License, where the 59 | Licensed Material is a musical work, performance, or sound recording, Adapted 60 | Material is always produced where the Licensed Material is synched in timed 61 | relation with a moving image. 62 | 63 | b. Adapter's License means the license You apply to Your Copyright and Similar 64 | Rights in Your contributions to Adapted Material in accordance with the terms 65 | and conditions of this Public License. 66 | 67 | c. Copyright and Similar Rights means copyright and/or similar rights closely 68 | related to copyright including, without limitation, performance, broadcast, 69 | sound recording, and Sui Generis Database Rights, without regard to how the 70 | rights are labeled or categorized. For purposes of this Public License, the 71 | rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. 72 | 73 | d. Effective Technological Measures means those measures that, in the absence 74 | of proper authority, may not be circumvented under laws fulfilling obligations 75 | under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, 76 | and/or similar international agreements. 77 | 78 | e. Exceptions and Limitations means fair use, fair dealing, and/or any other 79 | exception or limitation to Copyright and Similar Rights that applies to Your 80 | use of the Licensed Material. 81 | 82 | f. Licensed Material means the artistic or literary work, database, or other 83 | material to which the Licensor applied this Public License. 84 | 85 | g. Licensed Rights means the rights granted to You subject to the terms and 86 | conditions of this Public License, which are limited to all Copyright and 87 | Similar Rights that apply to Your use of the Licensed Material and that the 88 | Licensor has authority to license. 89 | 90 | h. Licensor means the individual(s) or entity(ies) granting rights under this 91 | Public License. 92 | 93 | i. Share means to provide material to the public by any means or process that 94 | requires permission under the Licensed Rights, such as reproduction, public 95 | display, public performance, distribution, dissemination, communication, or 96 | importation, and to make material available to the public including in ways 97 | that members of the public may access the material from a place and at a time 98 | individually chosen by them. 99 | 100 | j. Sui Generis Database Rights means rights other than copyright resulting 101 | from Directive 96/9/EC of the European Parliament and of the Council of 11 102 | March 1996 on the legal protection of databases, as amended and/or succeeded, 103 | as well as other essentially equivalent rights anywhere in the world. 104 | 105 | k. You means the individual or entity exercising the Licensed Rights under 106 | this Public License. Your has a corresponding meaning. 107 | 108 | Section 2 – Scope. 109 | 110 | a. License grant. 111 | 112 | 1. Subject to the terms and conditions of this Public License, the Licensor 113 | hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, 114 | irrevocable license to exercise the Licensed Rights in the Licensed Material 115 | to: 116 | 117 | A. reproduce and Share the Licensed Material, in whole or in part; and 118 | 119 | B. produce, reproduce, and Share Adapted Material. 120 | 121 | 2. Exceptions and Limitations. For the avoidance of doubt, where Exceptions 122 | and Limitations apply to Your use, this Public License does not apply, and 123 | You do not need to comply with its terms and conditions. 124 | 125 | 3. Term. The term of this Public License is specified in Section 6(a). 126 | 127 | 4. Media and formats; technical modifications allowed. The Licensor authorizes 128 | You to exercise the Licensed Rights in all media and formats whether now known 129 | or hereafter created, and to make technical modifications necessary to do 130 | so. The Licensor waives and/or agrees not to assert any right or authority 131 | to forbid You from making technical modifications necessary to exercise the 132 | Licensed Rights, including technical modifications necessary to circumvent 133 | Effective Technological Measures. For purposes of this Public License, simply 134 | making modifications authorized by this Section 2(a)(4) never produces Adapted 135 | Material. 136 | 137 | 5. Downstream recipients. 138 | 139 | A. Offer from the Licensor – Licensed Material. Every recipient of the Licensed 140 | Material automatically receives an offer from the Licensor to exercise the 141 | Licensed Rights under the terms and conditions of this Public License. 142 | 143 | B. No downstream restrictions. You may not offer or impose any additional 144 | or different terms or conditions on, or apply any Effective Technological 145 | Measures to, the Licensed Material if doing so restricts exercise of the Licensed 146 | Rights by any recipient of the Licensed Material. 147 | 148 | 6. No endorsement. Nothing in this Public License constitutes or may be construed 149 | as permission to assert or imply that You are, or that Your use of the Licensed 150 | Material is, connected with, or sponsored, endorsed, or granted official status 151 | by, the Licensor or others designated to receive attribution as provided in 152 | Section 3(a)(1)(A)(i). 153 | 154 | b. Other rights. 155 | 156 | 1. Moral rights, such as the right of integrity, are not licensed under this 157 | Public License, nor are publicity, privacy, and/or other similar personality 158 | rights; however, to the extent possible, the Licensor waives and/or agrees 159 | not to assert any such rights held by the Licensor to the limited extent necessary 160 | to allow You to exercise the Licensed Rights, but not otherwise. 161 | 162 | 2. Patent and trademark rights are not licensed under this Public License. 163 | 164 | 3. To the extent possible, the Licensor waives any right to collect royalties 165 | from You for the exercise of the Licensed Rights, whether directly or through 166 | a collecting society under any voluntary or waivable statutory or compulsory 167 | licensing scheme. In all other cases the Licensor expressly reserves any right 168 | to collect such royalties. 169 | 170 | Section 3 – License Conditions. 171 | 172 | Your exercise of the Licensed Rights is expressly made subject to the following 173 | conditions. 174 | 175 | a. Attribution. 176 | 177 | 1. If You Share the Licensed Material (including in modified form), You must: 178 | 179 | A. retain the following if it is supplied by the Licensor with the Licensed 180 | Material: 181 | 182 | i. identification of the creator(s) of the Licensed Material and any others 183 | designated to receive attribution, in any reasonable manner requested by the 184 | Licensor (including by pseudonym if designated); 185 | 186 | ii. a copyright notice; 187 | 188 | iii. a notice that refers to this Public License; 189 | 190 | iv. a notice that refers to the disclaimer of warranties; 191 | 192 | v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; 193 | 194 | B. indicate if You modified the Licensed Material and retain an indication 195 | of any previous modifications; and 196 | 197 | C. indicate the Licensed Material is licensed under this Public License, and 198 | include the text of, or the URI or hyperlink to, this Public License. 199 | 200 | 2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner 201 | based on the medium, means, and context in which You Share the Licensed Material. 202 | For example, it may be reasonable to satisfy the conditions by providing a 203 | URI or hyperlink to a resource that includes the required information. 204 | 205 | 3. If requested by the Licensor, You must remove any of the information required 206 | by Section 3(a)(1)(A) to the extent reasonably practicable. 207 | 208 | 4. If You Share Adapted Material You produce, the Adapter's License You apply 209 | must not prevent recipients of the Adapted Material from complying with this 210 | Public License. 211 | 212 | Section 4 – Sui Generis Database Rights. 213 | 214 | Where the Licensed Rights include Sui Generis Database Rights that apply to 215 | Your use of the Licensed Material: 216 | 217 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, 218 | reuse, reproduce, and Share all or a substantial portion of the contents of 219 | the database; 220 | 221 | b. if You include all or a substantial portion of the database contents in 222 | a database in which You have Sui Generis Database Rights, then the database 223 | in which You have Sui Generis Database Rights (but not its individual contents) 224 | is Adapted Material; and 225 | 226 | c. You must comply with the conditions in Section 3(a) if You Share all or 227 | a substantial portion of the contents of the database. 228 | 229 | For the avoidance of doubt, this Section 4 supplements and does not replace 230 | Your obligations under this Public License where the Licensed Rights include 231 | other Copyright and Similar Rights. 232 | 233 | Section 5 – Disclaimer of Warranties and Limitation of Liability. 234 | 235 | a. Unless otherwise separately undertaken by the Licensor, to the extent possible, 236 | the Licensor offers the Licensed Material as-is and as-available, and makes 237 | no representations or warranties of any kind concerning the Licensed Material, 238 | whether express, implied, statutory, or other. This includes, without limitation, 239 | warranties of title, merchantability, fitness for a particular purpose, non-infringement, 240 | absence of latent or other defects, accuracy, or the presence or absence of 241 | errors, whether or not known or discoverable. Where disclaimers of warranties 242 | are not allowed in full or in part, this disclaimer may not apply to You. 243 | 244 | b. To the extent possible, in no event will the Licensor be liable to You 245 | on any legal theory (including, without limitation, negligence) or otherwise 246 | for any direct, special, indirect, incidental, consequential, punitive, exemplary, 247 | or other losses, costs, expenses, or damages arising out of this Public License 248 | or use of the Licensed Material, even if the Licensor has been advised of 249 | the possibility of such losses, costs, expenses, or damages. Where a limitation 250 | of liability is not allowed in full or in part, this limitation may not apply 251 | to You. 252 | 253 | c. The disclaimer of warranties and limitation of liability provided above 254 | shall be interpreted in a manner that, to the extent possible, most closely 255 | approximates an absolute disclaimer and waiver of all liability. 256 | 257 | Section 6 – Term and Termination. 258 | 259 | a. This Public License applies for the term of the Copyright and Similar Rights 260 | licensed here. However, if You fail to comply with this Public License, then 261 | Your rights under this Public License terminate automatically. 262 | 263 | b. Where Your right to use the Licensed Material has terminated under Section 264 | 6(a), it reinstates: 265 | 266 | 1. automatically as of the date the violation is cured, provided it is cured 267 | within 30 days of Your discovery of the violation; or 268 | 269 | 2. upon express reinstatement by the Licensor. 270 | 271 | c. For the avoidance of doubt, this Section 6(b) does not affect any right 272 | the Licensor may have to seek remedies for Your violations of this Public 273 | License. 274 | 275 | d. For the avoidance of doubt, the Licensor may also offer the Licensed Material 276 | under separate terms or conditions or stop distributing the Licensed Material 277 | at any time; however, doing so will not terminate this Public License. 278 | 279 | e. Sections 1, 5, 6, 7, and 8 survive termination of this Public License. 280 | 281 | Section 7 – Other Terms and Conditions. 282 | 283 | a. The Licensor shall not be bound by any additional or different terms or 284 | conditions communicated by You unless expressly agreed. 285 | 286 | b. Any arrangements, understandings, or agreements regarding the Licensed 287 | Material not stated herein are separate from and independent of the terms 288 | and conditions of this Public License. 289 | 290 | Section 8 – Interpretation. 291 | 292 | a. For the avoidance of doubt, this Public License does not, and shall not 293 | be interpreted to, reduce, limit, restrict, or impose conditions on any use 294 | of the Licensed Material that could lawfully be made without permission under 295 | this Public License. 296 | 297 | b. To the extent possible, if any provision of this Public License is deemed 298 | unenforceable, it shall be automatically reformed to the minimum extent necessary 299 | to make it enforceable. If the provision cannot be reformed, it shall be severed 300 | from this Public License without affecting the enforceability of the remaining 301 | terms and conditions. 302 | 303 | c. No term or condition of this Public License will be waived and no failure 304 | to comply consented to unless expressly agreed to by the Licensor. 305 | 306 | d. Nothing in this Public License constitutes or may be interpreted as a limitation 307 | upon, or waiver of, any privileges and immunities that apply to the Licensor 308 | or You, including from the legal processes of any jurisdiction or authority. 309 | 310 | Creative Commons is not a party to its public licenses. Notwithstanding, Creative 311 | Commons may elect to apply one of its public licenses to material it publishes 312 | and in those instances will be considered the "Licensor." The text of the 313 | Creative Commons public licenses is dedicated to the public domain under the 314 | CC0 Public Domain Dedication. Except for the limited purpose of indicating 315 | that material is shared under a Creative Commons public license or as otherwise 316 | permitted by the Creative Commons policies published at creativecommons.org/policies, 317 | Creative Commons does not authorize the use of the trademark "Creative Commons" 318 | or any other trademark or logo of Creative Commons without its prior written 319 | consent including, without limitation, in connection with any unauthorized 320 | modifications to any of its public licenses or any other arrangements, understandings, 321 | or agreements concerning use of licensed material. For the avoidance of doubt, 322 | this paragraph does not form part of the public licenses. 323 | 324 | Creative Commons may be contacted at creativecommons.org. 325 | -------------------------------------------------------------------------------- /LICENSES/MIT.txt: -------------------------------------------------------------------------------- 1 | MIT License Copyright (c) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice (including the next 11 | paragraph) shall be included in all copies or substantial portions of the 12 | Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 17 | OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 18 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 19 | OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /LICENSES/Unlicense.txt: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute 4 | this software, either in source code form or as a compiled binary, for any 5 | purpose, commercial or non-commercial, and by any means. 6 | 7 | In jurisdictions that recognize copyright laws, the author or authors of this 8 | software dedicate any and all copyright interest in the software to the public 9 | domain. We make this dedication for the benefit of the public at large and 10 | to the detriment of our heirs and successors. We intend this dedication to 11 | be an overt act of relinquishment in perpetuity of all present and future 12 | rights to this software under copyright law. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 17 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 18 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH 19 | THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. For more information, 20 | please refer to 21 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Introduction 2 | ============ 3 | 4 | .. image:: https://readthedocs.org/projects/adafruit-circuitpython-bmp280/badge/?version=latest 5 | :target: https://docs.circuitpython.org/projects/bmp280/en/latest/ 6 | :alt: Documentation Status 7 | 8 | .. image:: https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_Bundle/main/badges/adafruit_discord.svg 9 | :target: https://adafru.it/discord 10 | :alt: Discord 11 | 12 | .. image:: https://github.com/adafruit/Adafruit_CircuitPython_BMP280/workflows/Build%20CI/badge.svg 13 | :target: https://github.com/adafruit/Adafruit_CircuitPython_BMP280/actions/ 14 | :alt: Build Status 15 | 16 | .. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json 17 | :target: https://github.com/astral-sh/ruff 18 | :alt: Code Style: Ruff 19 | 20 | CircuitPython driver from BMP280 Temperature and Barometic Pressure sensor 21 | 22 | Installation and Dependencies 23 | ============================= 24 | 25 | This driver depends on: 26 | 27 | * `Adafruit CircuitPython `_ 28 | * `Bus Device `_ 29 | 30 | Please ensure all dependencies are available on the CircuitPython filesystem. 31 | This is easily achieved by downloading 32 | `the Adafruit library and driver bundle `_. 33 | 34 | Installing from PyPI 35 | -------------------- 36 | 37 | On supported GNU/Linux systems like the Raspberry Pi, you can install the driver 38 | `from PyPI `_. To install 39 | for the current user: 40 | 41 | .. code-block:: shell 42 | 43 | pip3 install adafruit-circuitpython-bmp280 44 | 45 | To install system-wide (this may be required in some cases): 46 | 47 | .. code-block:: shell 48 | 49 | sudo pip3 install adafruit-circuitpython-bmp280 50 | 51 | To install in a virtual environment in your current project: 52 | 53 | .. code-block:: shell 54 | 55 | mkdir project-name && cd project-name 56 | python3 -m venv .venv 57 | source .venv/bin/activate 58 | pip3 install adafruit-circuitpython-bmp280 59 | 60 | Usage Example 61 | ============= 62 | 63 | .. code-block:: python 64 | 65 | import time 66 | import board 67 | # import digitalio # For use with SPI 68 | import adafruit_bmp280 69 | 70 | # Create sensor object, communicating over the board's default I2C bus 71 | i2c = board.I2C() # uses board.SCL and board.SDA 72 | bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c) 73 | 74 | # OR Create sensor object, communicating over the board's default SPI bus 75 | # spi = board.SPI() 76 | # bmp_cs = digitalio.DigitalInOut(board.D10) 77 | # bmp280 = adafruit_bmp280.Adafruit_BMP280_SPI(spi, bmp_cs) 78 | 79 | # change this to match the location's pressure (hPa) at sea level 80 | bmp280.sea_level_pressure = 1013.25 81 | 82 | while True: 83 | print("\nTemperature: %0.1f C" % bmp280.temperature) 84 | print("Pressure: %0.1f hPa" % bmp280.pressure) 85 | print("Altitude = %0.2f meters" % bmp280.altitude) 86 | time.sleep(2) 87 | 88 | Documentation 89 | ============= 90 | 91 | API documentation for this library can be found on `Read the Docs `_. 92 | 93 | For information on building library documentation, please check out `this guide `_. 94 | 95 | Contributing 96 | ============ 97 | 98 | Contributions are welcome! Please read our `Code of Conduct 99 | `_ 100 | before contributing to help this project stay welcoming. 101 | -------------------------------------------------------------------------------- /README.rst.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | 3 | SPDX-License-Identifier: MIT 4 | -------------------------------------------------------------------------------- /adafruit_bmp280.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | # SPDX-FileCopyrightText: 2022 Bill Van Leeuwen for Adafruit Industries 6 | # 7 | # SPDX-License-Identifier: MIT 8 | 9 | """ 10 | `adafruit_bmp280` 11 | =============================================================================== 12 | 13 | CircuitPython driver from BMP280 Temperature and Barometric Pressure sensor 14 | 15 | * Author(s): ladyada 16 | 17 | Implementation Notes 18 | -------------------- 19 | 20 | **Hardware:** 21 | 22 | * `Adafruit from BMP280 Temperature and Barometric 23 | Pressure sensor `_ 24 | 25 | **Software and Dependencies:** 26 | 27 | * Adafruit CircuitPython firmware for the supported boards: 28 | https://github.com/adafruit/circuitpython/releases 29 | * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice 30 | """ 31 | 32 | import math 33 | import struct 34 | from time import sleep 35 | 36 | from micropython import const 37 | 38 | try: 39 | from typing import Optional 40 | 41 | # Used only for type annotations. 42 | from busio import I2C, SPI 43 | from digitalio import DigitalInOut 44 | 45 | except ImportError: 46 | pass 47 | 48 | __version__ = "0.0.0+auto.0" 49 | __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BMP280.git" 50 | 51 | # I2C ADDRESS/BITS/SETTINGS 52 | # ----------------------------------------------------------------------- 53 | _CHIP_ID = const(0x58) 54 | 55 | _REGISTER_CHIPID = const(0xD0) 56 | _REGISTER_DIG_T1 = const(0x88) 57 | _REGISTER_SOFTRESET = const(0xE0) 58 | _REGISTER_STATUS = const(0xF3) 59 | _REGISTER_CTRL_MEAS = const(0xF4) 60 | _REGISTER_CONFIG = const(0xF5) 61 | _REGISTER_PRESSUREDATA = const(0xF7) 62 | _REGISTER_TEMPDATA = const(0xFA) 63 | 64 | 65 | """iir_filter values""" 66 | IIR_FILTER_DISABLE = const(0) 67 | IIR_FILTER_X2 = const(0x01) 68 | IIR_FILTER_X4 = const(0x02) 69 | IIR_FILTER_X8 = const(0x03) 70 | IIR_FILTER_X16 = const(0x04) 71 | 72 | _BMP280_IIR_FILTERS = ( 73 | IIR_FILTER_DISABLE, 74 | IIR_FILTER_X2, 75 | IIR_FILTER_X4, 76 | IIR_FILTER_X8, 77 | IIR_FILTER_X16, 78 | ) 79 | 80 | """overscan values for temperature, pressure, and humidity""" 81 | OVERSCAN_DISABLE = const(0x00) 82 | OVERSCAN_X1 = const(0x01) 83 | OVERSCAN_X2 = const(0x02) 84 | OVERSCAN_X4 = const(0x03) 85 | OVERSCAN_X8 = const(0x04) 86 | OVERSCAN_X16 = const(0x05) 87 | 88 | _BMP280_OVERSCANS = { 89 | OVERSCAN_DISABLE: 0, 90 | OVERSCAN_X1: 1, 91 | OVERSCAN_X2: 2, 92 | OVERSCAN_X4: 4, 93 | OVERSCAN_X8: 8, 94 | OVERSCAN_X16: 16, 95 | } 96 | 97 | """mode values""" 98 | MODE_SLEEP = const(0x00) 99 | MODE_FORCE = const(0x01) 100 | MODE_NORMAL = const(0x03) 101 | 102 | _BMP280_MODES = (MODE_SLEEP, MODE_FORCE, MODE_NORMAL) 103 | """ 104 | standby timeconstant values 105 | TC_X[_Y] where X=milliseconds and Y=tenths of a millisecond 106 | """ 107 | STANDBY_TC_0_5 = const(0x00) # 0.5ms 108 | STANDBY_TC_10 = const(0x06) # 10ms 109 | STANDBY_TC_20 = const(0x07) # 20ms 110 | STANDBY_TC_62_5 = const(0x01) # 62.5ms 111 | STANDBY_TC_125 = const(0x02) # 125ms 112 | STANDBY_TC_250 = const(0x03) # 250ms 113 | STANDBY_TC_500 = const(0x04) # 500ms 114 | STANDBY_TC_1000 = const(0x05) # 1000ms 115 | 116 | _BMP280_STANDBY_TCS = ( 117 | STANDBY_TC_0_5, 118 | STANDBY_TC_10, 119 | STANDBY_TC_20, 120 | STANDBY_TC_62_5, 121 | STANDBY_TC_125, 122 | STANDBY_TC_250, 123 | STANDBY_TC_500, 124 | STANDBY_TC_1000, 125 | ) 126 | 127 | 128 | class Adafruit_BMP280: 129 | """Base BMP280 object. Use :class:`Adafruit_BMP280_I2C` or :class:`Adafruit_BMP280_SPI` 130 | instead of this. This checks the BMP280 was found, reads the coefficients and 131 | enables the sensor for continuous reads 132 | 133 | .. note:: 134 | The operational range of the BMP280 is 300-1100 hPa. 135 | Pressure measurements outside this range may not be as accurate. 136 | 137 | """ 138 | 139 | def __init__(self) -> None: 140 | # Check device ID. 141 | chip_id = self._read_byte(_REGISTER_CHIPID) 142 | if _CHIP_ID != chip_id: 143 | raise RuntimeError("Failed to find BMP280! Chip ID 0x%x" % chip_id) 144 | # Set some reasonable defaults. 145 | self._iir_filter = IIR_FILTER_DISABLE 146 | self._overscan_temperature = OVERSCAN_X2 147 | self._overscan_pressure = OVERSCAN_X16 148 | self._t_standby = STANDBY_TC_0_5 149 | self._mode = MODE_SLEEP 150 | self._reset() 151 | self._read_coefficients() 152 | self._write_ctrl_meas() 153 | self._write_config() 154 | self.sea_level_pressure = 1013.25 155 | """Pressure in hectoPascals at sea level. Used to calibrate `altitude`.""" 156 | self._t_fine = None 157 | 158 | def _read_temperature(self) -> None: 159 | # perform one measurement 160 | if self.mode != MODE_NORMAL: 161 | self.mode = MODE_FORCE 162 | # Wait for conversion to complete 163 | while self._get_status() & 0x08: 164 | sleep(0.002) 165 | raw_temperature = self._read24(_REGISTER_TEMPDATA) / 16 # lowest 4 bits get dropped 166 | # print("raw temp: ", UT) 167 | var1 = (raw_temperature / 16384.0 - self._temp_calib[0] / 1024.0) * self._temp_calib[1] 168 | # print(var1) 169 | var2 = ( 170 | (raw_temperature / 131072.0 - self._temp_calib[0] / 8192.0) 171 | * (raw_temperature / 131072.0 - self._temp_calib[0] / 8192.0) 172 | ) * self._temp_calib[2] 173 | # print(var2) 174 | 175 | self._t_fine = int(var1 + var2) 176 | # print("t_fine: ", self.t_fine) 177 | 178 | def _reset(self) -> None: 179 | """Soft reset the sensor""" 180 | self._write_register_byte(_REGISTER_SOFTRESET, 0xB6) 181 | sleep(0.004) # Datasheet says 2ms. Using 4ms just to be safe 182 | 183 | def _write_ctrl_meas(self) -> None: 184 | """ 185 | Write the values to the ctrl_meas register in the device 186 | ctrl_meas sets the pressure and temperature data acquisition options 187 | """ 188 | self._write_register_byte(_REGISTER_CTRL_MEAS, self._ctrl_meas) 189 | 190 | def _get_status(self) -> int: 191 | """Get the value from the status register in the device""" 192 | return self._read_byte(_REGISTER_STATUS) 193 | 194 | def _read_config(self) -> int: 195 | """Read the value from the config register in the device""" 196 | return self._read_byte(_REGISTER_CONFIG) 197 | 198 | def _write_config(self) -> None: 199 | """Write the value to the config register in the device""" 200 | normal_flag = False 201 | if self._mode == MODE_NORMAL: 202 | # Writes to the config register may be ignored while in Normal mode 203 | normal_flag = True 204 | self.mode = MODE_SLEEP # So we switch to Sleep mode first 205 | self._write_register_byte(_REGISTER_CONFIG, self._config) 206 | if normal_flag: 207 | self.mode = MODE_NORMAL 208 | 209 | @property 210 | def mode(self) -> int: 211 | """ 212 | Operation mode 213 | Allowed values are set in the MODE enum class 214 | """ 215 | return self._mode 216 | 217 | @mode.setter 218 | def mode(self, value: int) -> None: 219 | if not value in _BMP280_MODES: 220 | raise ValueError("Mode '%s' not supported" % (value)) 221 | self._mode = value 222 | self._write_ctrl_meas() 223 | 224 | @property 225 | def standby_period(self) -> int: 226 | """ 227 | Control the inactive period when in Normal mode 228 | Allowed standby periods are set the STANDBY enum class 229 | """ 230 | return self._t_standby 231 | 232 | @standby_period.setter 233 | def standby_period(self, value: int) -> None: 234 | if not value in _BMP280_STANDBY_TCS: 235 | raise ValueError("Standby Period '%s' not supported" % (value)) 236 | if self._t_standby == value: 237 | return 238 | self._t_standby = value 239 | self._write_config() 240 | 241 | @property 242 | def overscan_temperature(self) -> int: 243 | """ 244 | Temperature Oversampling 245 | Allowed values are set in the OVERSCAN enum class 246 | """ 247 | return self._overscan_temperature 248 | 249 | @overscan_temperature.setter 250 | def overscan_temperature(self, value: int) -> None: 251 | if not value in _BMP280_OVERSCANS: 252 | raise ValueError("Overscan value '%s' not supported" % (value)) 253 | self._overscan_temperature = value 254 | self._write_ctrl_meas() 255 | 256 | @property 257 | def overscan_pressure(self) -> int: 258 | """ 259 | Pressure Oversampling 260 | Allowed values are set in the OVERSCAN enum class 261 | """ 262 | return self._overscan_pressure 263 | 264 | @overscan_pressure.setter 265 | def overscan_pressure(self, value: int) -> None: 266 | if not value in _BMP280_OVERSCANS: 267 | raise ValueError("Overscan value '%s' not supported" % (value)) 268 | self._overscan_pressure = value 269 | self._write_ctrl_meas() 270 | 271 | @property 272 | def iir_filter(self) -> int: 273 | """ 274 | Controls the time constant of the IIR filter 275 | Allowed values are set in the IIR_FILTER enum class 276 | """ 277 | return self._iir_filter 278 | 279 | @iir_filter.setter 280 | def iir_filter(self, value: int) -> None: 281 | if not value in _BMP280_IIR_FILTERS: 282 | raise ValueError("IIR Filter '%s' not supported" % (value)) 283 | self._iir_filter = value 284 | self._write_config() 285 | 286 | @property 287 | def _config(self) -> int: 288 | """Value to be written to the device's config register""" 289 | config = 0 290 | if self.mode == MODE_NORMAL: 291 | config += self._t_standby << 5 292 | if self._iir_filter: 293 | config += self._iir_filter << 2 294 | return config 295 | 296 | @property 297 | def _ctrl_meas(self) -> int: 298 | """Value to be written to the device's ctrl_meas register""" 299 | ctrl_meas = self.overscan_temperature << 5 300 | ctrl_meas += self.overscan_pressure << 2 301 | ctrl_meas += self.mode 302 | return ctrl_meas 303 | 304 | @property 305 | def measurement_time_typical(self) -> float: 306 | """Typical time in milliseconds required to complete a measurement in normal mode""" 307 | meas_time_ms = 1 308 | if self.overscan_temperature != OVERSCAN_DISABLE: 309 | meas_time_ms += 2 * _BMP280_OVERSCANS.get(self.overscan_temperature) 310 | if self.overscan_pressure != OVERSCAN_DISABLE: 311 | meas_time_ms += 2 * _BMP280_OVERSCANS.get(self.overscan_pressure) + 0.5 312 | return meas_time_ms 313 | 314 | @property 315 | def measurement_time_max(self) -> float: 316 | """Maximum time in milliseconds required to complete a measurement in normal mode""" 317 | meas_time_ms = 1.25 318 | if self.overscan_temperature != OVERSCAN_DISABLE: 319 | meas_time_ms += 2.3 * _BMP280_OVERSCANS.get(self.overscan_temperature) 320 | if self.overscan_pressure != OVERSCAN_DISABLE: 321 | meas_time_ms += 2.3 * _BMP280_OVERSCANS.get(self.overscan_pressure) + 0.575 322 | return meas_time_ms 323 | 324 | @property 325 | def temperature(self) -> float: 326 | """The compensated temperature in degrees Celsius.""" 327 | self._read_temperature() 328 | return self._t_fine / 5120.0 329 | 330 | @property 331 | def pressure(self) -> Optional[float]: 332 | """ 333 | The compensated pressure in hectoPascals. 334 | returns `None` if pressure measurement is disabled 335 | """ 336 | self._read_temperature() 337 | 338 | # Algorithm from the BMP280 driver 339 | # https://github.com/BoschSensortec/BMP280_driver/blob/master/bmp280.c 340 | adc = self._read24(_REGISTER_PRESSUREDATA) / 16 # lowest 4 bits get dropped 341 | var1 = float(self._t_fine) / 2.0 - 64000.0 342 | var2 = var1 * var1 * self._pressure_calib[5] / 32768.0 343 | var2 = var2 + var1 * self._pressure_calib[4] * 2.0 344 | var2 = var2 / 4.0 + self._pressure_calib[3] * 65536.0 345 | var3 = self._pressure_calib[2] * var1 * var1 / 524288.0 346 | var1 = (var3 + self._pressure_calib[1] * var1) / 524288.0 347 | var1 = (1.0 + var1 / 32768.0) * self._pressure_calib[0] 348 | if not var1: # avoid exception caused by division by zero 349 | raise ArithmeticError( 350 | "Invalid result possibly related to error while reading the calibration registers" 351 | ) 352 | pressure = 1048576.0 - adc 353 | pressure = ((pressure - var2 / 4096.0) * 6250.0) / var1 354 | var1 = self._pressure_calib[8] * pressure * pressure / 2147483648.0 355 | var2 = pressure * self._pressure_calib[7] / 32768.0 356 | pressure = pressure + (var1 + var2 + self._pressure_calib[6]) / 16.0 357 | pressure /= 100 358 | 359 | return pressure 360 | 361 | @property 362 | def altitude(self) -> float: 363 | """The altitude based on the sea level pressure (:attr:`sea_level_pressure`) 364 | - which you must enter ahead of time)""" 365 | p = self.pressure # in Si units for hPascal 366 | return 44330 * (1.0 - math.pow(p / self.sea_level_pressure, 0.1903)) 367 | 368 | @altitude.setter 369 | def altitude(self, value: float) -> None: 370 | p = self.pressure # in Si units for hPascal 371 | self.sea_level_pressure = p / math.pow(1.0 - value / 44330.0, 5.255) 372 | 373 | ####################### Internal helpers ################################ 374 | def _read_coefficients(self) -> None: 375 | """Read & save the calibration coefficients""" 376 | coeff = self._read_register(_REGISTER_DIG_T1, 24) 377 | coeff = list(struct.unpack(" int: 391 | """Read a byte register value and return it""" 392 | return self._read_register(register, 1)[0] 393 | 394 | def _read24(self, register: int) -> float: 395 | """Read an unsigned 24-bit value as a floating point and return it.""" 396 | ret = 0.0 397 | for b in self._read_register(register, 3): 398 | ret *= 256.0 399 | ret += float(b & 0xFF) 400 | return ret 401 | 402 | def _read_register(self, register: int, length: int) -> None: 403 | """Low level register reading, not implemented in base class""" 404 | raise NotImplementedError() 405 | 406 | def _write_register_byte(self, register: int, value: int) -> None: 407 | """Low level register writing, not implemented in base class""" 408 | raise NotImplementedError() 409 | 410 | 411 | class Adafruit_BMP280_I2C(Adafruit_BMP280): 412 | """Driver for I2C connected BMP280. 413 | 414 | :param ~busio.I2C i2c: The I2C bus the BMP280 is connected to. 415 | :param int address: I2C device address. Defaults to :const:`0x77`. 416 | but another address can be passed in as an argument 417 | 418 | **Quickstart: Importing and using the BMP280** 419 | 420 | Here is an example of using the :class:`BMP280_I2C` class. 421 | First you will need to import the libraries to use the sensor 422 | 423 | .. code-block:: python 424 | 425 | import board 426 | import adafruit_bmp280 427 | 428 | Once this is done you can define your `board.I2C` object and define your sensor object 429 | 430 | .. code-block:: python 431 | 432 | i2c = board.I2C() # uses board.SCL and board.SDA 433 | bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c) 434 | 435 | You need to setup the pressure at sea level 436 | 437 | .. code-block:: python 438 | 439 | bmp280.sea_level_pressure = 1013.25 440 | 441 | Now you have access to the :attr:`temperature`, 442 | :attr:`pressure` and :attr:`altitude` attributes 443 | 444 | .. code-block:: python 445 | 446 | temperature = bmp280.temperature 447 | pressure = bmp280.pressure 448 | altitude = bmp280.altitude 449 | 450 | """ 451 | 452 | def __init__(self, i2c: I2C, address: int = 0x77) -> None: 453 | from adafruit_bus_device import ( # noqa: PLC0415 454 | i2c_device, 455 | ) 456 | 457 | self._i2c = i2c_device.I2CDevice(i2c, address) 458 | super().__init__() 459 | 460 | def _read_register(self, register: int, length: int) -> bytearray: 461 | """Low level register reading over I2C, returns a list of values""" 462 | with self._i2c as i2c: 463 | i2c.write(bytes([register & 0xFF])) 464 | result = bytearray(length) 465 | i2c.readinto(result) 466 | # print("$%02X => %s" % (register, [hex(i) for i in result])) 467 | return result 468 | 469 | def _write_register_byte(self, register: int, value: int) -> None: 470 | """Low level register writing over I2C, writes one 8-bit value""" 471 | with self._i2c as i2c: 472 | i2c.write(bytes([register & 0xFF, value & 0xFF])) 473 | # print("$%02X <= 0x%02X" % (register, value)) 474 | 475 | 476 | class Adafruit_BMP280_SPI(Adafruit_BMP280): 477 | """Driver for SPI connected BMP280. 478 | 479 | :param ~busio.SPI spi: SPI device 480 | :param ~digitalio.DigitalInOut cs: Chip Select 481 | :param int baudrate: Clock rate, default is 100000. Can be changed with :meth:`baudrate` 482 | 483 | 484 | **Quickstart: Importing and using the BMP280** 485 | 486 | Here is an example of using the :class:`BMP280_SPI` class. 487 | First you will need to import the libraries to use the sensor 488 | 489 | .. code-block:: python 490 | 491 | import board 492 | from digitalio import DigitalInOut, Direction 493 | import adafruit_bmp280 494 | 495 | 496 | Once this is done you can define your `board.SPI` object and define your sensor object 497 | 498 | .. code-block:: python 499 | 500 | cs = digitalio.DigitalInOut(board.D10) 501 | spi = board.SPI() 502 | bme280 = adafruit_bmp280.Adafruit_bmp280_SPI(spi, cs) 503 | 504 | You need to setup the pressure at sea level 505 | 506 | .. code-block:: python 507 | 508 | bmp280.sea_level_pressure = 1013.25 509 | 510 | Now you have access to the :attr:`temperature`, :attr:`pressure` and 511 | :attr:`altitude` attributes 512 | 513 | .. code-block:: python 514 | 515 | temperature = bmp280.temperature 516 | pressure = bmp280.pressure 517 | altitude = bmp280.altitude 518 | 519 | """ 520 | 521 | def __init__(self, spi: SPI, cs: DigitalInOut, baudrate=100000) -> None: 522 | from adafruit_bus_device import ( # noqa: PLC0415 523 | spi_device, 524 | ) 525 | 526 | self._spi = spi_device.SPIDevice(spi, cs, baudrate=baudrate) 527 | super().__init__() 528 | 529 | def _read_register(self, register: int, length: int) -> bytearray: 530 | """Low level register reading over SPI, returns a list of values""" 531 | register = (register | 0x80) & 0xFF # Read single, bit 7 high. 532 | with self._spi as spi: 533 | spi.write(bytearray([register])) 534 | result = bytearray(length) 535 | spi.readinto(result) 536 | # print("$%02X => %s" % (register, [hex(i) for i in result])) 537 | return result 538 | 539 | def _write_register_byte(self, register: int, value: int) -> None: 540 | """Low level register writing over SPI, writes one 8-bit value""" 541 | register &= 0x7F # Write, bit 7 low. 542 | with self._spi as spi: 543 | spi.write(bytes([register, value & 0xFF])) 544 | -------------------------------------------------------------------------------- /docs/_static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_BMP280/eea18d65c88835430952d0ece2697256060656d2/docs/_static/favicon.ico -------------------------------------------------------------------------------- /docs/_static/favicon.ico.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2018 Phillip Torrone for Adafruit Industries 2 | 3 | SPDX-License-Identifier: CC-BY-4.0 4 | -------------------------------------------------------------------------------- /docs/api.rst: -------------------------------------------------------------------------------- 1 | 2 | .. If you created a package, create one automodule per module in the package. 3 | 4 | API Reference 5 | ############# 6 | 7 | .. automodule:: adafruit_bmp280 8 | :members: 9 | -------------------------------------------------------------------------------- /docs/api.rst.license: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | import datetime 6 | import os 7 | import sys 8 | 9 | sys.path.insert(0, os.path.abspath("..")) 10 | 11 | # -- General configuration ------------------------------------------------ 12 | 13 | # Add any Sphinx extension module names here, as strings. They can be 14 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 15 | # ones. 16 | extensions = [ 17 | "sphinx.ext.autodoc", 18 | "sphinxcontrib.jquery", 19 | "sphinx.ext.intersphinx", 20 | "sphinx.ext.viewcode", 21 | ] 22 | 23 | intersphinx_mapping = { 24 | "python": ("https://docs.python.org/3", None), 25 | "BusDevice": ( 26 | "https://docs.circuitpython.org/projects/busdevice/en/latest/", 27 | None, 28 | ), 29 | "Register": ( 30 | "https://docs.circuitpython.org/projects/register/en/latest/", 31 | None, 32 | ), 33 | "CircuitPython": ("https://docs.circuitpython.org/en/latest/", None), 34 | } 35 | 36 | # Add any paths that contain templates here, relative to this directory. 37 | templates_path = ["_templates"] 38 | 39 | source_suffix = ".rst" 40 | 41 | # The master toctree document. 42 | master_doc = "index" 43 | 44 | # General information about the project. 45 | project = "Adafruit BMP280 Library" 46 | creation_year = "2017" 47 | current_year = str(datetime.datetime.now().year) 48 | year_duration = ( 49 | current_year if current_year == creation_year else creation_year + " - " + current_year 50 | ) 51 | copyright = year_duration + " ladyada" 52 | author = "ladyada" 53 | 54 | # The version info for the project you're documenting, acts as replacement for 55 | # |version| and |release|, also used in various other places throughout the 56 | # built documents. 57 | # 58 | # The short X.Y version. 59 | version = "1.0" 60 | # The full version, including alpha/beta/rc tags. 61 | release = "1.0" 62 | 63 | # The language for content autogenerated by Sphinx. Refer to documentation 64 | # for a list of supported languages. 65 | # 66 | # This is also used if you do content translation via gettext catalogs. 67 | # Usually you set "language" from the command line for these cases. 68 | language = "en" 69 | 70 | # List of patterns, relative to source directory, that match files and 71 | # directories to ignore when looking for source files. 72 | # This patterns also effect to html_static_path and html_extra_path 73 | exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"] 74 | 75 | # The reST default role (used for this markup: `text`) to use for all 76 | # documents. 77 | # 78 | default_role = "any" 79 | 80 | # If true, '()' will be appended to :func: etc. cross-reference text. 81 | # 82 | add_function_parentheses = True 83 | 84 | # The name of the Pygments (syntax highlighting) style to use. 85 | pygments_style = "sphinx" 86 | 87 | # If true, `todo` and `todoList` produce output, else they produce nothing. 88 | todo_include_todos = False 89 | 90 | # If this is True, todo emits a warning for each TODO entries. The default is False. 91 | todo_emit_warnings = True 92 | 93 | 94 | # -- Options for HTML output ---------------------------------------------- 95 | 96 | # The theme to use for HTML and HTML Help pages. See the documentation for 97 | # a list of builtin themes. 98 | # 99 | import sphinx_rtd_theme 100 | 101 | html_theme = "sphinx_rtd_theme" 102 | 103 | # Add any paths that contain custom static files (such as style sheets) here, 104 | # relative to this directory. They are copied after the builtin static files, 105 | # so a file named "default.css" will overwrite the builtin "default.css". 106 | html_static_path = ["_static"] 107 | 108 | # The name of an image file (relative to this directory) to use as a favicon of 109 | # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 110 | # pixels large. 111 | # 112 | html_favicon = "_static/favicon.ico" 113 | 114 | # Output file base name for HTML help builder. 115 | htmlhelp_basename = "AdafruitBMP280Librarydoc" 116 | 117 | # -- Options for LaTeX output --------------------------------------------- 118 | 119 | latex_elements = { 120 | # The paper size ('letterpaper' or 'a4paper'). 121 | # 122 | # 'papersize': 'letterpaper', 123 | # The font size ('10pt', '11pt' or '12pt'). 124 | # 125 | # 'pointsize': '10pt', 126 | # Additional stuff for the LaTeX preamble. 127 | # 128 | # 'preamble': '', 129 | # Latex figure (float) alignment 130 | # 131 | # 'figure_align': 'htbp', 132 | } 133 | 134 | # Grouping the document tree into LaTeX files. List of tuples 135 | # (source start file, target name, title, 136 | # author, documentclass [howto, manual, or own class]). 137 | latex_documents = [ 138 | ( 139 | master_doc, 140 | "AdafruitBMP280Library.tex", 141 | "Adafruit BMP280 Library Documentation", 142 | author, 143 | "manual", 144 | ), 145 | ] 146 | 147 | # -- Options for manual page output --------------------------------------- 148 | 149 | # One entry per manual page. List of tuples 150 | # (source start file, name, description, authors, manual section). 151 | man_pages = [ 152 | ( 153 | master_doc, 154 | "adafruitBMP280library", 155 | "Adafruit BMP280 Library Documentation", 156 | [author], 157 | 1, 158 | ) 159 | ] 160 | 161 | # -- Options for Texinfo output ------------------------------------------- 162 | 163 | # Grouping the document tree into Texinfo files. List of tuples 164 | # (source start file, target name, title, author, 165 | # dir menu entry, description, category) 166 | texinfo_documents = [ 167 | ( 168 | master_doc, 169 | "AdafruitBMP280Library", 170 | "Adafruit BMP280 Library Documentation", 171 | author, 172 | "AdafruitBMP280Library", 173 | "One line description of project.", 174 | "Miscellaneous", 175 | ), 176 | ] 177 | 178 | # API docs fix 179 | autodoc_mock_imports = ["micropython"] 180 | -------------------------------------------------------------------------------- /docs/examples.rst: -------------------------------------------------------------------------------- 1 | Simple test 2 | ------------ 3 | 4 | Ensure your device works with this simple test. 5 | 6 | .. literalinclude:: ../examples/bmp280_simpletest.py 7 | :caption: examples/bmp280_simpletest.py 8 | :linenos: 9 | 10 | Normal Mode 11 | ----------- 12 | 13 | Example showing how the BMP280 library can be used to set the various 14 | parameters supported by the sensor. 15 | 16 | .. literalinclude:: ../examples/bmp280_normal_mode.py 17 | :caption: examples/bmp280_normal_mode.py 18 | :linenos: 19 | 20 | DisplayIO Simpletest 21 | --------------------- 22 | 23 | This is a simple test for boards with built-in display. 24 | 25 | .. literalinclude:: ../examples/bmp280_displayio_simpletest.py 26 | :caption: examples/bmp280_displayio_simpletest.py 27 | :linenos: 28 | -------------------------------------------------------------------------------- /docs/examples.rst.license: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../README.rst 2 | 3 | Table of Contents 4 | ================= 5 | 6 | .. toctree:: 7 | :maxdepth: 4 8 | :hidden: 9 | 10 | self 11 | 12 | .. toctree:: 13 | :caption: Examples 14 | 15 | examples 16 | 17 | .. toctree:: 18 | :caption: API Reference 19 | :maxdepth: 3 20 | 21 | api 22 | 23 | .. toctree:: 24 | :caption: Tutorials 25 | 26 | Adafruit BMP280 I2C or SPI Barometric Pressure & Altitude Sensor Learning Guide 27 | 28 | .. toctree:: 29 | :caption: Related Products 30 | 31 | Adafruit BMP280 I2C or SPI Barometric Pressure & Altitude Sensor 32 | 33 | .. toctree:: 34 | :caption: Other Links 35 | 36 | Download from GitHub 37 | Download Library Bundle 38 | CircuitPython Reference Documentation 39 | CircuitPython Support Forum 40 | Discord Chat 41 | Adafruit Learning System 42 | Adafruit Blog 43 | Adafruit Store 44 | 45 | Indices and tables 46 | ================== 47 | 48 | * :ref:`genindex` 49 | * :ref:`modindex` 50 | * :ref:`search` 51 | -------------------------------------------------------------------------------- /docs/index.rst.license: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | sphinx 6 | sphinxcontrib-jquery 7 | sphinx-rtd-theme 8 | -------------------------------------------------------------------------------- /examples/bmp280_displayio_simpletest.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries 2 | # SPDX-FileCopyrightText: 2024 Jose D. Montoya 3 | # 4 | # SPDX-License-Identifier: MIT 5 | 6 | import time 7 | 8 | import board 9 | from adafruit_display_text.bitmap_label import Label 10 | from displayio import Group 11 | from terminalio import FONT 12 | 13 | import adafruit_bmp280 14 | 15 | # Simple demo of the BMP280 barometric pressure sensor. 16 | # create a main_group to hold anything we want to show on the display. 17 | main_group = Group() 18 | # Initialize I2C bus and sensor. 19 | i2c = board.I2C() # uses board.SCL and board.SDA 20 | bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c) 21 | 22 | # change this to match the location's pressure (hPa) at sea level 23 | bmp280.sea_level_pressure = 1013.25 24 | 25 | # Create two Labels to show the readings. If you have a very small 26 | # display you may need to change to scale=1. 27 | tempandpress_output_label = Label(FONT, text="", scale=2) 28 | altitude_output_label = Label(FONT, text="", scale=2) 29 | 30 | # place the labels in the middle of the screen with anchored positioning 31 | tempandpress_output_label.anchor_point = (0, 0) 32 | tempandpress_output_label.anchored_position = ( 33 | 4, 34 | board.DISPLAY.height // 2 - 40, 35 | ) 36 | altitude_output_label.anchor_point = (0, 0) 37 | altitude_output_label.anchored_position = (4, board.DISPLAY.height // 2 + 20) 38 | 39 | 40 | # add the label to the main_group 41 | main_group.append(tempandpress_output_label) 42 | main_group.append(altitude_output_label) 43 | 44 | # set the main_group as the root_group of the built-in DISPLAY 45 | board.DISPLAY.root_group = main_group 46 | 47 | # begin main loop 48 | while True: 49 | # Update the label.text property to change the text on the display 50 | tempandpress_output_label.text = ( 51 | f"Temperature:{bmp280.temperature:0.1f} C \nPressure:{bmp280.pressure:0.1f} hPa" 52 | ) 53 | altitude_output_label.text = f"Altitude:{bmp280.altitude:0.2f} mts" 54 | # wait for a bit 55 | time.sleep(2.0) 56 | -------------------------------------------------------------------------------- /examples/bmp280_normal_mode.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | """ 5 | Example showing how the BMP280 library can be used to set the various 6 | parameters supported by the sensor. 7 | Refer to the BMP280 datasheet to understand what these parameters do 8 | """ 9 | 10 | import time 11 | 12 | import board 13 | 14 | import adafruit_bmp280 15 | 16 | # Create sensor object, communicating over the board's default I2C bus 17 | i2c = board.I2C() # uses board.SCL and board.SDA 18 | # i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller 19 | bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c) 20 | 21 | # OR Create sensor object, communicating over the board's default SPI bus 22 | # spi = busio.SPI() 23 | # bmp_cs = digitalio.DigitalInOut(board.D5) 24 | # bmp280 = adafruit_bmp280.Adafruit_BMP280_SPI(spi, bmp_cs) 25 | 26 | # change this to match the location's pressure (hPa) at sea level 27 | bmp280.sea_level_pressure = 1013.25 28 | bmp280.mode = adafruit_bmp280.MODE_NORMAL 29 | bmp280.standby_period = adafruit_bmp280.STANDBY_TC_500 30 | bmp280.iir_filter = adafruit_bmp280.IIR_FILTER_X16 31 | bmp280.overscan_pressure = adafruit_bmp280.OVERSCAN_X16 32 | bmp280.overscan_temperature = adafruit_bmp280.OVERSCAN_X2 33 | # The sensor will need a moment to gather inital readings 34 | time.sleep(1) 35 | 36 | while True: 37 | print("\nTemperature: %0.1f C" % bmp280.temperature) 38 | print("Pressure: %0.1f hPa" % bmp280.pressure) 39 | print("Altitude = %0.2f meters" % bmp280.altitude) 40 | time.sleep(2) 41 | -------------------------------------------------------------------------------- /examples/bmp280_simpletest.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | """Simpletest Example that shows how to get temperature, 5 | pressure, and altitude readings from a BMP280""" 6 | 7 | import time 8 | 9 | import board 10 | 11 | # import digitalio # For use with SPI 12 | import adafruit_bmp280 13 | 14 | # Create sensor object, communicating over the board's default I2C bus 15 | i2c = board.I2C() # uses board.SCL and board.SDA 16 | # i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller 17 | bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c) 18 | 19 | # OR Create sensor object, communicating over the board's default SPI bus 20 | # spi = board.SPI() 21 | # bmp_cs = digitalio.DigitalInOut(board.D5) 22 | # bmp280 = adafruit_bmp280.Adafruit_BMP280_SPI(spi, bmp_cs) 23 | 24 | # change this to match the location's pressure (hPa) at sea level 25 | bmp280.sea_level_pressure = 1013.25 26 | 27 | while True: 28 | print("\nTemperature: %0.1f C" % bmp280.temperature) 29 | print("Pressure: %0.1f hPa" % bmp280.pressure) 30 | print("Altitude = %0.2f meters" % bmp280.altitude) 31 | time.sleep(2) 32 | -------------------------------------------------------------------------------- /optional_requirements.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Alec Delaney for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | [build-system] 6 | requires = [ 7 | "setuptools", 8 | "wheel", 9 | "setuptools-scm", 10 | ] 11 | 12 | [project] 13 | name = "adafruit-circuitpython-bmp280" 14 | description = "CircuitPython driver for the BMP280." 15 | version = "0.0.0+auto.0" 16 | readme = "README.rst" 17 | authors = [ 18 | {name = "Adafruit Industries", email = "circuitpython@adafruit.com"} 19 | ] 20 | urls = {Homepage = "https://github.com/adafruit/Adafruit_CircuitPython_BMP280"} 21 | keywords = [ 22 | "adafruit", 23 | "bmp280", 24 | "barometric", 25 | "pressure", 26 | "temperature", 27 | "hardware", 28 | "sensor", 29 | "micropython", 30 | "circuitpython", 31 | ] 32 | license = {text = "MIT"} 33 | classifiers = [ 34 | "Intended Audience :: Developers", 35 | "Topic :: Software Development :: Libraries", 36 | "Topic :: Software Development :: Embedded Systems", 37 | "Topic :: System :: Hardware", 38 | "License :: OSI Approved :: MIT License", 39 | "Programming Language :: Python :: 3", 40 | ] 41 | dynamic = ["dependencies", "optional-dependencies"] 42 | 43 | [tool.setuptools] 44 | py-modules = ["adafruit_bmp280"] 45 | 46 | [tool.setuptools.dynamic] 47 | dependencies = {file = ["requirements.txt"]} 48 | optional-dependencies = {optional = {file = ["optional_requirements.txt"]}} 49 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | Adafruit-Blinka 6 | adafruit-circuitpython-register 7 | adafruit-circuitpython-busdevice 8 | -------------------------------------------------------------------------------- /ruff.toml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | target-version = "py38" 6 | line-length = 100 7 | 8 | [lint] 9 | preview = true 10 | select = ["I", "PL", "UP"] 11 | 12 | extend-select = [ 13 | "D419", # empty-docstring 14 | "E501", # line-too-long 15 | "W291", # trailing-whitespace 16 | "PLC0414", # useless-import-alias 17 | "PLC2401", # non-ascii-name 18 | "PLC2801", # unnecessary-dunder-call 19 | "PLC3002", # unnecessary-direct-lambda-call 20 | "E999", # syntax-error 21 | "PLE0101", # return-in-init 22 | "F706", # return-outside-function 23 | "F704", # yield-outside-function 24 | "PLE0116", # continue-in-finally 25 | "PLE0117", # nonlocal-without-binding 26 | "PLE0241", # duplicate-bases 27 | "PLE0302", # unexpected-special-method-signature 28 | "PLE0604", # invalid-all-object 29 | "PLE0605", # invalid-all-format 30 | "PLE0643", # potential-index-error 31 | "PLE0704", # misplaced-bare-raise 32 | "PLE1141", # dict-iter-missing-items 33 | "PLE1142", # await-outside-async 34 | "PLE1205", # logging-too-many-args 35 | "PLE1206", # logging-too-few-args 36 | "PLE1307", # bad-string-format-type 37 | "PLE1310", # bad-str-strip-call 38 | "PLE1507", # invalid-envvar-value 39 | "PLE2502", # bidirectional-unicode 40 | "PLE2510", # invalid-character-backspace 41 | "PLE2512", # invalid-character-sub 42 | "PLE2513", # invalid-character-esc 43 | "PLE2514", # invalid-character-nul 44 | "PLE2515", # invalid-character-zero-width-space 45 | "PLR0124", # comparison-with-itself 46 | "PLR0202", # no-classmethod-decorator 47 | "PLR0203", # no-staticmethod-decorator 48 | "UP004", # useless-object-inheritance 49 | "PLR0206", # property-with-parameters 50 | "PLR0904", # too-many-public-methods 51 | "PLR0911", # too-many-return-statements 52 | "PLR0912", # too-many-branches 53 | "PLR0913", # too-many-arguments 54 | "PLR0914", # too-many-locals 55 | "PLR0915", # too-many-statements 56 | "PLR0916", # too-many-boolean-expressions 57 | "PLR1702", # too-many-nested-blocks 58 | "PLR1704", # redefined-argument-from-local 59 | "PLR1711", # useless-return 60 | "C416", # unnecessary-comprehension 61 | "PLR1733", # unnecessary-dict-index-lookup 62 | "PLR1736", # unnecessary-list-index-lookup 63 | 64 | # ruff reports this rule is unstable 65 | #"PLR6301", # no-self-use 66 | 67 | "PLW0108", # unnecessary-lambda 68 | "PLW0120", # useless-else-on-loop 69 | "PLW0127", # self-assigning-variable 70 | "PLW0129", # assert-on-string-literal 71 | "B033", # duplicate-value 72 | "PLW0131", # named-expr-without-context 73 | "PLW0245", # super-without-brackets 74 | "PLW0406", # import-self 75 | "PLW0602", # global-variable-not-assigned 76 | "PLW0603", # global-statement 77 | "PLW0604", # global-at-module-level 78 | 79 | # fails on the try: import typing used by libraries 80 | #"F401", # unused-import 81 | 82 | "F841", # unused-variable 83 | "E722", # bare-except 84 | "PLW0711", # binary-op-exception 85 | "PLW1501", # bad-open-mode 86 | "PLW1508", # invalid-envvar-default 87 | "PLW1509", # subprocess-popen-preexec-fn 88 | "PLW2101", # useless-with-lock 89 | "PLW3301", # nested-min-max 90 | ] 91 | 92 | ignore = [ 93 | "PLR2004", # magic-value-comparison 94 | "UP030", # format literals 95 | "PLW1514", # unspecified-encoding 96 | "PLR0913", # too-many-arguments 97 | "PLR0915", # too-many-statements 98 | "PLR0917", # too-many-positional-arguments 99 | "PLR0904", # too-many-public-methods 100 | "PLR0912", # too-many-branches 101 | "PLR0916", # too-many-boolean-expressions 102 | ] 103 | 104 | [format] 105 | line-ending = "lf" 106 | --------------------------------------------------------------------------------