PlatformIOでのIniファイル指定例


PlatformIOで、一度作ったプロジェクトを他のM5Stackモジュールで動かそうとしたときに、platformio.iniに記載するお決まりの記載をメモとして残しておきます。
また、Defineマクロも一緒に設定されるので、活用しましょう。

・M5Stick-C または M5Stick-C Plus
・M5Stack Core2
・M5Stack Fire
・M5Atom Matrixまたは M5Atom Lite または M5Atom Echo
・M5StampC3
・M5StampC3U
・M5AtomS3
・NanoC6
・汎用的なESP32
・汎用的なESP8266

# platformio.iniおよびDefineマクロ

※lib_deps内のライブラリバージョンは2022/9/19時点のものです。

## M5Stick-C または M5Stick-C Plus

〇platformio.ini

```ini
[env:m5stick-c]
platform = espressif32
board = m5stick-c
framework = arduino
monitor_speed = 115200
upload_port = COM4
monitor_port = COM4
board_build.partitions = no_ota.csv
lib_deps = 
	m5stack/M5StickC@^0.2.5
または
lib_deps = 
	m5stack/M5StickCPlus@^0.0.8
```

〇Defineマクロ
ARDUINO_M5Stick_C 

〇参考URL
https://www.switch-science.com/catalog/6470/
https://www.switch-science.com/catalog/5517/


## M5Stack Core2

〇platformio.ini

```ini
[env:m5stack-core2]
platform = espressif32
board = m5stack-core2
framework = arduino
monitor_speed = 115200
upload_port = COM14
monitor_port = COM14
build_flags = 
	-DBOARD_HAS_PSRAM
	-mfix-esp32-psram-cache-issue
board_build.partitions = no_ota.csv
lib_deps = 
	m5stack/M5Core2@^0.1.4
```

〇Defineマクロ
ARDUINO_M5STACK_Core2

〇参考URL
https://www.switch-science.com/catalog/6530/

## M5Stack Fire

〇platformio.ini

```ini
[env:m5stack-fire]
platform = espressif32
board = m5stack-fire
framework = arduino
monitor_speed = 115200
upload_port = COM12
monitor_port = COM12
build_flags = 
	-DBOARD_HAS_PSRAM
	-mfix-esp32-psram-cache-issue
board_build.partitions = no_ota.csv
lib_deps = 
	m5stack/M5Stack@^0.4.3
```

〇Defineマクロ
ARDUINO_M5STACK_FIRE

〇参考URL
https://www.switch-science.com/catalog/7364/

## M5Atom Matrixまたは M5Atom Lite または M5Atom Echo

〇platformio.ini

```ini
[env:m5stack-atom]
platform = espressif32
board = m5stack-atom
framework = arduino
monitor_speed = 115200
upload_port = COM8
monitor_port = COM8
board_build.partitions = no_ota.csv
lib_deps = 
	m5stack/M5Atom@^0.1.0
	fastled/FastLED@^3.5.0
```

〇Defineマクロ
ARDUINO_M5Stack_ATOM

〇参考URL
https://www.switch-science.com/catalog/6260/
https://www.switch-science.com/catalog/6262/
https://www.switch-science.com/catalog/6347/

## M5StampC3

〇platformio.ini

```ini
[env:esp32-c3-devkitm-1]
platform = espressif32
board = esp32-c3-devkitm-1
framework = arduino
monitor_speed = 115200
upload_port = COM5
monitor_port = COM5
board_build.partitions = no_ota.csv
build_flags = -DCORE_DEBUG_LEVEL=0
```

〇Defineマクロ
ARDUINO_ESP32C3_DEV

〇参考URL
https://www.switch-science.com/catalog/7473/

## M5StampC3U

〇platformio.ini

```ini
[env:esp32-c3u-devkitm-1]
platform = espressif32
board = esp32-c3-devkitm-1
framework = arduino
monitor_speed = 115200
upload_port = COM5
monitor_port = COM5
build_flags = 
	-DCORE_DEBUG_LEVEL=0
	-DARDUINO_USB_CDC_ON_BOOT
	-DARDUINO_USB_MODE
board_build.partitions = no_ota.csv
```

〇Defineマクロ
ARDUINO_ESP32C3_DEV

〇参考URL
https://www.switch-science.com/products/7894

## M5AtomS3

〇platformio.ini

```ini
[env:m5stack-atoms3]
platform = espressif32
board = m5stack-atoms3
framework = arduino
monitor_speed = 115200
upload_port = COM3
monitor_port = COM3
build_flags = 
	-DARDUINO_USB_CDC_ON_BOOT
	-DARDUINO_USB_MODE
board_build.partitions = no_ota.csv
lib_deps = 
	m5stack/M5AtomS3@^1.0.1
	m5stack/M5Unified@^0.1.17
 	fastled/FastLED@^3.8.0
```

## NanoC6

〇platformio.ini

```ini
[env:m5stack-atoms3]
platform = espressif32
board = esp32-c6-devkitm-1
framework = arduino
monitor_speed = 115200
upload_port = COM53
monitor_port = COM3
build_flags = 
	-DARDUINO_USB_CDC_ON_BOOT
	-DARDUINO_USB_MODE
board_build.partitions = no_ota.csv
platform_packages =
    platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git
    platformio/framework-arduinoespressif32-libs @ https://github.com/espressif/esp32-arduino-libs.git#idf-release/v5.1
```

〇Defineマクロ
ARDUINO_ESP32C6_DEV

〇参考URL
https://www.switch-science.com/products/9570

## 汎用的なESP32

〇platformio.ini

```ini
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = Arduino
monitor_speed = 115200
upload_port = COM8
monitor_port = COM8
board_build.partitions = no_ota.csv
```

〇Defineマクロ
ARDUINO_ESP32_DEV

## 汎用的なESP8266

〇platformio.ini

```ini
[env:esp_wroom_02]
platform = espressif8266
board = esp_wroom_02
framework = arduino
monitor_speed = 115200
upload_port = COM8
monitor_port = COM8
board_build.partitions = no_ota.csv
```

〇Defineマクロ
ARDUINO_ESP8266_ESP_WROOM_02

# その他使い方

## パーティションの指定例

board_build.partitions = default.csv

|プリセット名|プログラム|SPIFFS|EEPROM|OTA|
|---|---|---|---|---|
|default.csv|1.28MB|1.46MB|4KB|有効|
|minimal.csv|1.28MB|700KB|4KB|無効|
|no_ota.csv|2MB|1.98MB|4KB|無効|
|huge_app.csv|3.07MB|956KB|4KB|無効|
|min_spiffs.csv|1.92MB|188KB|4KB|有効|

## ボードの切り替え方法

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/261826/55f13c95-bc20-d2f7-6d90-51919a521a39.png)

## Defineマクロ切り替え方法

```cpp
#if defined(ARDUINO_M5Stack_ATOM)
・・・
#elif defined(ARDUINO_M5Stick_C)
・・・
#elif defined(ARDUINO_M5STACK_FIRE)
・・・
#elif defined(ARDUINO_M5STACK_Core2)
・・・
#elif defined(ARDUINO_ESP32C3_DEV)
・・・
#elif defined(ARDUINO_ESP32_DEV)
・・・
#elif defined(ARDUINO_ESP8266_ESP_WROOM_02)
・・・
#else
・・・
#endif
```

## ESP32用のコードをESP8266で動かすときの注意点

〇ESP32

```cpp
#include <WiFi.h>
#include <HTTPClient.h>

HTTPClient http;
http.begin(p_url);
```

〇ESP8266

```cpp
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

HTTPClient http;
WiFiClient client;
http.begin(client, p_url);
```

## ボード情報の場所

　[ユーザフォルダ]\\.platformio\platforms\espressif32
　[ユーザフォルダ]\\.platformio\platforms\espressif8266

以上