├── .codespellrc ├── .github ├── dependabot.yml └── workflows │ ├── check-arduino.yml │ ├── compile-examples.yml │ ├── report-size-deltas.yml │ ├── spell-check.yml │ └── sync-labels.yml ├── .gitignore ├── LICENSE.txt ├── README.adoc ├── examples ├── BLE Connectivity on Portenta H7 │ └── PortentaBLE │ │ └── PortentaBLE.ino ├── Creating GUIs with LVGL │ └── lvglCounter │ │ └── lvglCounter.ino ├── Creating a Flash-Optimised Key-Value Store │ └── FlashKeyValue │ │ ├── FlashIAPLimits.h │ │ └── FlashKeyValue.ino ├── Dual Core Processing │ ├── BlinkBothCores │ │ └── BlinkBothCores.ino │ ├── BlinkGreenLed_M4 │ │ └── BlinkGreenLed_M4.ino │ ├── BlinkRedLed │ │ └── BlinkRedLed.ino │ └── BlinkRedLed_M7 │ │ └── BlinkRedLed_M7.ino ├── Edge Control Getting Started │ └── EdgeControl │ │ └── EdgeControl.ino ├── Portenta H7 as a USB Host │ └── LEDKeyboardController │ │ └── LEDKeyboardController.ino ├── Portenta H7 as a WiFi Access Point │ └── SimpleWebServer │ │ ├── SimpleWebServer.ino │ │ └── arduino_secrets.h ├── Setting Up Portenta H7 For Arduino │ └── Blink │ │ └── Blink.ino └── Vision Shield to SD Card bmp │ └── visionShieldBitmap │ └── visionShieldBitmap.ino ├── library.properties └── src └── Arduino_Pro_Tutorials.h /.codespellrc: -------------------------------------------------------------------------------- 1 | # See: https://github.com/codespell-project/codespell#using-a-config-file 2 | [codespell] 3 | # In the event of a false positive, add the problematic word, in all lowercase, to a comma-separated list here: 4 | ignore-words-list = trun 5 | check-filenames = 6 | check-hidden = 7 | skip = ./.git 8 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # See: https://docs.github.com/en/github/administering-a-repository/configuration-options-for-dependency-updates#about-the-dependabotyml-file 2 | version: 2 3 | 4 | updates: 5 | # Configure check for outdated GitHub Actions actions in workflows. 6 | # See: https://docs.github.com/en/github/administering-a-repository/keeping-your-actions-up-to-date-with-dependabot 7 | - package-ecosystem: github-actions 8 | directory: / # Check the repository's workflows under /.github/workflows/ 9 | schedule: 10 | interval: daily 11 | labels: 12 | - "topic: infrastructure" 13 | -------------------------------------------------------------------------------- /.github/workflows/check-arduino.yml: -------------------------------------------------------------------------------- 1 | name: Check Arduino 2 | 3 | # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows 4 | on: 5 | push: 6 | pull_request: 7 | schedule: 8 | # Run every Tuesday at 8 AM UTC to catch breakage caused by new rules added to Arduino Lint. 9 | - cron: "0 8 * * TUE" 10 | workflow_dispatch: 11 | repository_dispatch: 12 | 13 | jobs: 14 | lint: 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - name: Checkout repository 19 | uses: actions/checkout@v4 20 | 21 | - name: Arduino Lint 22 | uses: arduino/arduino-lint-action@v2 23 | with: 24 | compliance: specification 25 | library-manager: update 26 | # Always use this setting for official repositories. Remove for 3rd party projects. 27 | official: true 28 | project-type: library 29 | -------------------------------------------------------------------------------- /.github/workflows/compile-examples.yml: -------------------------------------------------------------------------------- 1 | name: Compile Examples 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - ".github/workflows/compile-examples.yml" 7 | - "library.properties" 8 | - "examples/**" 9 | 10 | push: 11 | paths: 12 | - ".github/workflows/compile-examples.yml" 13 | - "library.properties" 14 | - "examples/**" 15 | 16 | # Scheduled trigger checks for breakage caused by changes to external resources (libraries, platforms) 17 | schedule: 18 | # run every Saturday at 3 AM UTC 19 | - cron: "0 3 * * 6" 20 | # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#workflow_dispatch 21 | workflow_dispatch: 22 | # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#repository_dispatch 23 | repository_dispatch: 24 | 25 | jobs: 26 | build: 27 | name: ${{ matrix.board.fqbn }} 28 | runs-on: ubuntu-latest 29 | 30 | env: 31 | SKETCHES_REPORTS_PATH: sketches-reports 32 | 33 | strategy: 34 | fail-fast: false 35 | 36 | matrix: 37 | board: 38 | - fqbn: arduino:mbed_portenta:envie_m7 39 | sketch-paths: | 40 | - examples/BLE Connectivity on Portenta H7/PortentaBLE 41 | - examples/Creating a Flash-Optimised Key-Value Store/FlashKeyValue 42 | - examples/Creating GUIs with LVGL/lvglCounter 43 | - examples/Dual Core Processing/BlinkRedLed 44 | - examples/Dual Core Processing/BlinkRedLed_M7 45 | - examples/Portenta H7 as a USB Host/LEDKeyboardController 46 | - examples/Portenta H7 as a WiFi Access Point/SimpleWebServer 47 | - examples/Setting Up Portenta H7 For Arduino/Blink 48 | - examples/Vision Shield to SD Card bmp/visionShieldBitmap 49 | artifact-name-suffix: arduino-mbed_portenta-envie_m7 50 | 51 | - fqbn: arduino:mbed_portenta:envie_m7:target_core=cm4 52 | sketch-paths: | 53 | - examples/Dual Core Processing/BlinkGreenLed_M4 54 | artifact-name-suffix: arduino-mbed_portenta-envie_m7-target_core-cm4 55 | 56 | - fqbn: arduino:mbed_edge:edge_control 57 | sketch-paths: | 58 | - examples/Edge Control Getting Started 59 | artifact-name-suffix: arduino-mbed_edge-edge_control 60 | 61 | steps: 62 | - name: Checkout 63 | uses: actions/checkout@v4 64 | 65 | - name: Compile examples 66 | uses: arduino/compile-sketches@v1 67 | with: 68 | github-token: ${{ secrets.GITHUB_TOKEN }} 69 | fqbn: ${{ matrix.board.fqbn }} 70 | libraries: | 71 | # Install the library from the local path. 72 | - source-path: ./ 73 | # Install library dependencies. 74 | - name: ArduinoBLE 75 | - name: Arduino_EdgeControl 76 | - name: lvgl 77 | version: 7.11.0 78 | - name: Arduino_BHY2 79 | 80 | sketch-paths: | 81 | # Sketches to compile for all boards 82 | - examples/Dual Core Processing/BlinkBothCores 83 | # Board-specific sketches 84 | ${{ matrix.board.sketch-paths }} 85 | enable-deltas-report: true 86 | sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }} 87 | 88 | - name: Save memory usage change report as artifact 89 | uses: actions/upload-artifact@v4 90 | with: 91 | if-no-files-found: error 92 | name: sketches-report-${{ matrix.board.artifact-name-suffix }} 93 | path: ${{ env.SKETCHES_REPORTS_PATH }} 94 | -------------------------------------------------------------------------------- /.github/workflows/report-size-deltas.yml: -------------------------------------------------------------------------------- 1 | name: Report Size Deltas 2 | 3 | # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows 4 | on: 5 | push: 6 | paths: 7 | - ".github/workflows/report-size-deltas.yml" 8 | schedule: 9 | # Run at the minimum interval allowed by GitHub Actions. 10 | # Note: GitHub Actions periodically has outages which result in workflow failures. 11 | # In this event, the workflows will start passing again once the service recovers. 12 | - cron: "*/5 * * * *" 13 | workflow_dispatch: 14 | repository_dispatch: 15 | 16 | jobs: 17 | report: 18 | runs-on: ubuntu-latest 19 | steps: 20 | - name: Comment size deltas reports to PRs 21 | uses: arduino/report-size-deltas@v1 22 | with: 23 | # Regex matching the names of the workflow artifacts created by the "Compile Examples" workflow 24 | sketches-reports-source: ^sketches-report-.+ 25 | -------------------------------------------------------------------------------- /.github/workflows/spell-check.yml: -------------------------------------------------------------------------------- 1 | name: Spell Check 2 | 3 | # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows 4 | on: 5 | push: 6 | pull_request: 7 | schedule: 8 | # Run every Tuesday at 8 AM UTC to catch new misspelling detections resulting from dictionary updates. 9 | - cron: "0 8 * * TUE" 10 | workflow_dispatch: 11 | repository_dispatch: 12 | 13 | jobs: 14 | spellcheck: 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - name: Checkout repository 19 | uses: actions/checkout@v4 20 | 21 | - name: Spell check 22 | uses: codespell-project/actions-codespell@master 23 | -------------------------------------------------------------------------------- /.github/workflows/sync-labels.yml: -------------------------------------------------------------------------------- 1 | # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/sync-labels.md 2 | name: Sync Labels 3 | 4 | # See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows 5 | on: 6 | push: 7 | paths: 8 | - ".github/workflows/sync-labels.ya?ml" 9 | - ".github/label-configuration-files/*.ya?ml" 10 | pull_request: 11 | paths: 12 | - ".github/workflows/sync-labels.ya?ml" 13 | - ".github/label-configuration-files/*.ya?ml" 14 | schedule: 15 | # Run daily at 8 AM UTC to sync with changes to shared label configurations. 16 | - cron: "0 8 * * *" 17 | workflow_dispatch: 18 | repository_dispatch: 19 | 20 | env: 21 | CONFIGURATIONS_FOLDER: .github/label-configuration-files 22 | CONFIGURATIONS_ARTIFACT: label-configuration-files 23 | 24 | jobs: 25 | check: 26 | runs-on: ubuntu-latest 27 | 28 | steps: 29 | - name: Checkout repository 30 | uses: actions/checkout@v4 31 | 32 | - name: Download JSON schema for labels configuration file 33 | id: download-schema 34 | uses: carlosperate/download-file-action@v2 35 | with: 36 | file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/arduino-tooling-gh-label-configuration-schema.json 37 | location: ${{ runner.temp }}/label-configuration-schema 38 | 39 | - name: Install JSON schema validator 40 | run: | 41 | sudo npm install \ 42 | --global \ 43 | ajv-cli \ 44 | ajv-formats 45 | 46 | - name: Validate local labels configuration 47 | run: | 48 | # See: https://github.com/ajv-validator/ajv-cli#readme 49 | ajv validate \ 50 | --all-errors \ 51 | -c ajv-formats \ 52 | -s "${{ steps.download-schema.outputs.file-path }}" \ 53 | -d "${{ env.CONFIGURATIONS_FOLDER }}/*.{yml,yaml}" 54 | 55 | download: 56 | needs: check 57 | runs-on: ubuntu-latest 58 | 59 | strategy: 60 | matrix: 61 | filename: 62 | # Filenames of the shared configurations to apply to the repository in addition to the local configuration. 63 | # https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/sync-labels 64 | - universal.yml 65 | 66 | steps: 67 | - name: Download 68 | uses: carlosperate/download-file-action@v2 69 | with: 70 | file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }} 71 | 72 | - name: Pass configuration files to next job via workflow artifact 73 | uses: actions/upload-artifact@v4 74 | with: 75 | path: | 76 | *.yaml 77 | *.yml 78 | if-no-files-found: error 79 | name: ${{ env.CONFIGURATIONS_ARTIFACT }} 80 | 81 | sync: 82 | needs: download 83 | runs-on: ubuntu-latest 84 | 85 | steps: 86 | - name: Set environment variables 87 | run: | 88 | # See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable 89 | echo "MERGED_CONFIGURATION_PATH=${{ runner.temp }}/labels.yml" >> "$GITHUB_ENV" 90 | 91 | - name: Determine whether to dry run 92 | id: dry-run 93 | if: > 94 | github.event_name == 'pull_request' || 95 | ( 96 | ( 97 | github.event_name == 'push' || 98 | github.event_name == 'workflow_dispatch' 99 | ) && 100 | github.ref != format('refs/heads/{0}', github.event.repository.default_branch) 101 | ) 102 | run: | 103 | # Use of this flag in the github-label-sync command will cause it to only check the validity of the 104 | # configuration. 105 | echo "::set-output name=flag::--dry-run" 106 | 107 | - name: Checkout repository 108 | uses: actions/checkout@v4 109 | 110 | - name: Download configuration files artifact 111 | uses: actions/download-artifact@v4 112 | with: 113 | name: ${{ env.CONFIGURATIONS_ARTIFACT }} 114 | path: ${{ env.CONFIGURATIONS_FOLDER }} 115 | 116 | - name: Remove unneeded artifact 117 | uses: geekyeggo/delete-artifact@v5 118 | with: 119 | name: ${{ env.CONFIGURATIONS_ARTIFACT }} 120 | 121 | - name: Merge label configuration files 122 | run: | 123 | # Merge all configuration files 124 | shopt -s extglob 125 | cat "${{ env.CONFIGURATIONS_FOLDER }}"/*.@(yml|yaml) > "${{ env.MERGED_CONFIGURATION_PATH }}" 126 | 127 | - name: Install github-label-sync 128 | run: sudo npm install --global github-label-sync 129 | 130 | - name: Sync labels 131 | env: 132 | GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} 133 | run: | 134 | # See: https://github.com/Financial-Times/github-label-sync 135 | github-label-sync \ 136 | --labels "${{ env.MERGED_CONFIGURATION_PATH }}" \ 137 | ${{ steps.dry-run.outputs.flag }} \ 138 | ${{ github.repository }} 139 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | 474 | Copyright (C) 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 489 | USA 490 | 491 | Also add information on how to contact you by electronic and paper mail. 492 | 493 | You should also get your employer (if you work as a programmer) or your 494 | school, if any, to sign a "copyright disclaimer" for the library, if 495 | necessary. Here is a sample; alter the names: 496 | 497 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 498 | library `Frob' (a library for tweaking knobs) written by James Random 499 | Hacker. 500 | 501 | , 1 April 1990 502 | Ty Coon, President of Vice 503 | 504 | That's all there is to it! 505 | -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | :repository-owner: arduino-libraries 2 | :repository-name: Arduino_Pro_Tutorials 3 | 4 | = {repository-name} Library for Arduino = 5 | 6 | image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] 7 | image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] 8 | image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] 9 | 10 | This library contains the complete Arduino sketches from the Arduino Pro Tutorials found on the Arduino docs website under the Tutorials title of the corresponding product. 11 | 12 | * https://docs.arduino.cc/hardware/portenta-h7#tutorials[Arduino Portenta H7] 13 | * https://docs.arduino.cc/hardware/portenta-h7-lite#tutorials[Arduino Portenta H7 Lite] 14 | * https://docs.arduino.cc/hardware/edge-control#tutorials[Arduino Edge Control] 15 | * https://docs.arduino.cc/hardware/portenta-vision-shield#tutorials[Arduino Portenta Vision Shield] 16 | * https://docs.arduino.cc/hardware/nicla-sense-me#tutorials[Arduino Nicla Sense ME] 17 | 18 | 19 | 20 | == License == 21 | 22 | Copyright (c) 2021 Arduino SA. All rights reserved. 23 | 24 | This library is free software; you can redistribute it and/or 25 | modify it under the terms of the GNU Lesser General Public 26 | License as published by the Free Software Foundation; either 27 | version 2.1 of the License, or (at your option) any later version. 28 | 29 | This library is distributed in the hope that it will be useful, 30 | but WITHOUT ANY WARRANTY; without even the implied warranty of 31 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 32 | Lesser General Public License for more details. 33 | 34 | You should have received a copy of the GNU Lesser General Public 35 | License along with this library; if not, write to the Free Software 36 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 37 | -------------------------------------------------------------------------------- /examples/BLE Connectivity on Portenta H7/PortentaBLE/PortentaBLE.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | BLEService ledService("19b10000-e8f2-537e-4f6c-d104768a1214"); 4 | 5 | // BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central 6 | BLEByteCharacteristic switchCharacteristic("19b10000-e8f2-537e-4f6c-d104768a1214", BLERead | BLEWrite); 7 | 8 | const int ledPin = LED_BUILTIN; // Pin to use for the LED 9 | 10 | void setup() { 11 | Serial.begin(9600); 12 | //while (!Serial); // Uncomment to wait for serial port to connect. 13 | 14 | // Set LED pin to output mode 15 | pinMode(ledPin, OUTPUT); 16 | digitalWrite(ledPin, HIGH); 17 | 18 | // Begin initialization 19 | if (!BLE.begin()) { 20 | Serial.println("Starting BLE failed!"); 21 | digitalWrite(LEDR, LOW); 22 | delay(1000); 23 | digitalWrite(LEDR, HIGH); 24 | 25 | // Stop if BLE couldn't be initialized. 26 | while (1); 27 | } 28 | 29 | // Set advertised local name and service UUID: 30 | BLE.setLocalName("LED-Portenta-01"); 31 | BLE.setAdvertisedService(ledService); 32 | 33 | // Add the characteristic to the service 34 | ledService.addCharacteristic(switchCharacteristic); 35 | 36 | // Add service 37 | BLE.addService(ledService); 38 | 39 | // Set the initial value for the characeristic: 40 | switchCharacteristic.writeValue(0); 41 | 42 | // start advertising 43 | BLE.advertise(); 44 | digitalWrite(LEDB, LOW); 45 | delay(1000); 46 | digitalWrite(LEDB, HIGH); 47 | Serial.println("BLE LED Control ready"); 48 | } 49 | 50 | void loop() { 51 | // Listen for BLE peripherals to connect: 52 | BLEDevice central = BLE.central(); 53 | 54 | // If a central is connected to peripheral: 55 | if (central) { 56 | Serial.print("Connected to central: "); 57 | // Print the central's MAC address: 58 | Serial.println(central.address()); 59 | digitalWrite(LEDB, HIGH); 60 | delay(100); 61 | digitalWrite(LEDB, LOW); 62 | delay(100); 63 | digitalWrite(LEDB, HIGH); 64 | 65 | // While the central is still connected to peripheral: 66 | while (central.connected()) { 67 | // If the remote device wrote to the characteristic, 68 | // Use the value to control the LED: 69 | if (switchCharacteristic.written()) { 70 | if (switchCharacteristic.value()) { // Any value other than 0 71 | Serial.println("LED on"); 72 | digitalWrite(ledPin, LOW); // Will turn the Portenta LED on 73 | } else { 74 | Serial.println("LED off"); 75 | digitalWrite(ledPin, HIGH); // Will turn the Portenta LED off 76 | } 77 | } 78 | } 79 | 80 | // When the central disconnects, print it out: 81 | Serial.print("Disconnected from central: "); 82 | Serial.println(central.address()); 83 | digitalWrite(LEDB, HIGH); 84 | delay(100); 85 | digitalWrite(LEDB, LOW); 86 | delay(100); 87 | digitalWrite(LEDB, HIGH); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /examples/Creating GUIs with LVGL/lvglCounter/lvglCounter.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Using LVGL v7.11 3 | */ 4 | 5 | #include "Portenta_LittleVGL.h" 6 | 7 | static lv_obj_t *label; 8 | int counter = 0; 9 | 10 | static void updateCounterTask(lv_task_t *task) { 11 | // Print the count to the Serial monitor 12 | Serial.println(counter); 13 | 14 | // Update the text of the label 15 | lv_label_set_text_fmt(label, "%d" , counter); 16 | 17 | // Increase the count number 18 | counter++; 19 | } 20 | 21 | void setup() { 22 | Serial.begin(9600); 23 | 24 | // Initialize Portenta's video interface 25 | portenta_init_video(); 26 | 27 | // Setting up the label making it a child of the screen 28 | label = lv_label_create(lv_scr_act(), NULL); 29 | 30 | // Set the label's text 31 | lv_label_set_text(label , "Counter"); 32 | 33 | // We move it to the center of the screen and align it centered 34 | lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); 35 | 36 | // Create a task to update the counter 37 | lv_task_create(updateCounterTask, 1000, LV_TASK_PRIO_MID, NULL); 38 | } 39 | 40 | void loop() { 41 | // put your main code here, to run repeatedly: 42 | lv_task_handler(); 43 | } -------------------------------------------------------------------------------- /examples/Creating a Flash-Optimised Key-Value Store/FlashKeyValue/FlashIAPLimits.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Helper functions for calculating limits for the FlashIAP block device 3 | * */ 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | using namespace mbed; 12 | 13 | // An helper struct for FlashIAP limits 14 | struct FlashIAPLimits { 15 | size_t flash_size; 16 | uint32_t start_address; 17 | uint32_t available_size; 18 | }; 19 | 20 | // Get the actual start address and available size for the FlashIAP Block Device 21 | // considering the space already occupied by the sketch. 22 | FlashIAPLimits getFlashIAPLimits() 23 | { 24 | // Alignment lambdas 25 | auto align_down = [](uint64_t val, uint64_t size) { return (((val) / size)) * size; }; 26 | auto align_up = [](uint32_t val, uint32_t size) { return (((val - 1) / size) + 1) * size; }; 27 | 28 | size_t flash_size; 29 | uint32_t flash_start_address; 30 | uint32_t start_address; 31 | FlashIAP flash; 32 | 33 | auto result = flash.init(); 34 | if (result != 0) 35 | return { }; 36 | 37 | // Find the start of first sector after text area 38 | int sector_size = flash.get_sector_size(FLASHIAP_APP_ROM_END_ADDR); 39 | start_address = align_up(FLASHIAP_APP_ROM_END_ADDR, sector_size); 40 | flash_start_address = flash.get_flash_start(); 41 | flash_size = flash.get_flash_size(); 42 | 43 | result = flash.deinit(); 44 | 45 | int available_size = flash_start_address + flash_size - start_address; 46 | if (available_size % (sector_size * 2)) { 47 | available_size = align_down(available_size, sector_size * 2); 48 | } 49 | 50 | return { flash_size, start_address, available_size }; 51 | } 52 | -------------------------------------------------------------------------------- /examples/Creating a Flash-Optimised Key-Value Store/FlashKeyValue/FlashKeyValue.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace mbed; 5 | 6 | // Get limits of the In Application Program (IAP) flash, ie. the internal MCU flash. 7 | #include "FlashIAPLimits.h" 8 | auto iapLimits { getFlashIAPLimits() }; 9 | 10 | // Create a block device on the available space of the FlashIAP 11 | FlashIAPBlockDevice blockDevice(iapLimits.start_address, iapLimits.available_size); 12 | 13 | // Create a key/value store on the Flash IAP block device 14 | TDBStore store(&blockDevice); 15 | 16 | // Dummy sketch stats for demonstration purposes 17 | struct SketchStats { 18 | uint32_t startupTime; 19 | uint32_t randomValue; 20 | uint32_t runCount; 21 | }; 22 | 23 | void setup() 24 | { 25 | Serial.begin(115200); 26 | while (!Serial); 27 | 28 | // Wait for terminal to come up 29 | delay(1000); 30 | 31 | Serial.println("FlashIAPBlockDevice + TDBStore Test"); 32 | 33 | // Feed the RNG for later content generation 34 | srand(micros()); 35 | 36 | // Initialize the flash IAP block device and print the memory layout 37 | blockDevice.init(); 38 | Serial.print("FlashIAP block device size: "); 39 | Serial.println(blockDevice.size()); 40 | Serial.print("FlashIAP block device read size: "); 41 | Serial.println(blockDevice.get_read_size()); 42 | Serial.print("FlashIAP block device program size: "); 43 | Serial.println(blockDevice.get_program_size()); 44 | Serial.print("FlashIAP block device erase size: "); 45 | Serial.println(blockDevice.get_erase_size()); 46 | // Deinitialize the device 47 | blockDevice.deinit(); 48 | 49 | // Initialize the key/value store 50 | Serial.print("Initializing TDBStore: "); 51 | auto result = store.init(); 52 | Serial.println(result == MBED_SUCCESS ? "OK" : "KO"); 53 | if (result != MBED_SUCCESS) 54 | while (true); 55 | 56 | // An example key name for the stats on the store 57 | const char statsKey[] { "stats" }; 58 | 59 | // Keep track of the number of sketch executions 60 | uint32_t runCount { 0 }; 61 | 62 | // Previous stats 63 | SketchStats previousStats; 64 | 65 | // Get previous run stats from the key/value store 66 | Serial.println("Retrieving Sketch Stats"); 67 | result = getSketchStats(statsKey, &previousStats); 68 | if (result == MBED_SUCCESS) { 69 | Serial.println("Previous Stats"); 70 | Serial.print("\tStartup Time: "); 71 | Serial.println(previousStats.startupTime); 72 | Serial.print("\tRandom Value: "); 73 | Serial.println(previousStats.randomValue); 74 | Serial.print("\tRun Count: "); 75 | Serial.println(previousStats.runCount); 76 | 77 | runCount = previousStats.runCount; 78 | 79 | } else if (result == MBED_ERROR_ITEM_NOT_FOUND) { 80 | Serial.println("First execution"); 81 | } else { 82 | Serial.println("Error reading from key/value store."); 83 | while (true); 84 | } 85 | 86 | //Update the stats and save them to the store 87 | SketchStats currentStats { millis(), rand(), ++runCount }; 88 | result = setSketchStats(statsKey, currentStats); 89 | 90 | if (result == MBED_SUCCESS) { 91 | Serial.println("Sketch Stats updated"); 92 | Serial.println("Current Stats"); 93 | Serial.print("\tStartup Time: "); 94 | Serial.println(currentStats.startupTime); 95 | Serial.print("\tRandom Value: "); 96 | Serial.println(currentStats.randomValue); 97 | Serial.print("\tRun Count: "); 98 | Serial.println(currentStats.runCount); 99 | } else { 100 | Serial.println("Error storing to key/value store"); 101 | while (true); 102 | } 103 | } 104 | 105 | void loop() 106 | { 107 | // Do nothing 108 | } 109 | 110 | // Retrieve a SketchStats from the k/v store 111 | int getSketchStats(const char* key, SketchStats* stats) 112 | { 113 | // Retrieve key/value info 114 | TDBStore::info_t info; 115 | auto result = store.get_info(key, &info); 116 | if (result == MBED_ERROR_ITEM_NOT_FOUND) 117 | return result; 118 | 119 | // Allocate space for the value 120 | uint8_t buffer[info.size] {}; 121 | size_t actual_size; 122 | 123 | // Get the value 124 | result = store.get(key, buffer, sizeof(buffer), &actual_size); 125 | if (result != MBED_SUCCESS) 126 | return result; 127 | 128 | memcpy(stats, buffer, sizeof(SketchStats)); 129 | return result; 130 | } 131 | 132 | // Store a SketchStats to the the k/v store 133 | int setSketchStats(const char* key, SketchStats stats) 134 | { 135 | auto result = store.set(key, reinterpret_cast(&stats), sizeof(SketchStats), 0); 136 | return result; 137 | } 138 | -------------------------------------------------------------------------------- /examples/Dual Core Processing/BlinkBothCores/BlinkBothCores.ino: -------------------------------------------------------------------------------- 1 | int myLED; 2 | 3 | void setup() { 4 | // put your setup code here, to run once: 5 | randomSeed(analogRead(0)); 6 | 7 | #ifdef CORE_CM7 8 | bootM4(); 9 | myLED = LEDB; // built-in blue LED 10 | #endif 11 | #ifdef CORE_CM4 12 | myLED = LEDG; // built-in greeen LED 13 | #endif 14 | pinMode(myLED, OUTPUT); 15 | } 16 | 17 | void loop() { 18 | // put your main code here, to run repeatedly: 19 | digitalWrite(myLED, LOW); // turn the LED on 20 | delay(200); 21 | digitalWrite(myLED, HIGH); // turn the LED off 22 | delay( rand() % 2000 + 1000); // wait for a random amount of time between 1 and 3 seconds. 23 | 24 | } 25 | -------------------------------------------------------------------------------- /examples/Dual Core Processing/BlinkGreenLed_M4/BlinkGreenLed_M4.ino: -------------------------------------------------------------------------------- 1 | // the setup function runs once when you press reset or power the board 2 | void setup() { 3 | // initialize digital pin LED_BUILTIN as an output. 4 | pinMode(LEDG, OUTPUT); 5 | } 6 | 7 | // the loop function runs over and over again forever 8 | void loop() { 9 | digitalWrite(LEDG, LOW); // turn the LED on (LOW is the voltage level) 10 | delay(500); // wait for half a second 11 | digitalWrite(LEDG, HIGH); // turn the LED off by making the voltage HIGH 12 | delay(500); // wait for half a second 13 | } 14 | -------------------------------------------------------------------------------- /examples/Dual Core Processing/BlinkRedLed/BlinkRedLed.ino: -------------------------------------------------------------------------------- 1 | // the setup function runs once when you press reset or power the board 2 | void setup() { 3 | // initialize digital pin LED_BUILTIN as an output. 4 | bootM4(); 5 | pinMode(LEDR, OUTPUT); 6 | } 7 | 8 | // the loop function runs over and over again forever 9 | void loop() { 10 | digitalWrite(LEDR, LOW); // turn the red LED on (LOW is the voltage level) 11 | delay(200); // wait for 200 milliseconds 12 | digitalWrite(LEDR, HIGH); // turn the LED off by setting the voltage HIGH 13 | delay(200); // wait for 200 milliseconds 14 | } 15 | -------------------------------------------------------------------------------- /examples/Dual Core Processing/BlinkRedLed_M7/BlinkRedLed_M7.ino: -------------------------------------------------------------------------------- 1 | // the setup function runs once when you press reset or power the board 2 | void setup() { 3 | // initialize digital pin LED_BUILTIN as an output. 4 | pinMode(LEDR, OUTPUT); 5 | } 6 | 7 | // the loop function runs over and over again forever 8 | void loop() { 9 | digitalWrite(LEDR, HIGH); // turn the LED off (HIGH is the voltage level) 10 | delay(200); // wait for 200 milliseconds 11 | digitalWrite(LEDR, LOW); // turn the LED on by making the voltage LOW 12 | delay(200); // wait for 200 milliseconds 13 | } 14 | -------------------------------------------------------------------------------- /examples/Edge Control Getting Started/EdgeControl/EdgeControl.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void setup() { 4 | Serial.begin(9600); 5 | 6 | // Set the timeout 7 | auto startNow = millis() + 2500; 8 | while (!Serial && millis() < startNow); 9 | Serial.println("Hello, Edge Control Sketch!"); 10 | 11 | // Enable power lines 12 | Power.enable3V3(); 13 | Power.enable5V(); 14 | 15 | // Start the I2C connection 16 | Wire.begin(); 17 | 18 | // Initialize the expander pins 19 | Expander.begin(); 20 | Expander.pinMode(EXP_LED1, OUTPUT); 21 | } 22 | 23 | void loop() { 24 | // put your main code here, to run repeatedly: 25 | Serial.println("Blink"); 26 | Expander.digitalWrite(EXP_LED1, LOW); 27 | delay(500); 28 | Expander.digitalWrite(EXP_LED1, HIGH); 29 | delay(500); 30 | } -------------------------------------------------------------------------------- /examples/Portenta H7 as a USB Host/LEDKeyboardController/LEDKeyboardController.ino: -------------------------------------------------------------------------------- 1 | /* 2 | _______ _ _ _____ ____ 3 | |__ __| | | | |/ ____| _ \ 4 | | | ___ ___ _ __ _ _| | | | (___ | |_) | 5 | | |/ _ \/ _ \ '_ \| | | | | | |\___ \| _ < 6 | | | __/ __/ | | | |_| | |__| |____) | |_) | 7 | |_|\___|\___|_| |_|\__, |\____/|_____/|____/ 8 | __/ | 9 | |___/ 10 | 11 | TeenyUSB - light weight usb stack for STM32 micro controllers 12 | 13 | Copyright (c) 2019 XToolBox - admin@xtoolbox.org 14 | www.tusb.org 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining a copy 17 | of this software and associated documentation files (the "Software"), to deal 18 | in the Software without restriction, including without limitation the rights 19 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | copies of the Software, and to permit persons to whom the Software is 21 | furnished to do so, subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be included in all 24 | copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32 | SOFTWARE. 33 | */ 34 | 35 | #include "USBHost.h" 36 | 37 | USBHost usb; 38 | 39 | static int process_key(tusbh_ep_info_t* ep, const uint8_t* key); 40 | 41 | static const tusbh_boot_key_class_t cls_boot_key = { 42 | .backend = &tusbh_boot_keyboard_backend, 43 | .on_key = process_key 44 | }; 45 | 46 | static const tusbh_boot_mouse_class_t cls_boot_mouse = { 47 | .backend = &tusbh_boot_mouse_backend, 48 | // .on_mouse = process_mouse 49 | }; 50 | 51 | static const tusbh_hid_class_t cls_hid = { 52 | .backend = &tusbh_hid_backend, 53 | //.on_recv_data = process_hid_recv, 54 | //.on_send_done = process_hid_sent, 55 | }; 56 | 57 | static const tusbh_hub_class_t cls_hub = { 58 | .backend = &tusbh_hub_backend, 59 | }; 60 | 61 | static const tusbh_vendor_class_t cls_vendor = { 62 | .backend = &tusbh_vendor_backend, 63 | //.transfer_done = process_vendor_xfer_done 64 | }; 65 | 66 | int msc_ff_mount(tusbh_interface_t* interface, int max_lun, const tusbh_block_info_t* blocks); 67 | int msc_ff_unmount(tusbh_interface_t* interface); 68 | 69 | static const tusbh_msc_class_t cls_msc_bot = { 70 | .backend = &tusbh_msc_bot_backend, 71 | // .mount = msc_ff_mount, 72 | // .unmount = msc_ff_unmount, 73 | }; 74 | 75 | static const tusbh_cdc_acm_class_t cls_cdc_acm = { 76 | .backend = &tusbh_cdc_acm_backend, 77 | }; 78 | 79 | static const tusbh_cdc_rndis_class_t cls_cdc_rndis = { 80 | .backend = &tusbh_cdc_rndis_backend, 81 | }; 82 | 83 | static const tusbh_class_reg_t class_table[] = { 84 | (tusbh_class_reg_t)&cls_boot_key, 85 | (tusbh_class_reg_t)&cls_boot_mouse, 86 | (tusbh_class_reg_t)&cls_hub, 87 | (tusbh_class_reg_t)&cls_msc_bot, 88 | (tusbh_class_reg_t)&cls_cdc_acm, 89 | (tusbh_class_reg_t)&cls_cdc_rndis, 90 | (tusbh_class_reg_t)&cls_hid, 91 | (tusbh_class_reg_t)&cls_vendor, 92 | 0, 93 | }; 94 | 95 | bool ledRstate = false; 96 | bool ledGstate = false; 97 | bool ledBstate = false; 98 | 99 | void setup() 100 | { 101 | Serial1.begin(115200); 102 | usb.Init(USB_CORE_ID_HS, class_table); 103 | //usb.Init(USB_CORE_ID_FS, class_table); 104 | 105 | pinMode(LEDR, OUTPUT); 106 | pinMode(LEDG, OUTPUT); 107 | pinMode(LEDB, OUTPUT); 108 | 109 | //Turn off the LEDs 110 | digitalWrite(LEDR, HIGH); 111 | digitalWrite(LEDG, HIGH); 112 | digitalWrite(LEDB, HIGH); 113 | } 114 | 115 | void loop() { 116 | usb.Task(); 117 | } 118 | 119 | #define MOD_CTRL (0x01 | 0x10) 120 | #define MOD_SHIFT (0x02 | 0x20) 121 | #define MOD_ALT (0x04 | 0x40) 122 | #define MOD_WIN (0x08 | 0x80) 123 | 124 | #define LED_NUM_LOCK 1 125 | #define LED_CAPS_LOCK 2 126 | #define LED_SCROLL_LOCK 4 127 | 128 | #define stdin_recvchar Serial1.write 129 | 130 | static uint8_t key_leds; 131 | static const char knum[] = "1234567890"; 132 | static const char ksign[] = "!@#$%^&*()"; 133 | static const char tabA[] = "\t -=[]\\#;'`,./"; 134 | static const char tabB[] = "\t _+{}|~:\"~<>?"; 135 | // route the key event to stdin 136 | static int process_key(tusbh_ep_info_t* ep, const uint8_t* keys) 137 | { 138 | printf("\n"); 139 | uint8_t modify = keys[0]; 140 | uint8_t key = keys[2]; 141 | uint8_t last_leds = key_leds; 142 | if (key >= KEY_A && key <= KEY_Z) { 143 | char ch = 'A' + key - KEY_A; 144 | if ( (!!(modify & MOD_SHIFT)) == (!!(key_leds & LED_CAPS_LOCK)) ) { 145 | ch += 'a' - 'A'; 146 | } 147 | stdin_recvchar(ch); 148 | if (ch == 'r' || ch == 'R') 149 | { 150 | ledRstate = !ledRstate; 151 | if (ledRstate) 152 | digitalWrite(LEDR, LOW); 153 | else 154 | digitalWrite(LEDR, HIGH); 155 | } 156 | 157 | if (ch == 'g' || ch == 'G') 158 | { 159 | ledGstate = !ledGstate; 160 | if (ledGstate) 161 | digitalWrite(LEDG, LOW); 162 | else 163 | digitalWrite(LEDG, HIGH); 164 | } 165 | 166 | if (ch == 'b' || ch == 'B') 167 | { 168 | ledBstate = !ledBstate; 169 | if (ledBstate) 170 | digitalWrite(LEDB, LOW); 171 | else 172 | digitalWrite(LEDB, HIGH); 173 | } 174 | 175 | } else if (key >= KEY_1 && key <= KEY_0) { 176 | if (modify & MOD_SHIFT) { 177 | stdin_recvchar(ksign[key - KEY_1]); 178 | } else { 179 | stdin_recvchar(knum[key - KEY_1]); 180 | } 181 | } else if (key >= KEY_TAB && key <= KEY_SLASH) { 182 | if (modify & MOD_SHIFT) { 183 | stdin_recvchar(tabB[key - KEY_TAB]); 184 | } else { 185 | stdin_recvchar(tabA[key - KEY_TAB]); 186 | } 187 | } else if (key == KEY_ENTER) { 188 | stdin_recvchar('\r'); 189 | } else if (key == KEY_CAPSLOCK) { 190 | key_leds ^= LED_CAPS_LOCK; 191 | } else if (key == KEY_NUMLOCK) { 192 | key_leds ^= LED_NUM_LOCK; 193 | } else if (key == KEY_SCROLLLOCK) { 194 | key_leds ^= LED_SCROLL_LOCK; 195 | } 196 | 197 | if (key_leds != last_leds) { 198 | tusbh_set_keyboard_led(ep, key_leds); 199 | } 200 | return 0; 201 | } 202 | -------------------------------------------------------------------------------- /examples/Portenta H7 as a WiFi Access Point/SimpleWebServer/SimpleWebServer.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "arduino_secrets.h" 3 | 4 | ///////please enter your sensitive data in the Secret tab/arduino_secrets.h 5 | char ssid[] = SECRET_SSID; // your network SSID (name) 6 | char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) 7 | int keyIndex = 0; // your network key Index number (needed only for WEP) 8 | 9 | int status = WL_IDLE_STATUS; 10 | 11 | WiFiServer server(80); 12 | 13 | void setup() { 14 | // put your setup code here, to run once: 15 | Serial.begin(9600); 16 | while (!Serial) { 17 | ; // wait for serial port to connect. Needed for native USB port only 18 | } 19 | 20 | Serial.println("Access Point Web Server"); 21 | 22 | pinMode(LEDR, OUTPUT); 23 | pinMode(LEDG, OUTPUT); 24 | pinMode(LEDB, OUTPUT); 25 | 26 | // by default the local IP address of will be 192.168.3.1 27 | // you can override it with the following: 28 | // WiFi.config(IPAddress(10, 0, 0, 1)); 29 | 30 | // The AP needs the password be at least 8 characters long 31 | if(strlen(pass) < 8){ 32 | Serial.println("Creating access point failed"); 33 | Serial.println("The WiFi password must be at least 8 characters long"); 34 | // don't continue 35 | while(true); 36 | } 37 | 38 | // print the network name (SSID); 39 | Serial.print("Creating access point named: "); 40 | Serial.println(ssid); 41 | 42 | //Create the Access point 43 | status = WiFi.beginAP(ssid, pass); 44 | if (status != WL_AP_LISTENING) { 45 | Serial.println("Creating access point failed"); 46 | // don't continue 47 | while (true); 48 | } 49 | 50 | // wait 10 seconds for connection: 51 | delay(10000); 52 | 53 | // start the web server on port 80 54 | server.begin(); 55 | 56 | // you're connected now, so print out the status 57 | printWiFiStatus(); 58 | 59 | } 60 | 61 | void loop() { 62 | 63 | // compare the previous status to the current status 64 | if (status != WiFi.status()) { 65 | // it has changed update the variable 66 | status = WiFi.status(); 67 | 68 | if (status == WL_AP_CONNECTED) { 69 | // a device has connected to the AP 70 | Serial.println("Device connected to AP"); 71 | } else { 72 | // a device has disconnected from the AP, and we are back in listening mode 73 | Serial.println("Device disconnected from AP"); 74 | } 75 | } 76 | 77 | WiFiClient client = server.available(); // listen for incoming clients 78 | 79 | if (client) { // if you get a client, 80 | Serial.println("new client"); // print a message out the serial port 81 | String currentLine = ""; // make a String to hold incoming data from the client 82 | 83 | while (client.connected()) { // loop while the client's connected 84 | 85 | if (client.available()) { // if there's bytes to read from the client, 86 | char c = client.read(); // read a byte, then 87 | Serial.write(c); // print it out the serial monitor 88 | if (c == '\n') { // if the byte is a newline character 89 | 90 | // if the current line is blank, you got two newline characters in a row. 91 | // that's the end of the client HTTP request, so send a response: 92 | if (currentLine.length() == 0) { 93 | // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) 94 | // and a content-type so the client knows what's coming, then a blank line: 95 | client.println("HTTP/1.1 200 OK"); 96 | client.println("Content-type:text/html"); 97 | client.println(); 98 | 99 | // the content of the HTTP response follows the header: 100 | client.print(""); 101 | client.print(""); 106 | client.print("

LED CONTROLS

"); 107 | client.print("

RED LED

"); 108 | client.print("ON OFF"); 109 | client.print("

GREEN LED

"); 110 | client.print("ON OFF"); 111 | client.print("

BLUE LED

"); 112 | client.print("ON OFF"); 113 | client.print(""); 114 | 115 | // The HTTP response ends with another blank line: 116 | client.println(); 117 | // break out of the while loop: 118 | break; 119 | } else { // if you got a newline, then clear currentLine: 120 | currentLine = ""; 121 | } 122 | } else if (c != '\r') { // if you got anything else but a carriage return character, 123 | currentLine += c; // add it to the end of the currentLine 124 | } 125 | 126 | // Check to see if the client request was "GET /H" or "GET /L": 127 | if (currentLine.endsWith("GET /Hr")) { 128 | digitalWrite(LEDR, LOW); // GET /Hr turns the Red LED on 129 | } 130 | if (currentLine.endsWith("GET /Lr")) { 131 | digitalWrite(LEDR, HIGH); // GET /Lr turns the Red LED off 132 | } 133 | if (currentLine.endsWith("GET /Hg")) { 134 | digitalWrite(LEDG, LOW); // GET /Hg turns the Green LED on 135 | } 136 | if (currentLine.endsWith("GET /Lg")) { 137 | digitalWrite(LEDG, HIGH); // GET /Hg turns the Green LED on 138 | } 139 | if (currentLine.endsWith("GET /Hb")) { 140 | digitalWrite(LEDB, LOW); // GET /Hg turns the Green LED on 141 | } 142 | if (currentLine.endsWith("GET /Lb")) { 143 | digitalWrite(LEDB, HIGH); // GET /Hg turns the Green LED on 144 | } 145 | 146 | } 147 | } 148 | // close the connection: 149 | client.stop(); 150 | Serial.println("client disconnected"); 151 | } 152 | 153 | } 154 | 155 | void printWiFiStatus() { 156 | // print the SSID of the network you're attached to: 157 | Serial.print("SSID: "); 158 | Serial.println(WiFi.SSID()); 159 | 160 | // print your WiFi shield's IP address: 161 | IPAddress ip = WiFi.localIP(); 162 | Serial.print("IP Address: "); 163 | Serial.println(ip); 164 | 165 | // print where to go in a browser: 166 | Serial.print("To see this page in action, open a browser to http://"); 167 | Serial.println(ip); 168 | } 169 | -------------------------------------------------------------------------------- /examples/Portenta H7 as a WiFi Access Point/SimpleWebServer/arduino_secrets.h: -------------------------------------------------------------------------------- 1 | #define SECRET_SSID "PortentaAccessPoint" 2 | #define SECRET_PASS "123Qwerty" 3 | -------------------------------------------------------------------------------- /examples/Setting Up Portenta H7 For Arduino/Blink/Blink.ino: -------------------------------------------------------------------------------- 1 | // the setup function runs once when you press reset or power the board 2 | void setup(){ 3 | // initialize digital pin LED_BUILTIN as an output. 4 | pinMode(LED_BUILTIN, OUTPUT); 5 | digitalWrite(LED_BUILTIN, HIGH); // turn the LED off after being turned on by pinMode() 6 | } 7 | 8 | // the loop function runs over and over again forever 9 | void loop(){ 10 | digitalWrite(LED_BUILTIN, LOW); // turn the LED on (LOW is the voltage level) 11 | delay(1000); // wait for a second 12 | digitalWrite(LED_BUILTIN, HIGH); // turn the LED off by making the voltage HIGH 13 | delay(1000); // wait for a second 14 | } 15 | -------------------------------------------------------------------------------- /examples/Vision Shield to SD Card bmp/visionShieldBitmap/visionShieldBitmap.ino: -------------------------------------------------------------------------------- 1 | #include "SDMMCBlockDevice.h" // Multi Media Card APIs 2 | #include "FATFileSystem.h" // API to run operations on a FAT file system 3 | SDMMCBlockDevice blockDevice; 4 | mbed::FATFileSystem fileSystem("fs"); 5 | 6 | #include "camera.h" // Arduino Mbed Core Camera APIs 7 | #include "himax.h" // API to read from the Himax camera found on the Portenta Vision Shield 8 | HM01B0 himax; 9 | Camera cam(himax); 10 | 11 | FrameBuffer frameBuffer; // Buffer to save the camera stream 12 | 13 | // Settings for our setup 14 | #define IMAGE_HEIGHT (unsigned int)240 15 | #define IMAGE_WIDTH (unsigned int)320 16 | #define IMAGE_MODE CAMERA_GRAYSCALE 17 | #define BITS_PER_PIXEL (unsigned int)8 18 | #define PALETTE_COLORS_AMOUNT (unsigned int)(pow(2, BITS_PER_PIXEL)) 19 | #define PALETTE_SIZE (unsigned int)(PALETTE_COLORS_AMOUNT * 4) // 4 bytes = 32bit per color (3 bytes RGB and 1 byte 0x00) 20 | #define IMAGE_PATH "/fs/image.bmp" 21 | 22 | // Headers info 23 | #define BITMAP_FILE_HEADER_SIZE (unsigned int)14 // For storing general information about the bitmap image file 24 | #define DIB_HEADER_SIZE (unsigned int)40 // For storing information about the image and define the pixel format 25 | #define HEADER_SIZE (BITMAP_FILE_HEADER_SIZE + DIB_HEADER_SIZE) 26 | 27 | 28 | void setup(){ 29 | Serial.begin(115200); 30 | while (!Serial && millis() < 5000); 31 | 32 | Serial.println("Mounting SD Card..."); 33 | mountSDCard(); 34 | Serial.println("SD Card mounted."); 35 | 36 | // Init the cam QVGA, 30FPS, Grayscale 37 | if (!cam.begin(CAMERA_R320x240, IMAGE_MODE, 30)){ 38 | Serial.println("Unable to find the camera"); 39 | } 40 | countDownBlink(); 41 | Serial.println("Fetching camera image..."); 42 | unsigned char *imageData = captureImage(); 43 | digitalWrite(LEDB, HIGH); 44 | 45 | Serial.println("Saving image to SD card..."); 46 | saveImage(imageData, IMAGE_PATH); 47 | 48 | fileSystem.unmount(); 49 | Serial.println("Done. You can now remove the SD card."); 50 | } 51 | 52 | void loop(){ 53 | } 54 | 55 | // Mount File system block 56 | void mountSDCard(){ 57 | int error = fileSystem.mount(&blockDevice); 58 | if (error){ 59 | Serial.println("Trying to reformat..."); 60 | int formattingError = fileSystem.reformat(&blockDevice); 61 | if (formattingError) { 62 | Serial.println("No SD Card found"); 63 | while (1); 64 | } 65 | } 66 | } 67 | 68 | // Get the raw image data (8bpp grayscale) 69 | unsigned char * captureImage(){ 70 | if (cam.grabFrame(frameBuffer, 3000) == 0){ 71 | return frameBuffer.getBuffer(); 72 | } else { 73 | Serial.println("could not grab the frame"); 74 | while (1); 75 | } 76 | } 77 | 78 | // Set the headers data 79 | void setFileHeaders(unsigned char *bitmapFileHeader, unsigned char *bitmapDIBHeader, int fileSize){ 80 | // Set the headers to 0 81 | memset(bitmapFileHeader, (unsigned char)(0), BITMAP_FILE_HEADER_SIZE); 82 | memset(bitmapDIBHeader, (unsigned char)(0), DIB_HEADER_SIZE); 83 | 84 | // File header 85 | bitmapFileHeader[0] = 'B'; 86 | bitmapFileHeader[1] = 'M'; 87 | bitmapFileHeader[2] = (unsigned char)(fileSize); 88 | bitmapFileHeader[3] = (unsigned char)(fileSize >> 8); 89 | bitmapFileHeader[4] = (unsigned char)(fileSize >> 16); 90 | bitmapFileHeader[5] = (unsigned char)(fileSize >> 24); 91 | bitmapFileHeader[10] = (unsigned char)HEADER_SIZE + PALETTE_SIZE; 92 | 93 | // Info header 94 | bitmapDIBHeader[0] = (unsigned char)(DIB_HEADER_SIZE); 95 | bitmapDIBHeader[4] = (unsigned char)(IMAGE_WIDTH); 96 | bitmapDIBHeader[5] = (unsigned char)(IMAGE_WIDTH >> 8); 97 | bitmapDIBHeader[8] = (unsigned char)(IMAGE_HEIGHT); 98 | bitmapDIBHeader[9] = (unsigned char)(IMAGE_HEIGHT >> 8); 99 | bitmapDIBHeader[14] = (unsigned char)(BITS_PER_PIXEL); 100 | } 101 | 102 | void setColorMap(unsigned char *colorMap){ 103 | //Init the palette with zeroes 104 | memset(colorMap, (unsigned char)(0), PALETTE_SIZE); 105 | 106 | // Gray scale color palette, 4 bytes per color (R, G, B, 0x00) 107 | for (int i = 0; i < PALETTE_COLORS_AMOUNT; i++) { 108 | colorMap[i * 4] = i; 109 | colorMap[i * 4 + 1] = i; 110 | colorMap[i * 4 + 2] = i; 111 | } 112 | } 113 | 114 | // Save the headers and the image data into the .bmp file 115 | void saveImage(unsigned char *imageData, const char* imagePath){ 116 | int fileSize = BITMAP_FILE_HEADER_SIZE + DIB_HEADER_SIZE + IMAGE_WIDTH * IMAGE_HEIGHT; 117 | FILE *file = fopen(imagePath, "w"); 118 | 119 | // Bitmap structure (Head + DIB Head + ColorMap + binary image) 120 | unsigned char bitmapFileHeader[BITMAP_FILE_HEADER_SIZE]; 121 | unsigned char bitmapDIBHeader[DIB_HEADER_SIZE]; 122 | unsigned char colorMap[PALETTE_SIZE]; // Needed for <= 8bpp grayscale bitmaps 123 | 124 | setFileHeaders(bitmapFileHeader, bitmapDIBHeader, fileSize); 125 | setColorMap(colorMap); 126 | 127 | // Write the bitmap file 128 | fwrite(bitmapFileHeader, 1, BITMAP_FILE_HEADER_SIZE, file); 129 | fwrite(bitmapDIBHeader, 1, DIB_HEADER_SIZE, file); 130 | fwrite(colorMap, 1, PALETTE_SIZE, file); 131 | fwrite(imageData, 1, IMAGE_HEIGHT * IMAGE_WIDTH, file); 132 | 133 | // Close the file stream 134 | fclose(file); 135 | } 136 | 137 | void countDownBlink(){ 138 | for (int i = 0; i < 6; i++){ 139 | digitalWrite(LEDG, i % 2); 140 | delay(500); 141 | } 142 | digitalWrite(LEDG, HIGH); 143 | digitalWrite(LEDB, LOW); 144 | } -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Arduino_Pro_Tutorials 2 | version=1.0.6 3 | author=Martino Facchin, Riccardo Ricco, Dario Pennisi, Sebastian Romero, Lenard George, Ignacio Herrera, Jose García, Pablo Marquínez 4 | maintainer=Arduino 5 | sentence=This library contains the complete Arduino sketches from the Pro Tutorials. 6 | paragraph=Instructions on how to use these sketches can be found on the Arduino Pro website under Documentation->Tutorials. 7 | category=Other 8 | url=https://docs.arduino.cc/#pro-family 9 | architectures=mbed,mbed_portenta,mbed_nicla,mbed_edge 10 | precompiled=false 11 | depends=lvgl 12 | -------------------------------------------------------------------------------- /src/Arduino_Pro_Tutorials.h: -------------------------------------------------------------------------------- 1 | // Empty file to make Arduino IDE library checker happy :). 2 | --------------------------------------------------------------------------------