{"id":16321358,"url":"https://github.com/3110/m5stack-platformio-boilerplate-code","last_synced_at":"2026-03-07T15:05:31.355Z","repository":{"id":87809822,"uuid":"522868600","full_name":"3110/m5stack-platformio-boilerplate-code","owner":"3110","description":"PlatformIO IDE 向け M5Stack 定型コード環境 / Boilerplate Code for M5Stack in PlatformIO IDE Environment","archived":false,"fork":false,"pushed_at":"2026-01-27T17:42:22.000Z","size":111,"stargazers_count":25,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-01-28T03:43:05.543Z","etag":null,"topics":["m5stack","platformio"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/3110.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-08-09T08:39:58.000Z","updated_at":"2026-01-27T23:31:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"b100e251-f201-4c07-98da-04c4ed9c400d","html_url":"https://github.com/3110/m5stack-platformio-boilerplate-code","commit_stats":null,"previous_names":[],"tags_count":28,"template":true,"template_full_name":null,"purl":"pkg:github/3110/m5stack-platformio-boilerplate-code","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3110%2Fm5stack-platformio-boilerplate-code","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3110%2Fm5stack-platformio-boilerplate-code/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3110%2Fm5stack-platformio-boilerplate-code/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3110%2Fm5stack-platformio-boilerplate-code/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/3110","download_url":"https://codeload.github.com/3110/m5stack-platformio-boilerplate-code/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3110%2Fm5stack-platformio-boilerplate-code/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30219393,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-07T14:02:48.375Z","status":"ssl_error","status_checked_at":"2026-03-07T14:02:43.192Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["m5stack","platformio"],"created_at":"2024-10-10T22:47:28.421Z","updated_at":"2026-03-07T15:05:31.346Z","avatar_url":"https://github.com/3110.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"[In English](README_en_US.md)\n\n# PlatformIO IDE 向け M5Stack 定型コード環境\n\n[Arduino IDE](https://www.arduino.cc/en/software) 環境と同じように [PlatformIO IDE](https://platformio.org/platformio-ide) 環境でも `setup()`と`loop()`の中身を書いてすぐにコンパイルして実行できます。\n## 対応機種\n\n| 機種名                | 環境名                                                          | 備考                                                                                                                                                                                                                                 |\n| :------------------- | :------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| M5Stack BASIC        | env:m5stack-basic                                              | [公式ライブラリ](https://github.com/m5stack/M5Stack)を使用。                                                                                                                                                                           |\n| M5Stack Fire         | env:m5stack-fire                                               | [公式ライブラリ](https://github.com/m5stack/M5Stack)を使用。                                                                                                                                                                           |\n| M5Stack M5GO         | env:m5stack-m5go                                               | [公式ライブラリ](https://github.com/m5stack/M5Stack)を使用。                                                                                                                                                                           |\n| M5Stack CORE2        | env:m5stack-core2 \u003cbr\u003e env:m5stack-core2-m5unified             | [公式ライブラリ](https://github.com/m5stack/M5Core2)を使用（ライブラリ廃止予定）。\u003cbr\u003e[M5Unified](https://github.com/m5stack/M5Unified)を使用。                                                                                        |\n| M5Stack CORES3       | env:m5stack-cores3 \u003cbr\u003e env:m5stack-cores3-m5unified           | [公式ライブラリ](https://github.com/m5stack/M5CoreS3)を使用。\u003cbr\u003e[M5Unified](https://github.com/m5stack/M5Unified) を使用。USB CDC On Boot が有効。                                                                                    |\n| M5StickC             | env:m5stick-c                                                  | [公式ライブラリ](https://github.com/m5stack/M5StickC)を使用。                                                                                                                                                                          |\n| M5StickC Plus        | env:m5stick-c-plus                                             | [公式ライブラリ](https://github.com/m5stack/M5StickC-Plus)を使用。                                                                                                                                                                     |\n| M5StickC Plus2       | env:m5stick-c-plus2-m5unified                                  | [M5Unified](https://github.com/m5stack/M5Unified) を使用。                                                                                                                                                                             |\n| M5StickS3            | env:m5stick-s3                                                 | 公式ライブラリはなし。\u003cbr\u003e [M5Unified](https://github.com/m5stack/M5Unified)，[M5PM1](https://github.com/m5stack/M5PM1) を使用。USB CDC On Boot が有効。                                                                               |\n| M5ATOM Matrix        | env:m5stack-atom-matrix \u003cbr\u003e env:m5stack-atom-matrix-m5unified | [公式ライブラリ](https://github.com/m5stack/M5Atom)を使用。\u003cbr\u003e[M5Unified](https://github.com/m5stack/M5Unified) を使用。                                                                                                              |\n| M5ATOM Lite          | env:m5stack-atom-lite \u003cbr\u003e env:m5stack-atom-lite-m5unified     | [公式ライブラリ](https://github.com/m5stack/M5Atom)を使用。\u003cbr\u003e[M5Unified](https://github.com/m5stack/M5Unified) を使用。                                                                                                              |\n| M5ATOM Echo          | env:m5stack-atom-echo \u003cbr\u003e env:m5stack-atom-echo-m5unified     | [公式ライブラリ](https://github.com/m5stack/M5Atom)を使用。\u003cbr\u003e[M5Unified](https://github.com/m5stack/M5Unified) を使用。                                                                                                              |\n| M5ATOM U             | env:m5stack-atom-u \u003cbr\u003e env:m5stack-atom-u-m5unified           | [公式ライブラリ](https://github.com/m5stack/M5Atom)を使用。\u003cbr\u003e[M5Unified](https://github.com/m5stack/M5Unified) を使用。                                                                                                              |\n| M5ATOMS3             | env:m5stack-atoms3 \u003cbr\u003e env:m5stack-atoms3-m5unified           | [公式ライブラリ](https://github.com/m5stack/M5AtomS3)を使用（[M5Unified](https://github.com/m5stack/M5Unified)ベース）。USB CDC On Boot が有効。\u003cbr\u003e[M5Unified](https://github.com/m5stack/M5Unified) を使用。USB CDC On Boot が有効。 |\n| M5ATOMS3R            | env:m5stack-atoms3r-m5unified                                  | [M5Unified](https://github.com/m5stack/M5Unified) を使用。USB CDC On Boot が有効。                                                                                                                                                     |\n| M5ATOM EchoS3R       | env:m5stack-echo-atoms3r-m5unified                             | [M5Unified](https://github.com/m5stack/M5Unified) を使用。USB CDC On Boot が有効。                                                                                                                                                     |\n| M5ATOMS3 Lite        | env:m5stack-atoms3-lite \u003cbr\u003e env:m5stack-atoms3-lite-m5unified | [公式ライブラリ](https://github.com/m5stack/M5AtomS3)を使用（[M5Unified](https://github.com/m5stack/M5Unified)ベース）。USB CDC On Boot が有効。\u003cbr\u003e[M5Unified](https://github.com/m5stack/M5Unified) を使用。USB CDC On Boot が有効。 |\n| M5ATOMS3 U           | env:m5stack-atoms3-u \u003cbr\u003e env:m5stack-atoms3-u-m5unified       | [公式ライブラリ](https://github.com/m5stack/M5AtomS3)を使用（[M5Unified](https://github.com/m5stack/M5Unified)ベース）。USB CDC On Boot が有効。\u003cbr\u003e[M5Unified](https://github.com/m5stack/M5Unified) を使用。USB CDC On Boot が有効。 |\n| M5Stack CoreInk      | env:m5stack-core-ink                                           | [公式ライブラリ](https://github.com/m5stack/M5Core-Ink)を使用。                                                                                                                                                                        |\n| M5Stack Paper        | env:m5stack-paper                                              | [公式ライブラリ](https://github.com/m5stack/M5EPD)を使用。                                                                                                                                                                             |\n| M5Stack PaperS3      | env:m5stack-papers3                                            | 公式ライブラリはなし。\u003cbr\u003e[M5Unified](https://github.com/m5stack/M5Unified) を使用。                                                                                                                                                   |\n| M5StampS3            | env:m5stack-stamps3 \u003cbr\u003e env:m5stack-stamps3-m5unified         | 公式ライブラリはなし。\u003cbr\u003e[M5Unified](https://github.com/m5stack/M5Unified) を使用。USB CDC On Boot が有効。                                                                                                                           |\n| M5Capsule            | env:m5stack-capsule-m5unified                                  | [M5Unified](https://github.com/m5stack/M5Unified) を使用。USB CDC On Boot が有効。                                                                                                                                                     |\n| M5Dial               | env:m5stack-dial \u003cbr\u003e env:m5stack-dial-m5unified               | [公式ライブラリ](https://github.com/m5stack/M5Dial)を使用（[M5Unified](https://github.com/m5stack/M5Unified)ベース）。\u003cbr\u003e[M5Unified](https://github.com/m5stack/M5Unified)を使用。USB CDC On Boot が有効。                            |\n| M5Cardputer          | env:m5stack-cardputer                                          | [公式ライブラリ](https://github.com/m5stack/M5Cardputer)を使用（[M5Unified](https://github.com/m5stack/M5Unified)ベース）。USB CDC On Boot が有効。                                                                                    |\n| M5DinMeter           | env:m5stack-din-meter                                          | [公式ライブラリ](https://github.com/m5stack/M5DinMeter)を使用（[M5Unified](https://github.com/m5stack/M5Unified)ベース）。USB CDC On Boot が有効。                                                                                     |\n| M5NanoC6             | env:m5stack-nanoc6                                             | [公式ライブラリ](https://github.com/m5stack/M5NanoC6)を使用。プラットフォームは[pioarduino](https://github.com/pioarduino/platform-espressif32)を使用。                                                                                |\n| M5NanoH2             | env:m5stack-nanoh2                                             | プラットフォームは[pioarduino](https://github.com/pioarduino/platform-espressif32)を使用。                                                                                                                                             |\n| M5Stack Tab5         | env:m5stack-tab5                                               | [M5Unified](https://github.com/m5stack/M5Unified) を使用。プラットフォームは[pioarduino](https://github.com/pioarduino/platform-espressif32)を使用。                                                                                   |\n| M5Stack BASIC w/LLM  | env:m5stack-basic-m5unified-llm                                | [M5Unified](https://github.com/m5stack/M5Unified) を使用。                                                                                                                                                                             |\n| M5Stack Core2 w/LLM  | env:m5stack-core2-m5unified-llm                                | [M5Unified](https://github.com/m5stack/M5Unified) を使用。                                                                                                                                                                             |\n| M5Stack CoreS3 w/LLM | env:m5stack-cores3-m5unified-llm                               | [M5Unified](https://github.com/m5stack/M5Unified) を使用。                                                                                                                                                                             |\n\n## 事前準備\n\n### コード整形の設定\n\nコードの整形は`.vscode/settings.json`で`\"C_Cpp.clang_format_style\": \"file\"`にしているため，`.clang-format`で設定できます。ご自身の好きな設定に変更してください。\n\n### 環境設定\n\n#### 接続ポートの設定\n\n`platformio.ini`の`[platformio]`セクションにある`upload_port`と`monitor_port`のコメントを外し，`upload_port`に設定するポートを実機が接続しているポートに変更します。\n\n```platformio.ini\nupload_port = COM16\nmonitor_port = ${env.upload_port}\n```\n\n※PlatformIO IDE [v3.0.0](https://github.com/platformio/platformio-vscode-ide/releases/tag/v3.0.0)より，ステータスバーからポートの切り替えができるようになりました。\n\n#### 環境の設定\n\n「Switch PlatformIO Project Environment」（VSCode のステータスバーにある）で機種に合った環境名を設定します。\n\n`platformio.ini`の`[platformio]`セクションで`default_envs`を明示的に指定することでも環境を設定できます（既に書いてあるので，いずれかのコメントを外す）。以下の例では`m5stack-basic`を指定しています。\n\n```platformio.ini\n[platformio]\ndefault_envs = m5stack-basic\n; default_envs = m5stack-fire\n; default_envs = m5stack-m5go\n; default_envs = m5stack-core2\n; default_envs = m5stack-cores3\n; default_envs = m5stack-cores3-m5unified\n; default_envs = m5stick-c\n; default_envs = m5stick-c-plus\n; default_envs = m5stick-c-plus2-m5unified\n; default_envs = m5stick-s3\n; default_envs = m5stack-atom-matrix\n; default_envs = m5stack-atom-lite\n; default_envs = m5stack-atom-echo\n; default_envs = m5stack-atom-u\n; default_envs = m5stack-atom-matrix-m5unified\n; default_envs = m5stack-atom-lite-m5unified\n; default_envs = m5stack-atom-echo-m5unified\n; default_envs = m5stack-atom-u-m5unified\n; default_envs = m5stack-atoms3\n; default_envs = m5stack-atoms3r-m5unified\n; default_envs = m5stack-atom-echos3r-m5unified\n; default_envs = m5stack-atoms3-lite\n; default_envs = m5stack-atoms3-u\n; default_envs = m5stack-atoms3-m5unified\n; default_envs = m5stack-atoms3-lite-m5unified\n; default_envs = m5stack-atoms3-u-m5unified\n; default_envs = m5stack-coreink\n; default_envs = m5stack-paper\n; default_envs = m5stack-papers3\n; default_envs = m5stack-stamps3\n; default_envs = m5stack-stamps3-m5unified\n; default_envs = m5stack-capsule-m5unified\n; default_envs = m5stack-dial\n; default_envs = m5stack-dial-m5unified\n; default_envs = m5stack-cardputer\n; default_envs = m5stack-din-meter\n; default_envs = m5stack-nanoc6\n; default_envs = m5stack-nanoh2\n; default_envs = m5stack-tab5\n\n; default_envs = m5stack-basic-m5unified-llm\n; default_envs = m5stack-core2-m5unified-llm\n; default_envs = m5stack-cores3-m5unified-llm\n```\n\n### 外部ライブラリの追加\n\n外部ライブラリを使用する場合は，`[env]`セクションにある`lib_deps`に追加します。\n\n```ini\nlib_deps =\n    fastled/FastLED\n```\n\n### コードの記述\n\n`main.cpp`の`setup()`，`loop()`にコードを書きます。必要なヘッダファイルは`main.hpp`で環境名に合わせて実機に合ったヘッダファイルをインクルードするようにしています。\n\n各機種で`M5.begin()`の引数がまちまちでわかりにくく，`CoreS3.begin()`のように機種固有の名前が付いている場合もあるので，`M5_BEGIN`と`M5_UPDATE`というマクロで差異を吸収しています。\nまた，機種によっては`M5`のインスタンスに機種固有の名前（M5Stack CoreS3 の公式ライブラリの場合は`M5`ではなく`CoreS3`）がついている場合があるので，どの場合でも同じ`M5DEV`でアクセスできるように設定しています。\n\n共通の書き方でログの出力をするために，`M5DEV_LOGE()`，`M5DEV_LOGW()`，`M5DEV_LOGI()`，`M5DEV_LOGD()`，`M5DEV_LOGV()`を定義しました。\n\nそれぞれの定義内容に関しては`main.hpp`を参照してください。\n\n注意：M5Unified で`SD.h`や`SPIFFS.h`を使用する場合は，`#include \"main.hpp\"`より前に入れてください。\n\n```c++\n// clang-format off\n#include \u003cSPIFFS.h\u003e\n#include \"main.hpp\"\n// clang-format on\n```\n\n### 実機へのアップロード\n\nPlatformIO: Upload（VSCode のステータスバーにある → ボタン）を実行します。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F3110%2Fm5stack-platformio-boilerplate-code","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F3110%2Fm5stack-platformio-boilerplate-code","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F3110%2Fm5stack-platformio-boilerplate-code/lists"}