├── .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_ov7670.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 ├── ov7670_displayio_gcm4_tftshield18.py ├── ov7670_displayio_kaluga1_3_ili9341.py ├── ov7670_displayio_pico_st7789_2in.py └── ov7670_simpletest.py ├── optional_requirements.txt ├── pyproject.toml ├── requirements.txt └── ruff.toml /.gitattributes: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | .py text eol=lf 6 | .rst text eol=lf 7 | .txt text eol=lf 8 | .yaml text eol=lf 9 | .toml text eol=lf 10 | .license text eol=lf 11 | .md text eol=lf 12 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | Thank you for contributing! Before you submit a pull request, please read the following. 6 | 7 | Make sure any changes you're submitting are in line with the CircuitPython Design Guide, available here: https://docs.circuitpython.org/en/latest/docs/design_guide.html 8 | 9 | If your changes are to documentation, please verify that the documentation builds locally by following the steps found here: https://adafru.it/build-docs 10 | 11 | Before submitting the pull request, make sure you've run Pylint and Black locally on your code. You can do this manually or using pre-commit. Instructions are available here: https://adafru.it/check-your-code 12 | 13 | Please remove all of this text before submitting. Include an explanation or list of changes included in your PR, as well as, if applicable, a link to any related issues. 14 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: Build CI 6 | 7 | on: [pull_request, push] 8 | 9 | jobs: 10 | test: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Run Build CI workflow 14 | uses: adafruit/workflows-circuitpython-libs/build@main 15 | -------------------------------------------------------------------------------- /.github/workflows/failure-help-text.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Scott Shawcroft for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: Failure help text 6 | 7 | on: 8 | workflow_run: 9 | workflows: ["Build CI"] 10 | types: 11 | - completed 12 | 13 | jobs: 14 | post-help: 15 | runs-on: ubuntu-latest 16 | if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.event == 'pull_request' }} 17 | steps: 18 | - name: Post comment to help 19 | uses: adafruit/circuitpython-action-library-ci-failed@v1 20 | -------------------------------------------------------------------------------- /.github/workflows/release_gh.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: GitHub Release Actions 6 | 7 | on: 8 | release: 9 | types: [published] 10 | 11 | jobs: 12 | upload-release-assets: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Run GitHub Release CI workflow 16 | uses: adafruit/workflows-circuitpython-libs/release-gh@main 17 | with: 18 | github-token: ${{ secrets.GITHUB_TOKEN }} 19 | upload-url: ${{ github.event.release.upload_url }} 20 | -------------------------------------------------------------------------------- /.github/workflows/release_pypi.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: PyPI Release Actions 6 | 7 | on: 8 | release: 9 | types: [published] 10 | 11 | jobs: 12 | upload-release-assets: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Run PyPI Release CI workflow 16 | uses: adafruit/workflows-circuitpython-libs/release-pypi@main 17 | with: 18 | pypi-username: ${{ secrets.pypi_username }} 19 | pypi-password: ${{ secrets.pypi_password }} 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Kattni Rembor, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | # Do not include files and directories created by your personal work environment, such as the IDE 6 | # you use, except for those already listed here. Pull requests including changes to this file will 7 | # not be accepted. 8 | 9 | # This .gitignore file contains rules for files generated by working with CircuitPython libraries, 10 | # including building Sphinx, testing with pip, and creating a virual environment, as well as the 11 | # MacOS and IDE-specific files generated by using MacOS in general, or the PyCharm or VSCode IDEs. 12 | 13 | # If you find that there are files being generated on your machine that should not be included in 14 | # your git commit, you should create a .gitignore_global file on your computer to include the 15 | # files created by your personal setup. To do so, follow the two steps below. 16 | 17 | # First, create a file called .gitignore_global somewhere convenient for you, and add rules for 18 | # the files you want to exclude from git commits. 19 | 20 | # Second, configure Git to use the exclude file for all Git repositories by running the 21 | # following via commandline, replacing "path/to/your/" with the actual path to your newly created 22 | # .gitignore_global file: 23 | # git config --global core.excludesfile path/to/your/.gitignore_global 24 | 25 | # CircuitPython-specific files 26 | *.mpy 27 | 28 | # Python-specific files 29 | __pycache__ 30 | *.pyc 31 | 32 | # Sphinx build-specific files 33 | _build 34 | 35 | # This file results from running `pip -e install .` in a local repository 36 | *.egg-info 37 | 38 | # Virtual environment-specific files 39 | .env 40 | .venv 41 | 42 | # MacOS-specific files 43 | *.DS_Store 44 | 45 | # IDE-specific files 46 | .idea 47 | .vscode 48 | *~ 49 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | repos: 6 | - repo: https://github.com/pre-commit/pre-commit-hooks 7 | rev: v4.5.0 8 | hooks: 9 | - id: check-yaml 10 | - id: end-of-file-fixer 11 | - id: trailing-whitespace 12 | - repo: https://github.com/astral-sh/ruff-pre-commit 13 | rev: v0.3.4 14 | hooks: 15 | - id: ruff-format 16 | - id: ruff 17 | args: ["--fix"] 18 | - repo: https://github.com/fsfe/reuse-tool 19 | rev: v3.0.1 20 | hooks: 21 | - id: reuse 22 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | # Read the Docs configuration file 6 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 7 | 8 | # Required 9 | version: 2 10 | 11 | sphinx: 12 | configuration: docs/conf.py 13 | 14 | build: 15 | os: ubuntu-20.04 16 | tools: 17 | python: "3" 18 | 19 | python: 20 | install: 21 | - requirements: docs/requirements.txt 22 | - requirements: requirements.txt 23 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 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, @danh#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], 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 | 137 | [Contributor Covenant]: https://www.contributor-covenant.org 138 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2021 Jeff Epler 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 | 5 | .. image:: https://readthedocs.org/projects/adafruit-circuitpython-ov7670/badge/?version=latest 6 | :target: https://docs.circuitpython.org/projects/ov7670/en/latest/ 7 | :alt: Documentation Status 8 | 9 | 10 | .. image:: https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_Bundle/main/badges/adafruit_discord.svg 11 | :target: https://adafru.it/discord 12 | :alt: Discord 13 | 14 | 15 | .. image:: https://github.com/adafruit/Adafruit_CircuitPython_OV7670/workflows/Build%20CI/badge.svg 16 | :target: https://github.com/adafruit/Adafruit_CircuitPython_OV7670/actions 17 | :alt: Build Status 18 | 19 | 20 | .. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json 21 | :target: https://github.com/astral-sh/ruff 22 | :alt: Code Style: Ruff 23 | 24 | CircuitPython driver for OV7670 cameras 25 | 26 | .. warning:: 27 | This module requires the CircuitPython ``imagecapture`` module which is only in the unreleased development version ("Absolute Newest") of CircuitPython and is only supported on specific boards. 28 | 29 | Dependencies 30 | ============= 31 | This driver depends on: 32 | 33 | * `Adafruit CircuitPython `_ 34 | * `Bus Device `_ 35 | 36 | Please ensure all dependencies are available on the CircuitPython filesystem. 37 | This is easily achieved by downloading 38 | `the Adafruit library and driver bundle `_ 39 | or individual libraries can be installed using 40 | `circup `_. 41 | 42 | .. :: Describe the Adafruit product this library works with. For PCBs, you can also add the image from the assets folder in the PCB's github repo. 43 | .. :: `Purchase one from the Adafruit shop `_ 44 | 45 | 46 | 47 | Usage Example 48 | ============= 49 | 50 | On an Adafruit Metro M4 Grand Central, capture a 40x30 image into a buffer: 51 | 52 | .. code-block:: python3 53 | 54 | import board 55 | from adafruit_ov7670 import OV7670 56 | 57 | cam = OV7670( 58 | bus, 59 | data_pins=[board.PCC_D0, board.PCC_D1, board.PCC_D2, board.PCC_D3, board.PCC_D4, board.PCC_D5, board.PCC_D6, board.PCC_D7], 60 | clock=board.PCC_CLK, 61 | vsync=board.PCC_DEN1, 62 | href=board.PCC_DEN2, 63 | mclk=board.D29, 64 | shutdown=board.D39, 65 | reset=board.D38, 66 | ) 67 | cam.size = OV7670_SIZE_DIV16 68 | 69 | buf = bytearray(2 * cam.width * cam.height) 70 | 71 | cam.capture(buf) 72 | 73 | Documentation 74 | ============= 75 | 76 | API documentation for this library can be found on `Read the Docs `_. 77 | 78 | For information on building library documentation, please check out `this guide `_. 79 | 80 | Contributing 81 | ============ 82 | 83 | Contributions are welcome! Please read our `Code of Conduct 84 | `_ 85 | before contributing to help this project stay welcoming. 86 | -------------------------------------------------------------------------------- /README.rst.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | SPDX-FileCopyrightText: Copyright (c) 2021 Jeff Epler for Adafruit Industries 3 | SPDX-License-Identifier: MIT 4 | -------------------------------------------------------------------------------- /adafruit_ov7670.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # SPDX-FileCopyrightText: Copyright (c) 2021 Jeff Epler for Adafruit Industries 3 | # 4 | # SPDX-License-Identifier: MIT 5 | """ 6 | `adafruit_ov7670` 7 | ================================================================================ 8 | 9 | CircuitPython driver for OV7670 cameras 10 | 11 | 12 | * Author(s): Jeff Epler 13 | 14 | Implementation Notes 15 | -------------------- 16 | 17 | **Hardware:** 18 | 19 | **Software and Dependencies:** 20 | 21 | * Adafruit CircuitPython firmware for the supported boards: 22 | https://github.com/adafruit/circuitpython/releases 23 | * The CircuitPython build for your board must support the ``imagecapture`` module. 24 | * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice 25 | """ 26 | 27 | # imports 28 | 29 | __version__ = "0.0.0+auto.0" 30 | __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_OV7670.git" 31 | 32 | import time 33 | 34 | import digitalio 35 | import imagecapture 36 | import pwmio 37 | from adafruit_bus_device.i2c_device import I2CDevice 38 | from micropython import const 39 | 40 | try: 41 | from typing import List, Optional 42 | 43 | from busio import I2C 44 | from circuitpython_typing import WriteableBuffer 45 | from microcontroller import Pin 46 | except ImportError: 47 | pass 48 | 49 | # Supported color formats 50 | OV7670_COLOR_RGB = 0 51 | """RGB565 big-endian""" 52 | OV7670_COLOR_YUV = 1 53 | """YUV/YCbCr 422 big-endian""" 54 | 55 | # Supported sizes (VGA division factor) for OV7670_set_size() 56 | OV7670_SIZE_DIV1 = 0 57 | """640 x 480""" 58 | OV7670_SIZE_DIV2 = 1 59 | """320 x 240""" 60 | OV7670_SIZE_DIV4 = 2 61 | """160 x 120""" 62 | OV7670_SIZE_DIV8 = 3 63 | """80 x 60""" 64 | OV7670_SIZE_DIV16 = 4 65 | """40 x 30""" 66 | 67 | # Test patterns 68 | OV7670_TEST_PATTERN_NONE = 0 69 | """Normal operation mode (no test pattern)""" 70 | OV7670_TEST_PATTERN_SHIFTING_1 = 1 71 | """"Shifting 1" pattern""" 72 | OV7670_TEST_PATTERN_COLOR_BAR = 2 73 | """8 color bars""" 74 | OV7670_TEST_PATTERN_COLOR_BAR_FADE = 3 75 | """Color bars w/fade to white""" 76 | 77 | # Table of bit patterns for the different supported night modes. 78 | # There's a "same frame rate" option for OV7670 night mode but it 79 | # doesn't seem to do anything useful and can be skipped over. 80 | OV7670_NIGHT_MODE_OFF = 0 81 | """Disable night mode""" 82 | OV7670_NIGHT_MODE_2 = 0b10100000 83 | """Night mode 1/2 frame rate""" 84 | OV7670_NIGHT_MODE_4 = 0b11000000 85 | """Night mode 1/4 frame rate""" 86 | OV7670_NIGHT_MODE_8 = 0b11100000 87 | """Night mode 1/8 frame rate""" 88 | 89 | OV7670_ADDR = 0x21 90 | """Default I2C address if unspecified""" 91 | 92 | _OV7670_REG_GAIN = const(0x00) # AGC gain bits 7:0 (9:8 in VREF) 93 | _OV7670_REG_BLUE = const(0x01) # AWB blue channel gain 94 | _OV7670_REG_RED = const(0x02) # AWB red channel gain 95 | _OV7670_REG_VREF = const(0x03) # Vert frame control bits 96 | _OV7670_REG_COM1 = const(0x04) # Common control 1 97 | _OV7670_COM1_R656 = const(0x40) # COM1 enable R656 format 98 | _OV7670_REG_BAVE = const(0x05) # U/B average level 99 | _OV7670_REG_GbAVE = const(0x06) # Y/Gb average level 100 | _OV7670_REG_AECHH = const(0x07) # Exposure value - AEC 15:10 bits 101 | _OV7670_REG_RAVE = const(0x08) # V/R average level 102 | _OV7670_REG_COM2 = const(0x09) # Common control 2 103 | _OV7670_COM2_SSLEEP = const(0x10) # COM2 soft sleep mode 104 | _OV7670_REG_PID = const(0x0A) # Product ID MSB (read-only) 105 | _OV7670_REG_VER = const(0x0B) # Product ID LSB (read-only) 106 | _OV7670_REG_COM3 = const(0x0C) # Common control 3 107 | _OV7670_COM3_SWAP = const(0x40) # COM3 output data MSB/LSB swap 108 | _OV7670_COM3_SCALEEN = const(0x08) # COM3 scale enable 109 | _OV7670_COM3_DCWEN = const(0x04) # COM3 DCW enable 110 | _OV7670_REG_COM4 = const(0x0D) # Common control 4 111 | _OV7670_REG_COM5 = const(0x0E) # Common control 5 112 | _OV7670_REG_COM6 = const(0x0F) # Common control 6 113 | _OV7670_REG_AECH = const(0x10) # Exposure value 9:2 114 | _OV7670_REG_CLKRC = const(0x11) # Internal clock 115 | _OV7670_CLK_EXT = const(0x40) # CLKRC Use ext clock directly 116 | _OV7670_CLK_SCALE = const(0x3F) # CLKRC Int clock prescale mask 117 | _OV7670_REG_COM7 = const(0x12) # Common control 7 118 | _OV7670_COM7_RESET = const(0x80) # COM7 SCCB register reset 119 | _OV7670_COM7_SIZE_MASK = const(0x38) # COM7 output size mask 120 | _OV7670_COM7_PIXEL_MASK = const(0x05) # COM7 output pixel format mask 121 | _OV7670_COM7_SIZE_VGA = const(0x00) # COM7 output size VGA 122 | _OV7670_COM7_SIZE_CIF = const(0x20) # COM7 output size CIF 123 | _OV7670_COM7_SIZE_QVGA = const(0x10) # COM7 output size QVGA 124 | _OV7670_COM7_SIZE_QCIF = const(0x08) # COM7 output size QCIF 125 | _OV7670_COM7_RGB = const(0x04) # COM7 pixel format RGB 126 | _OV7670_COM7_YUV = const(0x00) # COM7 pixel format YUV 127 | _OV7670_COM7_BAYER = const(0x01) # COM7 pixel format Bayer RAW 128 | _OV7670_COM7_PBAYER = const(0x05) # COM7 pixel fmt proc Bayer RAW 129 | _OV7670_COM7_COLORBAR = const(0x02) # COM7 color bar enable 130 | _OV7670_REG_COM8 = const(0x13) # Common control 8 131 | _OV7670_COM8_FASTAEC = const(0x80) # COM8 Enable fast AGC/AEC algo, 132 | _OV7670_COM8_AECSTEP = const(0x40) # COM8 AEC step size unlimited 133 | _OV7670_COM8_BANDING = const(0x20) # COM8 Banding filter enable 134 | _OV7670_COM8_AGC = const(0x04) # COM8 AGC (auto gain) enable 135 | _OV7670_COM8_AWB = const(0x02) # COM8 AWB (auto white balance) 136 | _OV7670_COM8_AEC = const(0x01) # COM8 AEC (auto exposure) enable 137 | _OV7670_REG_COM9 = const(0x14) # Common control 9 - max AGC value 138 | _OV7670_REG_COM10 = const(0x15) # Common control 10 139 | _OV7670_COM10_HSYNC = const(0x40) # COM10 HREF changes to HSYNC 140 | _OV7670_COM10_PCLK_HB = const(0x20) # COM10 Suppress PCLK on hblank 141 | _OV7670_COM10_HREF_REV = const(0x08) # COM10 HREF reverse 142 | _OV7670_COM10_VS_EDGE = const(0x04) # COM10 VSYNC chg on PCLK rising 143 | _OV7670_COM10_VS_NEG = const(0x02) # COM10 VSYNC negative 144 | _OV7670_COM10_HS_NEG = const(0x01) # COM10 HSYNC negative 145 | _OV7670_REG_HSTART = const(0x17) # Horiz frame start high bits 146 | _OV7670_REG_HSTOP = const(0x18) # Horiz frame end high bits 147 | _OV7670_REG_VSTART = const(0x19) # Vert frame start high bits 148 | _OV7670_REG_VSTOP = const(0x1A) # Vert frame end high bits 149 | _OV7670_REG_PSHFT = const(0x1B) # Pixel delay select 150 | _OV7670_REG_MIDH = const(0x1C) # Manufacturer ID high byte 151 | _OV7670_REG_MIDL = const(0x1D) # Manufacturer ID low byte 152 | _OV7670_REG_MVFP = const(0x1E) # Mirror / vert-flip enable 153 | _OV7670_MVFP_MIRROR = const(0x20) # MVFP Mirror image 154 | _OV7670_MVFP_VFLIP = const(0x10) # MVFP Vertical flip 155 | _OV7670_REG_LAEC = const(0x1F) # Reserved 156 | _OV7670_REG_ADCCTR0 = const(0x20) # ADC control 157 | _OV7670_REG_ADCCTR1 = const(0x21) # Reserved 158 | _OV7670_REG_ADCCTR2 = const(0x22) # Reserved 159 | _OV7670_REG_ADCCTR3 = const(0x23) # Reserved 160 | _OV7670_REG_AEW = const(0x24) # AGC/AEC upper limit 161 | _OV7670_REG_AEB = const(0x25) # AGC/AEC lower limit 162 | _OV7670_REG_VPT = const(0x26) # AGC/AEC fast mode op region 163 | _OV7670_REG_BBIAS = const(0x27) # B channel signal output bias 164 | _OV7670_REG_GbBIAS = const(0x28) # Gb channel signal output bias 165 | _OV7670_REG_EXHCH = const(0x2A) # Dummy pixel insert MSB 166 | _OV7670_REG_EXHCL = const(0x2B) # Dummy pixel insert LSB 167 | _OV7670_REG_RBIAS = const(0x2C) # R channel signal output bias 168 | _OV7670_REG_ADVFL = const(0x2D) # Insert dummy lines MSB 169 | _OV7670_REG_ADVFH = const(0x2E) # Insert dummy lines LSB 170 | _OV7670_REG_YAVE = const(0x2F) # Y/G channel average value 171 | _OV7670_REG_HSYST = const(0x30) # HSYNC rising edge delay 172 | _OV7670_REG_HSYEN = const(0x31) # HSYNC falling edge delay 173 | _OV7670_REG_HREF = const(0x32) # HREF control 174 | _OV7670_REG_CHLF = const(0x33) # Array current control 175 | _OV7670_REG_ARBLM = const(0x34) # Array ref control - reserved 176 | _OV7670_REG_ADC = const(0x37) # ADC control - reserved 177 | _OV7670_REG_ACOM = const(0x38) # ADC & analog common - reserved 178 | _OV7670_REG_OFON = const(0x39) # ADC offset control - reserved 179 | _OV7670_REG_TSLB = const(0x3A) # Line buffer test option 180 | _OV7670_TSLB_NEG = const(0x20) # TSLB Negative image enable 181 | _OV7670_TSLB_YLAST = const(0x04) # TSLB UYVY or VYUY, see COM13 182 | _OV7670_TSLB_AOW = const(0x01) # TSLB Auto output window 183 | _OV7670_REG_COM11 = const(0x3B) # Common control 11 184 | _OV7670_COM11_NIGHT = const(0x80) # COM11 Night mode 185 | _OV7670_COM11_NMFR = const(0x60) # COM11 Night mode frame rate mask 186 | _OV7670_COM11_HZAUTO = const(0x10) # COM11 Auto detect 50/60 Hz 187 | _OV7670_COM11_BAND = const(0x08) # COM11 Banding filter val select 188 | _OV7670_COM11_EXP = const(0x02) # COM11 Exposure timing control 189 | _OV7670_REG_COM12 = const(0x3C) # Common control 12 190 | _OV7670_COM12_HREF = const(0x80) # COM12 Always has HREF 191 | _OV7670_REG_COM13 = const(0x3D) # Common control 13 192 | _OV7670_COM13_GAMMA = const(0x80) # COM13 Gamma enable 193 | _OV7670_COM13_UVSAT = const(0x40) # COM13 UV saturation auto adj 194 | _OV7670_COM13_UVSWAP = const(0x01) # COM13 UV swap, use w TSLB[3] 195 | _OV7670_REG_COM14 = const(0x3E) # Common control 14 196 | _OV7670_COM14_DCWEN = const(0x10) # COM14 DCW & scaling PCLK enable 197 | _OV7670_REG_EDGE = const(0x3F) # Edge enhancement adjustment 198 | _OV7670_REG_COM15 = const(0x40) # Common control 15 199 | _OV7670_COM15_RMASK = const(0xC0) # COM15 Output range mask 200 | _OV7670_COM15_R10F0 = const(0x00) # COM15 Output range 10 to F0 201 | _OV7670_COM15_R01FE = const(0x80) # COM15 01 to FE 202 | _OV7670_COM15_R00FF = const(0xC0) # COM15 00 to FF 203 | _OV7670_COM15_RGBMASK = const(0x30) # COM15 RGB 555/565 option mask 204 | _OV7670_COM15_RGB = const(0x00) # COM15 Normal RGB out 205 | _OV7670_COM15_RGB565 = const(0x10) # COM15 RGB 565 output 206 | _OV7670_COM15_RGB555 = const(0x30) # COM15 RGB 555 output 207 | _OV7670_REG_COM16 = const(0x41) # Common control 16 208 | _OV7670_COM16_AWBGAIN = const(0x08) # COM16 AWB gain enable 209 | _OV7670_REG_COM17 = const(0x42) # Common control 17 210 | _OV7670_COM17_AECWIN = const(0xC0) # COM17 AEC window must match COM4 211 | _OV7670_COM17_CBAR = const(0x08) # COM17 DSP Color bar enable 212 | _OV7670_REG_AWBC1 = const(0x43) # Reserved 213 | _OV7670_REG_AWBC2 = const(0x44) # Reserved 214 | _OV7670_REG_AWBC3 = const(0x45) # Reserved 215 | _OV7670_REG_AWBC4 = const(0x46) # Reserved 216 | _OV7670_REG_AWBC5 = const(0x47) # Reserved 217 | _OV7670_REG_AWBC6 = const(0x48) # Reserved 218 | _OV7670_REG_REG4B = const(0x4B) # UV average enable 219 | _OV7670_REG_DNSTH = const(0x4C) # De-noise strength 220 | _OV7670_REG_MTX1 = const(0x4F) # Matrix coefficient 1 221 | _OV7670_REG_MTX2 = const(0x50) # Matrix coefficient 2 222 | _OV7670_REG_MTX3 = const(0x51) # Matrix coefficient 3 223 | _OV7670_REG_MTX4 = const(0x52) # Matrix coefficient 4 224 | _OV7670_REG_MTX5 = const(0x53) # Matrix coefficient 5 225 | _OV7670_REG_MTX6 = const(0x54) # Matrix coefficient 6 226 | _OV7670_REG_BRIGHT = const(0x55) # Brightness control 227 | _OV7670_REG_CONTRAS = const(0x56) # Contrast control 228 | _OV7670_REG_CONTRAS_CENTER = const(0x57) # Contrast center 229 | _OV7670_REG_MTXS = const(0x58) # Matrix coefficient sign 230 | _OV7670_REG_LCC1 = const(0x62) # Lens correction option 1 231 | _OV7670_REG_LCC2 = const(0x63) # Lens correction option 2 232 | _OV7670_REG_LCC3 = const(0x64) # Lens correction option 3 233 | _OV7670_REG_LCC4 = const(0x65) # Lens correction option 4 234 | _OV7670_REG_LCC5 = const(0x66) # Lens correction option 5 235 | _OV7670_REG_MANU = const(0x67) # Manual U value 236 | _OV7670_REG_MANV = const(0x68) # Manual V value 237 | _OV7670_REG_GFIX = const(0x69) # Fix gain control 238 | _OV7670_REG_GGAIN = const(0x6A) # G channel AWB gain 239 | _OV7670_REG_DBLV = const(0x6B) # PLL & regulator control 240 | _OV7670_REG_AWBCTR3 = const(0x6C) # AWB control 3 241 | _OV7670_REG_AWBCTR2 = const(0x6D) # AWB control 2 242 | _OV7670_REG_AWBCTR1 = const(0x6E) # AWB control 1 243 | _OV7670_REG_AWBCTR0 = const(0x6F) # AWB control 0 244 | _OV7670_REG_SCALING_XSC = const(0x70) # Test pattern X scaling 245 | _OV7670_REG_SCALING_YSC = const(0x71) # Test pattern Y scaling 246 | _OV7670_REG_SCALING_DCWCTR = const(0x72) # DCW control 247 | _OV7670_REG_SCALING_PCLK_DIV = const(0x73) # DSP scale control clock divide 248 | _OV7670_REG_REG74 = const(0x74) # Digital gain control 249 | _OV7670_REG_REG76 = const(0x76) # Pixel correction 250 | _OV7670_REG_SLOP = const(0x7A) # Gamma curve highest seg slope 251 | _OV7670_REG_GAM_BASE = const(0x7B) # Gamma register base (1 of 15) 252 | _OV7670_GAM_LEN = const(15) # Number of gamma registers 253 | _OV7670_R76_BLKPCOR = const(0x80) # REG76 black pixel corr enable 254 | _OV7670_R76_WHTPCOR = const(0x40) # REG76 white pixel corr enable 255 | _OV7670_REG_RGB444 = const(0x8C) # RGB 444 control 256 | _OV7670_R444_ENABLE = const(0x02) # RGB444 enable 257 | _OV7670_R444_RGBX = const(0x01) # RGB444 word format 258 | _OV7670_REG_DM_LNL = const(0x92) # Dummy line LSB 259 | _OV7670_REG_LCC6 = const(0x94) # Lens correction option 6 260 | _OV7670_REG_LCC7 = const(0x95) # Lens correction option 7 261 | _OV7670_REG_HAECC1 = const(0x9F) # Histogram-based AEC/AGC ctrl 1 262 | _OV7670_REG_HAECC2 = const(0xA0) # Histogram-based AEC/AGC ctrl 2 263 | _OV7670_REG_SCALING_PCLK_DELAY = const(0xA2) # Scaling pixel clock delay 264 | _OV7670_REG_BD50MAX = const(0xA5) # 50 Hz banding step limit 265 | _OV7670_REG_HAECC3 = const(0xA6) # Histogram-based AEC/AGC ctrl 3 266 | _OV7670_REG_HAECC4 = const(0xA7) # Histogram-based AEC/AGC ctrl 4 267 | _OV7670_REG_HAECC5 = const(0xA8) # Histogram-based AEC/AGC ctrl 5 268 | _OV7670_REG_HAECC6 = const(0xA9) # Histogram-based AEC/AGC ctrl 6 269 | _OV7670_REG_HAECC7 = const(0xAA) # Histogram-based AEC/AGC ctrl 7 270 | _OV7670_REG_BD60MAX = const(0xAB) # 60 Hz banding step limit 271 | _OV7670_REG_ABLC1 = const(0xB1) # ABLC enable 272 | _OV7670_REG_THL_ST = const(0xB3) # ABLC target 273 | _OV7670_REG_SATCTR = const(0xC9) # Saturation control 274 | 275 | _OV7670_REG_LAST = const(_OV7670_REG_SATCTR) # Maximum register address 276 | 277 | # Manual output format, RGB, use RGB565 and full 0-255 output range 278 | _OV7670_rgb = bytes( 279 | [ 280 | _OV7670_REG_COM7, 281 | _OV7670_COM7_RGB, 282 | _OV7670_REG_RGB444, 283 | 0, 284 | _OV7670_REG_COM15, 285 | _OV7670_COM15_RGB565 | _OV7670_COM15_R00FF, 286 | ] 287 | ) 288 | 289 | # Manual output format, YUV, use full output range 290 | _OV7670_yuv = bytes( 291 | [ 292 | _OV7670_REG_COM7, 293 | _OV7670_COM7_YUV, 294 | _OV7670_REG_COM15, 295 | _OV7670_COM15_R00FF, 296 | ] 297 | ) 298 | 299 | _OV7670_init = bytes( 300 | [ 301 | _OV7670_REG_TSLB, 302 | _OV7670_TSLB_YLAST, # No auto window 303 | _OV7670_REG_COM10, 304 | _OV7670_COM10_VS_NEG, # -VSYNC (req by SAMD PCC) 305 | _OV7670_REG_SLOP, 306 | 0x20, 307 | _OV7670_REG_GAM_BASE, 308 | 0x1C, 309 | _OV7670_REG_GAM_BASE + 1, 310 | 0x28, 311 | _OV7670_REG_GAM_BASE + 2, 312 | 0x3C, 313 | _OV7670_REG_GAM_BASE + 3, 314 | 0x55, 315 | _OV7670_REG_GAM_BASE + 4, 316 | 0x68, 317 | _OV7670_REG_GAM_BASE + 5, 318 | 0x76, 319 | _OV7670_REG_GAM_BASE + 6, 320 | 0x80, 321 | _OV7670_REG_GAM_BASE + 7, 322 | 0x88, 323 | _OV7670_REG_GAM_BASE + 8, 324 | 0x8F, 325 | _OV7670_REG_GAM_BASE + 9, 326 | 0x96, 327 | _OV7670_REG_GAM_BASE + 10, 328 | 0xA3, 329 | _OV7670_REG_GAM_BASE + 11, 330 | 0xAF, 331 | _OV7670_REG_GAM_BASE + 12, 332 | 0xC4, 333 | _OV7670_REG_GAM_BASE + 13, 334 | 0xD7, 335 | _OV7670_REG_GAM_BASE + 14, 336 | 0xE8, 337 | _OV7670_REG_COM8, 338 | _OV7670_COM8_FASTAEC | _OV7670_COM8_AECSTEP | _OV7670_COM8_BANDING, 339 | _OV7670_REG_GAIN, 340 | 0x00, 341 | _OV7670_COM2_SSLEEP, 342 | 0x00, 343 | _OV7670_REG_COM4, 344 | 0x00, 345 | _OV7670_REG_COM9, 346 | 0x20, # Max AGC value 347 | _OV7670_REG_BD50MAX, 348 | 0x05, 349 | _OV7670_REG_BD60MAX, 350 | 0x07, 351 | _OV7670_REG_AEW, 352 | 0x75, 353 | _OV7670_REG_AEB, 354 | 0x63, 355 | _OV7670_REG_VPT, 356 | 0xA5, 357 | _OV7670_REG_HAECC1, 358 | 0x78, 359 | _OV7670_REG_HAECC2, 360 | 0x68, 361 | 0xA1, 362 | 0x03, # Reserved register? 363 | _OV7670_REG_HAECC3, 364 | 0xDF, # Histogram-based AEC/AGC setup 365 | _OV7670_REG_HAECC4, 366 | 0xDF, 367 | _OV7670_REG_HAECC5, 368 | 0xF0, 369 | _OV7670_REG_HAECC6, 370 | 0x90, 371 | _OV7670_REG_HAECC7, 372 | 0x94, 373 | _OV7670_REG_COM8, 374 | _OV7670_COM8_FASTAEC 375 | | _OV7670_COM8_AECSTEP 376 | | _OV7670_COM8_BANDING 377 | | _OV7670_COM8_AGC 378 | | _OV7670_COM8_AEC, 379 | _OV7670_REG_COM5, 380 | 0x61, 381 | _OV7670_REG_COM6, 382 | 0x4B, 383 | 0x16, 384 | 0x02, # Reserved register? 385 | _OV7670_REG_MVFP, 386 | 0x07, # 0x07, 387 | _OV7670_REG_ADCCTR1, 388 | 0x02, 389 | _OV7670_REG_ADCCTR2, 390 | 0x91, 391 | 0x29, 392 | 0x07, # Reserved register? 393 | _OV7670_REG_CHLF, 394 | 0x0B, 395 | 0x35, 396 | 0x0B, # Reserved register? 397 | _OV7670_REG_ADC, 398 | 0x1D, 399 | _OV7670_REG_ACOM, 400 | 0x71, 401 | _OV7670_REG_OFON, 402 | 0x2A, 403 | _OV7670_REG_COM12, 404 | 0x78, 405 | 0x4D, 406 | 0x40, # Reserved register? 407 | 0x4E, 408 | 0x20, # Reserved register? 409 | _OV7670_REG_GFIX, 410 | 0x5D, 411 | _OV7670_REG_REG74, 412 | 0x19, 413 | 0x8D, 414 | 0x4F, # Reserved register? 415 | 0x8E, 416 | 0x00, # Reserved register? 417 | 0x8F, 418 | 0x00, # Reserved register? 419 | 0x90, 420 | 0x00, # Reserved register? 421 | 0x91, 422 | 0x00, # Reserved register? 423 | _OV7670_REG_DM_LNL, 424 | 0x00, 425 | 0x96, 426 | 0x00, # Reserved register? 427 | 0x9A, 428 | 0x80, # Reserved register? 429 | 0xB0, 430 | 0x84, # Reserved register? 431 | _OV7670_REG_ABLC1, 432 | 0x0C, 433 | 0xB2, 434 | 0x0E, # Reserved register? 435 | _OV7670_REG_THL_ST, 436 | 0x82, 437 | 0xB8, 438 | 0x0A, # Reserved register? 439 | _OV7670_REG_AWBC1, 440 | 0x14, 441 | _OV7670_REG_AWBC2, 442 | 0xF0, 443 | _OV7670_REG_AWBC3, 444 | 0x34, 445 | _OV7670_REG_AWBC4, 446 | 0x58, 447 | _OV7670_REG_AWBC5, 448 | 0x28, 449 | _OV7670_REG_AWBC6, 450 | 0x3A, 451 | 0x59, 452 | 0x88, # Reserved register? 453 | 0x5A, 454 | 0x88, # Reserved register? 455 | 0x5B, 456 | 0x44, # Reserved register? 457 | 0x5C, 458 | 0x67, # Reserved register? 459 | 0x5D, 460 | 0x49, # Reserved register? 461 | 0x5E, 462 | 0x0E, # Reserved register? 463 | _OV7670_REG_LCC3, 464 | 0x04, 465 | _OV7670_REG_LCC4, 466 | 0x20, 467 | _OV7670_REG_LCC5, 468 | 0x05, 469 | _OV7670_REG_LCC6, 470 | 0x04, 471 | _OV7670_REG_LCC7, 472 | 0x08, 473 | _OV7670_REG_AWBCTR3, 474 | 0x0A, 475 | _OV7670_REG_AWBCTR2, 476 | 0x55, 477 | _OV7670_REG_MTX1, 478 | 0x80, 479 | _OV7670_REG_MTX2, 480 | 0x80, 481 | _OV7670_REG_MTX3, 482 | 0x00, 483 | _OV7670_REG_MTX4, 484 | 0x22, 485 | _OV7670_REG_MTX5, 486 | 0x5E, 487 | _OV7670_REG_MTX6, 488 | 0x80, # 0x40? 489 | _OV7670_REG_AWBCTR1, 490 | 0x11, 491 | _OV7670_REG_AWBCTR0, 492 | 0x9F, # Or use 0x9E for advance AWB 493 | _OV7670_REG_BRIGHT, 494 | 0x00, 495 | _OV7670_REG_CONTRAS, 496 | 0x40, 497 | _OV7670_REG_CONTRAS_CENTER, 498 | 0x80, # 0x40? 499 | ] 500 | ) 501 | 502 | _window = [ 503 | [9, 162, 2, 2], # SIZE_DIV1 640x480 VGA 504 | [10, 174, 0, 2], # SIZE_DIV2 320x240 QVGA 505 | [11, 186, 2, 2], # SIZE_DIV4 160x120 QQVGA 506 | [12, 210, 0, 2], # SIZE_DIV8 80x60 ... 507 | [15, 252, 3, 2], # SIZE_DIV16 40x30 508 | ] 509 | 510 | 511 | class OV7670: 512 | """Library for the OV7670 digital camera""" 513 | 514 | def __init__( 515 | self, 516 | i2c_bus: I2C, 517 | data_pins: List[Pin], 518 | clock: Pin, 519 | vsync: Pin, 520 | href: Pin, 521 | shutdown: Optional[Pin] = None, 522 | reset: Optional[Pin] = None, 523 | mclk: Optional[Pin] = None, 524 | mclk_frequency: int = 16_000_000, 525 | i2c_address: int = 0x21, 526 | ) -> None: 527 | """ 528 | Args: 529 | i2c_bus (busio.I2C): The I2C bus used to configure the OV7670 530 | data_pins (List[microcontroller.Pin]): A list of 8 data pins, in order. 531 | clock (microcontroller.Pin): The pixel clock from the OV7670. 532 | vsync (microcontroller.Pin): The vsync signal from the OV7670. 533 | href (microcontroller.Pin): The href signal from the OV7670, \ 534 | sometimes inaccurately called hsync. 535 | shutdown (Optional[microcontroller.Pin]): If not None, the shutdown 536 | signal to the camera, also called the powerdown or enable pin. 537 | reset (Optional[microcontroller.Pin]): If not None, the reset signal 538 | to the camera. 539 | mclk (Optional[microcontroller.Pin]): The pin on which to create a 540 | master clock signal, or None if the master clock signal is 541 | already being generated. 542 | mclk_frequency (int): The frequency of the master clock to generate, \ 543 | ignored if mclk is None, requred if it is specified 544 | i2c_address (int): The I2C address of the camera. 545 | """ 546 | # Initialize the master clock 547 | if mclk: 548 | self._mclk_pwm = pwmio.PWMOut(mclk, frequency=mclk_frequency) 549 | self._mclk_pwm.duty_cycle = 32768 550 | else: 551 | self._mclk_pwm = None 552 | 553 | if shutdown: 554 | self._shutdown = digitalio.DigitalInOut(shutdown) 555 | self._shutdown.switch_to_output(True) 556 | time.sleep(0.001) 557 | self._shutdown.switch_to_output(False) 558 | time.sleep(0.3) 559 | else: 560 | self._shutdown = None 561 | 562 | if reset: 563 | self._reset = digitalio.DigitalInOut(reset) 564 | self._reset.switch_to_output(False) 565 | time.sleep(0.001) 566 | self._reset.switch_to_output(True) 567 | 568 | self._i2c_device = I2CDevice(i2c_bus, i2c_address) 569 | 570 | if not reset: 571 | self._write_register(_OV7670_REG_COM7, _OV7670_COM7_RESET) 572 | 573 | time.sleep(0.001) 574 | 575 | self._colorspace = None 576 | self.colorspace = OV7670_COLOR_RGB 577 | 578 | self._write_list(_OV7670_init) 579 | 580 | self._size = None 581 | self.size = OV7670_SIZE_DIV8 582 | 583 | self._test_pattern = None 584 | self.test_pattern = OV7670_TEST_PATTERN_NONE 585 | 586 | self._flip_x = False 587 | self._flip_y = False 588 | 589 | self._night = OV7670_NIGHT_MODE_OFF 590 | 591 | self._imagecapture = imagecapture.ParallelImageCapture( 592 | data_pins=data_pins, clock=clock, vsync=vsync, href=href 593 | ) 594 | 595 | def capture(self, buf: WriteableBuffer) -> None: 596 | """Capture an image into the buffer. 597 | 598 | Args: 599 | buf (Union[bytearray, memoryview]): A WritableBuffer to contain the \ 600 | captured image. Note that this can be a ulab array or a displayio Bitmap. 601 | """ 602 | self._imagecapture.capture(buf) 603 | 604 | @property 605 | def mclk_frequency(self) -> Optional[int]: 606 | """Get the actual frequency the generated mclk, or None""" 607 | return self._mclk_pwm.frequency if self._mclk_pwm else None 608 | 609 | @property 610 | def width(self): 611 | """Get the image width in pixels. A buffer of 2*width*height bytes \ 612 | stores a whole image.""" 613 | return 640 >> self._size 614 | 615 | @property 616 | def height(self): 617 | """Get the image height in pixels. A buffer of 2*width*height bytes \ 618 | stores a whole image.""" 619 | return 480 >> self._size 620 | 621 | @property 622 | def colorspace(self) -> int: 623 | """Get or set the colorspace, one of the ``OV7670_COLOR_`` constants.""" 624 | return self._colorspace 625 | 626 | @colorspace.setter 627 | def colorspace(self, colorspace: int) -> None: 628 | self._colorspace = colorspace 629 | self._write_list(_OV7670_rgb if colorspace == OV7670_COLOR_RGB else _OV7670_yuv) 630 | 631 | def deinit(self) -> None: 632 | """Deinitialize the camera""" 633 | self._imagecapture.deinit() 634 | if self._mclk_pwm: 635 | self._mclk_pwm.deinit() 636 | if self._shutdown: 637 | self._shutdown.deinit() 638 | if self._reset: 639 | self._reset.deinit() 640 | 641 | @property 642 | def size(self) -> int: 643 | """Get or set the captured image size, one of the ``OV7670_SIZE_`` constants.""" 644 | return self._size 645 | 646 | @size.setter 647 | def size(self, size): 648 | self._frame_control(size, *_window[size]) 649 | self._size = size 650 | 651 | @property 652 | def test_pattern(self): 653 | """Get or set the test pattern, one of the ``OV7670_TEST_PATTERN_`` constants.""" 654 | return self._test_pattern 655 | 656 | @test_pattern.setter 657 | def test_pattern(self, pattern: int) -> None: 658 | # Modify only test pattern bits (not scaling bits) 659 | xsc = self._read_register(_OV7670_REG_SCALING_XSC) & ~0x80 660 | ysc = self._read_register(_OV7670_REG_SCALING_YSC) & ~0x80 661 | if pattern & 1: 662 | xsc |= 0x80 663 | if pattern & 2: 664 | ysc |= 0x80 665 | # Write modified result back to SCALING_XSC and SCALING_YSC 666 | self._write_register(_OV7670_REG_SCALING_XSC, xsc) 667 | self._write_register(_OV7670_REG_SCALING_YSC, ysc) 668 | 669 | def _set_flip(self) -> None: 670 | mvfp = self._read_register(_OV7670_REG_MVFP) 671 | if self._flip_x: 672 | mvfp |= _OV7670_MVFP_MIRROR 673 | else: 674 | mvfp &= ~_OV7670_MVFP_MIRROR 675 | if self._flip_y: 676 | mvfp |= _OV7670_MVFP_VFLIP 677 | else: 678 | mvfp &= ~_OV7670_MVFP_VFLIP 679 | self._write_register(_OV7670_REG_MVFP, mvfp) 680 | 681 | @property 682 | def flip_x(self) -> bool: 683 | """Get or set the X-flip flag""" 684 | return self._flip_x 685 | 686 | @flip_x.setter 687 | def flip_x(self, value: bool) -> None: 688 | self._flip_x = bool(value) 689 | self._set_flip() 690 | 691 | @property 692 | def flip_y(self) -> bool: 693 | """Get or set the Y-flip flag""" 694 | return self._flip_y 695 | 696 | @flip_y.setter 697 | def flip_y(self, value: bool) -> None: 698 | self._flip_y = bool(value) 699 | self._set_flip() 700 | 701 | @property 702 | def night(self) -> int: 703 | """Get or set the night-vision mode, one of the ``OV7670_NIGHT_MODE_`` constants.""" 704 | return self._night 705 | 706 | @night.setter 707 | def night(self, value: int) -> None: 708 | com11 = self._read_register(_OV7670_REG_COM11) 709 | com11 = (com11 & 0b00011111) | value 710 | self._write_register(_OV7670_REG_COM11, com11) 711 | self._night = value 712 | 713 | @property 714 | def product_id(self) -> int: 715 | """Get the product id (PID) register. The expected value is 0x76.""" 716 | return self._read_register(_OV7670_REG_PID) 717 | 718 | @property 719 | def product_version(self) -> int: 720 | """Get the version (VER) register. The expected value is 0x73.""" 721 | return self._read_register(_OV7670_REG_VER) 722 | 723 | def _write_list(self, reg_list: bytes) -> None: 724 | for i in range(0, len(reg_list), 2): 725 | self._write_register(reg_list[i], reg_list[i + 1]) 726 | time.sleep(0.001) 727 | 728 | def _write_register(self, reg: int, value: int) -> None: 729 | b = bytearray(2) 730 | b[0] = reg 731 | b[1] = value 732 | with self._i2c_device as i2c: 733 | i2c.write(b) 734 | 735 | def _read_register(self, reg: int) -> int: 736 | b = bytearray(1) 737 | b[0] = reg 738 | with self._i2c_device as i2c: 739 | i2c.write(b) 740 | i2c.readinto(b) 741 | return b[0] 742 | 743 | def _frame_control( 744 | self, size: int, vstart: int, hstart: int, edge_offset: int, pclk_delay: int 745 | ) -> None: 746 | # Enable downsampling if sub-VGA, and zoom if 1:16 scale 747 | value = _OV7670_COM3_DCWEN if (size > OV7670_SIZE_DIV1) else 0 748 | if size == OV7670_SIZE_DIV16: 749 | value |= _OV7670_COM3_SCALEEN 750 | self._write_register(_OV7670_REG_COM3, value) 751 | 752 | # Enable PCLK division if sub-VGA 2,4,8,16 = 0x19,1A,1B,1C 753 | value = (0x18 + size) if (size > OV7670_SIZE_DIV1) else 0 754 | self._write_register(_OV7670_REG_COM14, value) 755 | 756 | # Horiz/vert downsample ratio, 1:8 max (H,V are always equal for now) 757 | value = size if (size <= OV7670_SIZE_DIV8) else OV7670_SIZE_DIV8 758 | self._write_register(_OV7670_REG_SCALING_DCWCTR, value * 0x11) 759 | 760 | # Pixel clock divider if sub-VGA 761 | value = (0xF0 + size) if (size > OV7670_SIZE_DIV1) else 0x08 762 | self._write_register(_OV7670_REG_SCALING_PCLK_DIV, value) 763 | 764 | # Apply 0.5 digital zoom at 1:16 size (others are downsample only) 765 | value = 0x40 if (size == OV7670_SIZE_DIV16) else 0x20 # 0.5, 1.0 766 | 767 | # Read current SCALING_XSC and SCALING_YSC register values because 768 | # test pattern settings are also stored in those registers and we 769 | # don't want to corrupt anything there. 770 | xsc = self._read_register(_OV7670_REG_SCALING_XSC) 771 | ysc = self._read_register(_OV7670_REG_SCALING_YSC) 772 | xsc = (xsc & 0x80) | value # Modify only scaling bits (not test pattern) 773 | ysc = (ysc & 0x80) | value 774 | # Write modified result back to SCALING_XSC and SCALING_YSC 775 | self._write_register(_OV7670_REG_SCALING_XSC, xsc) 776 | self._write_register(_OV7670_REG_SCALING_YSC, ysc) 777 | 778 | # Window size is scattered across multiple registers. 779 | # Horiz/vert stops can be automatically calc'd from starts. 780 | vstop = vstart + 480 781 | hstop = (hstart + 640) % 784 782 | self._write_register(_OV7670_REG_HSTART, hstart >> 3) 783 | self._write_register(_OV7670_REG_HSTOP, hstop >> 3) 784 | self._write_register( 785 | _OV7670_REG_HREF, 786 | (edge_offset << 6) | ((hstop & 0b111) << 3) | (hstart & 0b111), 787 | ) 788 | self._write_register(_OV7670_REG_VSTART, vstart >> 2) 789 | self._write_register(_OV7670_REG_VSTOP, vstop >> 2) 790 | self._write_register(_OV7670_REG_VREF, ((vstop & 0b11) << 2) | (vstart & 0b11)) 791 | 792 | self._write_register(_OV7670_REG_SCALING_PCLK_DELAY, pclk_delay) 793 | -------------------------------------------------------------------------------- /docs/_static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_OV7670/3f60d0ec0249fa5a6accb553edb3da1a26a4b66d/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_ov7670 11 | :members: 12 | -------------------------------------------------------------------------------- /docs/api.rst.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | SPDX-FileCopyrightText: Copyright (c) 2021 Jeff Epler for Adafruit Industries 3 | 4 | SPDX-License-Identifier: MIT 5 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written 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 | # Uncomment the below if you use native CircuitPython modules such as 25 | # digitalio, micropython and busio. List the modules you use. Without it, the 26 | # autodoc module docs will fail to generate with a warning. 27 | autodoc_mock_imports = ["digitalio", "imagecapture", "pwmio"] 28 | 29 | 30 | intersphinx_mapping = { 31 | "python": ("https://docs.python.org/3", None), 32 | "BusDevice": ( 33 | "https://docs.circuitpython.org/projects/busdevice/en/latest/", 34 | None, 35 | ), 36 | "CircuitPython": ("https://docs.circuitpython.org/en/latest/", None), 37 | } 38 | 39 | # Show the docstring from both the class and its __init__() method. 40 | autoclass_content = "both" 41 | 42 | # Add any paths that contain templates here, relative to this directory. 43 | templates_path = ["_templates"] 44 | 45 | source_suffix = ".rst" 46 | 47 | # The master toctree document. 48 | master_doc = "index" 49 | 50 | # General information about the project. 51 | project = "Adafruit CircuitPython ov7670 Library" 52 | creation_year = "2021" 53 | current_year = str(datetime.datetime.now().year) 54 | year_duration = ( 55 | current_year if current_year == creation_year else creation_year + " - " + current_year 56 | ) 57 | copyright = year_duration + " Jeff Epler" 58 | author = "Jeff Epler" 59 | 60 | # The version info for the project you're documenting, acts as replacement for 61 | # |version| and |release|, also used in various other places throughout the 62 | # built documents. 63 | # 64 | # The short X.Y version. 65 | version = "1.0" 66 | # The full version, including alpha/beta/rc tags. 67 | release = "1.0" 68 | 69 | # The language for content autogenerated by Sphinx. Refer to documentation 70 | # for a list of supported languages. 71 | # 72 | # This is also used if you do content translation via gettext catalogs. 73 | # Usually you set "language" from the command line for these cases. 74 | language = "en" 75 | 76 | # List of patterns, relative to source directory, that match files and 77 | # directories to ignore when looking for source files. 78 | # This patterns also effect to html_static_path and html_extra_path 79 | exclude_patterns = [ 80 | "_build", 81 | "Thumbs.db", 82 | ".DS_Store", 83 | ".env", 84 | "CODE_OF_CONDUCT.md", 85 | ] 86 | 87 | # The reST default role (used for this markup: `text`) to use for all 88 | # documents. 89 | # 90 | default_role = "any" 91 | 92 | # If true, '()' will be appended to :func: etc. cross-reference text. 93 | # 94 | add_function_parentheses = True 95 | 96 | # The name of the Pygments (syntax highlighting) style to use. 97 | pygments_style = "sphinx" 98 | 99 | # If true, `todo` and `todoList` produce output, else they produce nothing. 100 | todo_include_todos = False 101 | 102 | # If this is True, todo emits a warning for each TODO entries. The default is False. 103 | todo_emit_warnings = True 104 | 105 | napoleon_numpy_docstring = False 106 | 107 | # -- Options for HTML output ---------------------------------------------- 108 | 109 | # The theme to use for HTML and HTML Help pages. See the documentation for 110 | # a list of builtin themes. 111 | # 112 | import sphinx_rtd_theme 113 | 114 | html_theme = "sphinx_rtd_theme" 115 | 116 | # Add any paths that contain custom static files (such as style sheets) here, 117 | # relative to this directory. They are copied after the builtin static files, 118 | # so a file named "default.css" will overwrite the builtin "default.css". 119 | html_static_path = ["_static"] 120 | 121 | # The name of an image file (relative to this directory) to use as a favicon of 122 | # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 123 | # pixels large. 124 | # 125 | html_favicon = "_static/favicon.ico" 126 | 127 | # Output file base name for HTML help builder. 128 | htmlhelp_basename = "Adafruit_CircuitPython_Ov7670Librarydoc" 129 | 130 | # -- Options for LaTeX output --------------------------------------------- 131 | 132 | latex_elements = { 133 | # The paper size ('letterpaper' or 'a4paper'). 134 | # 'papersize': 'letterpaper', 135 | # The font size ('10pt', '11pt' or '12pt'). 136 | # 'pointsize': '10pt', 137 | # Additional stuff for the LaTeX preamble. 138 | # 'preamble': '', 139 | # Latex figure (float) alignment 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 | "Adafruit_CircuitPython_OV7670Library.tex", 150 | "Adafruit CircuitPython ov7670 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 | "Adafruit_CircuitPython_OV7670Library", 164 | "Adafruit CircuitPython ov7670 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 | "Adafruit_CircuitPython_OV7670Library", 179 | "Adafruit CircuitPython ov7670 Library Documentation", 180 | author, 181 | "Adafruit_CircuitPython_OV7670Library", 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/ov7670_simpletest.py 7 | :caption: examples/ov7670_simpletest.py 8 | :linenos: 9 | -------------------------------------------------------------------------------- /docs/examples.rst.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | SPDX-FileCopyrightText: Copyright (c) 2021 Jeff Epler for Adafruit Industries 3 | 4 | SPDX-License-Identifier: MIT 5 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | 2 | .. include:: ../README.rst 3 | 4 | Table of Contents 5 | ================= 6 | 7 | .. toctree:: 8 | :maxdepth: 4 9 | :hidden: 10 | 11 | self 12 | 13 | .. toctree:: 14 | :caption: Examples 15 | 16 | examples 17 | 18 | .. toctree:: 19 | :caption: API Reference 20 | :maxdepth: 3 21 | 22 | api 23 | 24 | .. toctree:: 25 | :caption: Tutorials 26 | 27 | .. toctree:: 28 | :caption: Related Products 29 | 30 | Adafruit Metro M4 Grand Central 31 | 32 | .. toctree:: 33 | :caption: Other Links 34 | 35 | Download from GitHub 36 | Download Library Bundle 37 | CircuitPython Reference Documentation 38 | CircuitPython Support Forum 39 | Discord Chat 40 | Adafruit Learning System 41 | Adafruit Blog 42 | Adafruit Store 43 | 44 | Indices and tables 45 | ================== 46 | 47 | * :ref:`genindex` 48 | * :ref:`modindex` 49 | * :ref:`search` 50 | -------------------------------------------------------------------------------- /docs/index.rst.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | SPDX-FileCopyrightText: Copyright (c) 2021 Jeff Epler for Adafruit Industries 3 | 4 | SPDX-License-Identifier: MIT 5 | -------------------------------------------------------------------------------- /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/ov7670_displayio_gcm4_tftshield18.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # SPDX-FileCopyrightText: Copyright (c) 2021 Jeff Epler for Adafruit Industries 3 | # 4 | # SPDX-License-Identifier: Unlicense 5 | 6 | import time 7 | 8 | import board 9 | import busio 10 | import digitalio 11 | import displayio 12 | import fourwire 13 | from adafruit_seesaw.tftshield18 import TFTShield18 14 | from adafruit_st7735r import ST7735R 15 | 16 | from adafruit_ov7670 import ( 17 | OV7670, 18 | OV7670_NIGHT_MODE_2, 19 | OV7670_SIZE_DIV4, 20 | OV7670_SIZE_DIV8, 21 | OV7670_TEST_PATTERN_COLOR_BAR, 22 | ) 23 | 24 | # Pylint is unable to see that the "size" property of OV7670_GrandCentral exists 25 | 26 | # Release any resources currently in use for the displays 27 | displayio.release_displays() 28 | 29 | ss = TFTShield18() 30 | 31 | spi = board.SPI() 32 | tft_cs = board.D10 33 | tft_dc = board.D8 34 | 35 | display_bus = fourwire.FourWire(spi, command=tft_dc, chip_select=tft_cs) 36 | 37 | ss.tft_reset() 38 | display = ST7735R(display_bus, width=160, height=128, rotation=90, bgr=True, auto_refresh=False) 39 | 40 | ss.set_backlight(True) 41 | 42 | 43 | class OV7670_GrandCentral(OV7670): 44 | def __init__(self): 45 | with digitalio.DigitalInOut(board.D39) as shutdown: 46 | shutdown.switch_to_output(True) 47 | time.sleep(0.001) 48 | bus = busio.I2C(board.D24, board.D25) 49 | self._bus = bus 50 | OV7670.__init__( 51 | self, 52 | bus, 53 | mclk=board.PCC_XCLK, 54 | data_pins=[ 55 | board.PCC_D0, 56 | board.PCC_D1, 57 | board.PCC_D2, 58 | board.PCC_D3, 59 | board.PCC_D4, 60 | board.PCC_D5, 61 | board.PCC_D6, 62 | board.PCC_D7, 63 | ], 64 | clock=board.PCC_CLK, 65 | vsync=board.PCC_DEN1, 66 | href=board.PCC_DEN2, 67 | shutdown=board.D39, 68 | reset=board.D38, 69 | ) 70 | 71 | def deinit(self): 72 | self._bus.deinit() 73 | OV7670.deinit(self) 74 | 75 | 76 | cam = OV7670_GrandCentral() 77 | 78 | cam.size = OV7670_SIZE_DIV4 79 | cam.flip_x = False 80 | cam.flip_y = True 81 | pid = cam.product_id 82 | ver = cam.product_version 83 | print(f"Detected pid={pid:x} ver={ver:x}") 84 | # cam.test_pattern = OV7670_TEST_PATTERN_COLOR_BAR 85 | 86 | g = displayio.Group(scale=1) 87 | bitmap = displayio.Bitmap(160, 120, 65536) 88 | tg = displayio.TileGrid( 89 | bitmap, 90 | pixel_shader=displayio.ColorConverter(input_colorspace=displayio.Colorspace.RGB565_SWAPPED), 91 | ) 92 | g.append(tg) 93 | display.root_group = g 94 | 95 | t0 = time.monotonic_ns() 96 | display.auto_refresh = False 97 | while True: 98 | cam.capture(bitmap) 99 | bitmap.dirty() 100 | display.refresh(minimum_frames_per_second=0) 101 | t1 = time.monotonic_ns() 102 | print("fps", 1e9 / (t1 - t0)) 103 | t0 = t1 104 | 105 | cam.deinit() 106 | -------------------------------------------------------------------------------- /examples/ov7670_displayio_kaluga1_3_ili9341.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # SPDX-FileCopyrightText: Copyright (c) 2021 Jeff Epler for Adafruit Industries 3 | # 4 | # SPDX-License-Identifier: Unlicense 5 | 6 | """ 7 | The Kaluga development kit comes in two versions (v1.2 and v1.3); this demo is 8 | tested on v1.3. It probably won't work on v1.2 without modification. 9 | 10 | The v1.3 development kit's LCD can have one of two chips, the ili9341 or 11 | st7789. Furthermore, there are at least 2 ILI9341 variants, one of which needs 12 | rotation=90! This demo is for the ili9341. If the display is garbled, try adding 13 | rotation=90, or try modifying it to use ST7799. 14 | 15 | The camera included with the Kaluga development kit is the incompatible OV2640, 16 | it won't work. 17 | 18 | The audio board must be mounted between the Kaluga and the LCD, it provides the 19 | I2C pull-ups(!) 20 | """ 21 | 22 | import time 23 | 24 | import board 25 | import busio 26 | import displayio 27 | import fourwire 28 | from adafruit_ili9341 import ILI9341 29 | 30 | from adafruit_ov7670 import ( 31 | OV7670, 32 | OV7670_NIGHT_MODE_2, 33 | OV7670_SIZE_DIV2, 34 | OV7670_TEST_PATTERN_COLOR_BAR, 35 | ) 36 | 37 | # Release any resources currently in use for the displays 38 | displayio.release_displays() 39 | 40 | spi = busio.SPI(MOSI=board.LCD_MOSI, clock=board.LCD_CLK) 41 | display_bus = fourwire.FourWire( 42 | spi, command=board.LCD_D_C, chip_select=board.LCD_CS, reset=board.LCD_RST 43 | ) 44 | display = ILI9341(display_bus, width=320, height=240) 45 | 46 | bus = busio.I2C(scl=board.CAMERA_SIOC, sda=board.CAMERA_SIOD) 47 | cam = OV7670( 48 | bus, 49 | data_pins=board.CAMERA_DATA, 50 | clock=board.CAMERA_PCLK, 51 | vsync=board.CAMERA_VSYNC, 52 | href=board.CAMERA_HREF, 53 | mclk=board.CAMERA_XCLK, 54 | mclk_frequency=20_000_000, 55 | ) 56 | 57 | cam.size = OV7670_SIZE_DIV2 58 | cam.flip_x = False 59 | cam.flip_y = True 60 | pid = cam.product_id 61 | ver = cam.product_version 62 | print(f"Detected pid={pid:x} ver={ver:x}") 63 | # cam.test_pattern = OV7670_TEST_PATTERN_COLOR_BAR 64 | 65 | g = displayio.Group(scale=1) 66 | bitmap = displayio.Bitmap(320, 240, 65536) 67 | tg = displayio.TileGrid( 68 | bitmap, 69 | pixel_shader=displayio.ColorConverter(input_colorspace=displayio.Colorspace.RGB565_SWAPPED), 70 | ) 71 | g.append(tg) 72 | display.root_group = g 73 | 74 | t0 = time.monotonic_ns() 75 | display.auto_refresh = False 76 | while True: 77 | cam.capture(bitmap) 78 | bitmap.dirty() 79 | display.refresh(minimum_frames_per_second=0) 80 | t1 = time.monotonic_ns() 81 | print("fps", 1e9 / (t1 - t0)) 82 | t0 = t1 83 | 84 | cam.deinit() 85 | -------------------------------------------------------------------------------- /examples/ov7670_displayio_pico_st7789_2in.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # SPDX-FileCopyrightText: Copyright (c) 2021 Jeff Epler for Adafruit Industries 3 | # 4 | # SPDX-License-Identifier: Unlicense 5 | 6 | """ 7 | Capture an image from the camera and display it on a supported LCD. 8 | """ 9 | 10 | import time 11 | 12 | import board 13 | import busio 14 | import digitalio 15 | from adafruit_st7789 import ST7789 16 | from displayio import ( 17 | Bitmap, 18 | ColorConverter, 19 | Colorspace, 20 | FourWire, 21 | Group, 22 | TileGrid, 23 | release_displays, 24 | ) 25 | 26 | from adafruit_ov7670 import ( 27 | OV7670, 28 | OV7670_SIZE_DIV1, 29 | OV7670_SIZE_DIV16, 30 | ) 31 | 32 | # Set up the display (You must customize this block for your display!) 33 | release_displays() 34 | spi = busio.SPI(clock=board.GP2, MOSI=board.GP3) 35 | display_bus = FourWire(spi, command=board.GP0, chip_select=board.GP1, reset=None) 36 | display = ST7789(display_bus, width=320, height=240, rotation=270) 37 | 38 | 39 | # Ensure the camera is shut down, so that it releases the SDA/SCL lines, 40 | # then create the configuration I2C bus 41 | 42 | with digitalio.DigitalInOut(board.GP10) as reset: 43 | reset.switch_to_output(False) 44 | time.sleep(0.001) 45 | bus = busio.I2C(board.GP9, board.GP8) 46 | 47 | # Set up the camera (you must customize this for your board!) 48 | cam = OV7670( 49 | bus, 50 | data_pins=[ 51 | board.GP12, 52 | board.GP13, 53 | board.GP14, 54 | board.GP15, 55 | board.GP16, 56 | board.GP17, 57 | board.GP18, 58 | board.GP19, 59 | ], # [16] [org] etc 60 | clock=board.GP11, # [15] [blk] 61 | vsync=board.GP7, # [10] [brn] 62 | href=board.GP21, # [27/o14] [red] 63 | mclk=board.GP20, # [16/o15] 64 | shutdown=None, 65 | reset=board.GP10, 66 | ) # [14] 67 | 68 | width = display.width 69 | height = display.height 70 | 71 | # cam.test_pattern = OV7670_TEST_PATTERN_COLOR_BAR 72 | 73 | bitmap = None 74 | # Select the biggest size for which we can allocate a bitmap successfully, and 75 | # which is not bigger than the display 76 | for size in range(OV7670_SIZE_DIV1, OV7670_SIZE_DIV16 + 1): 77 | cam.size = size 78 | if cam.width > width: 79 | continue 80 | if cam.height > height: 81 | continue 82 | try: 83 | bitmap = Bitmap(cam.width, cam.height, 65536) 84 | break 85 | except MemoryError: 86 | continue 87 | 88 | print(width, height, cam.width, cam.height) 89 | if bitmap is None: 90 | raise SystemExit("Could not allocate a bitmap") 91 | 92 | g = Group(scale=1, x=(width - cam.width) // 2, y=(height - cam.height) // 2) 93 | tg = TileGrid(bitmap, pixel_shader=ColorConverter(input_colorspace=Colorspace.RGB565_SWAPPED)) 94 | g.append(tg) 95 | display.root_group = g 96 | 97 | t0 = time.monotonic_ns() 98 | display.auto_refresh = False 99 | while True: 100 | cam.capture(bitmap) 101 | bitmap.dirty() 102 | display.refresh(minimum_frames_per_second=0) 103 | t1 = time.monotonic_ns() 104 | print("fps", 1e9 / (t1 - t0)) 105 | t0 = t1 106 | -------------------------------------------------------------------------------- /examples/ov7670_simpletest.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # SPDX-FileCopyrightText: Copyright (c) 2021 Jeff Epler for Adafruit Industries 3 | # 4 | # SPDX-License-Identifier: Unlicense 5 | 6 | """Capture an image from the camera and display it as ASCII art. 7 | 8 | The camera is placed in YUV mode, so the top 8 bits of each color 9 | value can be treated as "greyscale". 10 | 11 | It's important that you use a terminal program that can interpret 12 | "ANSI" escape sequences. The demo uses them to "paint" each frame 13 | on top of the prevous one, rather than scrolling. 14 | 15 | Remember to take the lens cap off, or un-comment the line setting 16 | the test pattern! 17 | """ 18 | 19 | import sys 20 | import time 21 | 22 | import board 23 | import busio 24 | import digitalio 25 | 26 | from adafruit_ov7670 import ( 27 | OV7670, 28 | OV7670_COLOR_YUV, 29 | OV7670_SIZE_DIV16, 30 | OV7670_TEST_PATTERN_COLOR_BAR_FADE, 31 | ) 32 | 33 | # Ensure the camera is shut down, so that it releases the SDA/SCL lines, 34 | # then create the configuration I2C bus 35 | 36 | with digitalio.DigitalInOut(board.D39) as shutdown: 37 | shutdown.switch_to_output(True) 38 | time.sleep(0.001) 39 | bus = busio.I2C(board.D24, board.D25) 40 | 41 | cam = OV7670( 42 | bus, 43 | data0=board.PCC_D0, 44 | clock=board.PCC_CLK, 45 | vsync=board.PCC_DEN1, 46 | href=board.PCC_DEN2, 47 | mclk=board.D29, 48 | shutdown=board.D39, 49 | reset=board.D38, 50 | ) 51 | cam.size = OV7670_SIZE_DIV16 52 | cam.colorspace = OV7670_COLOR_YUV 53 | cam.flip_y = True 54 | # cam.test_pattern = OV7670_TEST_PATTERN_COLOR_BAR_FADE 55 | 56 | buf = bytearray(2 * cam.width * cam.height) 57 | chars = b" .:-=+*#%@" 58 | 59 | width = cam.width 60 | row = bytearray(2 * width) 61 | 62 | sys.stdout.write("\033[2J") 63 | while True: 64 | cam.capture(buf) 65 | for j in range(cam.height): 66 | sys.stdout.write(f"\033[{j}H") 67 | for i in range(cam.width): 68 | row[i * 2] = row[i * 2 + 1] = chars[buf[2 * (width * j + i)] * (len(chars) - 1) // 255] 69 | sys.stdout.write(row) 70 | sys.stdout.write("\033[K") 71 | sys.stdout.write("\033[J") 72 | time.sleep(0.05) 73 | -------------------------------------------------------------------------------- /optional_requirements.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Alec Delaney for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | [build-system] 6 | requires = [ 7 | "setuptools", 8 | "wheel", 9 | "setuptools-scm", 10 | ] 11 | 12 | [project] 13 | name = "adafruit-circuitpython-ov7670" 14 | description = "CircuitPython driver for OV7670 cameras" 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_OV7670"} 21 | keywords = [ 22 | "adafruit", 23 | "ov7670", 24 | "camera", 25 | "breakout", 26 | "hardware", 27 | "micropythoncircuitpython", 28 | ] 29 | license = {text = "MIT"} 30 | classifiers = [ 31 | "Intended Audience :: Developers", 32 | "Topic :: Software Development :: Libraries", 33 | "Topic :: Software Development :: Embedded Systems", 34 | "Topic :: System :: Hardware", 35 | "License :: OSI Approved :: MIT License", 36 | "Programming Language :: Python :: 3", 37 | ] 38 | dynamic = ["dependencies", "optional-dependencies"] 39 | 40 | [tool.setuptools] 41 | py-modules = ["adafruit_ov7670"] 42 | 43 | [tool.setuptools.dynamic] 44 | dependencies = {file = ["requirements.txt"]} 45 | optional-dependencies = {optional = {file = ["optional_requirements.txt"]}} 46 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | Adafruit-Blinka 6 | adafruit-circuitpython-busdevice 7 | -------------------------------------------------------------------------------- /ruff.toml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | target-version = "py38" 6 | line-length = 100 7 | 8 | [lint] 9 | 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 | "PLR6301", # could-be-static no-self-use 103 | "PLC0415", # import outside toplevel 104 | ] 105 | 106 | [format] 107 | line-ending = "lf" 108 | --------------------------------------------------------------------------------