├── .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_rfm69.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 ├── rfm69_header.py ├── rfm69_node1.py ├── rfm69_node1_ack.py ├── rfm69_node1_bonnet.py ├── rfm69_node2.py ├── rfm69_node2_ack.py ├── rfm69_rpi_interrupt.py ├── rfm69_rpi_simpletest.py ├── rfm69_simpletest.py └── rfm69_transmit.py ├── optional_requirements.txt ├── pyproject.toml ├── requirements.txt └── ruff.toml /.gitattributes: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | .py text eol=lf 6 | .rst text eol=lf 7 | .txt text eol=lf 8 | .yaml text eol=lf 9 | .toml text eol=lf 10 | .license text eol=lf 11 | .md text eol=lf 12 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | Thank you for contributing! Before you submit a pull request, please read the following. 6 | 7 | Make sure any changes you're submitting are in line with the CircuitPython Design Guide, available here: https://docs.circuitpython.org/en/latest/docs/design_guide.html 8 | 9 | If your changes are to documentation, please verify that the documentation builds locally by following the steps found here: https://adafru.it/build-docs 10 | 11 | Before submitting the pull request, make sure you've run Pylint and Black locally on your code. You can do this manually or using pre-commit. Instructions are available here: https://adafru.it/check-your-code 12 | 13 | Please remove all of this text before submitting. Include an explanation or list of changes included in your PR, as well as, if applicable, a link to any related issues. 14 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: Build CI 6 | 7 | on: [pull_request, push] 8 | 9 | jobs: 10 | test: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Run Build CI workflow 14 | uses: adafruit/workflows-circuitpython-libs/build@main 15 | -------------------------------------------------------------------------------- /.github/workflows/failure-help-text.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Scott Shawcroft for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: Failure help text 6 | 7 | on: 8 | workflow_run: 9 | workflows: ["Build CI"] 10 | types: 11 | - completed 12 | 13 | jobs: 14 | post-help: 15 | runs-on: ubuntu-latest 16 | if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.event == 'pull_request' }} 17 | steps: 18 | - name: Post comment to help 19 | uses: adafruit/circuitpython-action-library-ci-failed@v1 20 | -------------------------------------------------------------------------------- /.github/workflows/release_gh.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: GitHub Release Actions 6 | 7 | on: 8 | release: 9 | types: [published] 10 | 11 | jobs: 12 | upload-release-assets: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Run GitHub Release CI workflow 16 | uses: adafruit/workflows-circuitpython-libs/release-gh@main 17 | with: 18 | github-token: ${{ secrets.GITHUB_TOKEN }} 19 | upload-url: ${{ github.event.release.upload_url }} 20 | -------------------------------------------------------------------------------- /.github/workflows/release_pypi.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: PyPI Release Actions 6 | 7 | on: 8 | release: 9 | types: [published] 10 | 11 | jobs: 12 | upload-release-assets: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Run PyPI Release CI workflow 16 | uses: adafruit/workflows-circuitpython-libs/release-pypi@main 17 | with: 18 | pypi-username: ${{ secrets.pypi_username }} 19 | pypi-password: ${{ secrets.pypi_password }} 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Kattni Rembor, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | # Do not include files and directories created by your personal work environment, such as the IDE 6 | # you use, except for those already listed here. Pull requests including changes to this file will 7 | # not be accepted. 8 | 9 | # This .gitignore file contains rules for files generated by working with CircuitPython libraries, 10 | # including building Sphinx, testing with pip, and creating a virual environment, as well as the 11 | # MacOS and IDE-specific files generated by using MacOS in general, or the PyCharm or VSCode IDEs. 12 | 13 | # If you find that there are files being generated on your machine that should not be included in 14 | # your git commit, you should create a .gitignore_global file on your computer to include the 15 | # files created by your personal setup. To do so, follow the two steps below. 16 | 17 | # First, create a file called .gitignore_global somewhere convenient for you, and add rules for 18 | # the files you want to exclude from git commits. 19 | 20 | # Second, configure Git to use the exclude file for all Git repositories by running the 21 | # following via commandline, replacing "path/to/your/" with the actual path to your newly created 22 | # .gitignore_global file: 23 | # git config --global core.excludesfile path/to/your/.gitignore_global 24 | 25 | # CircuitPython-specific files 26 | *.mpy 27 | 28 | # Python-specific files 29 | __pycache__ 30 | *.pyc 31 | 32 | # Sphinx build-specific files 33 | _build 34 | 35 | # This file results from running `pip -e install .` in a local repository 36 | *.egg-info 37 | 38 | # Virtual environment-specific files 39 | .env 40 | .venv 41 | 42 | # MacOS-specific files 43 | *.DS_Store 44 | 45 | # IDE-specific files 46 | .idea 47 | .vscode 48 | *~ 49 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | repos: 6 | - repo: https://github.com/pre-commit/pre-commit-hooks 7 | rev: v4.5.0 8 | hooks: 9 | - id: check-yaml 10 | - id: end-of-file-fixer 11 | - id: trailing-whitespace 12 | - repo: https://github.com/astral-sh/ruff-pre-commit 13 | rev: v0.3.4 14 | hooks: 15 | - id: ruff-format 16 | - id: ruff 17 | args: ["--fix"] 18 | - repo: https://github.com/fsfe/reuse-tool 19 | rev: v3.0.1 20 | hooks: 21 | - id: reuse 22 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | # Read the Docs configuration file 6 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 7 | 8 | # Required 9 | version: 2 10 | 11 | sphinx: 12 | configuration: docs/conf.py 13 | 14 | build: 15 | os: ubuntu-20.04 16 | tools: 17 | python: "3" 18 | 19 | python: 20 | install: 21 | - requirements: docs/requirements.txt 22 | - requirements: requirements.txt 23 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 6 | 7 | # Adafruit Community Code of Conduct 8 | 9 | ## Our Pledge 10 | 11 | In the interest of fostering an open and welcoming environment, we as 12 | contributors and leaders pledge to making participation in our project and 13 | our community a harassment-free experience for everyone, regardless of age, body 14 | size, disability, ethnicity, gender identity and expression, level or type of 15 | experience, education, socio-economic status, nationality, personal appearance, 16 | race, religion, or sexual identity and orientation. 17 | 18 | ## Our Standards 19 | 20 | We are committed to providing a friendly, safe and welcoming environment for 21 | all. 22 | 23 | Examples of behavior that contributes to creating a positive environment 24 | include: 25 | 26 | * Be kind and courteous to others 27 | * Using welcoming and inclusive language 28 | * Being respectful of differing viewpoints and experiences 29 | * Collaborating with other community members 30 | * Gracefully accepting constructive criticism 31 | * Focusing on what is best for the community 32 | * Showing empathy towards other community members 33 | 34 | Examples of unacceptable behavior by participants include: 35 | 36 | * The use of sexualized language or imagery and sexual attention or advances 37 | * The use of inappropriate images, including in a community member's avatar 38 | * The use of inappropriate language, including in a community member's nickname 39 | * Any spamming, flaming, baiting or other attention-stealing behavior 40 | * Excessive or unwelcome helping; answering outside the scope of the question 41 | asked 42 | * Trolling, insulting/derogatory comments, and personal or political attacks 43 | * Promoting or spreading disinformation, lies, or conspiracy theories against 44 | a person, group, organisation, project, or community 45 | * Public or private harassment 46 | * Publishing others' private information, such as a physical or electronic 47 | address, without explicit permission 48 | * Other conduct which could reasonably be considered inappropriate 49 | 50 | The goal of the standards and moderation guidelines outlined here is to build 51 | and maintain a respectful community. We ask that you don’t just aim to be 52 | "technically unimpeachable", but rather try to be your best self. 53 | 54 | We value many things beyond technical expertise, including collaboration and 55 | supporting others within our community. Providing a positive experience for 56 | other community members can have a much more significant impact than simply 57 | providing the correct answer. 58 | 59 | ## Our Responsibilities 60 | 61 | Project leaders are responsible for clarifying the standards of acceptable 62 | behavior and are expected to take appropriate and fair corrective action in 63 | response to any instances of unacceptable behavior. 64 | 65 | Project leaders have the right and responsibility to remove, edit, or 66 | reject messages, comments, commits, code, issues, and other contributions 67 | that are not aligned to this Code of Conduct, or to ban temporarily or 68 | permanently any community member for other behaviors that they deem 69 | inappropriate, threatening, offensive, or harmful. 70 | 71 | ## Moderation 72 | 73 | Instances of behaviors that violate the Adafruit Community Code of Conduct 74 | may be reported by any member of the community. Community members are 75 | encouraged to report these situations, including situations they witness 76 | involving other community members. 77 | 78 | You may report in the following ways: 79 | 80 | In any situation, you may send an email to . 81 | 82 | On the Adafruit Discord, you may send an open message from any channel 83 | to all Community Moderators by tagging @community moderators. You may 84 | also send an open message from any channel, or a direct message to 85 | @kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442, 86 | @sommersoft#0222, @Mr. Certainly#0472 or @Andon#8175. 87 | 88 | Email and direct message reports will be kept confidential. 89 | 90 | In situations on Discord where the issue is particularly egregious, possibly 91 | illegal, requires immediate action, or violates the Discord terms of service, 92 | you should also report the message directly to Discord. 93 | 94 | These are the steps for upholding our community’s standards of conduct. 95 | 96 | 1. Any member of the community may report any situation that violates the 97 | Adafruit Community Code of Conduct. All reports will be reviewed and 98 | investigated. 99 | 2. If the behavior is an egregious violation, the community member who 100 | committed the violation may be banned immediately, without warning. 101 | 3. Otherwise, moderators will first respond to such behavior with a warning. 102 | 4. Moderators follow a soft "three strikes" policy - the community member may 103 | be given another chance, if they are receptive to the warning and change their 104 | behavior. 105 | 5. If the community member is unreceptive or unreasonable when warned by a 106 | moderator, or the warning goes unheeded, they may be banned for a first or 107 | second offense. Repeated offenses will result in the community member being 108 | banned. 109 | 110 | ## Scope 111 | 112 | This Code of Conduct and the enforcement policies listed above apply to all 113 | Adafruit Community venues. This includes but is not limited to any community 114 | spaces (both public and private), the entire Adafruit Discord server, and 115 | Adafruit GitHub repositories. Examples of Adafruit Community spaces include 116 | but are not limited to meet-ups, audio chats on the Adafruit Discord, or 117 | interaction at a conference. 118 | 119 | This Code of Conduct applies both within project spaces and in public spaces 120 | when an individual is representing the project or its community. As a community 121 | member, you are representing our community, and are expected to behave 122 | accordingly. 123 | 124 | ## Attribution 125 | 126 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 127 | version 1.4, available at 128 | , 129 | and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html). 130 | 131 | For other projects adopting the Adafruit Community Code of 132 | Conduct, please contact the maintainers of those projects for enforcement. 133 | If you wish to use this code of conduct for your own project, consider 134 | explicitly mentioning your moderation policy or making a copy with your 135 | own moderation policy so as to avoid confusion. 136 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Tony DiCola 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 | 2 | Introduction 3 | ============ 4 | 5 | .. image:: https://readthedocs.org/projects/adafruit-circuitpython-rfm69/badge/?version=latest 6 | :target: https://docs.circuitpython.org/projects/rfm69/en/latest/ 7 | :alt: Documentation Status 8 | 9 | .. image:: https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_Bundle/main/badges/adafruit_discord.svg 10 | :target: https://adafru.it/discord 11 | :alt: Discord 12 | 13 | .. image:: https://github.com/adafruit/Adafruit_CircuitPython_RFM69/workflows/Build%20CI/badge.svg 14 | :target: https://github.com/adafruit/Adafruit_CircuitPython_RFM69/actions/ 15 | :alt: Build Status 16 | 17 | .. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json 18 | :target: https://github.com/astral-sh/ruff 19 | :alt: Code Style: Ruff 20 | 21 | CircuitPython RFM69 packet radio module. This supports basic RadioHead-compatible sending and 22 | receiving of packets with RFM69 series radios (433/915Mhz). 23 | 24 | .. warning:: This is NOT for LoRa radios! 25 | 26 | .. note:: This is a 'best effort' at receiving data using pure Python code--there is not interrupt 27 | support so you might lose packets if they're sent too quickly for the board to process them. 28 | You will have the most luck using this in simple low bandwidth scenarios like sending and 29 | receiving a 60 byte packet at a time--don't try to receive many kilobytes of data at a time! 30 | 31 | Dependencies 32 | ============= 33 | This driver depends on: 34 | 35 | * `Adafruit CircuitPython `_ 36 | * `Bus Device `_ 37 | 38 | Please ensure all dependencies are available on the CircuitPython filesystem. 39 | This is easily achieved by downloading 40 | `the Adafruit library and driver bundle `_. 41 | 42 | Installing from PyPI 43 | ==================== 44 | 45 | On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from 46 | PyPI `_. To install for current user: 47 | 48 | .. code-block:: shell 49 | 50 | pip3 install adafruit-circuitpython-rfm69 51 | 52 | To install system-wide (this may be required in some cases): 53 | 54 | .. code-block:: shell 55 | 56 | sudo pip3 install adafruit-circuitpython-rfm69 57 | 58 | To install in a virtual environment in your current project: 59 | 60 | .. code-block:: shell 61 | 62 | mkdir project-name && cd project-name 63 | python3 -m venv .venv 64 | source .venv/bin/activate 65 | pip3 install adafruit-circuitpython-rfm69 66 | 67 | 68 | Usage Example 69 | ============= 70 | See examples/rfm69_simpletest.py for a simple demo of the usage. 71 | Note: the default baudrate for the SPI is 2000000 (2MHz). 72 | The maximum setting is 10Mhz but 73 | transmission errors have been observed expecially when using breakout boards. 74 | For breakout boards or other configurations where the boards are separated, 75 | it may be necessary to reduce the baudrate for reliable data transmission. 76 | The baud rate may be specified as an keyword parameter when initializing the board. 77 | To set it to 1000000 use : 78 | 79 | .. code-block:: python 80 | 81 | # Initialze RFM radio 82 | rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, RADIO_FREQ_MHZ, baudrate=1000000) 83 | 84 | 85 | Documentation 86 | ============= 87 | 88 | API documentation for this library can be found on `Read the Docs `_. 89 | 90 | For information on building library documentation, please check out `this guide `_. 91 | 92 | Contributing 93 | ============ 94 | 95 | Contributions are welcome! Please read our `Code of Conduct 96 | `_ 97 | before contributing to help this project stay welcoming. 98 | -------------------------------------------------------------------------------- /README.rst.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | 3 | SPDX-License-Identifier: MIT 4 | -------------------------------------------------------------------------------- /adafruit_rfm69.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Tony DiCola for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | """ 6 | `adafruit_rfm69` 7 | ==================================================== 8 | 9 | CircuitPython RFM69 packet radio module. This supports basic RadioHead-compatible sending and 10 | receiving of packets with RFM69 series radios (433/915Mhz). 11 | 12 | .. warning:: This is NOT for LoRa radios! 13 | 14 | .. note:: This is a 'best effort' at receiving data using pure Python code--there is not interrupt 15 | support so you might lose packets if they're sent too quickly for the board to process them. 16 | You will have the most luck using this in simple low bandwidth scenarios like sending and 17 | receiving a 60 byte packet at a time--don't try to receive many kilobytes of data at a time! 18 | 19 | * Author(s): Tony DiCola, Jerry Needell 20 | 21 | Implementation Notes 22 | -------------------- 23 | 24 | **Hardware:** 25 | 26 | * Adafruit `RFM69HCW Transceiver Radio Breakout - 868 or 915 MHz - RadioFruit 27 | `_ (Product ID: 3070) 28 | 29 | * Adafruit `RFM69HCW Transceiver Radio Breakout - 433 MHz - RadioFruit 30 | `_ (Product ID: 3071) 31 | 32 | * Adafruit `Feather M0 RFM69HCW Packet Radio - 868 or 915 MHz - RadioFruit 33 | `_ (Product ID: 3176) 34 | 35 | * Adafruit `Feather M0 RFM69HCW Packet Radio - 433 MHz - RadioFruit 36 | `_ (Product ID: 3177) 37 | 38 | * Adafruit `Radio FeatherWing - RFM69HCW 900MHz - RadioFruit 39 | `_ (Product ID: 3229) 40 | 41 | * Adafruit `Radio FeatherWing - RFM69HCW 433MHz - RadioFruit 42 | `_ (Product ID: 3230) 43 | 44 | **Software and Dependencies:** 45 | 46 | * Adafruit CircuitPython firmware for the ESP8622 and M0-based boards: 47 | https://github.com/adafruit/circuitpython/releases 48 | * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice 49 | """ 50 | 51 | import random 52 | import time 53 | 54 | import adafruit_bus_device.spi_device as spidev 55 | from micropython import const 56 | 57 | HAS_SUPERVISOR = False 58 | 59 | try: 60 | import supervisor 61 | 62 | HAS_SUPERVISOR = hasattr(supervisor, "ticks_ms") 63 | except ImportError: 64 | pass 65 | 66 | try: 67 | from typing import Callable, Optional, Type 68 | 69 | from busio import SPI 70 | from circuitpython_typing import ReadableBuffer, WriteableBuffer 71 | from digitalio import DigitalInOut 72 | except ImportError: 73 | pass 74 | 75 | __version__ = "0.0.0+auto.0" 76 | __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_RFM69.git" 77 | 78 | 79 | # Internal constants: 80 | _REG_FIFO = const(0x00) 81 | _REG_OP_MODE = const(0x01) 82 | _REG_DATA_MOD = const(0x02) 83 | _REG_BITRATE_MSB = const(0x03) 84 | _REG_BITRATE_LSB = const(0x04) 85 | _REG_FDEV_MSB = const(0x05) 86 | _REG_FDEV_LSB = const(0x06) 87 | _REG_FRF_MSB = const(0x07) 88 | _REG_FRF_MID = const(0x08) 89 | _REG_FRF_LSB = const(0x09) 90 | _REG_VERSION = const(0x10) 91 | _REG_PA_LEVEL = const(0x11) 92 | _REG_OCP = const(0x13) 93 | _REG_RX_BW = const(0x19) 94 | _REG_AFC_BW = const(0x1A) 95 | _REG_RSSI_VALUE = const(0x24) 96 | _REG_DIO_MAPPING1 = const(0x25) 97 | _REG_IRQ_FLAGS1 = const(0x27) 98 | _REG_IRQ_FLAGS2 = const(0x28) 99 | _REG_PREAMBLE_MSB = const(0x2C) 100 | _REG_PREAMBLE_LSB = const(0x2D) 101 | _REG_SYNC_CONFIG = const(0x2E) 102 | _REG_SYNC_VALUE1 = const(0x2F) 103 | _REG_PACKET_CONFIG1 = const(0x37) 104 | _REG_FIFO_THRESH = const(0x3C) 105 | _REG_PACKET_CONFIG2 = const(0x3D) 106 | _REG_AES_KEY1 = const(0x3E) 107 | _REG_TEMP1 = const(0x4E) 108 | _REG_TEMP2 = const(0x4F) 109 | _REG_TEST_PA1 = const(0x5A) 110 | _REG_TEST_PA2 = const(0x5C) 111 | _REG_TEST_DAGC = const(0x6F) 112 | 113 | _TEST_PA1_NORMAL = const(0x55) 114 | _TEST_PA1_BOOST = const(0x5D) 115 | _TEST_PA2_NORMAL = const(0x70) 116 | _TEST_PA2_BOOST = const(0x7C) 117 | _OCP_NORMAL = const(0x1A) 118 | _OCP_HIGH_POWER = const(0x0F) 119 | 120 | # The crystal oscillator frequency and frequency synthesizer step size. 121 | # See the datasheet for details of this calculation. 122 | _FXOSC = 32000000.0 123 | _FSTEP = _FXOSC / 524288 124 | 125 | # RadioHead specific compatibility constants. 126 | _RH_BROADCAST_ADDRESS = const(0xFF) 127 | # The acknowledgement bit in the FLAGS 128 | # The top 4 bits of the flags are reserved for RadioHead. The lower 4 bits are reserved 129 | # for application layer use. 130 | _RH_FLAGS_ACK = const(0x80) 131 | _RH_FLAGS_RETRY = const(0x40) 132 | 133 | # User facing constants: 134 | SLEEP_MODE = 0b000 135 | STANDBY_MODE = 0b001 136 | FS_MODE = 0b010 137 | TX_MODE = 0b011 138 | RX_MODE = 0b100 139 | # supervisor.ticks_ms() contants 140 | _TICKS_PERIOD = const(1 << 29) 141 | _TICKS_MAX = const(_TICKS_PERIOD - 1) 142 | _TICKS_HALFPERIOD = const(_TICKS_PERIOD // 2) 143 | 144 | # This is a complex chip which requires exposing many attributes and state. 145 | 146 | 147 | def ticks_diff(ticks1: int, ticks2: int) -> int: 148 | """Compute the signed difference between two ticks values 149 | assuming that they are within 2**28 ticks 150 | """ 151 | diff = (ticks1 - ticks2) & _TICKS_MAX 152 | diff = ((diff + _TICKS_HALFPERIOD) & _TICKS_MAX) - _TICKS_HALFPERIOD 153 | return diff 154 | 155 | 156 | def check_timeout(flag: Callable, limit: float) -> bool: 157 | """test for timeout waiting for specified flag""" 158 | timed_out = False 159 | if HAS_SUPERVISOR: 160 | start = supervisor.ticks_ms() 161 | while not timed_out and not flag(): 162 | if ticks_diff(supervisor.ticks_ms(), start) >= limit * 1000: 163 | timed_out = True 164 | else: 165 | start = time.monotonic() 166 | while not timed_out and not flag(): 167 | if time.monotonic() - start >= limit: 168 | timed_out = True 169 | return timed_out 170 | 171 | 172 | class RFM69: 173 | """Interface to a RFM69 series packet radio. Allows simple sending and 174 | receiving of wireless data at supported frequencies of the radio 175 | (433/915mhz). 176 | 177 | :param busio.SPI spi: The SPI bus connected to the chip. Ensure SCK, MOSI, and MISO are 178 | connected. 179 | :param ~digitalio.DigitalInOut cs: A DigitalInOut object connected to the chip's CS/chip select 180 | line. 181 | :param ~digitalio.DigitalInOut reset: A DigitalInOut object connected to the chip's RST/reset 182 | line. 183 | :param int frequency: The center frequency to configure for radio transmission and reception. 184 | Must be a frequency supported by your hardware (i.e. either 433 or 915mhz). 185 | :param bytes sync_word: A byte string up to 8 bytes long which represents the syncronization 186 | word used by received and transmitted packets. Read the datasheet for a full understanding 187 | of this value! However by default the library will set a value that matches the RadioHead 188 | Arduino library. 189 | :param int preamble_length: The number of bytes to pre-pend to a data packet as a preamble. 190 | This is by default 4 to match the RadioHead library. 191 | :param bytes encryption_key: A 16 byte long string that represents the AES encryption key to use 192 | when encrypting and decrypting packets. Both the transmitter and receiver MUST have the 193 | same key value! By default no encryption key is set or used. 194 | :param bool high_power: Indicate if the chip is a high power variant that supports boosted 195 | transmission power. The default is True as it supports the common RFM69HCW modules sold by 196 | Adafruit. 197 | 198 | .. note:: The D0/interrupt line is currently unused by this module and can remain unconnected. 199 | 200 | Remember this library makes a best effort at receiving packets with pure Python code. Trying 201 | to receive packets too quickly will result in lost data so limit yourself to simple scenarios 202 | of sending and receiving single packets at a time. 203 | 204 | Also note this library tries to be compatible with raw RadioHead Arduino library communication. 205 | This means the library sets up the radio modulation to match RadioHead's default of GFSK 206 | encoding, 250kbit/s bitrate, and 250khz frequency deviation. To change this requires explicitly 207 | setting the radio's bitrate and encoding register bits. Read the datasheet and study the init 208 | function to see an example of this--advanced users only! Advanced RadioHead features like 209 | address/node specific packets or "reliable datagram" delivery are supported however due to the 210 | limitations noted, "reliable datagram" is still subject to missed packets but with it, the 211 | sender is notified if a packet has potentially been missed. 212 | """ 213 | 214 | # Global buffer for SPI commands. 215 | _BUFFER = bytearray(4) 216 | 217 | class _RegisterBits: 218 | # Class to simplify access to the many configuration bits avaialable 219 | # on the chip's registers. This is a subclass here instead of using 220 | # a higher level module to increase the efficiency of memory usage 221 | # (all of the instances of this bit class will share the same buffer 222 | # used by the parent RFM69 class instance vs. each having their own 223 | # buffer and taking too much memory). 224 | 225 | # This is a decorator class in Python and by design it has no public methods. 226 | # Instead it uses dunder accessors like get and set below. 227 | 228 | # This is an internally used class that calls the read/write functions 229 | # of the parent class. 230 | 231 | def __init__(self, address: int, *, offset: int = 0, bits: int = 1) -> None: 232 | assert 0 <= offset <= 7 233 | assert 1 <= bits <= 8 234 | assert (offset + bits) <= 8 235 | self._address = address 236 | self._mask = 0 237 | for _ in range(bits): 238 | self._mask <<= 1 239 | self._mask |= 1 240 | self._mask <<= offset 241 | self._offset = offset 242 | 243 | def __get__(self, obj: Optional["RFM69"], objtype: Type["RFM69"]): 244 | reg_value = obj._read_u8(self._address) 245 | return (reg_value & self._mask) >> self._offset 246 | 247 | def __set__(self, obj: Optional["RFM69"], val: int) -> None: 248 | reg_value = obj._read_u8(self._address) 249 | reg_value &= ~self._mask 250 | reg_value |= (val & 0xFF) << self._offset 251 | obj._write_u8(self._address, reg_value) 252 | 253 | # Control bits from the registers of the chip: 254 | data_mode = _RegisterBits(_REG_DATA_MOD, offset=5, bits=2) 255 | modulation_type = _RegisterBits(_REG_DATA_MOD, offset=3, bits=2) 256 | modulation_shaping = _RegisterBits(_REG_DATA_MOD, offset=0, bits=2) 257 | temp_start = _RegisterBits(_REG_TEMP1, offset=3) 258 | temp_running = _RegisterBits(_REG_TEMP1, offset=2) 259 | sync_on = _RegisterBits(_REG_SYNC_CONFIG, offset=7) 260 | sync_size = _RegisterBits(_REG_SYNC_CONFIG, offset=3, bits=3) 261 | aes_on = _RegisterBits(_REG_PACKET_CONFIG2, offset=0) 262 | pa_0_on = _RegisterBits(_REG_PA_LEVEL, offset=7) 263 | pa_1_on = _RegisterBits(_REG_PA_LEVEL, offset=6) 264 | pa_2_on = _RegisterBits(_REG_PA_LEVEL, offset=5) 265 | output_power = _RegisterBits(_REG_PA_LEVEL, offset=0, bits=5) 266 | rx_bw_dcc_freq = _RegisterBits(_REG_RX_BW, offset=5, bits=3) 267 | rx_bw_mantissa = _RegisterBits(_REG_RX_BW, offset=3, bits=2) 268 | rx_bw_exponent = _RegisterBits(_REG_RX_BW, offset=0, bits=3) 269 | afc_bw_dcc_freq = _RegisterBits(_REG_AFC_BW, offset=5, bits=3) 270 | afc_bw_mantissa = _RegisterBits(_REG_AFC_BW, offset=3, bits=2) 271 | afc_bw_exponent = _RegisterBits(_REG_AFC_BW, offset=0, bits=3) 272 | packet_format = _RegisterBits(_REG_PACKET_CONFIG1, offset=7, bits=1) 273 | dc_free = _RegisterBits(_REG_PACKET_CONFIG1, offset=5, bits=2) 274 | crc_on = _RegisterBits(_REG_PACKET_CONFIG1, offset=4, bits=1) 275 | crc_auto_clear_off = _RegisterBits(_REG_PACKET_CONFIG1, offset=3, bits=1) 276 | address_filter = _RegisterBits(_REG_PACKET_CONFIG1, offset=1, bits=2) 277 | mode_ready = _RegisterBits(_REG_IRQ_FLAGS1, offset=7) 278 | dio_0_mapping = _RegisterBits(_REG_DIO_MAPPING1, offset=6, bits=2) 279 | 280 | def __init__( 281 | self, 282 | spi: SPI, 283 | cs: DigitalInOut, 284 | reset: DigitalInOut, 285 | frequency: int, 286 | *, 287 | sync_word: bytes = b"\x2d\xd4", 288 | preamble_length: int = 4, 289 | encryption_key: Optional[bytes] = None, 290 | high_power: bool = True, 291 | baudrate: int = 2000000, 292 | ) -> None: 293 | self._tx_power = 13 294 | self.high_power = high_power 295 | # Device support SPI mode 0 (polarity & phase = 0) up to a max of 10mhz. 296 | self._device = spidev.SPIDevice(spi, cs, baudrate=baudrate, polarity=0, phase=0) 297 | # Setup reset as a digital output that's low. 298 | self._reset = reset 299 | self._reset.switch_to_output(value=False) 300 | self.reset() # Reset the chip. 301 | # Check the version of the chip. 302 | version = self._read_u8(_REG_VERSION) 303 | if version not in {0x23, 0x24}: 304 | raise RuntimeError("Invalid RFM69 version, check wiring!") 305 | self.idle() # Enter idle state. 306 | # Setup the chip in a similar way to the RadioHead RFM69 library. 307 | # Set FIFO TX condition to not empty and the default FIFO threshold to 15. 308 | self._write_u8(_REG_FIFO_THRESH, 0b10001111) 309 | # Configure low beta off. 310 | self._write_u8(_REG_TEST_DAGC, 0x30) 311 | # Set the syncronization word. 312 | self.sync_word = sync_word 313 | self.preamble_length = preamble_length # Set the preamble length. 314 | self.frequency_mhz = frequency # Set frequency. 315 | self.encryption_key = encryption_key # Set encryption key. 316 | # Configure modulation for RadioHead library GFSK_Rb250Fd250 mode 317 | # by default. Users with advanced knowledge can manually reconfigure 318 | # for any other mode (consulting the datasheet is absolutely 319 | # necessary!). 320 | self.modulation_shaping = 0b01 # Gaussian filter, BT=1.0 321 | self.bitrate = 250000 # 250kbs 322 | self.frequency_deviation = 250000 # 250khz 323 | self.rx_bw_dcc_freq = 0b111 # RxBw register = 0xE0 324 | self.rx_bw_mantissa = 0b00 325 | self.rx_bw_exponent = 0b000 326 | self.afc_bw_dcc_freq = 0b111 # AfcBw register = 0xE0 327 | self.afc_bw_mantissa = 0b00 328 | self.afc_bw_exponent = 0b000 329 | self.packet_format = 1 # Variable length. 330 | self.dc_free = 0b10 # Whitening 331 | # Set transmit power to 13 dBm, a safe value any module supports. 332 | self.tx_power = 13 333 | 334 | # initialize last RSSI reading 335 | self.last_rssi = 0.0 336 | """The RSSI of the last received packet. Stored when the packet was received. 337 | This instantaneous RSSI value may not be accurate once the 338 | operating mode has been changed. 339 | """ 340 | # initialize timeouts and delays delays 341 | self.ack_wait = 0.5 342 | """The delay time before attempting a retry after not receiving an ACK""" 343 | self.receive_timeout = 0.5 344 | """The amount of time to poll for a received packet. 345 | If no packet is received, the returned packet will be None 346 | """ 347 | self.xmit_timeout = 2.0 348 | """The amount of time to wait for the HW to transmit the packet. 349 | This is mainly used to prevent a hang due to a HW issue 350 | """ 351 | self.ack_retries = 5 352 | """The number of ACK retries before reporting a failure.""" 353 | self.ack_delay = None 354 | """The delay time before attemting to send an ACK. 355 | If ACKs are being missed try setting this to .1 or .2. 356 | """ 357 | # initialize sequence number counter for reliabe datagram mode 358 | self.sequence_number = 0 359 | # create seen Ids list 360 | self.seen_ids = bytearray(256) 361 | # initialize packet header 362 | # node address - default is broadcast 363 | self.node = _RH_BROADCAST_ADDRESS 364 | """The default address of this Node. (0-255). 365 | If not 255 (0xff) then only packets address to this node will be accepted. 366 | First byte of the RadioHead header. 367 | """ 368 | # destination address - default is broadcast 369 | self.destination = _RH_BROADCAST_ADDRESS 370 | """The default destination address for packet transmissions. (0-255). 371 | If 255 (0xff) then any receiving node should accept the packet. 372 | Second byte of the RadioHead header. 373 | """ 374 | # ID - contains seq count for reliable datagram mode 375 | self.identifier = 0 376 | """Automatically set to the sequence number when send_with_ack() used. 377 | Third byte of the RadioHead header. 378 | """ 379 | # flags - identifies ack/reetry packet for reliable datagram mode 380 | self.flags = 0 381 | """Upper 4 bits reserved for use by Reliable Datagram Mode. 382 | Lower 4 bits may be used to pass information. 383 | Fourth byte of the RadioHead header. 384 | """ 385 | 386 | # Reconsider this disable when it can be tested. 387 | def _read_into(self, address: int, buf: WriteableBuffer, length: Optional[int] = None) -> None: 388 | # Read a number of bytes from the specified address into the provided 389 | # buffer. If length is not specified (the default) the entire buffer 390 | # will be filled. 391 | if length is None: 392 | length = len(buf) 393 | with self._device as device: 394 | self._BUFFER[0] = address & 0x7F # Strip out top bit to set 0 395 | # value (read). 396 | device.write(self._BUFFER, end=1) 397 | device.readinto(buf, end=length) 398 | 399 | def _read_u8(self, address: int) -> int: 400 | # Read a single byte from the provided address and return it. 401 | self._read_into(address, self._BUFFER, length=1) 402 | return self._BUFFER[0] 403 | 404 | def _write_from(self, address: int, buf: ReadableBuffer, length: Optional[int] = None) -> None: 405 | # Write a number of bytes to the provided address and taken from the 406 | # provided buffer. If no length is specified (the default) the entire 407 | # buffer is written. 408 | if length is None: 409 | length = len(buf) 410 | with self._device as device: 411 | self._BUFFER[0] = (address | 0x80) & 0xFF # Set top bit to 1 to 412 | # indicate a write. 413 | device.write(self._BUFFER, end=1) 414 | device.write(buf, end=length) # send data 415 | 416 | def _write_u8(self, address: int, val: int) -> None: 417 | # Write a byte register to the chip. Specify the 7-bit address and the 418 | # 8-bit value to write to that address. 419 | with self._device as device: 420 | self._BUFFER[0] = (address | 0x80) & 0xFF # Set top bit to 1 to 421 | # indicate a write. 422 | self._BUFFER[1] = val & 0xFF 423 | device.write(self._BUFFER, end=2) 424 | 425 | def reset(self) -> None: 426 | """Perform a reset of the chip.""" 427 | # See section 7.2.2 of the datasheet for reset description. 428 | self._reset.value = True 429 | time.sleep(0.0001) # 100 us 430 | self._reset.value = False 431 | time.sleep(0.005) # 5 ms 432 | 433 | def disable_boost(self) -> None: 434 | """Disable preamp boost.""" 435 | if self.high_power: 436 | self._write_u8(_REG_TEST_PA1, _TEST_PA1_NORMAL) 437 | self._write_u8(_REG_TEST_PA2, _TEST_PA2_NORMAL) 438 | self._write_u8(_REG_OCP, _OCP_NORMAL) 439 | 440 | def idle(self) -> None: 441 | """Enter idle standby mode (switching off high power amplifiers if necessary).""" 442 | # Like RadioHead library, turn off high power boost if enabled. 443 | self.disable_boost() 444 | self.operation_mode = STANDBY_MODE 445 | 446 | def sleep(self) -> None: 447 | """Enter sleep mode.""" 448 | self.operation_mode = SLEEP_MODE 449 | 450 | def listen(self) -> None: 451 | """Listen for packets to be received by the chip. Use :py:func:`receive` to listen, wait 452 | and retrieve packets as they're available. 453 | """ 454 | # Like RadioHead library, turn off high power boost if enabled. 455 | self.disable_boost() 456 | # Enable payload ready interrupt for D0 line. 457 | self.dio_0_mapping = 0b01 458 | # Enter RX mode (will clear FIFO!). 459 | self.operation_mode = RX_MODE 460 | 461 | def transmit(self) -> None: 462 | """Transmit a packet which is queued in the FIFO. This is a low level function for 463 | entering transmit mode and more. For generating and transmitting a packet of data use 464 | :py:func:`send` instead. 465 | """ 466 | # Like RadioHead library, turn on high power boost if needed. 467 | if self.high_power and (self._tx_power >= 18): 468 | self._write_u8(_REG_TEST_PA1, _TEST_PA1_BOOST) 469 | self._write_u8(_REG_TEST_PA2, _TEST_PA2_BOOST) 470 | self._write_u8(_REG_OCP, _OCP_HIGH_POWER) 471 | # Enable packet sent interrupt for D0 line. 472 | self.dio_0_mapping = 0b00 473 | # Enter TX mode (will clear FIFO!). 474 | self.operation_mode = TX_MODE 475 | 476 | @property 477 | def temperature(self) -> float: 478 | """The internal temperature of the chip in degrees Celsius. Be warned this is not 479 | calibrated or very accurate. 480 | 481 | .. warning:: Reading this will STOP any receiving/sending that might be happening! 482 | """ 483 | # Start a measurement then poll the measurement finished bit. 484 | self.temp_start = 1 485 | while self.temp_running > 0: 486 | pass 487 | # Grab the temperature value and convert it to Celsius. 488 | # This uses the same observed value formula from the Radiohead library. 489 | temp = self._read_u8(_REG_TEMP2) 490 | return 166.0 - temp 491 | 492 | @property 493 | def operation_mode(self) -> int: 494 | """The operation mode value. Unless you're manually controlling the chip you shouldn't 495 | change the operation_mode with this property as other side-effects are required for 496 | changing logical modes--use :py:func:`idle`, :py:func:`sleep`, :py:func:`transmit`, 497 | :py:func:`listen` instead to signal intent for explicit logical modes. 498 | """ 499 | op_mode = self._read_u8(_REG_OP_MODE) 500 | return (op_mode >> 2) & 0b111 501 | 502 | @operation_mode.setter 503 | def operation_mode(self, val: int) -> None: 504 | assert 0 <= val <= 4 505 | # Set the mode bits inside the operation mode register. 506 | op_mode = self._read_u8(_REG_OP_MODE) 507 | op_mode &= 0b11100011 508 | op_mode |= val << 2 509 | self._write_u8(_REG_OP_MODE, op_mode) 510 | # Wait for mode to change by polling interrupt bit. 511 | if HAS_SUPERVISOR: 512 | start = supervisor.ticks_ms() 513 | while not self.mode_ready: 514 | if ticks_diff(supervisor.ticks_ms(), start) >= 1000: 515 | raise TimeoutError("Operation Mode failed to set.") 516 | else: 517 | start = time.monotonic() 518 | while not self.mode_ready: 519 | if time.monotonic() - start >= 1: 520 | raise TimeoutError("Operation Mode failed to set.") 521 | 522 | @property 523 | def sync_word(self) -> bytearray: 524 | """The synchronization word value. This is a byte string up to 8 bytes long (64 bits) 525 | which indicates the synchronization word for transmitted and received packets. Any 526 | received packet which does not include this sync word will be ignored. The default value 527 | is 0x2D, 0xD4 which matches the RadioHead RFM69 library. Setting a value of None will 528 | disable synchronization word matching entirely. 529 | """ 530 | # Handle when sync word is disabled.. 531 | if not self.sync_on: 532 | return None 533 | # Sync word is not disabled so read the current value. 534 | sync_word_length = self.sync_size + 1 # Sync word size is offset by 1 535 | # according to datasheet. 536 | sync_word = bytearray(sync_word_length) 537 | self._read_into(_REG_SYNC_VALUE1, sync_word) 538 | return sync_word 539 | 540 | @sync_word.setter 541 | def sync_word(self, val: Optional[bytearray]) -> None: 542 | # Handle disabling sync word when None value is set. 543 | if val is None: 544 | self.sync_on = 0 545 | else: 546 | # Check sync word is at most 8 bytes. 547 | assert 1 <= len(val) <= 8 548 | # Update the value, size and turn on the sync word. 549 | self._write_from(_REG_SYNC_VALUE1, val) 550 | self.sync_size = len(val) - 1 # Again sync word size is offset by 551 | # 1 according to datasheet. 552 | self.sync_on = 1 553 | 554 | @property 555 | def preamble_length(self) -> int: 556 | """The length of the preamble for sent and received packets, an unsigned 16-bit value. 557 | Received packets must match this length or they are ignored! Set to 4 to match the 558 | RadioHead RFM69 library. 559 | """ 560 | msb = self._read_u8(_REG_PREAMBLE_MSB) 561 | lsb = self._read_u8(_REG_PREAMBLE_LSB) 562 | return ((msb << 8) | lsb) & 0xFFFF 563 | 564 | @preamble_length.setter 565 | def preamble_length(self, val: int) -> None: 566 | assert 0 <= val <= 65535 567 | self._write_u8(_REG_PREAMBLE_MSB, (val >> 8) & 0xFF) 568 | self._write_u8(_REG_PREAMBLE_LSB, val & 0xFF) 569 | 570 | @property 571 | def frequency_mhz(self) -> float: 572 | """The frequency of the radio in Megahertz. Only the allowed values for your radio must be 573 | specified (i.e. 433 vs. 915 mhz)! 574 | """ 575 | # FRF register is computed from the frequency following the datasheet. 576 | # See section 6.2 and FRF register description. 577 | # Read bytes of FRF register and assemble into a 24-bit unsigned value. 578 | msb = self._read_u8(_REG_FRF_MSB) 579 | mid = self._read_u8(_REG_FRF_MID) 580 | lsb = self._read_u8(_REG_FRF_LSB) 581 | frf = ((msb << 16) | (mid << 8) | lsb) & 0xFFFFFF 582 | frequency = (frf * _FSTEP) / 1000000.0 583 | return frequency 584 | 585 | @frequency_mhz.setter 586 | def frequency_mhz(self, val: float) -> None: 587 | assert 290 <= val <= 1020 588 | # Calculate FRF register 24-bit value using section 6.2 of the datasheet. 589 | frf = int((val * 1000000.0) / _FSTEP) & 0xFFFFFF 590 | # Extract byte values and update registers. 591 | msb = frf >> 16 592 | mid = (frf >> 8) & 0xFF 593 | lsb = frf & 0xFF 594 | self._write_u8(_REG_FRF_MSB, msb) 595 | self._write_u8(_REG_FRF_MID, mid) 596 | self._write_u8(_REG_FRF_LSB, lsb) 597 | 598 | @property 599 | def encryption_key(self) -> bytearray: 600 | """The AES encryption key used to encrypt and decrypt packets by the chip. This can be set 601 | to None to disable encryption (the default), otherwise it must be a 16 byte long byte 602 | string which defines the key (both the transmitter and receiver must use the same key 603 | value). 604 | """ 605 | # Handle if encryption is disabled. 606 | if self.aes_on == 0: 607 | return None 608 | # Encryption is enabled so read the key and return it. 609 | key = bytearray(16) 610 | self._read_into(_REG_AES_KEY1, key) 611 | return key 612 | 613 | @encryption_key.setter 614 | def encryption_key(self, val: bytearray) -> None: 615 | # Handle if unsetting the encryption key (None value). 616 | if val is None: 617 | self.aes_on = 0 618 | else: 619 | # Set the encryption key and enable encryption. 620 | assert len(val) == 16 621 | self._write_from(_REG_AES_KEY1, val) 622 | self.aes_on = 1 623 | 624 | @property 625 | def tx_power(self) -> int: 626 | """The transmit power in dBm. Can be set to a value from -2 to 20 for high power devices 627 | (RFM69HCW, high_power=True) or -18 to 13 for low power devices. Only integer power 628 | levels are actually set (i.e. 12.5 will result in a value of 12 dBm). 629 | """ 630 | # Follow table 10 truth table from the datasheet for determining power 631 | # level from the individual PA level bits and output power register. 632 | pa0 = self.pa_0_on 633 | pa1 = self.pa_1_on 634 | pa2 = self.pa_2_on 635 | current_output_power = self.output_power 636 | if pa0 and not pa1 and not pa2: 637 | # -18 to 13 dBm range 638 | return -18 + current_output_power 639 | if not pa0 and pa1 and not pa2: 640 | # -2 to 13 dBm range 641 | return -18 + current_output_power 642 | if not pa0 and pa1 and pa2 and self.high_power and self._tx_power < 18: 643 | # 2 to 17 dBm range 644 | return -14 + current_output_power 645 | if not pa0 and pa1 and pa2 and self.high_power and self._tx_power >= 18: 646 | # 5 to 20 dBm range 647 | return -11 + current_output_power 648 | raise RuntimeError("Power amps state unknown!") 649 | 650 | @tx_power.setter 651 | def tx_power(self, val: float): 652 | val = int(val) 653 | # Determine power amplifier and output power values depending on 654 | # high power state and requested power. 655 | pa_0_on = pa_1_on = pa_2_on = 0 656 | output_power = 0 657 | if self.high_power: 658 | # Handle high power mode. 659 | assert -2 <= val <= 20 660 | pa_1_on = 1 661 | if val <= 13: 662 | output_power = val + 18 663 | elif 13 < val <= 17: 664 | pa_2_on = 1 665 | output_power = val + 14 666 | else: # power >= 18 dBm 667 | # Note this also needs PA boost enabled separately! 668 | pa_2_on = 1 669 | output_power = val + 11 670 | else: 671 | # Handle non-high power mode. 672 | assert -18 <= val <= 13 673 | # Enable only power amplifier 0 and set output power. 674 | pa_0_on = 1 675 | output_power = val + 18 676 | # Set power amplifiers and output power as computed above. 677 | self.pa_0_on = pa_0_on 678 | self.pa_1_on = pa_1_on 679 | self.pa_2_on = pa_2_on 680 | self.output_power = output_power 681 | self._tx_power = val 682 | 683 | @property 684 | def rssi(self) -> float: 685 | """The received strength indicator (in dBm). 686 | May be inaccurate if not read immediately. last_rssi contains the value read immediately 687 | receipt of the last packet. 688 | """ 689 | # Read RSSI register and convert to value using formula in datasheet. 690 | return -self._read_u8(_REG_RSSI_VALUE) / 2.0 691 | 692 | @property 693 | def bitrate(self) -> float: 694 | """The modulation bitrate in bits/second (or chip rate if Manchester encoding is enabled). 695 | Can be a value from ~489 to 32mbit/s, but see the datasheet for the exact supported 696 | values. 697 | """ 698 | msb = self._read_u8(_REG_BITRATE_MSB) 699 | lsb = self._read_u8(_REG_BITRATE_LSB) 700 | return _FXOSC / ((msb << 8) | lsb) 701 | 702 | @bitrate.setter 703 | def bitrate(self, val: float) -> None: 704 | assert (_FXOSC / 65535) <= val <= 32000000.0 705 | # Round up to the next closest bit-rate value with addition of 0.5. 706 | bitrate = int((_FXOSC / val) + 0.5) & 0xFFFF 707 | self._write_u8(_REG_BITRATE_MSB, bitrate >> 8) 708 | self._write_u8(_REG_BITRATE_LSB, bitrate & 0xFF) 709 | 710 | @property 711 | def frequency_deviation(self) -> float: 712 | """The frequency deviation in Hertz.""" 713 | msb = self._read_u8(_REG_FDEV_MSB) 714 | lsb = self._read_u8(_REG_FDEV_LSB) 715 | return _FSTEP * ((msb << 8) | lsb) 716 | 717 | @frequency_deviation.setter 718 | def frequency_deviation(self, val: float) -> None: 719 | assert 0 <= val <= (_FSTEP * 16383) # fdev is a 14-bit unsigned value 720 | # Round up to the next closest integer value with addition of 0.5. 721 | fdev = int((val / _FSTEP) + 0.5) & 0x3FFF 722 | self._write_u8(_REG_FDEV_MSB, fdev >> 8) 723 | self._write_u8(_REG_FDEV_LSB, fdev & 0xFF) 724 | 725 | def packet_sent(self) -> bool: 726 | """Transmit status""" 727 | return (self._read_u8(_REG_IRQ_FLAGS2) & 0x8) >> 3 728 | 729 | def payload_ready(self) -> bool: 730 | """Receive status""" 731 | return (self._read_u8(_REG_IRQ_FLAGS2) & 0x4) >> 2 732 | 733 | def send( 734 | self, 735 | data: ReadableBuffer, 736 | *, 737 | keep_listening: bool = False, 738 | destination: Optional[int] = None, 739 | node: Optional[int] = None, 740 | identifier: Optional[int] = None, 741 | flags: Optional[int] = None, 742 | ) -> bool: 743 | """Send a string of data using the transmitter. 744 | You can only send 60 bytes at a time 745 | (limited by chip's FIFO size and appended headers). 746 | This appends a 4 byte header to be compatible with the RadioHead library. 747 | The header defaults to using the initialized attributes: 748 | (destination,node,identifier,flags) 749 | It may be temporarily overidden via the kwargs - destination,node,identifier,flags. 750 | Values passed via kwargs do not alter the attribute settings. 751 | The keep_listening argument should be set to True if you want to start listening 752 | automatically after the packet is sent. The default setting is False. 753 | 754 | Returns: True if success or False if the send timed out. 755 | """ 756 | # Ensure the provided buffer is within the expected range of bounds. 757 | assert 0 < len(data) <= 60 758 | self.idle() # Stop receiving to clear FIFO and keep it clear. 759 | # Fill the FIFO with a packet to send. 760 | # Combine header and data to form payload 761 | payload = bytearray(5) 762 | payload[0] = 4 + len(data) 763 | if destination is None: # use attribute 764 | payload[1] = self.destination 765 | else: # use kwarg 766 | payload[1] = destination 767 | if node is None: # use attribute 768 | payload[2] = self.node 769 | else: # use kwarg 770 | payload[2] = node 771 | if identifier is None: # use attribute 772 | payload[3] = self.identifier 773 | else: # use kwarg 774 | payload[3] = identifier 775 | if flags is None: # use attribute 776 | payload[4] = self.flags 777 | else: # use kwarg 778 | payload[4] = flags 779 | payload = payload + data 780 | # Write payload to transmit fifo 781 | self._write_from(_REG_FIFO, payload) 782 | # Turn on transmit mode to send out the packet. 783 | self.transmit() 784 | # Wait for packet sent interrupt with explicit polling (not ideal but 785 | # best that can be done right now without interrupts). 786 | timed_out = check_timeout(self.packet_sent, self.xmit_timeout) 787 | # Listen again if requested. 788 | if keep_listening: 789 | self.listen() 790 | else: # Enter idle mode to stop receiving other packets. 791 | self.idle() 792 | return not timed_out 793 | 794 | def send_with_ack(self, data: int) -> bool: 795 | """Reliable Datagram mode: 796 | Send a packet with data and wait for an ACK response. 797 | The packet header is automatically generated. 798 | If enabled, the packet transmission will be retried on failure 799 | """ 800 | if self.ack_retries: 801 | retries_remaining = self.ack_retries 802 | else: 803 | retries_remaining = 1 804 | got_ack = False 805 | self.sequence_number = (self.sequence_number + 1) & 0xFF 806 | while not got_ack and retries_remaining: 807 | self.identifier = self.sequence_number 808 | self.send(data, keep_listening=True) 809 | # Don't look for ACK from Broadcast message 810 | if self.destination == _RH_BROADCAST_ADDRESS: 811 | got_ack = True 812 | else: 813 | # wait for a packet from our destination 814 | ack_packet = self.receive(timeout=self.ack_wait, with_header=True) 815 | if ack_packet is not None: 816 | if ack_packet[3] & _RH_FLAGS_ACK: 817 | # check the ID 818 | if ack_packet[2] == self.identifier: 819 | got_ack = True 820 | break 821 | # pause before next retry -- random delay 822 | if not got_ack: 823 | # delay by random amount before next try 824 | time.sleep(self.ack_wait + self.ack_wait * random.random()) 825 | retries_remaining = retries_remaining - 1 826 | # set retry flag in packet header 827 | self.flags |= _RH_FLAGS_RETRY 828 | self.flags = 0 # clear flags 829 | return got_ack 830 | 831 | def receive( 832 | self, 833 | *, 834 | keep_listening: bool = True, 835 | with_ack: bool = False, 836 | timeout: Optional[float] = None, 837 | with_header: bool = False, 838 | ) -> int: 839 | """Wait to receive a packet from the receiver. If a packet is found the payload bytes 840 | are returned, otherwise None is returned (which indicates the timeout elapsed with no 841 | reception). 842 | If keep_listening is True (the default) the chip will immediately enter listening mode 843 | after reception of a packet, otherwise it will fall back to idle mode and ignore any 844 | future reception. 845 | All packets must have a 4 byte header for compatibilty with the 846 | RadioHead library. 847 | The header consists of 4 bytes (To,From,ID,Flags). The default setting will strip 848 | the header before returning the packet to the caller. 849 | If with_header is True then the 4 byte header will be returned with the packet. 850 | The payload then begins at packet[4]. 851 | If with_ack is True, send an ACK after receipt (Reliable Datagram mode) 852 | """ 853 | timed_out = False 854 | if timeout is None: 855 | timeout = self.receive_timeout 856 | if timeout is not None: 857 | # Wait for the payload_ready signal. This is not ideal and will 858 | # surely miss or overflow the FIFO when packets aren't read fast 859 | # enough, however it's the best that can be done from Python without 860 | # interrupt supports. 861 | # Make sure we are listening for packets. 862 | self.listen() 863 | timed_out = check_timeout(self.payload_ready, timeout) 864 | # Payload ready is set, a packet is in the FIFO. 865 | packet = None 866 | # save last RSSI reading 867 | self.last_rssi = self.rssi 868 | # Enter idle mode to stop receiving other packets. 869 | self.idle() 870 | if not timed_out: 871 | # Read the length of the FIFO. 872 | fifo_length = self._read_u8(_REG_FIFO) 873 | # Handle if the received packet is too small to include the 4 byte 874 | # RadioHead header and at least one byte of data --reject this packet and ignore it. 875 | if fifo_length > 0: # read and clear the FIFO if anything in it 876 | packet = bytearray(fifo_length) 877 | self._read_into(_REG_FIFO, packet, fifo_length) 878 | 879 | if fifo_length < 5: 880 | packet = None 881 | else: 882 | if self.node != _RH_BROADCAST_ADDRESS and packet[0] not in { 883 | _RH_BROADCAST_ADDRESS, 884 | self.node, 885 | }: 886 | packet = None 887 | # send ACK unless this was an ACK or a broadcast 888 | elif ( 889 | with_ack 890 | and ((packet[3] & _RH_FLAGS_ACK) == 0) 891 | and (packet[0] != _RH_BROADCAST_ADDRESS) 892 | ): 893 | # delay before sending Ack to give receiver a chance to get ready 894 | if self.ack_delay is not None: 895 | time.sleep(self.ack_delay) 896 | # send ACK packet to sender (data is b'!') 897 | self.send( 898 | b"!", 899 | destination=packet[1], 900 | node=packet[0], 901 | identifier=packet[2], 902 | flags=(packet[3] | _RH_FLAGS_ACK), 903 | ) 904 | # reject Retries if we have seen this idetifier from this source before 905 | if (self.seen_ids[packet[1]] == packet[2]) and (packet[3] & _RH_FLAGS_RETRY): 906 | packet = None 907 | else: # save the packet identifier for this source 908 | self.seen_ids[packet[1]] = packet[2] 909 | if not with_header and packet is not None: # skip the header if not wanted 910 | packet = packet[4:] 911 | # Listen again if necessary and return the result packet. 912 | if keep_listening: 913 | self.listen() 914 | else: 915 | # Enter idle mode to stop receiving other packets. 916 | self.idle() 917 | return packet 918 | -------------------------------------------------------------------------------- /docs/_static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_RFM69/cfeba6feb3ee9d01df87607ca98c7eea1c199e3d/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_rfm69 11 | :members: 12 | -------------------------------------------------------------------------------- /docs/api.rst.license: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | import datetime 6 | import os 7 | import sys 8 | 9 | sys.path.insert(0, os.path.abspath("..")) 10 | 11 | # -- General configuration ------------------------------------------------ 12 | 13 | # Add any Sphinx extension module names here, as strings. They can be 14 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 15 | # ones. 16 | extensions = [ 17 | "sphinx.ext.autodoc", 18 | "sphinxcontrib.jquery", 19 | "sphinx.ext.intersphinx", 20 | "sphinx.ext.viewcode", 21 | ] 22 | 23 | # Uncomment the below if you use native CircuitPython modules such as 24 | # digitalio, micropython and busio. List the modules you use. Without it, the 25 | # autodoc module docs will fail to generate with a warning. 26 | # autodoc_mock_imports = ["adafruit_bus_device", "micropython"] 27 | 28 | intersphinx_mapping = { 29 | "python": ("https://docs.python.org/3", None), 30 | "BusDevice": ( 31 | "https://docs.circuitpython.org/projects/busdevice/en/latest/", 32 | None, 33 | ), 34 | "CircuitPython": ("https://docs.circuitpython.org/en/latest/", None), 35 | } 36 | 37 | # Add any paths that contain templates here, relative to this directory. 38 | templates_path = ["_templates"] 39 | 40 | source_suffix = ".rst" 41 | 42 | # The master toctree document. 43 | master_doc = "index" 44 | 45 | # General information about the project. 46 | project = "Adafruit RFM69 Library" 47 | creation_year = "2017" 48 | current_year = str(datetime.datetime.now().year) 49 | year_duration = ( 50 | current_year if current_year == creation_year else creation_year + " - " + current_year 51 | ) 52 | copyright = year_duration + " Tony DiCola" 53 | author = "Tony DiCola" 54 | 55 | # The version info for the project you're documenting, acts as replacement for 56 | # |version| and |release|, also used in various other places throughout the 57 | # built documents. 58 | # 59 | # The short X.Y version. 60 | version = "1.0" 61 | # The full version, including alpha/beta/rc tags. 62 | release = "1.0" 63 | 64 | # The language for content autogenerated by Sphinx. Refer to documentation 65 | # for a list of supported languages. 66 | # 67 | # This is also used if you do content translation via gettext catalogs. 68 | # Usually you set "language" from the command line for these cases. 69 | language = "en" 70 | 71 | # List of patterns, relative to source directory, that match files and 72 | # directories to ignore when looking for source files. 73 | # This patterns also effect to html_static_path and html_extra_path 74 | exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"] 75 | 76 | # The reST default role (used for this markup: `text`) to use for all 77 | # documents. 78 | # 79 | default_role = "any" 80 | 81 | # If true, '()' will be appended to :func: etc. cross-reference text. 82 | # 83 | add_function_parentheses = True 84 | 85 | # The name of the Pygments (syntax highlighting) style to use. 86 | pygments_style = "sphinx" 87 | 88 | # If true, `todo` and `todoList` produce output, else they produce nothing. 89 | todo_include_todos = False 90 | 91 | # If this is True, todo emits a warning for each TODO entries. The default is False. 92 | todo_emit_warnings = True 93 | 94 | 95 | # -- Options for HTML output ---------------------------------------------- 96 | 97 | # The theme to use for HTML and HTML Help pages. See the documentation for 98 | # a list of builtin themes. 99 | # 100 | import sphinx_rtd_theme 101 | 102 | html_theme = "sphinx_rtd_theme" 103 | 104 | # Add any paths that contain custom static files (such as style sheets) here, 105 | # relative to this directory. They are copied after the builtin static files, 106 | # so a file named "default.css" will overwrite the builtin "default.css". 107 | html_static_path = ["_static"] 108 | 109 | # The name of an image file (relative to this directory) to use as a favicon of 110 | # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 111 | # pixels large. 112 | # 113 | html_favicon = "_static/favicon.ico" 114 | 115 | # Output file base name for HTML help builder. 116 | htmlhelp_basename = "AdafruitRfm69Librarydoc" 117 | 118 | # -- Options for LaTeX output --------------------------------------------- 119 | 120 | latex_elements = { 121 | # The paper size ('letterpaper' or 'a4paper'). 122 | # 123 | # 'papersize': 'letterpaper', 124 | # The font size ('10pt', '11pt' or '12pt'). 125 | # 126 | # 'pointsize': '10pt', 127 | # Additional stuff for the LaTeX preamble. 128 | # 129 | # 'preamble': '', 130 | # Latex figure (float) alignment 131 | # 132 | # 'figure_align': 'htbp', 133 | } 134 | 135 | # Grouping the document tree into LaTeX files. List of tuples 136 | # (source start file, target name, title, 137 | # author, documentclass [howto, manual, or own class]). 138 | latex_documents = [ 139 | ( 140 | master_doc, 141 | "AdafruitRFM69Library.tex", 142 | "AdafruitRFM69 Library Documentation", 143 | author, 144 | "manual", 145 | ), 146 | ] 147 | 148 | # -- Options for manual page output --------------------------------------- 149 | 150 | # One entry per manual page. List of tuples 151 | # (source start file, name, description, authors, manual section). 152 | man_pages = [ 153 | ( 154 | master_doc, 155 | "AdafruitRFM69library", 156 | "Adafruit RFM69 Library Documentation", 157 | [author], 158 | 1, 159 | ) 160 | ] 161 | 162 | # -- Options for Texinfo output ------------------------------------------- 163 | 164 | # Grouping the document tree into Texinfo files. List of tuples 165 | # (source start file, target name, title, author, 166 | # dir menu entry, description, category) 167 | texinfo_documents = [ 168 | ( 169 | master_doc, 170 | "AdafruitRFM69Library", 171 | "Adafruit RFM69 Library Documentation", 172 | author, 173 | "AdafruitRFM69Library", 174 | "One line description of project.", 175 | "Miscellaneous", 176 | ), 177 | ] 178 | -------------------------------------------------------------------------------- /docs/examples.rst: -------------------------------------------------------------------------------- 1 | Simple test 2 | ------------ 3 | 4 | Ensure your device works with this simple test. 5 | 6 | .. literalinclude:: ../examples/rfm69_simpletest.py 7 | :caption: examples/rfm69_simpletest.py 8 | :linenos: 9 | -------------------------------------------------------------------------------- /docs/examples.rst.license: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../README.rst 2 | 3 | Table of Contents 4 | ================= 5 | 6 | .. toctree:: 7 | :maxdepth: 4 8 | :hidden: 9 | 10 | self 11 | 12 | .. toctree:: 13 | :caption: Examples 14 | 15 | examples 16 | 17 | .. toctree:: 18 | :caption: API Reference 19 | :maxdepth: 3 20 | 21 | api 22 | 23 | .. toctree:: 24 | :caption: Tutorials 25 | 26 | .. toctree:: 27 | :caption: Related Products 28 | 29 | Adafruit RFM69HCW Transceiver Radio Breakout - 868 or 915 MHz - RadioFruit 30 | 31 | Adafruit RFM69HCW Transceiver Radio Breakout - 433 MHz - RadioFruit 32 | 33 | Adafruit Feather M0 RFM69HCW Packet Radio - 868 or 915 MHz - RadioFruit 34 | 35 | Adafruit Feather M0 RFM69HCW Packet Radio - 433 MHz - RadioFruit 36 | 37 | Adafruit Radio FeatherWing - RFM69HCW 900MHz - RadioFruit 38 | 39 | Adafruit Radio FeatherWing - RFM69HCW 433MHz - RadioFruit 40 | 41 | .. toctree:: 42 | :caption: Other Links 43 | 44 | Download from GitHub 45 | Download Library Bundle 46 | CircuitPython Reference Documentation 47 | CircuitPython Support Forum 48 | Discord Chat 49 | Adafruit Learning System 50 | Adafruit Blog 51 | Adafruit Store 52 | 53 | Indices and tables 54 | ================== 55 | 56 | * :ref:`genindex` 57 | * :ref:`modindex` 58 | * :ref:`search` 59 | -------------------------------------------------------------------------------- /docs/index.rst.license: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | sphinx 6 | sphinxcontrib-jquery 7 | sphinx-rtd-theme 8 | -------------------------------------------------------------------------------- /examples/rfm69_header.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020 Jerry Needell for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | # Example to display raw packets including header 5 | 6 | import board 7 | import busio 8 | import digitalio 9 | 10 | import adafruit_rfm69 11 | 12 | # set the time interval (seconds) for sending packets 13 | transmit_interval = 10 14 | 15 | # Define radio parameters. 16 | RADIO_FREQ_MHZ = 915.0 # Frequency of the radio in Mhz. Must match your 17 | # module! Can be a value like 915.0, 433.0, etc. 18 | 19 | # Define pins connected to the chip. 20 | CS = digitalio.DigitalInOut(board.CE1) 21 | RESET = digitalio.DigitalInOut(board.D25) 22 | 23 | # Initialize SPI bus. 24 | spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) 25 | 26 | # Initialze RFM radio 27 | rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, RADIO_FREQ_MHZ) 28 | 29 | # Optionally set an encryption key (16 byte AES key). MUST match both 30 | # on the transmitter and receiver (or be set to None to disable/the default). 31 | rfm69.encryption_key = b"\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08" 32 | 33 | # Wait to receive packets. 34 | print("Waiting for packets...") 35 | # initialize flag and timer 36 | while True: 37 | # Look for a new packet: only accept if addresses to my_node 38 | packet = rfm69.receive(with_header=True) 39 | # If no packet was received during the timeout then None is returned. 40 | if packet is not None: 41 | # Received a packet! 42 | # Print out the raw bytes of the packet: 43 | print("Received (raw header):", [hex(x) for x in packet[0:4]]) 44 | print(f"Received (raw payload): {packet[4:]}") 45 | print(f"RSSI: {rfm69.last_rssi}") 46 | # send reading after any packet received 47 | -------------------------------------------------------------------------------- /examples/rfm69_node1.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020 Jerry Needell for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | # Example to send a packet periodically between addressed nodes 5 | 6 | import time 7 | 8 | import board 9 | import busio 10 | import digitalio 11 | 12 | import adafruit_rfm69 13 | 14 | # set the time interval (seconds) for sending packets 15 | transmit_interval = 10 16 | 17 | # Define radio parameters. 18 | RADIO_FREQ_MHZ = 915.0 # Frequency of the radio in Mhz. Must match your 19 | # module! Can be a value like 915.0, 433.0, etc. 20 | 21 | # Define pins connected to the chip. 22 | CS = digitalio.DigitalInOut(board.CE1) 23 | RESET = digitalio.DigitalInOut(board.D25) 24 | 25 | # Initialize SPI bus. 26 | spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) 27 | # Initialze RFM radio 28 | rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, RADIO_FREQ_MHZ) 29 | 30 | # Optionally set an encryption key (16 byte AES key). MUST match both 31 | # on the transmitter and receiver (or be set to None to disable/the default). 32 | rfm69.encryption_key = b"\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08" 33 | 34 | # set node addresses 35 | rfm69.node = 1 36 | rfm69.destination = 2 37 | # initialize counter 38 | counter = 0 39 | # send a broadcast message from my_node with ID = counter 40 | rfm69.send(bytes(f"Startup message {counter} from node {rfm69.node}", "UTF-8")) 41 | 42 | # Wait to receive packets. 43 | print("Waiting for packets...") 44 | now = time.monotonic() 45 | while True: 46 | # Look for a new packet: only accept if addresses to my_node 47 | packet = rfm69.receive(with_header=True) 48 | # If no packet was received during the timeout then None is returned. 49 | if packet is not None: 50 | # Received a packet! 51 | # Print out the raw bytes of the packet: 52 | print("Received (raw header):", [hex(x) for x in packet[0:4]]) 53 | print(f"Received (raw payload): {packet[4:]}") 54 | print(f"Received RSSI: {rfm69.last_rssi}") 55 | if time.monotonic() - now > transmit_interval: 56 | now = time.monotonic() 57 | counter = counter + 1 58 | # send a mesage to destination_node from my_node 59 | rfm69.send( 60 | bytes(f"message number {counter} from node {rfm69.node}", "UTF-8"), 61 | keep_listening=True, 62 | ) 63 | button_pressed = None 64 | -------------------------------------------------------------------------------- /examples/rfm69_node1_ack.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020 Jerry Needell for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | # Example to send a packet periodically between addressed nodes with ACK 5 | 6 | import time 7 | 8 | import board 9 | import busio 10 | import digitalio 11 | 12 | import adafruit_rfm69 13 | 14 | # set the time interval (seconds) for sending packets 15 | transmit_interval = 10 16 | 17 | # Define radio parameters. 18 | RADIO_FREQ_MHZ = 915.0 # Frequency of the radio in Mhz. Must match your 19 | # module! Can be a value like 915.0, 433.0, etc. 20 | 21 | # Define pins connected to the chip. 22 | # set GPIO pins as necessary -- this example is for Raspberry Pi 23 | CS = digitalio.DigitalInOut(board.CE1) 24 | RESET = digitalio.DigitalInOut(board.D25) 25 | 26 | # Initialize SPI bus. 27 | spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) 28 | # Initialze RFM radio 29 | rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, RADIO_FREQ_MHZ) 30 | 31 | # Optionally set an encryption key (16 byte AES key). MUST match both 32 | # on the transmitter and receiver (or be set to None to disable/the default). 33 | rfm69.encryption_key = b"\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08" 34 | 35 | # set delay before sending ACK 36 | rfm69.ack_delay = 0.1 37 | # set node addresses 38 | rfm69.node = 1 39 | rfm69.destination = 2 40 | # initialize counter 41 | counter = 0 42 | ack_failed_counter = 0 43 | # send startup message from my_node 44 | rfm69.send_with_ack(bytes(f"startup message from node {rfm69.node}", "UTF-8")) 45 | 46 | # Wait to receive packets. 47 | print("Waiting for packets...") 48 | # initialize flag and timer 49 | time_now = time.monotonic() 50 | while True: 51 | # Look for a new packet: only accept if addresses to my_node 52 | packet = rfm69.receive(with_ack=True, with_header=True) 53 | # If no packet was received during the timeout then None is returned. 54 | if packet is not None: 55 | # Received a packet! 56 | # Print out the raw bytes of the packet: 57 | print("Received (raw header):", [hex(x) for x in packet[0:4]]) 58 | print(f"Received (raw payload): {packet[4:]}") 59 | print(f"RSSI: {rfm69.last_rssi}") 60 | # send reading after any packet received 61 | if time.monotonic() - time_now > transmit_interval: 62 | # reset timeer 63 | time_now = time.monotonic() 64 | counter += 1 65 | # send a mesage to destination_node from my_node 66 | if not rfm69.send_with_ack( 67 | bytes(f"message from node node {rfm69.node} {counter}", "UTF-8") 68 | ): 69 | ack_failed_counter += 1 70 | print(" No Ack: ", counter, ack_failed_counter) 71 | -------------------------------------------------------------------------------- /examples/rfm69_node1_bonnet.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020 Jerry Needell for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | # Example to send a packet periodically between addressed nodes 5 | 6 | # Import the SSD1306 module. 7 | import adafruit_ssd1306 8 | import board 9 | import busio 10 | import digitalio 11 | 12 | import adafruit_rfm69 13 | 14 | # Button A 15 | btnA = digitalio.DigitalInOut(board.D5) 16 | btnA.direction = digitalio.Direction.INPUT 17 | btnA.pull = digitalio.Pull.UP 18 | 19 | # Button B 20 | btnB = digitalio.DigitalInOut(board.D6) 21 | btnB.direction = digitalio.Direction.INPUT 22 | btnB.pull = digitalio.Pull.UP 23 | 24 | # Button C 25 | btnC = digitalio.DigitalInOut(board.D12) 26 | btnC.direction = digitalio.Direction.INPUT 27 | btnC.pull = digitalio.Pull.UP 28 | 29 | # Create the I2C interface. 30 | i2c = busio.I2C(board.SCL, board.SDA) 31 | 32 | # 128x32 OLED Display 33 | reset_pin = digitalio.DigitalInOut(board.D4) 34 | display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, reset=reset_pin) 35 | # Clear the display. 36 | display.fill(0) 37 | display.show() 38 | width = display.width 39 | height = display.height 40 | 41 | 42 | # set the time interval (seconds) for sending packets 43 | transmit_interval = 10 44 | 45 | # Define radio parameters. 46 | RADIO_FREQ_MHZ = 915.0 # Frequency of the radio in Mhz. Must match your 47 | # module! Can be a value like 915.0, 433.0, etc. 48 | 49 | # Define pins connected to the chip. 50 | CS = digitalio.DigitalInOut(board.CE1) 51 | RESET = digitalio.DigitalInOut(board.D25) 52 | 53 | # Initialize SPI bus. 54 | spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) 55 | 56 | # Initialze RFM radio 57 | 58 | # Attempt to set up the RFM69 Module 59 | try: 60 | rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, RADIO_FREQ_MHZ) 61 | display.text("RFM69: Detected", 0, 0, 1) 62 | except RuntimeError: 63 | # Thrown on version mismatch 64 | display.text("RFM69: ERROR", 0, 0, 1) 65 | 66 | display.show() 67 | 68 | 69 | # Optionally set an encryption key (16 byte AES key). MUST match both 70 | # on the transmitter and receiver (or be set to None to disable/the default). 71 | rfm69.encryption_key = b"\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08" 72 | 73 | # set node addresses 74 | rfm69.node = 1 75 | rfm69.destination = 2 76 | # initialize counter 77 | counter = 0 78 | # send a broadcast message from my_node with ID = counter 79 | rfm69.send(bytes(f"Startup message {counter} from node {rfm69.node}", "UTF-8")) 80 | 81 | # Wait to receive packets. 82 | print("Waiting for packets...") 83 | button_pressed = None 84 | while True: 85 | # Look for a new packet: only accept if addresses to my_node 86 | packet = rfm69.receive(with_header=True) 87 | # If no packet was received during the timeout then None is returned. 88 | if packet is not None: 89 | # Received a packet! 90 | # Print out the raw bytes of the packet: 91 | print("Received (raw header):", [hex(x) for x in packet[0:4]]) 92 | print(f"Received (raw payload): {packet[4:]}") 93 | print(f"Received RSSI: {rfm69.last_rssi}") 94 | # Check buttons 95 | if not btnA.value: 96 | button_pressed = "A" 97 | # Button A Pressed 98 | display.fill(0) 99 | display.text("AAA", width - 85, height - 7, 1) 100 | display.show() 101 | if not btnB.value: 102 | button_pressed = "B" 103 | # Button B Pressed 104 | display.fill(0) 105 | display.text("BBB", width - 75, height - 7, 1) 106 | display.show() 107 | if not btnC.value: 108 | button_pressed = "C" 109 | # Button C Pressed 110 | display.fill(0) 111 | display.text("CCC", width - 65, height - 7, 1) 112 | display.show() 113 | # send reading after any button pressed 114 | if button_pressed is not None: 115 | counter = counter + 1 116 | # send a mesage to destination_node from my_node 117 | rfm69.send( 118 | bytes( 119 | f"message number {counter} from node {rfm69.node} button {button_pressed}", 120 | "UTF-8", 121 | ), 122 | keep_listening=True, 123 | ) 124 | button_pressed = None 125 | -------------------------------------------------------------------------------- /examples/rfm69_node2.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020 Jerry Needell for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | # Example to send a packet periodically between addressed nodes 5 | 6 | import time 7 | 8 | import board 9 | import busio 10 | import digitalio 11 | 12 | import adafruit_rfm69 13 | 14 | # Define radio parameters. 15 | RADIO_FREQ_MHZ = 915.0 # Frequency of the radio in Mhz. Must match your 16 | # module! Can be a value like 915.0, 433.0, etc. 17 | 18 | # Define pins connected to the chip. 19 | CS = digitalio.DigitalInOut(board.CE1) 20 | RESET = digitalio.DigitalInOut(board.D25) 21 | 22 | # Initialize SPI bus. 23 | spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) 24 | 25 | # Initialze RFM radio 26 | rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, RADIO_FREQ_MHZ) 27 | 28 | # Optionally set an encryption key (16 byte AES key). MUST match both 29 | # on the transmitter and receiver (or be set to None to disable/the default). 30 | rfm69.encryption_key = b"\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08" 31 | 32 | # set node addresses 33 | rfm69.node = 2 34 | rfm69.destination = 1 35 | # initialize counter 36 | counter = 0 37 | # send a broadcast message from my_node with ID = counter 38 | rfm69.send(bytes(f"startup message from node {rfm69.node} ", "UTF-8")) 39 | 40 | # Wait to receive packets. 41 | print("Waiting for packets...") 42 | # initialize flag and timer 43 | time_now = time.monotonic() 44 | while True: 45 | # Look for a new packet: only accept if addresses to my_node 46 | packet = rfm69.receive(with_header=True) 47 | # If no packet was received during the timeout then None is returned. 48 | if packet is not None: 49 | # Received a packet! 50 | # Print out the raw bytes of the packet: 51 | print("Received (raw header):", [hex(x) for x in packet[0:4]]) 52 | print(f"Received (raw payload): {packet[4:]}") 53 | print(f"Received RSSI: {rfm69.last_rssi}") 54 | # send reading after any packet received 55 | counter = counter + 1 56 | # after 10 messages send a response to destination_node from my_node with ID = counter&0xff 57 | if counter % 10 == 0: 58 | time.sleep(0.5) # brief delay before responding 59 | rfm69.identifier = counter & 0xFF 60 | rfm69.send( 61 | bytes( 62 | f"message number {counter} from node {rfm69.node} ", 63 | "UTF-8", 64 | ), 65 | keep_listening=True, 66 | ) 67 | -------------------------------------------------------------------------------- /examples/rfm69_node2_ack.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020 Jerry Needell for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | # Example to receive addressed packed with ACK and send a response 5 | 6 | import time 7 | 8 | import board 9 | import busio 10 | import digitalio 11 | 12 | import adafruit_rfm69 13 | 14 | # Define radio parameters. 15 | RADIO_FREQ_MHZ = 915.0 # Frequency of the radio in Mhz. Must match your 16 | # module! Can be a value like 915.0, 433.0, etc. 17 | 18 | # Define pins connected to the chip. 19 | # set GPIO pins as necessary - this example is for Raspberry Pi 20 | CS = digitalio.DigitalInOut(board.CE1) 21 | RESET = digitalio.DigitalInOut(board.D25) 22 | 23 | # Initialize SPI bus. 24 | spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) 25 | # Initialze RFM radio 26 | rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, RADIO_FREQ_MHZ) 27 | 28 | # Optionally set an encryption key (16 byte AES key). MUST match both 29 | # on the transmitter and receiver (or be set to None to disable/the default). 30 | rfm69.encryption_key = b"\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08" 31 | 32 | # set delay before transmitting ACK (seconds) 33 | rfm69.ack_delay = 0.1 34 | # set node addresses 35 | rfm69.node = 2 36 | rfm69.destination = 1 37 | # initialize counter 38 | counter = 0 39 | ack_failed_counter = 0 40 | 41 | # Wait to receive packets. 42 | print("Waiting for packets...") 43 | while True: 44 | # Look for a new packet: only accept if addresses to my_node 45 | packet = rfm69.receive(with_ack=True, with_header=True) 46 | # If no packet was received during the timeout then None is returned. 47 | if packet is not None: 48 | # Received a packet! 49 | # Print out the raw bytes of the packet: 50 | print("Received (raw header):", [hex(x) for x in packet[0:4]]) 51 | print(f"Received (raw payload): {packet[4:]}") 52 | print(f"RSSI: {rfm69.last_rssi}") 53 | # send response 2 sec after any packet received 54 | time.sleep(2) 55 | counter += 1 56 | # send a mesage to destination_node from my_node 57 | if not rfm69.send_with_ack(bytes(f"response from node {rfm69.node} {counter}", "UTF-8")): 58 | ack_failed_counter += 1 59 | print(" No Ack: ", counter, ack_failed_counter) 60 | -------------------------------------------------------------------------------- /examples/rfm69_rpi_interrupt.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020 Tony DiCola, Jerry Needell for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | # Example using Interrupts to send a message and then wait indefinitely for messages 5 | # to be received. Interrupts are used only for receive. sending is done with polling. 6 | # This example is for systems that support interrupts like the Raspberry Pi with "blinka" 7 | # CircuitPython does not support interrupts so it will not work on Circutpython boards 8 | import time 9 | 10 | import board 11 | import busio 12 | import digitalio 13 | import RPi.GPIO as io 14 | 15 | import adafruit_rfm69 16 | 17 | 18 | # setup interrupt callback function 19 | def rfm69_callback(rfm69_irq): 20 | global packet_received # noqa: PLW0603 21 | print(f"IRQ detected on pin {rfm69_irq} payload_ready {rfm69.payload_ready} ") 22 | # see if this was a payload_ready interrupt ignore if not 23 | if rfm69.payload_ready: 24 | packet = rfm69.receive(timeout=None) 25 | if packet is not None: 26 | # Received a packet! 27 | packet_received = True 28 | # Print out the raw bytes of the packet: 29 | print(f"Received (raw bytes): {packet}") 30 | print([hex(x) for x in packet]) 31 | print(f"RSSI: {rfm69.last_rssi}") 32 | 33 | 34 | # Define radio parameters. 35 | RADIO_FREQ_MHZ = 915.0 # Frequency of the radio in Mhz. Must match your 36 | # module! Can be a value like 915.0, 433.0, etc. 37 | 38 | # Define pins connected to the chip, use these if wiring up the breakout according to the guide: 39 | CS = digitalio.DigitalInOut(board.CE1) 40 | RESET = digitalio.DigitalInOut(board.D25) 41 | 42 | # Initialize SPI bus. 43 | spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) 44 | 45 | # Initialze RFM radio 46 | rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, RADIO_FREQ_MHZ) 47 | 48 | # Optionally set an encryption key (16 byte AES key). MUST match both 49 | # on the transmitter and receiver (or be set to None to disable/the default). 50 | rfm69.encryption_key = b"\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08" 51 | 52 | # Print out some chip state: 53 | print(f"Temperature: {rfm69.temperature}C") 54 | print(f"Frequency: {rfm69.frequency_mhz}mhz") 55 | print(f"Bit rate: {rfm69.bitrate / 1000}kbit/s") 56 | print(f"Frequency deviation: {rfm69.frequency_deviation}hz") 57 | 58 | # configure the interrupt pin and event handling. 59 | RFM69_G0 = 22 60 | io.setmode(io.BCM) 61 | io.setup(RFM69_G0, io.IN, pull_up_down=io.PUD_DOWN) # activate input 62 | io.add_event_detect(RFM69_G0, io.RISING) 63 | io.add_event_callback(RFM69_G0, rfm69_callback) 64 | packet_received = False 65 | 66 | # Send a packet. Note you can only send a packet up to 60 bytes in length. 67 | # This is a limitation of the radio packet size, so if you need to send larger 68 | # amounts of data you will need to break it into smaller send calls. Each send 69 | # call will wait for the previous one to finish before continuing. 70 | rfm69.send(bytes("Hello world!\r\n", "utf-8"), keep_listening=True) 71 | print("Sent hello world message!") 72 | # If you don't wawnt to send a message to start you can just start lintening 73 | # rmf69.listen() 74 | 75 | # Wait to receive packets. Note that this library can't receive data at a fast 76 | # rate, in fact it can only receive and process one 60 byte packet at a time. 77 | # This means you should only use this for low bandwidth scenarios, like sending 78 | # and receiving a single message at a time. 79 | print("Waiting for packets...") 80 | 81 | # the loop is where you can do any desire processing 82 | # the global variable packet_received can be used to determine if a packet was received. 83 | while True: 84 | # the sleep time is arbitrary since any incomming packe will trigger an interrupt 85 | # and be received. 86 | time.sleep(0.1) 87 | if packet_received: 88 | print("received message!") 89 | packet_received = False 90 | -------------------------------------------------------------------------------- /examples/rfm69_rpi_simpletest.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2018 Tony DiCola for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | # Simple example to send a message and then wait indefinitely for messages 5 | # to be received. This uses the default RadioHead compatible GFSK_Rb250_Fd250 6 | # modulation and packet format for the radio. 7 | 8 | import board 9 | import busio 10 | import digitalio 11 | 12 | import adafruit_rfm69 13 | 14 | # Define radio parameters. 15 | RADIO_FREQ_MHZ = 915.0 # Frequency of the radio in Mhz. Must match your 16 | # module! Can be a value like 915.0, 433.0, etc. 17 | 18 | # Define pins connected to the chip, use these if wiring up the breakout according to the guide: 19 | CS = digitalio.DigitalInOut(board.CE1) 20 | RESET = digitalio.DigitalInOut(board.D25) 21 | # Or uncomment and instead use these if using a Feather M0 RFM69 board 22 | # and the appropriate CircuitPython build: 23 | # CS = digitalio.DigitalInOut(board.RFM69_CS) 24 | # RESET = digitalio.DigitalInOut(board.RFM69_RST) 25 | 26 | 27 | # Initialize SPI bus. 28 | spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) 29 | 30 | # Initialze RFM radio 31 | rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, RADIO_FREQ_MHZ) 32 | 33 | # Optionally set an encryption key (16 byte AES key). MUST match both 34 | # on the transmitter and receiver (or be set to None to disable/the default). 35 | rfm69.encryption_key = b"\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08" 36 | 37 | # Print out some chip state: 38 | print(f"Temperature: {rfm69.temperature}C") 39 | print(f"Frequency: {rfm69.frequency_mhz}mhz") 40 | print(f"Bit rate: {rfm69.bitrate / 1000}kbit/s") 41 | print(f"Frequency deviation: {rfm69.frequency_deviation}hz") 42 | 43 | # Send a packet. Note you can only send a packet up to 60 bytes in length. 44 | # This is a limitation of the radio packet size, so if you need to send larger 45 | # amounts of data you will need to break it into smaller send calls. Each send 46 | # call will wait for the previous one to finish before continuing. 47 | rfm69.send(bytes("Hello world!\r\n", "utf-8")) 48 | print("Sent hello world message!") 49 | 50 | # Wait to receive packets. Note that this library can't receive data at a fast 51 | # rate, in fact it can only receive and process one 60 byte packet at a time. 52 | # This means you should only use this for low bandwidth scenarios, like sending 53 | # and receiving a single message at a time. 54 | print("Waiting for packets...") 55 | while True: 56 | packet = rfm69.receive() 57 | # Optionally change the receive timeout from its default of 0.5 seconds: 58 | # packet = rfm69.receive(timeout=5.0) 59 | # If no packet was received during the timeout then None is returned. 60 | if packet is None: 61 | # Packet has not been received 62 | print("Received nothing! Listening again...") 63 | else: 64 | # Received a packet! 65 | # Print out the raw bytes of the packet: 66 | print(f"Received (raw bytes): {packet}") 67 | # And decode to ASCII text and print it too. Note that you always 68 | # receive raw bytes and need to convert to a text format like ASCII 69 | # if you intend to do string processing on your data. Make sure the 70 | # sending side is sending ASCII data before you try to decode! 71 | packet_text = str(packet, "ascii") 72 | print(f"Received (ASCII): {packet_text}") 73 | -------------------------------------------------------------------------------- /examples/rfm69_simpletest.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2018 Tony DiCola for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | # Simple example to send a message and then wait indefinitely for messages 5 | # to be received. This uses the default RadioHead compatible GFSK_Rb250_Fd250 6 | # modulation and packet format for the radio. 7 | import board 8 | import busio 9 | import digitalio 10 | 11 | import adafruit_rfm69 12 | 13 | # Define radio parameters. 14 | RADIO_FREQ_MHZ = 915.0 # Frequency of the radio in Mhz. Must match your 15 | # module! Can be a value like 915.0, 433.0, etc. 16 | 17 | # Define pins connected to the chip, use these if wiring up the breakout according to the guide: 18 | CS = digitalio.DigitalInOut(board.D5) 19 | RESET = digitalio.DigitalInOut(board.D6) 20 | # Or uncomment and instead use these if using a Feather M0 RFM69 board 21 | # and the appropriate CircuitPython build: 22 | # CS = digitalio.DigitalInOut(board.RFM69_CS) 23 | # RESET = digitalio.DigitalInOut(board.RFM69_RST) 24 | 25 | # Define the onboard LED 26 | LED = digitalio.DigitalInOut(board.D13) 27 | LED.direction = digitalio.Direction.OUTPUT 28 | 29 | # Initialize SPI bus. 30 | spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) 31 | 32 | # Initialze RFM radio 33 | rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, RADIO_FREQ_MHZ) 34 | 35 | # Optionally set an encryption key (16 byte AES key). MUST match both 36 | # on the transmitter and receiver (or be set to None to disable/the default). 37 | rfm69.encryption_key = b"\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08" 38 | 39 | # Print out some chip state: 40 | print(f"Temperature: {rfm69.temperature}C") 41 | print(f"Frequency: {rfm69.frequency_mhz}mhz") 42 | print(f"Bit rate: {rfm69.bitrate / 1000}kbit/s") 43 | print(f"Frequency deviation: {rfm69.frequency_deviation}hz") 44 | 45 | # Send a packet. Note you can only send a packet up to 60 bytes in length. 46 | # This is a limitation of the radio packet size, so if you need to send larger 47 | # amounts of data you will need to break it into smaller send calls. Each send 48 | # call will wait for the previous one to finish before continuing. 49 | rfm69.send(bytes("Hello world!\r\n", "utf-8")) 50 | print("Sent hello world message!") 51 | 52 | # Wait to receive packets. Note that this library can't receive data at a fast 53 | # rate, in fact it can only receive and process one 60 byte packet at a time. 54 | # This means you should only use this for low bandwidth scenarios, like sending 55 | # and receiving a single message at a time. 56 | print("Waiting for packets...") 57 | while True: 58 | packet = rfm69.receive() 59 | # Optionally change the receive timeout from its default of 0.5 seconds: 60 | # packet = rfm69.receive(timeout=5.0) 61 | # If no packet was received during the timeout then None is returned. 62 | if packet is None: 63 | # Packet has not been received 64 | LED.value = False 65 | print("Received nothing! Listening again...") 66 | else: 67 | # Received a packet! 68 | LED.value = True 69 | # Print out the raw bytes of the packet: 70 | print(f"Received (raw bytes): {packet}") 71 | # And decode to ASCII text and print it too. Note that you always 72 | # receive raw bytes and need to convert to a text format like ASCII 73 | # if you intend to do string processing on your data. Make sure the 74 | # sending side is sending ASCII data before you try to decode! 75 | packet_text = str(packet, "ascii") 76 | print(f"Received (ASCII): {packet_text}") 77 | -------------------------------------------------------------------------------- /examples/rfm69_transmit.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020 Jerry Needell for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | # Example to send a packet periodically 5 | 6 | import time 7 | 8 | import board 9 | import busio 10 | import digitalio 11 | 12 | import adafruit_rfm69 13 | 14 | # set the time interval (seconds) for sending packets 15 | transmit_interval = 10 16 | 17 | # Define radio parameters. 18 | RADIO_FREQ_MHZ = 915.0 # Frequency of the radio in Mhz. Must match your 19 | # module! Can be a value like 915.0, 433.0, etc. 20 | 21 | # Define pins connected to the chip. 22 | CS = digitalio.DigitalInOut(board.CE1) 23 | RESET = digitalio.DigitalInOut(board.D25) 24 | 25 | # Initialize SPI bus. 26 | spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) 27 | 28 | # Initialze RFM radio 29 | rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, RADIO_FREQ_MHZ) 30 | 31 | # Optionally set an encryption key (16 byte AES key). MUST match both 32 | # on the transmitter and receiver (or be set to None to disable/the default). 33 | rfm69.encryption_key = b"\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08" 34 | 35 | # initialize counter 36 | counter = 0 37 | # send a broadcast mesage 38 | rfm69.send(bytes(f"message number {counter}", "UTF-8")) 39 | 40 | # Wait to receive packets. 41 | print("Waiting for packets...") 42 | # initialize flag and timer 43 | send_reading = False 44 | time_now = time.monotonic() 45 | while True: 46 | # Look for a new packet - wait up to 5 seconds: 47 | packet = rfm69.receive(timeout=5.0) 48 | # If no packet was received during the timeout then None is returned. 49 | if packet is not None: 50 | # Received a packet! 51 | # Print out the raw bytes of the packet: 52 | print(f"Received (raw bytes): {packet}") 53 | # send reading after any packet received 54 | if time.monotonic() - time_now > transmit_interval: 55 | # reset timeer 56 | time_now = time.monotonic() 57 | # clear flag to send data 58 | send_reading = False 59 | counter = counter + 1 60 | rfm69.send(bytes(f"message number {counter}", "UTF-8")) 61 | -------------------------------------------------------------------------------- /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-rfm69" 14 | description = "CircuitPython library for RFM69 packet radio." 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_RFM69"} 21 | keywords = [ 22 | "adafruit", 23 | "rfm69", 24 | "packet", 25 | "radio", 26 | "hardware", 27 | "micropython", 28 | "circuitpython", 29 | ] 30 | license = {text = "MIT"} 31 | classifiers = [ 32 | "Intended Audience :: Developers", 33 | "Topic :: Software Development :: Libraries", 34 | "Topic :: Software Development :: Embedded Systems", 35 | "Topic :: System :: Hardware", 36 | "License :: OSI Approved :: MIT License", 37 | "Programming Language :: Python :: 3", 38 | ] 39 | dynamic = ["dependencies", "optional-dependencies"] 40 | 41 | [tool.setuptools] 42 | py-modules = ["adafruit_rfm69"] 43 | 44 | [tool.setuptools.dynamic] 45 | dependencies = {file = ["requirements.txt"]} 46 | optional-dependencies = {optional = {file = ["optional_requirements.txt"]}} 47 | -------------------------------------------------------------------------------- /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 | adafruit-circuitpython-typing 8 | -------------------------------------------------------------------------------- /ruff.toml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | target-version = "py38" 6 | line-length = 100 7 | 8 | [lint] 9 | preview = true 10 | select = ["I", "PL", "UP"] 11 | 12 | extend-select = [ 13 | "D419", # empty-docstring 14 | "E501", # line-too-long 15 | "W291", # trailing-whitespace 16 | "PLC0414", # useless-import-alias 17 | "PLC2401", # non-ascii-name 18 | "PLC2801", # unnecessary-dunder-call 19 | "PLC3002", # unnecessary-direct-lambda-call 20 | "E999", # syntax-error 21 | "PLE0101", # return-in-init 22 | "F706", # return-outside-function 23 | "F704", # yield-outside-function 24 | "PLE0116", # continue-in-finally 25 | "PLE0117", # nonlocal-without-binding 26 | "PLE0241", # duplicate-bases 27 | "PLE0302", # unexpected-special-method-signature 28 | "PLE0604", # invalid-all-object 29 | "PLE0605", # invalid-all-format 30 | "PLE0643", # potential-index-error 31 | "PLE0704", # misplaced-bare-raise 32 | "PLE1141", # dict-iter-missing-items 33 | "PLE1142", # await-outside-async 34 | "PLE1205", # logging-too-many-args 35 | "PLE1206", # logging-too-few-args 36 | "PLE1307", # bad-string-format-type 37 | "PLE1310", # bad-str-strip-call 38 | "PLE1507", # invalid-envvar-value 39 | "PLE2502", # bidirectional-unicode 40 | "PLE2510", # invalid-character-backspace 41 | "PLE2512", # invalid-character-sub 42 | "PLE2513", # invalid-character-esc 43 | "PLE2514", # invalid-character-nul 44 | "PLE2515", # invalid-character-zero-width-space 45 | "PLR0124", # comparison-with-itself 46 | "PLR0202", # no-classmethod-decorator 47 | "PLR0203", # no-staticmethod-decorator 48 | "UP004", # useless-object-inheritance 49 | "PLR0206", # property-with-parameters 50 | "PLR0904", # too-many-public-methods 51 | "PLR0911", # too-many-return-statements 52 | "PLR0912", # too-many-branches 53 | "PLR0913", # too-many-arguments 54 | "PLR0914", # too-many-locals 55 | "PLR0915", # too-many-statements 56 | "PLR0916", # too-many-boolean-expressions 57 | "PLR1702", # too-many-nested-blocks 58 | "PLR1704", # redefined-argument-from-local 59 | "PLR1711", # useless-return 60 | "C416", # unnecessary-comprehension 61 | "PLR1733", # unnecessary-dict-index-lookup 62 | "PLR1736", # unnecessary-list-index-lookup 63 | 64 | # ruff reports this rule is unstable 65 | #"PLR6301", # no-self-use 66 | 67 | "PLW0108", # unnecessary-lambda 68 | "PLW0120", # useless-else-on-loop 69 | "PLW0127", # self-assigning-variable 70 | "PLW0129", # assert-on-string-literal 71 | "B033", # duplicate-value 72 | "PLW0131", # named-expr-without-context 73 | "PLW0245", # super-without-brackets 74 | "PLW0406", # import-self 75 | "PLW0602", # global-variable-not-assigned 76 | "PLW0603", # global-statement 77 | "PLW0604", # global-at-module-level 78 | 79 | # fails on the try: import typing used by libraries 80 | #"F401", # unused-import 81 | 82 | "F841", # unused-variable 83 | "E722", # bare-except 84 | "PLW0711", # binary-op-exception 85 | "PLW1501", # bad-open-mode 86 | "PLW1508", # invalid-envvar-default 87 | "PLW1509", # subprocess-popen-preexec-fn 88 | "PLW2101", # useless-with-lock 89 | "PLW3301", # nested-min-max 90 | ] 91 | 92 | ignore = [ 93 | "PLR2004", # magic-value-comparison 94 | "UP030", # format literals 95 | "PLW1514", # unspecified-encoding 96 | "PLR0913", # too-many-arguments 97 | "PLR0915", # too-many-statements 98 | "PLR0917", # too-many-positional-arguments 99 | "PLR0904", # too-many-public-methods 100 | "PLR0912", # too-many-branches 101 | "PLR0916", # too-many-boolean-expressions 102 | ] 103 | 104 | [format] 105 | line-ending = "lf" 106 | --------------------------------------------------------------------------------