├── .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 ├── BSD-3-Clause.txt ├── CC-BY-4.0.txt ├── MIT.txt └── Unlicense.txt ├── README.rst ├── README.rst.license ├── adafruit_bme680.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 ├── bme680_displayio_simpletest.py ├── bme680_simpletest.py └── bme680_spi.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 | * text eol=lf 6 | -------------------------------------------------------------------------------- /.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: 2020 Diego Elio Pettenò 2 | # SPDX-FileCopyrightText: 2024 Justin Myers 3 | # 4 | # SPDX-License-Identifier: Unlicense 5 | 6 | repos: 7 | - repo: https://github.com/pre-commit/pre-commit-hooks 8 | rev: v4.5.0 9 | hooks: 10 | - id: check-yaml 11 | - id: end-of-file-fixer 12 | - id: trailing-whitespace 13 | - repo: https://github.com/astral-sh/ruff-pre-commit 14 | rev: v0.3.4 15 | hooks: 16 | - id: ruff-format 17 | - id: ruff 18 | args: ["--fix"] 19 | - repo: https://github.com/fsfe/reuse-tool 20 | rev: v3.0.1 21 | hooks: 22 | - id: reuse 23 | -------------------------------------------------------------------------------- /.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/BSD-3-Clause.txt: -------------------------------------------------------------------------------- 1 | BOSCH LICENSE 2 | 3 | Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved. 4 | 5 | BSD-3-Clause 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | 3. Neither the name of the copyright holder nor the names of its 18 | contributors may be used to endorse or promote products derived from 19 | this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 | COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | POSSIBILITY OF SUCH DAMAGE. 33 | -------------------------------------------------------------------------------- /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 | 2 | Introduction 3 | ============ 4 | 5 | .. image:: https://readthedocs.org/projects/adafruit-circuitpython-bme680/badge/?version=latest 6 | :target: https://docs.circuitpython.org/projects/bme680/en/latest/ 7 | :alt: Documentation Status 8 | 9 | .. image:: https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_Bundle/main/badges/adafruit_discord.svg 10 | :target: https://adafru.it/discord 11 | :alt: Discord 12 | 13 | .. image:: https://github.com/adafruit/Adafruit_CircuitPython_BME680/workflows/Build%20CI/badge.svg 14 | :target: https://github.com/adafruit/Adafruit_CircuitPython_BME680/actions/ 15 | :alt: Build Status 16 | 17 | .. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json 18 | :target: https://github.com/astral-sh/ruff 19 | :alt: Code Style: Ruff 20 | 21 | CircuitPython driver for BME680 sensor over I2C 22 | 23 | Dependencies 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 | On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from 37 | PyPI `_. To install for current user: 38 | 39 | .. code-block:: shell 40 | 41 | pip3 install adafruit-circuitpython-bme680 42 | 43 | To install system-wide (this may be required in some cases): 44 | 45 | .. code-block:: shell 46 | 47 | sudo pip3 install adafruit-circuitpython-bme680 48 | 49 | To install in a virtual environment in your current project: 50 | 51 | .. code-block:: shell 52 | 53 | mkdir project-name && cd project-name 54 | python3 -m venv .venv 55 | source .venv/bin/activate 56 | pip3 install adafruit-circuitpython-bme680 57 | 58 | Usage Example 59 | ============= 60 | 61 | .. code-block:: python3 62 | 63 | import adafruit_bme680 64 | import time 65 | import board 66 | 67 | # Create sensor object, communicating over the board's default I2C bus 68 | i2c = board.I2C() # uses board.SCL and board.SDA 69 | bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c) 70 | 71 | # change this to match the location's pressure (hPa) at sea level 72 | bme680.sea_level_pressure = 1013.25 73 | 74 | while True: 75 | print("\nTemperature: %0.1f C" % bme680.temperature) 76 | print("Gas: %d ohm" % bme680.gas) 77 | print("Humidity: %0.1f %%" % bme680.relative_humidity) 78 | print("Pressure: %0.3f hPa" % bme680.pressure) 79 | print("Altitude = %0.2f meters" % bme680.altitude) 80 | 81 | time.sleep(2) 82 | 83 | 84 | Documentation 85 | ============= 86 | 87 | API documentation for this library can be found on `Read the Docs `_. 88 | 89 | For information on building library documentation, please check out `this guide `_. 90 | 91 | Contributing 92 | ============ 93 | 94 | Contributions are welcome! Please read our `Code of Conduct 95 | `_ 96 | before contributing to help this project stay welcoming. 97 | -------------------------------------------------------------------------------- /README.rst.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | 3 | SPDX-License-Identifier: MIT 4 | -------------------------------------------------------------------------------- /adafruit_bme680.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT AND BSD-3-Clause 4 | 5 | 6 | """ 7 | `adafruit_bme680` 8 | ================================================================================ 9 | 10 | CircuitPython library for BME680 temperature, pressure and humidity sensor. 11 | 12 | 13 | * Author(s): Limor Fried, William Garber, many others 14 | 15 | 16 | Implementation Notes 17 | -------------------- 18 | 19 | **Hardware:** 20 | 21 | * `Adafruit BME680 Temp, Humidity, Pressure and Gas Sensor `_ 22 | 23 | **Software and Dependencies:** 24 | 25 | * Adafruit CircuitPython firmware for the supported boards: 26 | https://github.com/adafruit/circuitpython/releases 27 | * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice 28 | """ 29 | 30 | import math 31 | import struct 32 | import time 33 | 34 | from micropython import const 35 | 36 | 37 | def delay_microseconds(nusec): 38 | """HELP must be same as dev->delay_us""" 39 | time.sleep(nusec / 1000000.0) 40 | 41 | 42 | try: 43 | # Used only for type annotations. 44 | 45 | import typing 46 | 47 | from busio import I2C, SPI 48 | from circuitpython_typing import ReadableBuffer 49 | from digitalio import DigitalInOut 50 | 51 | except ImportError: 52 | pass 53 | 54 | __version__ = "0.0.0+auto.0" 55 | __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BME680.git" 56 | 57 | 58 | # I2C ADDRESS/BITS/SETTINGS NEW 59 | # ----------------------------------------------------------------------- 60 | _BME68X_ENABLE_HEATER = const(0x00) 61 | _BME68X_DISABLE_HEATER = const(0x01) 62 | _BME68X_DISABLE_GAS_MEAS = const(0x00) 63 | _BME68X_ENABLE_GAS_MEAS_L = const(0x01) 64 | _BME68X_ENABLE_GAS_MEAS_H = const(0x02) 65 | _BME68X_SLEEP_MODE = const(0) 66 | _BME68X_FORCED_MODE = const(1) 67 | _BME68X_VARIANT_GAS_LOW = const(0x00) 68 | _BME68X_VARIANT_GAS_HIGH = const(0x01) 69 | _BME68X_HCTRL_MSK = const(0x08) 70 | _BME68X_HCTRL_POS = const(3) 71 | _BME68X_NBCONV_MSK = const(0x0F) 72 | _BME68X_RUN_GAS_MSK = const(0x30) 73 | _BME68X_RUN_GAS_POS = const(4) 74 | _BME68X_MODE_MSK = const(0x03) 75 | _BME68X_PERIOD_POLL = const(10000) 76 | _BME68X_REG_CTRL_GAS_0 = const(0x70) 77 | _BME68X_REG_CTRL_GAS_1 = const(0x71) 78 | 79 | # I2C ADDRESS/BITS/SETTINGS 80 | # ----------------------------------------------------------------------- 81 | _BME680_CHIPID = const(0x61) 82 | 83 | _BME680_REG_CHIPID = const(0xD0) 84 | _BME68X_REG_VARIANT = const(0xF0) 85 | _BME680_BME680_COEFF_ADDR1 = const(0x89) 86 | _BME680_BME680_COEFF_ADDR2 = const(0xE1) 87 | _BME680_BME680_RES_HEAT_0 = const(0x5A) 88 | _BME680_BME680_GAS_WAIT_0 = const(0x64) 89 | 90 | _BME680_REG_SOFTRESET = const(0xE0) 91 | _BME680_REG_CTRL_GAS = const(0x71) 92 | _BME680_REG_CTRL_HUM = const(0x72) 93 | _BME680_REG_STATUS = const(0x73) 94 | _BME680_REG_CTRL_MEAS = const(0x74) 95 | _BME680_REG_CONFIG = const(0x75) 96 | 97 | _BME680_REG_MEAS_STATUS = const(0x1D) 98 | _BME680_REG_PDATA = const(0x1F) 99 | _BME680_REG_TDATA = const(0x22) 100 | _BME680_REG_HDATA = const(0x25) 101 | 102 | _BME680_SAMPLERATES = (0, 1, 2, 4, 8, 16) 103 | _BME680_FILTERSIZES = (0, 1, 3, 7, 15, 31, 63, 127) 104 | 105 | _BME680_RUNGAS = const(0x10) 106 | 107 | _LOOKUP_TABLE_1 = ( 108 | 2147483647.0, 109 | 2147483647.0, 110 | 2147483647.0, 111 | 2147483647.0, 112 | 2147483647.0, 113 | 2126008810.0, 114 | 2147483647.0, 115 | 2130303777.0, 116 | 2147483647.0, 117 | 2147483647.0, 118 | 2143188679.0, 119 | 2136746228.0, 120 | 2147483647.0, 121 | 2126008810.0, 122 | 2147483647.0, 123 | 2147483647.0, 124 | ) 125 | 126 | _LOOKUP_TABLE_2 = ( 127 | 4096000000.0, 128 | 2048000000.0, 129 | 1024000000.0, 130 | 512000000.0, 131 | 255744255.0, 132 | 127110228.0, 133 | 64000000.0, 134 | 32258064.0, 135 | 16016016.0, 136 | 8000000.0, 137 | 4000000.0, 138 | 2000000.0, 139 | 1000000.0, 140 | 500000.0, 141 | 250000.0, 142 | 125000.0, 143 | ) 144 | 145 | 146 | def bme_set_bits(reg_data, bitname_msk, bitname_pos, data): 147 | """ 148 | Macro to set bits 149 | data2 = data << bitname_pos 150 | set masked bits from data2 in reg_data 151 | """ 152 | return (reg_data & ~bitname_msk) | ((data << bitname_pos) & bitname_msk) 153 | 154 | 155 | def bme_set_bits_pos_0(reg_data, bitname_msk, data): 156 | """ 157 | Macro to set bits starting from position 0 158 | set masked bits from data in reg_data 159 | """ 160 | return (reg_data & ~bitname_msk) | (data & bitname_msk) 161 | 162 | 163 | def _read24(arr: ReadableBuffer) -> float: 164 | """Parse an unsigned 24-bit value as a floating point and return it.""" 165 | ret = 0.0 166 | # print([hex(i) for i in arr]) 167 | for b in arr: 168 | ret *= 256.0 169 | ret += float(b & 0xFF) 170 | return ret 171 | 172 | 173 | class Adafruit_BME680: 174 | """Driver from BME680 air quality sensor 175 | 176 | :param int refresh_rate: Maximum number of readings per second. Faster property reads 177 | will be from the previous reading.""" 178 | 179 | def __init__(self, *, refresh_rate: int = 10) -> None: 180 | """Check the BME680 was found, read the coefficients and enable the sensor for continuous 181 | reads.""" 182 | self._write(_BME680_REG_SOFTRESET, [0xB6]) 183 | time.sleep(0.005) 184 | 185 | # Check device ID. 186 | chip_id = self._read_byte(_BME680_REG_CHIPID) 187 | if chip_id != _BME680_CHIPID: 188 | raise RuntimeError("Failed to find BME680! Chip ID 0x%x" % chip_id) 189 | 190 | # Get variant 191 | self._chip_variant = self._read_byte(_BME68X_REG_VARIANT) 192 | 193 | self._read_calibration() 194 | 195 | # set up heater 196 | self._write(_BME680_BME680_RES_HEAT_0, [0x73]) 197 | self._write(_BME680_BME680_GAS_WAIT_0, [0x65]) 198 | 199 | self.sea_level_pressure = 1013.25 200 | """Pressure in hectoPascals at sea level. Used to calibrate :attr:`altitude`.""" 201 | 202 | # Default oversampling and filter register values. 203 | self._pressure_oversample = 0b011 204 | self._temp_oversample = 0b100 205 | self._humidity_oversample = 0b010 206 | self._filter = 0b010 207 | 208 | # Gas measurements, as a mask applied to _BME680_RUNGAS 209 | self._run_gas = 0xFF 210 | 211 | self._adc_pres = None 212 | self._adc_temp = None 213 | self._adc_hum = None 214 | self._adc_gas = None 215 | self._gas_range = None 216 | self._t_fine = None 217 | 218 | self._last_reading = 0 219 | self._min_refresh_time = 1 / refresh_rate 220 | 221 | self._amb_temp = 25 # Copy required parameters from reference bme68x_dev struct 222 | self.set_gas_heater(320, 150) # heater 320 deg C for 150 msec 223 | 224 | @property 225 | def pressure_oversample(self) -> int: 226 | """The oversampling for pressure sensor""" 227 | return _BME680_SAMPLERATES[self._pressure_oversample] 228 | 229 | @pressure_oversample.setter 230 | def pressure_oversample(self, sample_rate: int) -> None: 231 | if sample_rate in _BME680_SAMPLERATES: 232 | self._pressure_oversample = _BME680_SAMPLERATES.index(sample_rate) 233 | else: 234 | raise RuntimeError("Invalid oversample") 235 | 236 | @property 237 | def humidity_oversample(self) -> int: 238 | """The oversampling for humidity sensor""" 239 | return _BME680_SAMPLERATES[self._humidity_oversample] 240 | 241 | @humidity_oversample.setter 242 | def humidity_oversample(self, sample_rate: int) -> None: 243 | if sample_rate in _BME680_SAMPLERATES: 244 | self._humidity_oversample = _BME680_SAMPLERATES.index(sample_rate) 245 | else: 246 | raise RuntimeError("Invalid oversample") 247 | 248 | @property 249 | def temperature_oversample(self) -> int: 250 | """The oversampling for temperature sensor""" 251 | return _BME680_SAMPLERATES[self._temp_oversample] 252 | 253 | @temperature_oversample.setter 254 | def temperature_oversample(self, sample_rate: int) -> None: 255 | if sample_rate in _BME680_SAMPLERATES: 256 | self._temp_oversample = _BME680_SAMPLERATES.index(sample_rate) 257 | else: 258 | raise RuntimeError("Invalid oversample") 259 | 260 | @property 261 | def filter_size(self) -> int: 262 | """The filter size for the built in IIR filter""" 263 | return _BME680_FILTERSIZES[self._filter] 264 | 265 | @filter_size.setter 266 | def filter_size(self, size: int) -> None: 267 | if size in _BME680_FILTERSIZES: 268 | self._filter = _BME680_FILTERSIZES.index(size) 269 | else: 270 | raise RuntimeError("Invalid size") 271 | 272 | @property 273 | def temperature(self) -> float: 274 | """The compensated temperature in degrees Celsius.""" 275 | self._perform_reading() 276 | calc_temp = ((self._t_fine * 5) + 128) / 256 277 | return calc_temp / 100 278 | 279 | @property 280 | def pressure(self) -> float: 281 | """The barometric pressure in hectoPascals""" 282 | self._perform_reading() 283 | var1 = (self._t_fine / 2) - 64000 284 | var2 = ((var1 / 4) * (var1 / 4)) / 2048 285 | var2 = (var2 * self._pressure_calibration[5]) / 4 286 | var2 = var2 + (var1 * self._pressure_calibration[4] * 2) 287 | var2 = (var2 / 4) + (self._pressure_calibration[3] * 65536) 288 | var1 = ((((var1 / 4) * (var1 / 4)) / 8192) * (self._pressure_calibration[2] * 32) / 8) + ( 289 | (self._pressure_calibration[1] * var1) / 2 290 | ) 291 | var1 = var1 / 262144 292 | var1 = ((32768 + var1) * self._pressure_calibration[0]) / 32768 293 | calc_pres = 1048576 - self._adc_pres 294 | calc_pres = (calc_pres - (var2 / 4096)) * 3125 295 | calc_pres = (calc_pres / var1) * 2 296 | var1 = (self._pressure_calibration[8] * (((calc_pres / 8) * (calc_pres / 8)) / 8192)) / 4096 297 | var2 = ((calc_pres / 4) * self._pressure_calibration[7]) / 8192 298 | var3 = (((calc_pres / 256) ** 3) * self._pressure_calibration[9]) / 131072 299 | calc_pres += (var1 + var2 + var3 + (self._pressure_calibration[6] * 128)) / 16 300 | return calc_pres / 100 301 | 302 | @property 303 | def relative_humidity(self) -> float: 304 | """The relative humidity in RH %""" 305 | return self.humidity 306 | 307 | @property 308 | def humidity(self) -> float: 309 | """The relative humidity in RH %""" 310 | self._perform_reading() 311 | temp_scaled = ((self._t_fine * 5) + 128) / 256 312 | var1 = (self._adc_hum - (self._humidity_calibration[0] * 16)) - ( 313 | (temp_scaled * self._humidity_calibration[2]) / 200 314 | ) 315 | var2 = ( 316 | self._humidity_calibration[1] 317 | * ( 318 | ((temp_scaled * self._humidity_calibration[3]) / 100) 319 | + ( 320 | ((temp_scaled * ((temp_scaled * self._humidity_calibration[4]) / 100)) / 64) 321 | / 100 322 | ) 323 | + 16384 324 | ) 325 | ) / 1024 326 | var3 = var1 * var2 327 | var4 = self._humidity_calibration[5] * 128 328 | var4 = (var4 + ((temp_scaled * self._humidity_calibration[6]) / 100)) / 16 329 | var5 = ((var3 / 16384) * (var3 / 16384)) / 1024 330 | var6 = (var4 * var5) / 2 331 | calc_hum = (((var3 + var6) / 1024) * 1000) / 4096 332 | calc_hum /= 1000 # get back to RH 333 | 334 | calc_hum = min(calc_hum, 100) 335 | calc_hum = max(calc_hum, 0) 336 | return calc_hum 337 | 338 | @property 339 | def altitude(self) -> float: 340 | """The altitude based on current :attr:`pressure` vs the sea level pressure 341 | (:attr:`sea_level_pressure`) - which you must enter ahead of time)""" 342 | pressure = self.pressure # in Si units for hPascal 343 | return 44330 * (1.0 - math.pow(pressure / self.sea_level_pressure, 0.1903)) 344 | 345 | @property 346 | def gas(self) -> int: 347 | """The gas resistance in ohms""" 348 | self._perform_reading() 349 | if self._chip_variant == 0x01: 350 | # taken from https://github.com/BoschSensortec/BME68x-Sensor-API 351 | var1 = 262144 >> self._gas_range 352 | var2 = self._adc_gas - 512 353 | var2 *= 3 354 | var2 = 4096 + var2 355 | calc_gas_res = (10000 * var1) / var2 356 | calc_gas_res = calc_gas_res * 100 357 | else: 358 | var1 = ((1340 + (5 * self._sw_err)) * (_LOOKUP_TABLE_1[self._gas_range])) / 65536 359 | var2 = ((self._adc_gas * 32768) - 16777216) + var1 360 | var3 = (_LOOKUP_TABLE_2[self._gas_range] * var1) / 512 361 | calc_gas_res = (var3 + (var2 / 2)) / var2 362 | return int(calc_gas_res) 363 | 364 | def _perform_reading(self) -> None: 365 | """Perform a single-shot reading from the sensor and fill internal data structure for 366 | calculations""" 367 | if time.monotonic() - self._last_reading < self._min_refresh_time: 368 | return 369 | 370 | # set filter 371 | self._write(_BME680_REG_CONFIG, [self._filter << 2]) 372 | # turn on temp oversample & pressure oversample 373 | self._write( 374 | _BME680_REG_CTRL_MEAS, 375 | [(self._temp_oversample << 5) | (self._pressure_oversample << 2)], 376 | ) 377 | # turn on humidity oversample 378 | self._write(_BME680_REG_CTRL_HUM, [self._humidity_oversample]) 379 | # gas measurements enabled 380 | if self._chip_variant == 0x01: 381 | self._write(_BME680_REG_CTRL_GAS, [(self._run_gas & _BME680_RUNGAS) << 1]) 382 | else: 383 | self._write(_BME680_REG_CTRL_GAS, [(self._run_gas & _BME680_RUNGAS)]) 384 | ctrl = self._read_byte(_BME680_REG_CTRL_MEAS) 385 | ctrl = (ctrl & 0xFC) | 0x01 # enable single shot! 386 | self._write(_BME680_REG_CTRL_MEAS, [ctrl]) 387 | new_data = False 388 | start_time = time.monotonic() 389 | while not new_data: 390 | data = self._read(_BME680_REG_MEAS_STATUS, 17) 391 | new_data = data[0] & 0x80 != 0 392 | time.sleep(0.005) 393 | if time.monotonic() - start_time >= 3.0: 394 | raise RuntimeError("Timeout while reading sensor data") 395 | self._last_reading = time.monotonic() 396 | 397 | self._adc_pres = _read24(data[2:5]) / 16 398 | self._adc_temp = _read24(data[5:8]) / 16 399 | self._adc_hum = struct.unpack(">H", bytes(data[8:10]))[0] 400 | if self._chip_variant == 0x01: 401 | self._adc_gas = int(struct.unpack(">H", bytes(data[15:17]))[0] / 64) 402 | self._gas_range = data[16] & 0x0F 403 | else: 404 | self._adc_gas = int(struct.unpack(">H", bytes(data[13:15]))[0] / 64) 405 | self._gas_range = data[14] & 0x0F 406 | 407 | var1 = (self._adc_temp / 8) - (self._temp_calibration[0] * 2) 408 | var2 = (var1 * self._temp_calibration[1]) / 2048 409 | var3 = ((var1 / 2) * (var1 / 2)) / 4096 410 | var3 = (var3 * self._temp_calibration[2] * 16) / 16384 411 | self._t_fine = int(var2 + var3) 412 | 413 | def _read_calibration(self) -> None: 414 | """Read & save the calibration coefficients""" 415 | coeff = self._read(_BME680_BME680_COEFF_ADDR1, 25) 416 | coeff += self._read(_BME680_BME680_COEFF_ADDR2, 16) 417 | 418 | coeff = list(struct.unpack(" int: 436 | """Read a byte register value and return it""" 437 | return self._read(register, 1)[0] 438 | 439 | def _read(self, register: int, length: int) -> bytearray: 440 | raise NotImplementedError() 441 | 442 | def _write(self, register: int, values: bytearray) -> None: 443 | raise NotImplementedError() 444 | 445 | def set_gas_heater(self, heater_temp: int, heater_time: int) -> bool: 446 | """ 447 | Enable and configure gas reading + heater (None disables) 448 | :param heater_temp: Desired temperature in degrees Centigrade 449 | :param heater_time: Time to keep heater on in milliseconds 450 | :return: True on success, False on failure 451 | """ 452 | try: 453 | if (heater_temp is None) or (heater_time is None): 454 | self._set_heatr_conf(heater_temp or 0, heater_time or 0, enable=False) 455 | else: 456 | self._set_heatr_conf(heater_temp, heater_time) 457 | except OSError: 458 | return False 459 | return True 460 | 461 | def _set_heatr_conf(self, heater_temp: int, heater_time: int, enable: bool = True) -> None: 462 | # restrict to BME68X_FORCED_MODE 463 | op_mode: int = _BME68X_FORCED_MODE 464 | nb_conv: int = 0 465 | hctrl: int = _BME68X_ENABLE_HEATER 466 | run_gas: int = 0 467 | ctrl_gas_data_0: int = 0 468 | ctrl_gas_data_1: int = 0 469 | 470 | self._set_op_mode(_BME68X_SLEEP_MODE) 471 | self._set_conf(heater_temp, heater_time, op_mode) 472 | ctrl_gas_data_0 = self._read_byte(_BME68X_REG_CTRL_GAS_0) 473 | ctrl_gas_data_1 = self._read_byte(_BME68X_REG_CTRL_GAS_1) 474 | if enable: 475 | hctrl = _BME68X_ENABLE_HEATER 476 | if self._chip_variant == _BME68X_VARIANT_GAS_HIGH: 477 | run_gas = _BME68X_ENABLE_GAS_MEAS_H 478 | else: 479 | run_gas = _BME68X_ENABLE_GAS_MEAS_L 480 | else: 481 | hctrl = _BME68X_DISABLE_HEATER 482 | run_gas = _BME68X_DISABLE_GAS_MEAS 483 | self._run_gas = ~(run_gas - 1) 484 | 485 | ctrl_gas_data_0 = bme_set_bits(ctrl_gas_data_0, _BME68X_HCTRL_MSK, _BME68X_HCTRL_POS, hctrl) 486 | ctrl_gas_data_1 = bme_set_bits_pos_0(ctrl_gas_data_1, _BME68X_NBCONV_MSK, nb_conv) 487 | ctrl_gas_data_1 = bme_set_bits( 488 | ctrl_gas_data_1, _BME68X_RUN_GAS_MSK, _BME68X_RUN_GAS_POS, run_gas 489 | ) 490 | self._write(_BME68X_REG_CTRL_GAS_0, [ctrl_gas_data_0]) 491 | self._write(_BME68X_REG_CTRL_GAS_1, [ctrl_gas_data_1]) 492 | 493 | def _set_op_mode(self, op_mode: int) -> None: 494 | """ 495 | * @brief This API is used to set the operation mode of the sensor 496 | """ 497 | tmp_pow_mode: int = 0 498 | pow_mode: int = _BME68X_FORCED_MODE 499 | # Call until in sleep 500 | 501 | # was a do {} while() loop 502 | while pow_mode != _BME68X_SLEEP_MODE: 503 | tmp_pow_mode = self._read_byte(_BME680_REG_CTRL_MEAS) 504 | # Put to sleep before changing mode 505 | pow_mode = tmp_pow_mode & _BME68X_MODE_MSK 506 | if pow_mode != _BME68X_SLEEP_MODE: 507 | tmp_pow_mode &= ~_BME68X_MODE_MSK # Set to sleep 508 | self._write(_BME680_REG_CTRL_MEAS, [tmp_pow_mode]) 509 | # dev->delay_us(_BME68X_PERIOD_POLL, dev->intf_ptr) # HELP 510 | delay_microseconds(_BME68X_PERIOD_POLL) 511 | # Already in sleep 512 | if op_mode != _BME68X_SLEEP_MODE: 513 | tmp_pow_mode = (tmp_pow_mode & ~_BME68X_MODE_MSK) | (op_mode & _BME68X_MODE_MSK) 514 | self._write(_BME680_REG_CTRL_MEAS, [tmp_pow_mode]) 515 | 516 | def _set_conf(self, heater_temp: int, heater_time: int, op_mode: int) -> None: 517 | """ 518 | This internal API is used to set heater configurations 519 | """ 520 | 521 | if op_mode != _BME68X_FORCED_MODE: 522 | raise OSError("GasHeaterException: _set_conf not forced mode") 523 | rh_reg_data: int = self._calc_res_heat(heater_temp) 524 | gw_reg_data: int = self._calc_gas_wait(heater_time) 525 | self._write(_BME680_BME680_RES_HEAT_0, [rh_reg_data]) 526 | self._write(_BME680_BME680_GAS_WAIT_0, [gw_reg_data]) 527 | 528 | def _calc_res_heat(self, temp: int) -> int: 529 | """ 530 | This internal API is used to calculate the heater resistance value using float 531 | """ 532 | gh1: int = self._gas_calibration[0] 533 | gh2: int = self._gas_calibration[1] 534 | gh3: int = self._gas_calibration[2] 535 | htr: int = self._heat_range 536 | htv: int = self._heat_val 537 | amb: int = self._amb_temp 538 | 539 | temp = min(temp, 400) # Cap temperature 540 | 541 | var1: int = ((int(amb) * gh3) / 1000) * 256 542 | var2: int = (gh1 + 784) * (((((gh2 + 154009) * temp * 5) / 100) + 3276800) / 10) 543 | var3: int = var1 + (var2 / 2) 544 | var4: int = var3 / (htr + 4) 545 | var5: int = (131 * htv) + 65536 546 | heatr_res_x100: int = int(((var4 / var5) - 250) * 34) 547 | heatr_res: int = int((heatr_res_x100 + 50) / 100) 548 | 549 | return heatr_res 550 | 551 | def _calc_res_heat(self, temp: int) -> int: 552 | """ 553 | This internal API is used to calculate the heater resistance value 554 | """ 555 | gh1: float = float(self._gas_calibration[0]) 556 | gh2: float = float(self._gas_calibration[1]) 557 | gh3: float = float(self._gas_calibration[2]) 558 | htr: float = float(self._heat_range) 559 | htv: float = float(self._heat_val) 560 | amb: float = float(self._amb_temp) 561 | 562 | temp = min(temp, 400) # Cap temperature 563 | 564 | var1: float = (gh1 / (16.0)) + 49.0 565 | var2: float = ((gh2 / (32768.0)) * (0.0005)) + 0.00235 566 | var3: float = gh3 / (1024.0) 567 | var4: float = var1 * (1.0 + (var2 * float(temp))) 568 | var5: float = var4 + (var3 * amb) 569 | res_heat: int = int(3.4 * ((var5 * (4 / (4 + htr)) * (1 / (1 + (htv * 0.002)))) - 25)) 570 | return res_heat 571 | 572 | def _calc_gas_wait(self, dur: int) -> int: 573 | """ 574 | This internal API is used to calculate the gas wait 575 | """ 576 | factor: int = 0 577 | durval: int = 0xFF # Max duration 578 | 579 | if dur >= 0xFC0: 580 | return durval 581 | while dur > 0x3F: 582 | dur = dur / 4 583 | factor += 1 584 | durval = int(dur + (factor * 64)) 585 | return durval 586 | 587 | 588 | class Adafruit_BME680_I2C(Adafruit_BME680): 589 | """Driver for I2C connected BME680. 590 | 591 | :param ~busio.I2C i2c: The I2C bus the BME680 is connected to. 592 | :param int address: I2C device address. Defaults to :const:`0x77` 593 | :param bool debug: Print debug statements when `True`. Defaults to `False` 594 | :param int refresh_rate: Maximum number of readings per second. Faster property reads 595 | will be from the previous reading. 596 | 597 | **Quickstart: Importing and using the BME680** 598 | 599 | Here is an example of using the :class:`BMP680_I2C` class. 600 | First you will need to import the libraries to use the sensor 601 | 602 | .. code-block:: python 603 | 604 | import board 605 | import adafruit_bme680 606 | 607 | Once this is done you can define your ``board.I2C`` object and define your sensor object 608 | 609 | .. code-block:: python 610 | 611 | i2c = board.I2C() # uses board.SCL and board.SDA 612 | bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c) 613 | 614 | You need to setup the pressure at sea level 615 | 616 | .. code-block:: python 617 | 618 | bme680.sea_level_pressure = 1013.25 619 | 620 | Now you have access to the :attr:`temperature`, :attr:`gas`, :attr:`relative_humidity`, 621 | :attr:`pressure` and :attr:`altitude` attributes 622 | 623 | .. code-block:: python 624 | 625 | temperature = bme680.temperature 626 | gas = bme680.gas 627 | relative_humidity = bme680.relative_humidity 628 | pressure = bme680.pressure 629 | altitude = bme680.altitude 630 | 631 | """ 632 | 633 | def __init__( 634 | self, 635 | i2c: I2C, 636 | address: int = 0x77, 637 | debug: bool = False, 638 | *, 639 | refresh_rate: int = 10, 640 | ) -> None: 641 | """Initialize the I2C device at the 'address' given""" 642 | from adafruit_bus_device import ( 643 | i2c_device, 644 | ) 645 | 646 | self._i2c = i2c_device.I2CDevice(i2c, address) 647 | self._debug = debug 648 | super().__init__(refresh_rate=refresh_rate) 649 | 650 | def _read(self, register: int, length: int) -> bytearray: 651 | """Returns an array of 'length' bytes from the 'register'""" 652 | with self._i2c as i2c: 653 | i2c.write(bytes([register & 0xFF])) 654 | result = bytearray(length) 655 | i2c.readinto(result) 656 | if self._debug: 657 | print(f"\t${register:02X} => {[hex(i) for i in result]}") 658 | return result 659 | 660 | def _write(self, register: int, values: ReadableBuffer) -> None: 661 | """Writes an array of 'length' bytes to the 'register'""" 662 | with self._i2c as i2c: 663 | buffer = bytearray(2 * len(values)) 664 | for i, value in enumerate(values): 665 | buffer[2 * i] = register + i 666 | buffer[2 * i + 1] = value 667 | i2c.write(buffer) 668 | if self._debug: 669 | print(f"\t${values[0]:02X} <= {[hex(i) for i in values[1:]]}") 670 | 671 | 672 | class Adafruit_BME680_SPI(Adafruit_BME680): 673 | """Driver for SPI connected BME680. 674 | 675 | :param ~busio.SPI spi: SPI device 676 | :param ~digitalio.DigitalInOut cs: Chip Select 677 | :param bool debug: Print debug statements when `True`. Defaults to `False` 678 | :param int baudrate: Clock rate, default is :const:`100000` 679 | :param int refresh_rate: Maximum number of readings per second. Faster property reads 680 | will be from the previous reading. 681 | 682 | 683 | **Quickstart: Importing and using the BME680** 684 | 685 | Here is an example of using the :class:`BMP680_SPI` class. 686 | First you will need to import the libraries to use the sensor 687 | 688 | .. code-block:: python 689 | 690 | import board 691 | from digitalio import DigitalInOut, Direction 692 | import adafruit_bme680 693 | 694 | Once this is done you can define your ``board.SPI`` object and define your sensor object 695 | 696 | .. code-block:: python 697 | 698 | cs = digitalio.DigitalInOut(board.D10) 699 | spi = board.SPI() 700 | bme680 = adafruit_bme680.Adafruit_BME680_SPI(spi, cs) 701 | 702 | You need to setup the pressure at sea level 703 | 704 | .. code-block:: python 705 | 706 | bme680.sea_level_pressure = 1013.25 707 | 708 | Now you have access to the :attr:`temperature`, :attr:`gas`, :attr:`relative_humidity`, 709 | :attr:`pressure` and :attr:`altitude` attributes 710 | 711 | .. code-block:: python 712 | 713 | temperature = bme680.temperature 714 | gas = bme680.gas 715 | relative_humidity = bme680.relative_humidity 716 | pressure = bme680.pressure 717 | altitude = bme680.altitude 718 | 719 | """ 720 | 721 | def __init__( # noqa: PLR0913 Too many arguments in function definition 722 | self, 723 | spi: SPI, 724 | cs: DigitalInOut, 725 | baudrate: int = 100000, 726 | debug: bool = False, 727 | *, 728 | refresh_rate: int = 10, 729 | ) -> None: 730 | from adafruit_bus_device import ( 731 | spi_device, 732 | ) 733 | 734 | self._spi = spi_device.SPIDevice(spi, cs, baudrate=baudrate) 735 | self._debug = debug 736 | super().__init__(refresh_rate=refresh_rate) 737 | 738 | def _read(self, register: int, length: int) -> bytearray: 739 | if register != _BME680_REG_STATUS: 740 | # _BME680_REG_STATUS exists in both SPI memory pages 741 | # For all other registers, we must set the correct memory page 742 | self._set_spi_mem_page(register) 743 | 744 | register = (register | 0x80) & 0xFF # Read single, bit 7 high. 745 | with self._spi as spi: 746 | spi.write(bytearray([register])) 747 | result = bytearray(length) 748 | spi.readinto(result) 749 | if self._debug: 750 | print(f"\t${register:02X} => {[hex(i) for i in result]}") 751 | return result 752 | 753 | def _write(self, register: int, values: ReadableBuffer) -> None: 754 | if register != _BME680_REG_STATUS: 755 | # _BME680_REG_STATUS exists in both SPI memory pages 756 | # For all other registers, we must set the correct memory page 757 | self._set_spi_mem_page(register) 758 | register &= 0x7F # Write, bit 7 low. 759 | with self._spi as spi: 760 | buffer = bytearray(2 * len(values)) 761 | for i, value in enumerate(values): 762 | buffer[2 * i] = register + i 763 | buffer[2 * i + 1] = value & 0xFF 764 | spi.write(buffer) 765 | if self._debug: 766 | print(f"\t${values[0]:02X} <= {[hex(i) for i in values[1:]]}") 767 | 768 | def _set_spi_mem_page(self, register: int) -> None: 769 | spi_mem_page = 0x00 770 | if register < 0x80: 771 | spi_mem_page = 0x10 772 | self._write(_BME680_REG_STATUS, [spi_mem_page]) 773 | -------------------------------------------------------------------------------- /docs/_static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_BME680/ac537fa6c32c266d06f3bf215c5cd3b7c6d8e695/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 | .. automodule:: adafruit_bme680 5 | :members: 6 | -------------------------------------------------------------------------------- /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 | # Uncomment the below if you use native CircuitPython modules such as 24 | # digitalio, micropython and busio. List the modules you use. Without it, the 25 | # autodoc module docs will fail to generate with a warning. 26 | autodoc_mock_imports = ["micropython"] 27 | 28 | 29 | intersphinx_mapping = { 30 | "python": ("https://docs.python.org/3", None), 31 | "BusDevice": ( 32 | "https://docs.circuitpython.org/projects/busdevice/en/latest/", 33 | None, 34 | ), 35 | "CircuitPython": ("https://docs.circuitpython.org/en/latest/", None), 36 | } 37 | 38 | # Add any paths that contain templates here, relative to this directory. 39 | templates_path = ["_templates"] 40 | 41 | source_suffix = ".rst" 42 | 43 | # The master toctree document. 44 | master_doc = "index" 45 | 46 | # General information about the project. 47 | project = "Adafruit BME680 Library" 48 | creation_year = "2017" 49 | current_year = str(datetime.datetime.now().year) 50 | year_duration = ( 51 | current_year if current_year == creation_year else creation_year + " - " + current_year 52 | ) 53 | copyright = year_duration + " ladyada" 54 | author = "ladyada" 55 | 56 | # The version info for the project you're documenting, acts as replacement for 57 | # |version| and |release|, also used in various other places throughout the 58 | # built documents. 59 | # 60 | # The short X.Y version. 61 | version = "1.0" 62 | # The full version, including alpha/beta/rc tags. 63 | release = "1.0" 64 | 65 | # The language for content autogenerated by Sphinx. Refer to documentation 66 | # for a list of supported languages. 67 | # 68 | # This is also used if you do content translation via gettext catalogs. 69 | # Usually you set "language" from the command line for these cases. 70 | language = "en" 71 | 72 | # List of patterns, relative to source directory, that match files and 73 | # directories to ignore when looking for source files. 74 | # This patterns also effect to html_static_path and html_extra_path 75 | exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"] 76 | 77 | # The reST default role (used for this markup: `text`) to use for all 78 | # documents. 79 | # 80 | default_role = "any" 81 | 82 | # If true, '()' will be appended to :func: etc. cross-reference text. 83 | # 84 | add_function_parentheses = True 85 | 86 | # The name of the Pygments (syntax highlighting) style to use. 87 | pygments_style = "sphinx" 88 | 89 | # If true, `todo` and `todoList` produce output, else they produce nothing. 90 | todo_include_todos = False 91 | 92 | # If this is True, todo emits a warning for each TODO entries. The default is False. 93 | todo_emit_warnings = True 94 | 95 | 96 | # -- Options for HTML output ---------------------------------------------- 97 | 98 | # The theme to use for HTML and HTML Help pages. See the documentation for 99 | # a list of builtin themes. 100 | # 101 | import sphinx_rtd_theme 102 | 103 | html_theme = "sphinx_rtd_theme" 104 | 105 | # Add any paths that contain custom static files (such as style sheets) here, 106 | # relative to this directory. They are copied after the builtin static files, 107 | # so a file named "default.css" will overwrite the builtin "default.css". 108 | html_static_path = ["_static"] 109 | 110 | # The name of an image file (relative to this directory) to use as a favicon of 111 | # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 112 | # pixels large. 113 | # 114 | html_favicon = "_static/favicon.ico" 115 | 116 | # Output file base name for HTML help builder. 117 | htmlhelp_basename = "AdafruitBME680Librarydoc" 118 | 119 | # -- Options for LaTeX output --------------------------------------------- 120 | 121 | latex_elements = { 122 | # The paper size ('letterpaper' or 'a4paper'). 123 | # 124 | # 'papersize': 'letterpaper', 125 | # The font size ('10pt', '11pt' or '12pt'). 126 | # 127 | # 'pointsize': '10pt', 128 | # Additional stuff for the LaTeX preamble. 129 | # 130 | # 'preamble': '', 131 | # Latex figure (float) alignment 132 | # 133 | # 'figure_align': 'htbp', 134 | } 135 | 136 | # Grouping the document tree into LaTeX files. List of tuples 137 | # (source start file, target name, title, 138 | # author, documentclass [howto, manual, or own class]). 139 | latex_documents = [ 140 | ( 141 | master_doc, 142 | "AdafruitBME680Library.tex", 143 | "Adafruit BME680 Library Documentation", 144 | author, 145 | "manual", 146 | ), 147 | ] 148 | 149 | # -- Options for manual page output --------------------------------------- 150 | 151 | # One entry per manual page. List of tuples 152 | # (source start file, name, description, authors, manual section). 153 | man_pages = [ 154 | ( 155 | master_doc, 156 | "adafruitBME680library", 157 | "Adafruit BME680 Library Documentation", 158 | [author], 159 | 1, 160 | ) 161 | ] 162 | 163 | # -- Options for Texinfo output ------------------------------------------- 164 | 165 | # Grouping the document tree into Texinfo files. List of tuples 166 | # (source start file, target name, title, author, 167 | # dir menu entry, description, category) 168 | texinfo_documents = [ 169 | ( 170 | master_doc, 171 | "AdafruitBME680Library", 172 | "Adafruit BME680 Library Documentation", 173 | author, 174 | "AdafruitBME680Library", 175 | "One line description of project.", 176 | "Miscellaneous", 177 | ), 178 | ] 179 | -------------------------------------------------------------------------------- /docs/examples.rst: -------------------------------------------------------------------------------- 1 | Simple test 2 | ------------ 3 | 4 | Ensure your device works with this simple test. 5 | 6 | .. literalinclude:: ../examples/bme680_simpletest.py 7 | :caption: examples/bme680_simpletest.py 8 | :linenos: 9 | 10 | SPI Example 11 | ----------- 12 | 13 | Showcase the use of the SPI bus to read the sensor data. 14 | 15 | .. literalinclude:: ../examples/bme680_spi.py 16 | :caption: examples/bme680_spi.py 17 | :linenos: 18 | -------------------------------------------------------------------------------- /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 BME680 - Temperature, Humidity, Pressure and Gas Sensor Learning Guide 27 | 28 | .. toctree:: 29 | :caption: Related Products 30 | 31 | Adafruit BME680 - Temperature, Humidity, Pressure and Gas 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 | adafruit-circuitpython-typing 9 | -------------------------------------------------------------------------------- /examples/bme680_displayio_simpletest.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | import time 5 | 6 | import board 7 | from adafruit_display_text.bitmap_label import Label 8 | from displayio import Group 9 | from terminalio import FONT 10 | 11 | import adafruit_bme680 12 | 13 | # create a main_group to hold anything we want to show on the display. 14 | main_group = Group() 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 | bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c, debug=False) 20 | 21 | # change this to match the location's pressure (hPa) at sea level 22 | bme680.sea_level_pressure = 1013.25 23 | 24 | # You will usually have to add an offset to account for the temperature of 25 | # the sensor. This is usually around 5 degrees but varies by use. Use a 26 | # separate temperature sensor to calibrate this one. 27 | temperature_offset = -5 28 | 29 | # Create a Label to show the readings. If you have a very small 30 | # display you may need to change to scale=1. 31 | display_output_label = Label(FONT, text="", scale=2) 32 | 33 | # place the label near the top left corner with anchored positioning 34 | display_output_label.anchor_point = (0, 0) 35 | display_output_label.anchored_position = (4, 4) 36 | 37 | # add the label to the main_group 38 | main_group.append(display_output_label) 39 | 40 | # set the main_group as the root_group of the built-in DISPLAY 41 | board.DISPLAY.root_group = main_group 42 | 43 | # begin main loop 44 | while True: 45 | # Update the label.text property to change the text on the display 46 | display_output_label.text = f"""Temperature: {bme680.temperature + temperature_offset:.1f} C 47 | Humidity: {bme680.relative_humidity:.1f} %""" 48 | 49 | # wait for a bit 50 | time.sleep(1) 51 | -------------------------------------------------------------------------------- /examples/bme680_simpletest.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | import time 5 | 6 | import board 7 | 8 | import adafruit_bme680 9 | 10 | # Create sensor object, communicating over the board's default I2C bus 11 | i2c = board.I2C() # uses board.SCL and board.SDA 12 | # i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller 13 | bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c, debug=False) 14 | 15 | # change this to match the location's pressure (hPa) at sea level 16 | bme680.sea_level_pressure = 1013.25 17 | 18 | # You will usually have to add an offset to account for the temperature of 19 | # the sensor. This is usually around 5 degrees but varies by use. Use a 20 | # separate temperature sensor to calibrate this one. 21 | temperature_offset = -5 22 | 23 | while True: 24 | print("\nTemperature: %0.1f C" % (bme680.temperature + temperature_offset)) 25 | print("Gas: %d ohm" % bme680.gas) 26 | print("Humidity: %0.1f %%" % bme680.relative_humidity) 27 | print("Pressure: %0.3f hPa" % bme680.pressure) 28 | print("Altitude = %0.2f meters" % bme680.altitude) 29 | 30 | time.sleep(1) 31 | -------------------------------------------------------------------------------- /examples/bme680_spi.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Carter Nelson for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | import time 5 | 6 | import board 7 | import digitalio 8 | 9 | import adafruit_bme680 10 | 11 | # Create sensor object, communicating over the board's default SPI bus 12 | cs = digitalio.DigitalInOut(board.D10) 13 | spi = board.SPI() 14 | bme680 = adafruit_bme680.Adafruit_BME680_SPI(spi, cs) 15 | 16 | # change this to match the location's pressure (hPa) at sea level 17 | bme680.sea_level_pressure = 1013.25 18 | 19 | # You will usually have to add an offset to account for the temperature of 20 | # the sensor. This is usually around 5 degrees but varies by use. Use a 21 | # separate temperature sensor to calibrate this one. 22 | temperature_offset = -5 23 | 24 | while True: 25 | print("\nTemperature: %0.1f C" % (bme680.temperature + temperature_offset)) 26 | print("Gas: %d ohm" % bme680.gas) 27 | print("Humidity: %0.1f %%" % bme680.relative_humidity) 28 | print("Pressure: %0.3f hPa" % bme680.pressure) 29 | print("Altitude = %0.2f meters" % bme680.altitude) 30 | 31 | time.sleep(1) 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-bme680" 14 | description = "CircuitPython driver for BME680 sensor over I2C" 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_BME680"} 21 | keywords = [ 22 | "adafruit", 23 | "blinka", 24 | "circuitpython", 25 | "micropython", 26 | "bme680", 27 | "hardware", 28 | "temperature", 29 | "pressure", 30 | "humidity", 31 | "gas", 32 | ] 33 | license = {text = "MIT"} 34 | classifiers = [ 35 | "Intended Audience :: Developers", 36 | "Topic :: Software Development :: Libraries", 37 | "Topic :: Software Development :: Embedded Systems", 38 | "Topic :: System :: Hardware", 39 | "License :: OSI Approved :: MIT License", 40 | "Programming Language :: Python :: 3", 41 | ] 42 | dynamic = ["dependencies", "optional-dependencies"] 43 | 44 | [tool.setuptools] 45 | py-modules = ["adafruit_bme680"] 46 | 47 | [tool.setuptools.dynamic] 48 | dependencies = {file = ["requirements.txt"]} 49 | optional-dependencies = {optional = {file = ["optional_requirements.txt"]}} 50 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | Adafruit-Blinka 6 | adafruit-circuitpython-busdevice 7 | -------------------------------------------------------------------------------- /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 | select = ["I", "PL", "UP"] 10 | 11 | extend-select = [ 12 | "D419", # empty-docstring 13 | "E501", # line-too-long 14 | "W291", # trailing-whitespace 15 | "PLC0414", # useless-import-alias 16 | "PLC2401", # non-ascii-name 17 | "PLC2801", # unnecessary-dunder-call 18 | "PLC3002", # unnecessary-direct-lambda-call 19 | "E999", # syntax-error 20 | "PLE0101", # return-in-init 21 | "F706", # return-outside-function 22 | "F704", # yield-outside-function 23 | "PLE0116", # continue-in-finally 24 | "PLE0117", # nonlocal-without-binding 25 | "PLE0241", # duplicate-bases 26 | "PLE0302", # unexpected-special-method-signature 27 | "PLE0604", # invalid-all-object 28 | "PLE0605", # invalid-all-format 29 | "PLE0643", # potential-index-error 30 | "PLE0704", # misplaced-bare-raise 31 | "PLE1141", # dict-iter-missing-items 32 | "PLE1142", # await-outside-async 33 | "PLE1205", # logging-too-many-args 34 | "PLE1206", # logging-too-few-args 35 | "PLE1307", # bad-string-format-type 36 | "PLE1310", # bad-str-strip-call 37 | "PLE1507", # invalid-envvar-value 38 | "PLE2502", # bidirectional-unicode 39 | "PLE2510", # invalid-character-backspace 40 | "PLE2512", # invalid-character-sub 41 | "PLE2513", # invalid-character-esc 42 | "PLE2514", # invalid-character-nul 43 | "PLE2515", # invalid-character-zero-width-space 44 | "PLR0124", # comparison-with-itself 45 | "PLR0202", # no-classmethod-decorator 46 | "PLR0203", # no-staticmethod-decorator 47 | "UP004", # useless-object-inheritance 48 | "PLR0206", # property-with-parameters 49 | "PLR0904", # too-many-public-methods 50 | "PLR0911", # too-many-return-statements 51 | "PLR0912", # too-many-branches 52 | "PLR0913", # too-many-arguments 53 | "PLR0914", # too-many-locals 54 | "PLR0915", # too-many-statements 55 | "PLR0916", # too-many-boolean-expressions 56 | "PLR1702", # too-many-nested-blocks 57 | "PLR1704", # redefined-argument-from-local 58 | "PLR1711", # useless-return 59 | "C416", # unnecessary-comprehension 60 | "PLR1733", # unnecessary-dict-index-lookup 61 | "PLR1736", # unnecessary-list-index-lookup 62 | 63 | # ruff reports this rule is unstable 64 | #"PLR6301", # no-self-use 65 | 66 | "PLW0108", # unnecessary-lambda 67 | "PLW0120", # useless-else-on-loop 68 | "PLW0127", # self-assigning-variable 69 | "PLW0129", # assert-on-string-literal 70 | "B033", # duplicate-value 71 | "PLW0131", # named-expr-without-context 72 | "PLW0245", # super-without-brackets 73 | "PLW0406", # import-self 74 | "PLW0602", # global-variable-not-assigned 75 | "PLW0603", # global-statement 76 | "PLW0604", # global-at-module-level 77 | 78 | # fails on the try: import typing used by libraries 79 | #"F401", # unused-import 80 | 81 | "F841", # unused-variable 82 | "E722", # bare-except 83 | "PLW0711", # binary-op-exception 84 | "PLW1501", # bad-open-mode 85 | "PLW1508", # invalid-envvar-default 86 | "PLW1509", # subprocess-popen-preexec-fn 87 | "PLW2101", # useless-with-lock 88 | "PLW3301", # nested-min-max 89 | ] 90 | 91 | ignore = [ 92 | "PLR2004", # magic-value-comparison 93 | "UP030", # format literals 94 | "PLW1514", # unspecified-encoding 95 | 96 | ] 97 | 98 | [format] 99 | line-ending = "lf" 100 | --------------------------------------------------------------------------------