├── .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_mlx90640.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 ├── mlx90640_camtest.py ├── mlx90640_pil.py ├── mlx90640_pygamer.py └── mlx90640_simpletest.py ├── optional_requirements.txt ├── pygit_logger.log ├── 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) 2019 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-mlx90640/badge/?version=latest 5 | :target: https://docs.circuitpython.org/projects/mlx90640/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_MLX90640/workflows/Build%20CI/badge.svg 13 | :target: https://github.com/adafruit/Adafruit_CircuitPython_MLX90640/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 | Driver for the MLX90640 thermal camera 21 | 22 | 23 | Dependencies 24 | ============= 25 | This driver depends on: 26 | 27 | * `Adafruit CircuitPython `_ 28 | * `Bus Device `_ 29 | * `Register `_ 30 | 31 | Please ensure all dependencies are available on the CircuitPython filesystem. 32 | This is easily achieved by downloading 33 | `the Adafruit library and driver bundle `_. 34 | 35 | Installing from PyPI 36 | ===================== 37 | On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from 38 | PyPI `_. To install for current user: 39 | 40 | .. code-block:: shell 41 | 42 | pip3 install adafruit-circuitpython-mlx90640 43 | 44 | To install system-wide (this may be required in some cases): 45 | 46 | .. code-block:: shell 47 | 48 | sudo pip3 install adafruit-circuitpython-mlx90640 49 | 50 | To install in a virtual environment in your current project: 51 | 52 | .. code-block:: shell 53 | 54 | mkdir project-name && cd project-name 55 | python3 -m venv .venv 56 | source .venv/bin/activate 57 | pip3 install adafruit-circuitpython-mlx90640 58 | 59 | Usage Example 60 | ============= 61 | 62 | .. code-block:: python 63 | 64 | import time 65 | import board 66 | import busio 67 | import adafruit_mlx90640 68 | 69 | i2c = busio.I2C(board.SCL, board.SDA, frequency=800000) 70 | 71 | mlx = adafruit_mlx90640.MLX90640(i2c) 72 | print("MLX addr detected on I2C", [hex(i) for i in mlx.serial_number]) 73 | 74 | # if using higher refresh rates yields a 'too many retries' exception, 75 | # try decreasing this value to work with certain pi/camera combinations 76 | mlx.refresh_rate = adafruit_mlx90640.RefreshRate.REFRESH_2_HZ 77 | 78 | frame = [0] * 768 79 | while True: 80 | try: 81 | mlx.getFrame(frame) 82 | except ValueError: 83 | # these happen, no biggie - retry 84 | continue 85 | 86 | for h in range(24): 87 | for w in range(32): 88 | t = frame[h*32 + w] 89 | print("%0.1f, " % t, end="") 90 | print() 91 | print() 92 | 93 | Documentation 94 | ============= 95 | 96 | API documentation for this library can be found on `Read the Docs `_. 97 | 98 | For information on building library documentation, please check out `this guide `_. 99 | 100 | Contributing 101 | ============ 102 | 103 | Contributions are welcome! Please read our `Code of Conduct 104 | `_ 105 | before contributing to help this project stay welcoming. 106 | -------------------------------------------------------------------------------- /README.rst.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | 3 | SPDX-License-Identifier: MIT 4 | -------------------------------------------------------------------------------- /adafruit_mlx90640.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2019 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | """ 6 | `adafruit_mlx90640` 7 | ================================================================================ 8 | 9 | Driver for the MLX90640 thermal camera 10 | 11 | 12 | * Author(s): ladyada 13 | 14 | Implementation Notes 15 | -------------------- 16 | 17 | **Software and Dependencies:** 18 | 19 | * Adafruit CircuitPython firmware for the supported boards: 20 | https://github.com/adafruit/circuitpython/releases 21 | * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice 22 | * Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register 23 | """ 24 | 25 | import math 26 | import struct 27 | import time 28 | 29 | from adafruit_bus_device.i2c_device import I2CDevice 30 | 31 | try: 32 | from typing import List, Optional, Tuple, Union 33 | 34 | from busio import I2C 35 | except ImportError: 36 | pass 37 | 38 | __version__ = "0.0.0+auto.0" 39 | __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MLX90640.git" 40 | 41 | # We match the melexis library naming, and don't want to change 42 | 43 | eeData = [0] * 832 44 | I2C_READ_LEN = 2048 45 | SCALEALPHA = 0.000001 46 | MLX90640_DEVICEID1 = 0x2407 47 | OPENAIR_TA_SHIFT = 8 48 | 49 | 50 | class RefreshRate: 51 | """Enum-like class for MLX90640's refresh rate""" 52 | 53 | REFRESH_0_5_HZ = 0b000 # 0.5Hz 54 | REFRESH_1_HZ = 0b001 # 1Hz 55 | REFRESH_2_HZ = 0b010 # 2Hz 56 | REFRESH_4_HZ = 0b011 # 4Hz 57 | REFRESH_8_HZ = 0b100 # 8Hz 58 | REFRESH_16_HZ = 0b101 # 16Hz 59 | REFRESH_32_HZ = 0b110 # 32Hz 60 | REFRESH_64_HZ = 0b111 # 64Hz 61 | 62 | 63 | class MLX90640: 64 | """Interface to the MLX90640 temperature sensor.""" 65 | 66 | kVdd = 0 67 | vdd25 = 0 68 | KvPTAT = 0 69 | KtPTAT = 0 70 | vPTAT25 = 0 71 | alphaPTAT = 0 72 | gainEE = 0 73 | tgc = 0 74 | KsTa = 0 75 | resolutionEE = 0 76 | calibrationModeEE = 0 77 | ksTo = [0] * 5 78 | ct = [0] * 5 79 | alpha = [0] * 768 80 | alphaScale = 0 81 | offset = [0] * 768 82 | kta = [0] * 768 83 | ktaScale = 0 84 | kv = [0] * 768 85 | kvScale = 0 86 | cpAlpha = [0] * 2 87 | cpOffset = [0] * 2 88 | ilChessC = [0] * 3 89 | brokenPixels = [] 90 | outlierPixels = [] 91 | cpKta = 0 92 | cpKv = 0 93 | 94 | def __init__(self, i2c_bus: I2C, address: int = 0x33) -> None: 95 | self.i2c_device = I2CDevice(i2c_bus, address) 96 | self._I2CReadWords(0x2400, eeData) 97 | # print(eeData) 98 | self._ExtractParameters() 99 | 100 | @property 101 | def serial_number(self) -> Tuple[int, int, int]: 102 | """3-item tuple of hex values that are unique to each MLX90640""" 103 | serialWords = [0, 0, 0] 104 | self._I2CReadWords(MLX90640_DEVICEID1, serialWords) 105 | return serialWords 106 | 107 | @property 108 | def refresh_rate(self) -> int: 109 | """How fast the MLX90640 will spit out data. Start at lowest speed in 110 | RefreshRate and then slowly increase I2C clock rate and rate until you 111 | max out. The sensor does not like it if the I2C host cannot 'keep up'!""" 112 | controlRegister = [0] 113 | self._I2CReadWords(0x800D, controlRegister) 114 | return (controlRegister[0] >> 7) & 0x07 115 | 116 | @refresh_rate.setter 117 | def refresh_rate(self, rate: int) -> None: 118 | controlRegister = [0] 119 | value = (rate & 0x7) << 7 120 | self._I2CReadWords(0x800D, controlRegister) 121 | value |= controlRegister[0] & 0xFC7F 122 | self._I2CWriteWord(0x800D, value) 123 | 124 | def getFrame(self, framebuf: List[int]) -> None: 125 | """Request both 'halves' of a frame from the sensor, merge them 126 | and calculate the temperature in C for each of 32x24 pixels. Placed 127 | into the 768-element array passed in!""" 128 | emissivity = 0.95 129 | tr = 23.15 130 | mlx90640Frame = [0] * 834 131 | 132 | for _ in range(2): 133 | status = self._GetFrameData(mlx90640Frame) 134 | if status < 0: 135 | raise RuntimeError("Frame data error") 136 | # For a MLX90640 in the open air the shift is -8 degC. 137 | tr = self._GetTa(mlx90640Frame) - OPENAIR_TA_SHIFT 138 | self._CalculateTo(mlx90640Frame, emissivity, tr, framebuf) 139 | 140 | def _GetFrameData(self, frameData: List[int]) -> int: 141 | dataReady = 0 142 | cnt = 0 143 | statusRegister = [0] 144 | controlRegister = [0] 145 | 146 | while dataReady == 0: 147 | self._I2CReadWords(0x8000, statusRegister) 148 | dataReady = statusRegister[0] & 0x0008 149 | # print("ready status: 0x%x" % dataReady) 150 | 151 | while (dataReady != 0) and (cnt < 5): 152 | self._I2CWriteWord(0x8000, 0x0030) 153 | # print("Read frame", cnt) 154 | self._I2CReadWords(0x0400, frameData, end=832) 155 | 156 | self._I2CReadWords(0x8000, statusRegister) 157 | dataReady = statusRegister[0] & 0x0008 158 | # print("frame ready: 0x%x" % dataReady) 159 | cnt += 1 160 | 161 | if cnt > 4: 162 | raise RuntimeError("Too many retries") 163 | 164 | self._I2CReadWords(0x800D, controlRegister) 165 | frameData[832] = controlRegister[0] 166 | frameData[833] = statusRegister[0] & 0x0001 167 | return frameData[833] 168 | 169 | def _GetTa(self, frameData: List[int]) -> float: 170 | vdd = self._GetVdd(frameData) 171 | 172 | ptat = frameData[800] 173 | if ptat > 32767: 174 | ptat -= 65536 175 | 176 | ptatArt = frameData[768] 177 | if ptatArt > 32767: 178 | ptatArt -= 65536 179 | ptatArt = (ptat / (ptat * self.alphaPTAT + ptatArt)) * math.pow(2, 18) 180 | 181 | ta = ptatArt / (1 + self.KvPTAT * (vdd - 3.3)) - self.vPTAT25 182 | ta = ta / self.KtPTAT + 25 183 | return ta 184 | 185 | def _GetVdd(self, frameData: List[int]) -> int: 186 | vdd = frameData[810] 187 | if vdd > 32767: 188 | vdd -= 65536 189 | 190 | resolutionRAM = (frameData[832] & 0x0C00) >> 10 191 | resolutionCorrection = math.pow(2, self.resolutionEE) / math.pow(2, resolutionRAM) 192 | vdd = (resolutionCorrection * vdd - self.vdd25) / self.kVdd + 3.3 193 | 194 | return vdd 195 | 196 | def _CalculateTo( 197 | self, frameData: List[int], emissivity: float, tr: float, result: List[float] 198 | ) -> None: # noqa: PLR0914 199 | subPage = frameData[833] 200 | alphaCorrR = [0] * 4 201 | irDataCP = [0, 0] 202 | 203 | vdd = self._GetVdd(frameData) 204 | ta = self._GetTa(frameData) 205 | 206 | ta4 = ta + 273.15 207 | ta4 = ta4 * ta4 208 | ta4 = ta4 * ta4 209 | tr4 = tr + 273.15 210 | tr4 = tr4 * tr4 211 | tr4 = tr4 * tr4 212 | taTr = tr4 - (tr4 - ta4) / emissivity 213 | 214 | ktaScale = math.pow(2, self.ktaScale) 215 | kvScale = math.pow(2, self.kvScale) 216 | alphaScale = math.pow(2, self.alphaScale) 217 | 218 | alphaCorrR[0] = 1 / (1 + self.ksTo[0] * 40) 219 | alphaCorrR[1] = 1 220 | alphaCorrR[2] = 1 + self.ksTo[1] * self.ct[2] 221 | alphaCorrR[3] = alphaCorrR[2] * (1 + self.ksTo[2] * (self.ct[3] - self.ct[2])) 222 | 223 | # --------- Gain calculation ----------------------------------- 224 | gain = frameData[778] 225 | if gain > 32767: 226 | gain -= 65536 227 | gain = self.gainEE / gain 228 | 229 | # --------- To calculation ------------------------------------- 230 | mode = (frameData[832] & 0x1000) >> 5 231 | 232 | irDataCP[0] = frameData[776] 233 | irDataCP[1] = frameData[808] 234 | for i in range(2): 235 | if irDataCP[i] > 32767: 236 | irDataCP[i] -= 65536 237 | irDataCP[i] *= gain 238 | 239 | irDataCP[0] -= ( 240 | self.cpOffset[0] * (1 + self.cpKta * (ta - 25)) * (1 + self.cpKv * (vdd - 3.3)) 241 | ) 242 | if mode == self.calibrationModeEE: 243 | irDataCP[1] -= ( 244 | self.cpOffset[1] * (1 + self.cpKta * (ta - 25)) * (1 + self.cpKv * (vdd - 3.3)) 245 | ) 246 | else: 247 | irDataCP[1] -= ( 248 | (self.cpOffset[1] + self.ilChessC[0]) 249 | * (1 + self.cpKta * (ta - 25)) 250 | * (1 + self.cpKv * (vdd - 3.3)) 251 | ) 252 | 253 | for pixelNumber in range(768): 254 | if self._IsPixelBad(pixelNumber): 255 | # print("Fixing broken pixel %d" % pixelNumber) 256 | result[pixelNumber] = -273.15 257 | continue 258 | 259 | ilPattern = pixelNumber // 32 - (pixelNumber // 64) * 2 260 | chessPattern = ilPattern ^ (pixelNumber - (pixelNumber // 2) * 2) 261 | conversionPattern = ( 262 | (pixelNumber + 2) // 4 263 | - (pixelNumber + 3) // 4 264 | + (pixelNumber + 1) // 4 265 | - pixelNumber // 4 266 | ) * (1 - 2 * ilPattern) 267 | 268 | if mode == 0: 269 | pattern = ilPattern 270 | else: 271 | pattern = chessPattern 272 | 273 | if pattern == frameData[833]: 274 | irData = frameData[pixelNumber] 275 | if irData > 32767: 276 | irData -= 65536 277 | irData *= gain 278 | 279 | kta = self.kta[pixelNumber] / ktaScale 280 | kv = self.kv[pixelNumber] / kvScale 281 | irData -= self.offset[pixelNumber] * (1 + kta * (ta - 25)) * (1 + kv * (vdd - 3.3)) 282 | 283 | if mode != self.calibrationModeEE: 284 | irData += ( 285 | self.ilChessC[2] * (2 * ilPattern - 1) 286 | - self.ilChessC[1] * conversionPattern 287 | ) 288 | 289 | irData = irData - self.tgc * irDataCP[subPage] 290 | irData /= emissivity 291 | 292 | alphaCompensated = SCALEALPHA * alphaScale / self.alpha[pixelNumber] 293 | alphaCompensated *= 1 + self.KsTa * (ta - 25) 294 | 295 | Sx = ( 296 | alphaCompensated 297 | * alphaCompensated 298 | * alphaCompensated 299 | * (irData + alphaCompensated * taTr) 300 | ) 301 | Sx = math.sqrt(math.sqrt(Sx)) * self.ksTo[1] 302 | 303 | To = ( 304 | math.sqrt( 305 | math.sqrt( 306 | irData / (alphaCompensated * (1 - self.ksTo[1] * 273.15) + Sx) + taTr 307 | ) 308 | ) 309 | - 273.15 310 | ) 311 | 312 | if To < self.ct[1]: 313 | torange = 0 314 | elif To < self.ct[2]: 315 | torange = 1 316 | elif To < self.ct[3]: 317 | torange = 2 318 | else: 319 | torange = 3 320 | 321 | To = ( 322 | math.sqrt( 323 | math.sqrt( 324 | irData 325 | / ( 326 | alphaCompensated 327 | * alphaCorrR[torange] 328 | * (1 + self.ksTo[torange] * (To - self.ct[torange])) 329 | ) 330 | + taTr 331 | ) 332 | ) 333 | - 273.15 334 | ) 335 | 336 | result[pixelNumber] = To 337 | 338 | def _ExtractParameters(self) -> None: 339 | self._ExtractVDDParameters() 340 | self._ExtractPTATParameters() 341 | self._ExtractGainParameters() 342 | self._ExtractTgcParameters() 343 | self._ExtractResolutionParameters() 344 | self._ExtractKsTaParameters() 345 | self._ExtractKsToParameters() 346 | self._ExtractCPParameters() 347 | self._ExtractAlphaParameters() 348 | self._ExtractOffsetParameters() 349 | self._ExtractKtaPixelParameters() 350 | self._ExtractKvPixelParameters() 351 | self._ExtractCILCParameters() 352 | self._ExtractDeviatingPixels() 353 | 354 | # debug output 355 | # print('-'*40) 356 | # print("kVdd = %d, vdd25 = %d" % (self.kVdd, self.vdd25)) 357 | # print("KvPTAT = %f, KtPTAT = %f, vPTAT25 = %d, alphaPTAT = %f" % 358 | # (self.KvPTAT, self.KtPTAT, self.vPTAT25, self.alphaPTAT)) 359 | # print("Gain = %d, Tgc = %f, Resolution = %d" % (self.gainEE, self.tgc, self.resolutionEE)) 360 | # print("KsTa = %f, ksTo = %s, ct = %s" % (self.KsTa, self.ksTo, self.ct)) 361 | # print("cpAlpha:", self.cpAlpha, "cpOffset:", self.cpOffset) 362 | # print("alpha: ", self.alpha) 363 | # print("alphascale: ", self.alphaScale) 364 | # print("offset: ", self.offset) 365 | # print("kta:", self.kta) 366 | # print("ktaScale:", self.ktaScale) 367 | # print("kv:", self.kv) 368 | # print("kvScale:", self.kvScale) 369 | # print("calibrationModeEE:", self.calibrationModeEE) 370 | # print("ilChessC:", self.ilChessC) 371 | # print('-'*40) 372 | 373 | def _ExtractVDDParameters(self) -> None: 374 | # extract VDD 375 | self.kVdd = (eeData[51] & 0xFF00) >> 8 376 | if self.kVdd > 127: 377 | self.kVdd -= 256 # convert to signed 378 | self.kVdd *= 32 379 | self.vdd25 = eeData[51] & 0x00FF 380 | self.vdd25 = ((self.vdd25 - 256) << 5) - 8192 381 | 382 | def _ExtractPTATParameters(self) -> None: 383 | # extract PTAT 384 | self.KvPTAT = (eeData[50] & 0xFC00) >> 10 385 | if self.KvPTAT > 31: 386 | self.KvPTAT -= 64 387 | self.KvPTAT /= 4096 388 | self.KtPTAT = eeData[50] & 0x03FF 389 | if self.KtPTAT > 511: 390 | self.KtPTAT -= 1024 391 | self.KtPTAT /= 8 392 | self.vPTAT25 = eeData[49] 393 | self.alphaPTAT = (eeData[16] & 0xF000) / math.pow(2, 14) + 8 394 | 395 | def _ExtractGainParameters(self) -> None: 396 | # extract Gain 397 | self.gainEE = eeData[48] 398 | if self.gainEE > 32767: 399 | self.gainEE -= 65536 400 | 401 | def _ExtractTgcParameters(self) -> None: 402 | # extract Tgc 403 | self.tgc = eeData[60] & 0x00FF 404 | if self.tgc > 127: 405 | self.tgc -= 256 406 | self.tgc /= 32 407 | 408 | def _ExtractResolutionParameters(self) -> None: 409 | # extract resolution 410 | self.resolutionEE = (eeData[56] & 0x3000) >> 12 411 | 412 | def _ExtractKsTaParameters(self) -> None: 413 | # extract KsTa 414 | self.KsTa = (eeData[60] & 0xFF00) >> 8 415 | if self.KsTa > 127: 416 | self.KsTa -= 256 417 | self.KsTa /= 8192 418 | 419 | def _ExtractKsToParameters(self) -> None: 420 | # extract ksTo 421 | step = ((eeData[63] & 0x3000) >> 12) * 10 422 | self.ct[0] = -40 423 | self.ct[1] = 0 424 | self.ct[2] = (eeData[63] & 0x00F0) >> 4 425 | self.ct[3] = (eeData[63] & 0x0F00) >> 8 426 | self.ct[2] *= step 427 | self.ct[3] = self.ct[2] + self.ct[3] * step 428 | 429 | KsToScale = (eeData[63] & 0x000F) + 8 430 | KsToScale = 1 << KsToScale 431 | 432 | self.ksTo[0] = eeData[61] & 0x00FF 433 | self.ksTo[1] = (eeData[61] & 0xFF00) >> 8 434 | self.ksTo[2] = eeData[62] & 0x00FF 435 | self.ksTo[3] = (eeData[62] & 0xFF00) >> 8 436 | 437 | for i in range(4): 438 | if self.ksTo[i] > 127: 439 | self.ksTo[i] -= 256 440 | self.ksTo[i] /= KsToScale 441 | self.ksTo[4] = -0.0002 442 | 443 | def _ExtractCPParameters(self) -> None: 444 | # extract CP 445 | offsetSP = [0] * 2 446 | alphaSP = [0] * 2 447 | 448 | alphaScale = ((eeData[32] & 0xF000) >> 12) + 27 449 | 450 | offsetSP[0] = eeData[58] & 0x03FF 451 | if offsetSP[0] > 511: 452 | offsetSP[0] -= 1024 453 | 454 | offsetSP[1] = (eeData[58] & 0xFC00) >> 10 455 | if offsetSP[1] > 31: 456 | offsetSP[1] -= 64 457 | offsetSP[1] += offsetSP[0] 458 | 459 | alphaSP[0] = eeData[57] & 0x03FF 460 | if alphaSP[0] > 511: 461 | alphaSP[0] -= 1024 462 | alphaSP[0] /= math.pow(2, alphaScale) 463 | 464 | alphaSP[1] = (eeData[57] & 0xFC00) >> 10 465 | if alphaSP[1] > 31: 466 | alphaSP[1] -= 64 467 | alphaSP[1] = (1 + alphaSP[1] / 128) * alphaSP[0] 468 | 469 | cpKta = eeData[59] & 0x00FF 470 | if cpKta > 127: 471 | cpKta -= 256 472 | ktaScale1 = ((eeData[56] & 0x00F0) >> 4) + 8 473 | self.cpKta = cpKta / math.pow(2, ktaScale1) 474 | 475 | cpKv = (eeData[59] & 0xFF00) >> 8 476 | if cpKv > 127: 477 | cpKv -= 256 478 | kvScale = (eeData[56] & 0x0F00) >> 8 479 | self.cpKv = cpKv / math.pow(2, kvScale) 480 | 481 | self.cpAlpha[0] = alphaSP[0] 482 | self.cpAlpha[1] = alphaSP[1] 483 | self.cpOffset[0] = offsetSP[0] 484 | self.cpOffset[1] = offsetSP[1] 485 | 486 | def _ExtractAlphaParameters(self) -> None: 487 | # extract alpha 488 | accRemScale = eeData[32] & 0x000F 489 | accColumnScale = (eeData[32] & 0x00F0) >> 4 490 | accRowScale = (eeData[32] & 0x0F00) >> 8 491 | alphaScale = ((eeData[32] & 0xF000) >> 12) + 30 492 | alphaRef = eeData[33] 493 | accRow = [0] * 24 494 | accColumn = [0] * 32 495 | alphaTemp = [0] * 768 496 | 497 | for i in range(6): 498 | p = i * 4 499 | accRow[p + 0] = eeData[34 + i] & 0x000F 500 | accRow[p + 1] = (eeData[34 + i] & 0x00F0) >> 4 501 | accRow[p + 2] = (eeData[34 + i] & 0x0F00) >> 8 502 | accRow[p + 3] = (eeData[34 + i] & 0xF000) >> 12 503 | 504 | for i in range(24): 505 | if accRow[i] > 7: 506 | accRow[i] -= 16 507 | 508 | for i in range(8): 509 | p = i * 4 510 | accColumn[p + 0] = eeData[40 + i] & 0x000F 511 | accColumn[p + 1] = (eeData[40 + i] & 0x00F0) >> 4 512 | accColumn[p + 2] = (eeData[40 + i] & 0x0F00) >> 8 513 | accColumn[p + 3] = (eeData[40 + i] & 0xF000) >> 12 514 | 515 | for i in range(32): 516 | if accColumn[i] > 7: 517 | accColumn[i] -= 16 518 | 519 | for i in range(24): 520 | for j in range(32): 521 | p = 32 * i + j 522 | alphaTemp[p] = (eeData[64 + p] & 0x03F0) >> 4 523 | if alphaTemp[p] > 31: 524 | alphaTemp[p] -= 64 525 | alphaTemp[p] *= 1 << accRemScale 526 | alphaTemp[p] += ( 527 | alphaRef + (accRow[i] << accRowScale) + (accColumn[j] << accColumnScale) 528 | ) 529 | alphaTemp[p] /= math.pow(2, alphaScale) 530 | alphaTemp[p] -= self.tgc * (self.cpAlpha[0] + self.cpAlpha[1]) / 2 531 | alphaTemp[p] = SCALEALPHA / alphaTemp[p] 532 | # print("alphaTemp: ", alphaTemp) 533 | 534 | temp = max(alphaTemp) 535 | # print("temp", temp) 536 | 537 | alphaScale = 0 538 | while temp < 32768: 539 | temp *= 2 540 | alphaScale += 1 541 | 542 | for i in range(768): 543 | temp = alphaTemp[i] * math.pow(2, alphaScale) 544 | self.alpha[i] = int(temp + 0.5) 545 | 546 | self.alphaScale = alphaScale 547 | 548 | def _ExtractOffsetParameters(self) -> None: 549 | # extract offset 550 | occRow = [0] * 24 551 | occColumn = [0] * 32 552 | 553 | occRemScale = eeData[16] & 0x000F 554 | occColumnScale = (eeData[16] & 0x00F0) >> 4 555 | occRowScale = (eeData[16] & 0x0F00) >> 8 556 | offsetRef = eeData[17] 557 | if offsetRef > 32767: 558 | offsetRef -= 65536 559 | 560 | for i in range(6): 561 | p = i * 4 562 | occRow[p + 0] = eeData[18 + i] & 0x000F 563 | occRow[p + 1] = (eeData[18 + i] & 0x00F0) >> 4 564 | occRow[p + 2] = (eeData[18 + i] & 0x0F00) >> 8 565 | occRow[p + 3] = (eeData[18 + i] & 0xF000) >> 12 566 | 567 | for i in range(24): 568 | if occRow[i] > 7: 569 | occRow[i] -= 16 570 | 571 | for i in range(8): 572 | p = i * 4 573 | occColumn[p + 0] = eeData[24 + i] & 0x000F 574 | occColumn[p + 1] = (eeData[24 + i] & 0x00F0) >> 4 575 | occColumn[p + 2] = (eeData[24 + i] & 0x0F00) >> 8 576 | occColumn[p + 3] = (eeData[24 + i] & 0xF000) >> 12 577 | 578 | for i in range(32): 579 | if occColumn[i] > 7: 580 | occColumn[i] -= 16 581 | 582 | for i in range(24): 583 | for j in range(32): 584 | p = 32 * i + j 585 | self.offset[p] = (eeData[64 + p] & 0xFC00) >> 10 586 | if self.offset[p] > 31: 587 | self.offset[p] -= 64 588 | self.offset[p] *= 1 << occRemScale 589 | self.offset[p] += ( 590 | offsetRef + (occRow[i] << occRowScale) + (occColumn[j] << occColumnScale) 591 | ) 592 | 593 | def _ExtractKtaPixelParameters(self) -> None: 594 | # extract KtaPixel 595 | KtaRC = [0] * 4 596 | ktaTemp = [0] * 768 597 | 598 | KtaRoCo = (eeData[54] & 0xFF00) >> 8 599 | if KtaRoCo > 127: 600 | KtaRoCo -= 256 601 | KtaRC[0] = KtaRoCo 602 | 603 | KtaReCo = eeData[54] & 0x00FF 604 | if KtaReCo > 127: 605 | KtaReCo -= 256 606 | KtaRC[2] = KtaReCo 607 | 608 | KtaRoCe = (eeData[55] & 0xFF00) >> 8 609 | if KtaRoCe > 127: 610 | KtaRoCe -= 256 611 | KtaRC[1] = KtaRoCe 612 | 613 | KtaReCe = eeData[55] & 0x00FF 614 | if KtaReCe > 127: 615 | KtaReCe -= 256 616 | KtaRC[3] = KtaReCe 617 | 618 | ktaScale1 = ((eeData[56] & 0x00F0) >> 4) + 8 619 | ktaScale2 = eeData[56] & 0x000F 620 | 621 | for i in range(24): 622 | for j in range(32): 623 | p = 32 * i + j 624 | split = 2 * (p // 32 - (p // 64) * 2) + p % 2 625 | ktaTemp[p] = (eeData[64 + p] & 0x000E) >> 1 626 | if ktaTemp[p] > 3: 627 | ktaTemp[p] -= 8 628 | ktaTemp[p] *= 1 << ktaScale2 629 | ktaTemp[p] += KtaRC[split] 630 | ktaTemp[p] /= math.pow(2, ktaScale1) 631 | # ktaTemp[p] = ktaTemp[p] * mlx90640->offset[p]; 632 | 633 | temp = abs(ktaTemp[0]) 634 | for kta in ktaTemp: 635 | temp = max(temp, abs(kta)) 636 | 637 | ktaScale1 = 0 638 | while temp < 64: 639 | temp *= 2 640 | ktaScale1 += 1 641 | 642 | for i in range(768): 643 | temp = ktaTemp[i] * math.pow(2, ktaScale1) 644 | if temp < 0: 645 | self.kta[i] = int(temp - 0.5) 646 | else: 647 | self.kta[i] = int(temp + 0.5) 648 | self.ktaScale = ktaScale1 649 | 650 | def _ExtractKvPixelParameters(self) -> None: 651 | KvT = [0] * 4 652 | kvTemp = [0] * 768 653 | 654 | KvRoCo = (eeData[52] & 0xF000) >> 12 655 | if KvRoCo > 7: 656 | KvRoCo -= 16 657 | KvT[0] = KvRoCo 658 | 659 | KvReCo = (eeData[52] & 0x0F00) >> 8 660 | if KvReCo > 7: 661 | KvReCo -= 16 662 | KvT[2] = KvReCo 663 | 664 | KvRoCe = (eeData[52] & 0x00F0) >> 4 665 | if KvRoCe > 7: 666 | KvRoCe -= 16 667 | KvT[1] = KvRoCe 668 | 669 | KvReCe = eeData[52] & 0x000F 670 | if KvReCe > 7: 671 | KvReCe -= 16 672 | KvT[3] = KvReCe 673 | 674 | kvScale = (eeData[56] & 0x0F00) >> 8 675 | 676 | for i in range(24): 677 | for j in range(32): 678 | p = 32 * i + j 679 | split = 2 * (p // 32 - (p // 64) * 2) + p % 2 680 | kvTemp[p] = KvT[split] 681 | kvTemp[p] /= math.pow(2, kvScale) 682 | # kvTemp[p] = kvTemp[p] * mlx90640->offset[p]; 683 | 684 | temp = abs(kvTemp[0]) 685 | for kv in kvTemp: 686 | temp = max(temp, abs(kv)) 687 | 688 | kvScale = 0 689 | while temp < 64: 690 | temp *= 2 691 | kvScale += 1 692 | 693 | for i in range(768): 694 | temp = kvTemp[i] * math.pow(2, kvScale) 695 | if temp < 0: 696 | self.kv[i] = int(temp - 0.5) 697 | else: 698 | self.kv[i] = int(temp + 0.5) 699 | self.kvScale = kvScale 700 | 701 | def _ExtractCILCParameters(self) -> None: 702 | ilChessC = [0] * 3 703 | 704 | self.calibrationModeEE = (eeData[10] & 0x0800) >> 4 705 | self.calibrationModeEE = self.calibrationModeEE ^ 0x80 706 | 707 | ilChessC[0] = eeData[53] & 0x003F 708 | if ilChessC[0] > 31: 709 | ilChessC[0] -= 64 710 | ilChessC[0] /= 16.0 711 | 712 | ilChessC[1] = (eeData[53] & 0x07C0) >> 6 713 | if ilChessC[1] > 15: 714 | ilChessC[1] -= 32 715 | ilChessC[1] /= 2.0 716 | 717 | ilChessC[2] = (eeData[53] & 0xF800) >> 11 718 | if ilChessC[2] > 15: 719 | ilChessC[2] -= 32 720 | ilChessC[2] /= 8.0 721 | 722 | self.ilChessC = ilChessC 723 | 724 | def _ExtractDeviatingPixels(self) -> None: 725 | pixCnt = 0 726 | 727 | while (pixCnt < 768) and (len(self.brokenPixels) < 5) and (len(self.outlierPixels) < 5): 728 | if eeData[pixCnt + 64] == 0: 729 | self.brokenPixels.append(pixCnt) 730 | elif (eeData[pixCnt + 64] & 0x0001) != 0: 731 | self.outlierPixels.append(pixCnt) 732 | pixCnt += 1 733 | 734 | if len(self.brokenPixels) > 4: 735 | raise RuntimeError("More than 4 broken pixels") 736 | if len(self.outlierPixels) > 4: 737 | raise RuntimeError("More than 4 outlier pixels") 738 | if (len(self.brokenPixels) + len(self.outlierPixels)) > 4: 739 | raise RuntimeError("More than 4 faulty pixels") 740 | # print("Found %d broken pixels, %d outliers" 741 | # % (len(self.brokenPixels), len(self.outlierPixels))) 742 | 743 | for brokenPixel1, brokenPixel2 in self._UniqueListPairs(self.brokenPixels): 744 | if self._ArePixelsAdjacent(brokenPixel1, brokenPixel2): 745 | raise RuntimeError("Adjacent broken pixels") 746 | 747 | for outlierPixel1, outlierPixel2 in self._UniqueListPairs(self.outlierPixels): 748 | if self._ArePixelsAdjacent(outlierPixel1, outlierPixel2): 749 | raise RuntimeError("Adjacent outlier pixels") 750 | 751 | for brokenPixel in self.brokenPixels: 752 | for outlierPixel in self.outlierPixels: 753 | if self._ArePixelsAdjacent(brokenPixel, outlierPixel): 754 | raise RuntimeError("Adjacent broken and outlier pixels") 755 | 756 | def _UniqueListPairs(self, inputList: List[int]) -> Tuple[int, int]: # noqa: PLR6301 757 | for i, listValue1 in enumerate(inputList): 758 | for listValue2 in inputList[i + 1 :]: 759 | yield listValue1, listValue2 760 | 761 | def _ArePixelsAdjacent(self, pix1: int, pix2: int) -> bool: # noqa: PLR6301 762 | pixPosDif = pix1 - pix2 763 | 764 | if -34 < pixPosDif < -30: 765 | return True 766 | if -2 < pixPosDif < 2: 767 | return True 768 | if 30 < pixPosDif < 34: 769 | return True 770 | 771 | return False 772 | 773 | def _IsPixelBad(self, pixel: int) -> bool: 774 | if pixel in self.brokenPixels or pixel in self.outlierPixels: 775 | return True 776 | 777 | return False 778 | 779 | def _I2CWriteWord(self, writeAddress: int, data: int) -> None: 780 | cmd = bytearray(4) 781 | cmd[0] = writeAddress >> 8 782 | cmd[1] = writeAddress & 0x00FF 783 | cmd[2] = data >> 8 784 | cmd[3] = data & 0x00FF 785 | dataCheck = [0] 786 | 787 | with self.i2c_device as i2c: 788 | i2c.write(cmd) 789 | # print("Wrote:", [hex(i) for i in cmd]) 790 | time.sleep(0.001) 791 | self._I2CReadWords(writeAddress, dataCheck) 792 | # print("dataCheck: 0x%x" % dataCheck[0]) 793 | # if (dataCheck != data): 794 | # return -2 795 | 796 | def _I2CReadWords( 797 | self, addr: int, buffer: Union[int, List[int]], *, end: Optional[int] = None 798 | ) -> None: 799 | # stamp = time.monotonic() 800 | if end is None: 801 | remainingWords = len(buffer) 802 | else: 803 | remainingWords = end 804 | offset = 0 805 | addrbuf = bytearray(2) 806 | inbuf = bytearray(2 * I2C_READ_LEN) 807 | 808 | with self.i2c_device as i2c: 809 | while remainingWords: 810 | addrbuf[0] = addr >> 8 # MSB 811 | addrbuf[1] = addr & 0xFF # LSB 812 | read_words = min(remainingWords, I2C_READ_LEN) 813 | i2c.write_then_readinto(addrbuf, inbuf, in_end=read_words * 2) # in bytes 814 | # print("-> ", [hex(i) for i in addrbuf]) 815 | outwords = struct.unpack(">" + "H" * read_words, inbuf[0 : read_words * 2]) 816 | # print("<- (", read_words, ")", [hex(i) for i in outwords]) 817 | for i, w in enumerate(outwords): 818 | buffer[offset + i] = w 819 | offset += read_words 820 | remainingWords -= read_words 821 | addr += read_words 822 | # print("i2c read", read_words, "words in", time.monotonic()-stamp) 823 | # print("Read: ", [hex(i) for i in buffer[0:10]]) 824 | -------------------------------------------------------------------------------- /docs/_static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_MLX90640/86ffef0fc337bd834f747843b610115c1719ce99/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 | .. If your library file(s) are nested in a directory (e.g. /adafruit_foo/foo.py) 5 | .. use this format as the module name: "adafruit_foo.foo" 6 | 7 | API Reference 8 | ############# 9 | 10 | .. automodule:: adafruit_mlx90640 11 | :members: 12 | -------------------------------------------------------------------------------- /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.napoleon", 21 | "sphinx.ext.todo", 22 | ] 23 | 24 | # TODO: Please Read! 25 | # Uncomment the below if you use native CircuitPython modules such as 26 | # digitalio, micropython and busio. List the modules you use. Without it, the 27 | # autodoc module docs will fail to generate with a warning. 28 | # autodoc_mock_imports = ["digitalio", "busio"] 29 | 30 | 31 | intersphinx_mapping = { 32 | "python": ("https://docs.python.org/3", None), 33 | "BusDevice": ( 34 | "https://docs.circuitpython.org/projects/busdevice/en/latest/", 35 | None, 36 | ), 37 | "Register": ( 38 | "https://docs.circuitpython.org/projects/register/en/latest/", 39 | None, 40 | ), 41 | "CircuitPython": ("https://docs.circuitpython.org/en/latest/", None), 42 | } 43 | 44 | # Add any paths that contain templates here, relative to this directory. 45 | templates_path = ["_templates"] 46 | 47 | source_suffix = ".rst" 48 | 49 | # The master toctree document. 50 | master_doc = "index" 51 | 52 | # General information about the project. 53 | project = "Adafruit MLX90640 Library" 54 | creation_year = "2019" 55 | current_year = str(datetime.datetime.now().year) 56 | year_duration = ( 57 | current_year if current_year == creation_year else creation_year + " - " + current_year 58 | ) 59 | copyright = year_duration + " ladyada" 60 | author = "ladyada" 61 | 62 | # The version info for the project you're documenting, acts as replacement for 63 | # |version| and |release|, also used in various other places throughout the 64 | # built documents. 65 | # 66 | # The short X.Y version. 67 | version = "1.0" 68 | # The full version, including alpha/beta/rc tags. 69 | release = "1.0" 70 | 71 | # The language for content autogenerated by Sphinx. Refer to documentation 72 | # for a list of supported languages. 73 | # 74 | # This is also used if you do content translation via gettext catalogs. 75 | # Usually you set "language" from the command line for these cases. 76 | language = "en" 77 | 78 | # List of patterns, relative to source directory, that match files and 79 | # directories to ignore when looking for source files. 80 | # This patterns also effect to html_static_path and html_extra_path 81 | exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"] 82 | 83 | # The reST default role (used for this markup: `text`) to use for all 84 | # documents. 85 | # 86 | default_role = "any" 87 | 88 | # If true, '()' will be appended to :func: etc. cross-reference text. 89 | # 90 | add_function_parentheses = True 91 | 92 | # The name of the Pygments (syntax highlighting) style to use. 93 | pygments_style = "sphinx" 94 | 95 | # If true, `todo` and `todoList` produce output, else they produce nothing. 96 | todo_include_todos = False 97 | 98 | # If this is True, todo emits a warning for each TODO entries. The default is False. 99 | todo_emit_warnings = True 100 | 101 | napoleon_numpy_docstring = False 102 | 103 | # -- Options for HTML output ---------------------------------------------- 104 | 105 | # The theme to use for HTML and HTML Help pages. See the documentation for 106 | # a list of builtin themes. 107 | # 108 | import sphinx_rtd_theme 109 | 110 | html_theme = "sphinx_rtd_theme" 111 | 112 | # Add any paths that contain custom static files (such as style sheets) here, 113 | # relative to this directory. They are copied after the builtin static files, 114 | # so a file named "default.css" will overwrite the builtin "default.css". 115 | html_static_path = ["_static"] 116 | 117 | # The name of an image file (relative to this directory) to use as a favicon of 118 | # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 119 | # pixels large. 120 | # 121 | html_favicon = "_static/favicon.ico" 122 | 123 | # Output file base name for HTML help builder. 124 | htmlhelp_basename = "AdafruitMlx90640Librarydoc" 125 | 126 | # -- Options for LaTeX output --------------------------------------------- 127 | 128 | latex_elements = { 129 | # The paper size ('letterpaper' or 'a4paper'). 130 | # 131 | # 'papersize': 'letterpaper', 132 | # The font size ('10pt', '11pt' or '12pt'). 133 | # 134 | # 'pointsize': '10pt', 135 | # Additional stuff for the LaTeX preamble. 136 | # 137 | # 'preamble': '', 138 | # Latex figure (float) alignment 139 | # 140 | # 'figure_align': 'htbp', 141 | } 142 | 143 | # Grouping the document tree into LaTeX files. List of tuples 144 | # (source start file, target name, title, 145 | # author, documentclass [howto, manual, or own class]). 146 | latex_documents = [ 147 | ( 148 | master_doc, 149 | "AdafruitMLX90640Library.tex", 150 | "AdafruitMLX90640 Library Documentation", 151 | author, 152 | "manual", 153 | ), 154 | ] 155 | 156 | # -- Options for manual page output --------------------------------------- 157 | 158 | # One entry per manual page. List of tuples 159 | # (source start file, name, description, authors, manual section). 160 | man_pages = [ 161 | ( 162 | master_doc, 163 | "AdafruitMLX90640library", 164 | "Adafruit MLX90640 Library Documentation", 165 | [author], 166 | 1, 167 | ) 168 | ] 169 | 170 | # -- Options for Texinfo output ------------------------------------------- 171 | 172 | # Grouping the document tree into Texinfo files. List of tuples 173 | # (source start file, target name, title, author, 174 | # dir menu entry, description, category) 175 | texinfo_documents = [ 176 | ( 177 | master_doc, 178 | "AdafruitMLX90640Library", 179 | "Adafruit MLX90640 Library Documentation", 180 | author, 181 | "AdafruitMLX90640Library", 182 | "One line description of project.", 183 | "Miscellaneous", 184 | ), 185 | ] 186 | -------------------------------------------------------------------------------- /docs/examples.rst: -------------------------------------------------------------------------------- 1 | Simple test 2 | ------------ 3 | 4 | Ensure your device works with this simple test. 5 | 6 | .. literalinclude:: ../examples/mlx90640_simpletest.py 7 | :caption: examples/mlx90640_simpletest.py 8 | :linenos: 9 | -------------------------------------------------------------------------------- /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 | 27 | .. toctree:: 28 | :caption: Related Products 29 | 30 | 31 | .. toctree:: 32 | :caption: Other Links 33 | 34 | Download from GitHub 35 | Download Library Bundle 36 | CircuitPython Reference Documentation 37 | CircuitPython Support Forum 38 | Discord Chat 39 | Adafruit Learning System 40 | Adafruit Blog 41 | Adafruit Store 42 | 43 | Indices and tables 44 | ================== 45 | 46 | * :ref:`genindex` 47 | * :ref:`modindex` 48 | * :ref:`search` 49 | -------------------------------------------------------------------------------- /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/mlx90640_camtest.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | """This example is for Raspberry Pi (Linux) only! 5 | It will not work on microcontrollers running CircuitPython!""" 6 | 7 | import argparse 8 | import math 9 | import os 10 | import time 11 | 12 | import board 13 | import busio 14 | import pygame 15 | from PIL import Image 16 | 17 | import adafruit_mlx90640 18 | 19 | INTERPOLATE = 10 20 | 21 | # MUST set I2C freq to 1MHz in /boot/config.txt 22 | i2c = busio.I2C(board.SCL, board.SDA) 23 | 24 | # low range of the sensor (this will be black on the screen) 25 | MINTEMP = 20.0 26 | # high range of the sensor (this will be white on the screen) 27 | MAXTEMP = 50.0 28 | 29 | # if in windowed mode, make the window bigger by this factor 30 | WINDOW_SCALING_FACTOR = 50 31 | 32 | # parse command line arguments 33 | parser = argparse.ArgumentParser() 34 | parser.add_argument("--windowed", action="store_true", help="display in a window") 35 | parser.add_argument( 36 | "--disable-interpolation", 37 | action="store_true", 38 | help="disable interpolation in-between camera pixels", 39 | ) 40 | 41 | args = parser.parse_args() 42 | 43 | # set up display 44 | if not args.windowed: 45 | os.environ["SDL_FBDEV"] = "/dev/fb0" 46 | os.environ["SDL_VIDEODRIVER"] = "fbcon" 47 | pygame.init() 48 | if not args.windowed: 49 | screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) 50 | else: 51 | screen = pygame.display.set_mode([32 * WINDOW_SCALING_FACTOR, 24 * WINDOW_SCALING_FACTOR]) 52 | print(pygame.display.Info()) 53 | 54 | # the list of colors we can choose from 55 | heatmap = ( 56 | (0.0, (0, 0, 0)), 57 | (0.20, (0, 0, 0.5)), 58 | (0.40, (0, 0.5, 0)), 59 | (0.60, (0.5, 0, 0)), 60 | (0.80, (0.75, 0.75, 0)), 61 | (0.90, (1.0, 0.75, 0)), 62 | (1.00, (1.0, 1.0, 1.0)), 63 | ) 64 | 65 | # how many color values we can have 66 | COLORDEPTH = 1000 67 | 68 | colormap = [0] * COLORDEPTH 69 | 70 | 71 | # some utility functions 72 | def constrain(val, min_val, max_val): 73 | return min(max_val, max(min_val, val)) 74 | 75 | 76 | def map_value(x, in_min, in_max, out_min, out_max): 77 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min 78 | 79 | 80 | def gaussian(x, a, b, c, d=0): 81 | return a * math.exp(-((x - b) ** 2) / (2 * c**2)) + d 82 | 83 | 84 | def gradient(x, width, cmap, spread=1): 85 | width = float(width) 86 | r = sum(gaussian(x, p[1][0], p[0] * width, width / (spread * len(cmap))) for p in cmap) 87 | g = sum(gaussian(x, p[1][1], p[0] * width, width / (spread * len(cmap))) for p in cmap) 88 | b = sum(gaussian(x, p[1][2], p[0] * width, width / (spread * len(cmap))) for p in cmap) 89 | r = int(constrain(r * 255, 0, 255)) 90 | g = int(constrain(g * 255, 0, 255)) 91 | b = int(constrain(b * 255, 0, 255)) 92 | return r, g, b 93 | 94 | 95 | for i in range(COLORDEPTH): 96 | colormap[i] = gradient(i, COLORDEPTH, heatmap) 97 | 98 | pygame.mouse.set_visible(False) 99 | screen.fill((255, 0, 0)) 100 | pygame.display.update() 101 | screen.fill((0, 0, 0)) 102 | pygame.display.update() 103 | sensorout = pygame.Surface((32, 24)) 104 | 105 | 106 | # initialize the sensor 107 | mlx = adafruit_mlx90640.MLX90640(i2c) 108 | print("MLX addr detected on I2C, Serial #", [hex(i) for i in mlx.serial_number]) 109 | mlx.refresh_rate = adafruit_mlx90640.RefreshRate.REFRESH_32_HZ 110 | print(mlx.refresh_rate) 111 | print("Refresh rate: ", pow(2, (mlx.refresh_rate - 1)), "Hz") 112 | 113 | frame = [0] * 768 114 | while True: 115 | stamp = time.monotonic() 116 | try: 117 | mlx.getFrame(frame) 118 | except ValueError: 119 | continue # these happen, no biggie - retry 120 | 121 | print("Read 2 frames in %0.2f s" % (time.monotonic() - stamp)) 122 | 123 | pixels = [0] * 768 124 | for i, pixel in enumerate(frame): 125 | coloridx = map_value(pixel, MINTEMP, MAXTEMP, 0, COLORDEPTH - 1) 126 | coloridx = int(constrain(coloridx, 0, COLORDEPTH - 1)) 127 | pixels[i] = colormap[coloridx] 128 | 129 | for h in range(24): 130 | for w in range(32): 131 | pixel = pixels[h * 32 + w] 132 | sensorout.set_at((w, h), pixel) 133 | 134 | # pixelrgb = [colors[constrain(int(pixel), 0, COLORDEPTH-1)] for pixel in pixels] 135 | img = Image.new("RGB", (32, 24)) 136 | img.putdata(pixels) 137 | if not args.disable_interpolation: 138 | img = img.resize((32 * INTERPOLATE, 24 * INTERPOLATE), Image.BICUBIC) 139 | img_surface = pygame.image.fromstring(img.tobytes(), img.size, img.mode) 140 | pygame.transform.scale(img_surface.convert(), screen.get_size(), screen) 141 | pygame.display.update() 142 | if args.windowed: 143 | pygame.event.pump() 144 | print( 145 | "Completed 2 frames in %0.2f s (%d FPS)" 146 | % (time.monotonic() - stamp, 1.0 / (time.monotonic() - stamp)) 147 | ) 148 | -------------------------------------------------------------------------------- /examples/mlx90640_pil.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | """This example is for Raspberry Pi (Linux) only! 5 | It will not work on microcontrollers running CircuitPython!""" 6 | 7 | import math 8 | 9 | import board 10 | from PIL import Image 11 | 12 | import adafruit_mlx90640 13 | 14 | FILENAME = "mlx.jpg" 15 | 16 | MINTEMP = 25.0 # low range of the sensor (deg C) 17 | MAXTEMP = 45.0 # high range of the sensor (deg C) 18 | COLORDEPTH = 1000 # how many color values we can have 19 | INTERPOLATE = 10 # scale factor for final image 20 | 21 | mlx = adafruit_mlx90640.MLX90640(board.I2C()) # uses board.SCL and board.SDA 22 | 23 | # the list of colors we can choose from 24 | heatmap = ( 25 | (0.0, (0, 0, 0)), 26 | (0.20, (0, 0, 0.5)), 27 | (0.40, (0, 0.5, 0)), 28 | (0.60, (0.5, 0, 0)), 29 | (0.80, (0.75, 0.75, 0)), 30 | (0.90, (1.0, 0.75, 0)), 31 | (1.00, (1.0, 1.0, 1.0)), 32 | ) 33 | 34 | colormap = [0] * COLORDEPTH 35 | 36 | 37 | # some utility functions 38 | def constrain(val, min_val, max_val): 39 | return min(max_val, max(min_val, val)) 40 | 41 | 42 | def map_value(x, in_min, in_max, out_min, out_max): 43 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min 44 | 45 | 46 | def gaussian(x, a, b, c, d=0): 47 | return a * math.exp(-((x - b) ** 2) / (2 * c**2)) + d 48 | 49 | 50 | def gradient(x, width, cmap, spread=1): 51 | width = float(width) 52 | r = sum(gaussian(x, p[1][0], p[0] * width, width / (spread * len(cmap))) for p in cmap) 53 | g = sum(gaussian(x, p[1][1], p[0] * width, width / (spread * len(cmap))) for p in cmap) 54 | b = sum(gaussian(x, p[1][2], p[0] * width, width / (spread * len(cmap))) for p in cmap) 55 | r = int(constrain(r * 255, 0, 255)) 56 | g = int(constrain(g * 255, 0, 255)) 57 | b = int(constrain(b * 255, 0, 255)) 58 | return r, g, b 59 | 60 | 61 | for i in range(COLORDEPTH): 62 | colormap[i] = gradient(i, COLORDEPTH, heatmap) 63 | 64 | # get sensor data 65 | frame = [0] * 768 66 | success = False 67 | while not success: 68 | try: 69 | mlx.getFrame(frame) 70 | success = True 71 | except ValueError: 72 | continue 73 | 74 | # create the image 75 | pixels = [0] * 768 76 | for i, pixel in enumerate(frame): 77 | coloridx = map_value(pixel, MINTEMP, MAXTEMP, 0, COLORDEPTH - 1) 78 | coloridx = int(constrain(coloridx, 0, COLORDEPTH - 1)) 79 | pixels[i] = colormap[coloridx] 80 | 81 | # save to file 82 | img = Image.new("RGB", (32, 24)) 83 | img.putdata(pixels) 84 | img = img.transpose(Image.FLIP_TOP_BOTTOM) 85 | img = img.resize((32 * INTERPOLATE, 24 * INTERPOLATE), Image.BICUBIC) 86 | img.save("ir.jpg") 87 | -------------------------------------------------------------------------------- /examples/mlx90640_pygamer.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | import time 5 | 6 | import board 7 | import busio 8 | import displayio 9 | import terminalio 10 | from adafruit_display_text.label import Label 11 | from simpleio import map_range 12 | 13 | import adafruit_mlx90640 14 | 15 | number_of_colors = 64 # Number of color in the gradian 16 | last_color = number_of_colors - 1 # Last color in palette 17 | palette = displayio.Palette(number_of_colors) # Palette with all our colors 18 | 19 | ## Heatmap code inspired from: http://www.andrewnoske.com/wiki/Code_-_heatmaps_and_color_gradients 20 | color_A = [ 21 | [0, 0, 0], 22 | [0, 0, 255], 23 | [0, 255, 255], 24 | [0, 255, 0], 25 | [255, 255, 0], 26 | [255, 0, 0], 27 | [255, 255, 255], 28 | ] 29 | color_B = [[0, 0, 255], [0, 255, 255], [0, 255, 0], [255, 255, 0], [255, 0, 0]] 30 | color_C = [[0, 0, 0], [255, 255, 255]] 31 | color_D = [[0, 0, 255], [255, 0, 0]] 32 | 33 | color = color_B 34 | NUM_COLORS = len(color) 35 | 36 | 37 | def MakeHeatMapColor(): 38 | for c in range(number_of_colors): 39 | value = c * (NUM_COLORS - 1) / last_color 40 | idx1 = int(value) # Our desired color will be after this index. 41 | if idx1 == value: # This is the corner case 42 | red = color[idx1][0] 43 | green = color[idx1][1] 44 | blue = color[idx1][2] 45 | else: 46 | idx2 = idx1 + 1 # ... and before this index (inclusive). 47 | fractBetween = value - idx1 # Distance between the two indexes (0-1). 48 | red = int(round((color[idx2][0] - color[idx1][0]) * fractBetween + color[idx1][0])) 49 | green = int(round((color[idx2][1] - color[idx1][1]) * fractBetween + color[idx1][1])) 50 | blue = int(round((color[idx2][2] - color[idx1][2]) * fractBetween + color[idx1][2])) 51 | palette[c] = (0x010000 * red) + (0x000100 * green) + (0x000001 * blue) 52 | 53 | 54 | MakeHeatMapColor() 55 | 56 | # Bitmap for colour coded thermal value 57 | image_bitmap = displayio.Bitmap(32, 24, number_of_colors) 58 | # Create a TileGrid using the Bitmap and Palette 59 | image_tile = displayio.TileGrid(image_bitmap, pixel_shader=palette) 60 | # Create a Group that scale 32*24 to 128*96 61 | image_group = displayio.Group(scale=4) 62 | image_group.append(image_tile) 63 | 64 | scale_bitmap = displayio.Bitmap(number_of_colors, 1, number_of_colors) 65 | # Create a Group Scale must be 128 divided by number_of_colors 66 | scale_group = displayio.Group(scale=2) 67 | scale_tile = displayio.TileGrid(scale_bitmap, pixel_shader=palette, x=0, y=60) 68 | scale_group.append(scale_tile) 69 | 70 | for i in range(number_of_colors): 71 | scale_bitmap[i, 0] = i # Fill the scale with the palette gradian 72 | 73 | # Create the super Group 74 | group = displayio.Group() 75 | 76 | min_label = Label(terminalio.FONT, color=palette[0], x=0, y=110) 77 | max_label = Label(terminalio.FONT, color=palette[last_color], x=80, y=110) 78 | 79 | # Add all the sub-group to the SuperGroup 80 | group.append(image_group) 81 | group.append(scale_group) 82 | group.append(min_label) 83 | group.append(max_label) 84 | 85 | # Add the SuperGroup to the Display 86 | board.DISPLAY.root_group = group 87 | 88 | min_t = 20 # Initial minimum temperature range, before auto scale 89 | max_t = 37 # Initial maximum temperature range, before auto scale 90 | 91 | i2c = busio.I2C(board.SCL, board.SDA, frequency=800000) 92 | # i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller 93 | 94 | mlx = adafruit_mlx90640.MLX90640(i2c) 95 | print("MLX addr detected on I2C") 96 | print([hex(i) for i in mlx.serial_number]) 97 | 98 | # mlx.refresh_rate = adafruit_mlx90640.RefreshRate.REFRESH_2_HZ 99 | mlx.refresh_rate = adafruit_mlx90640.RefreshRate.REFRESH_4_HZ 100 | 101 | frame = [0] * 768 102 | 103 | while True: 104 | stamp = time.monotonic() 105 | try: 106 | mlx.getFrame(frame) 107 | except ValueError: 108 | # these happen, no biggie - retry 109 | continue 110 | 111 | # print("Time for data aquisition: %0.2f s" % (time.monotonic()-stamp)) 112 | 113 | mini = frame[0] # Define a min temperature of current image 114 | maxi = frame[0] # Define a max temperature of current image 115 | 116 | for h in range(24): 117 | for w in range(32): 118 | t = frame[h * 32 + w] 119 | if t > maxi: 120 | maxi = t 121 | if t < mini: 122 | mini = t 123 | image_bitmap[w, (23 - h)] = int(map_range(t, min_t, max_t, 0, last_color)) 124 | 125 | min_label.text = "%0.2f" % (min_t) 126 | 127 | max_string = "%0.2f" % (max_t) 128 | max_label.x = 120 - (5 * len(max_string)) # Tricky calculation to left align 129 | max_label.text = max_string 130 | 131 | min_t = mini # Automatically change the color scale 132 | max_t = maxi 133 | # print((mini, maxi)) # Use this line to display min and max graph in Mu 134 | # print("Total time for aquisition and display %0.2f s" % (time.monotonic()-stamp)) 135 | -------------------------------------------------------------------------------- /examples/mlx90640_simpletest.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | import time 5 | 6 | import board 7 | import busio 8 | 9 | import adafruit_mlx90640 10 | 11 | PRINT_TEMPERATURES = False 12 | PRINT_ASCIIART = True 13 | 14 | i2c = busio.I2C(board.SCL, board.SDA, frequency=800000) 15 | # i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller 16 | 17 | mlx = adafruit_mlx90640.MLX90640(i2c) 18 | print("MLX addr detected on I2C") 19 | print([hex(i) for i in mlx.serial_number]) 20 | 21 | mlx.refresh_rate = adafruit_mlx90640.RefreshRate.REFRESH_2_HZ 22 | 23 | frame = [0] * 768 24 | while True: 25 | stamp = time.monotonic() 26 | try: 27 | mlx.getFrame(frame) 28 | except ValueError: 29 | # these happen, no biggie - retry 30 | continue 31 | print("Read 2 frames in %0.2f s" % (time.monotonic() - stamp)) 32 | for h in range(24): 33 | for w in range(32): 34 | t = frame[h * 32 + w] 35 | if PRINT_TEMPERATURES: 36 | print("%0.1f, " % t, end="") 37 | if PRINT_ASCIIART: 38 | c = "&" 39 | if t < 20: 40 | c = " " 41 | elif t < 23: 42 | c = "." 43 | elif t < 25: 44 | c = "-" 45 | elif t < 27: 46 | c = "*" 47 | elif t < 29: 48 | c = "+" 49 | elif t < 31: 50 | c = "x" 51 | elif t < 33: 52 | c = "%" 53 | elif t < 35: 54 | c = "#" 55 | elif t < 37: 56 | c = "X" 57 | print(c, end="") 58 | print() 59 | print() 60 | -------------------------------------------------------------------------------- /optional_requirements.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | -------------------------------------------------------------------------------- /pygit_logger.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_MLX90640/86ffef0fc337bd834f747843b610115c1719ce99/pygit_logger.log -------------------------------------------------------------------------------- /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-mlx90640" 14 | description = "Driver for the MLX90640 thermal camera" 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_MLX90640"} 21 | keywords = [ 22 | "adafruit", 23 | "blinka", 24 | "circuitpython", 25 | "micropython", 26 | "mlx90640", 27 | "thermal", 28 | "camera", 29 | "ir", 30 | "flir", 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_mlx90640"] 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 | "PLR0914", # too-many-local-vars 103 | ] 104 | 105 | [format] 106 | line-ending = "lf" 107 | --------------------------------------------------------------------------------