概要
ESP32のArudinoライブラリのメジャーバージョンが3にアップしました。内部で利用しているESP-IDFも5系になり大幅に変更が入っているので差分を確認してみたいと思います。
基本情報
ESP32は内部でESP-IDFというSDKを利用して開発を行います。ESP-IDFを利用してArduiono CoreのAPIを実装したものの正式名称が「Arduino core for the ESP32, ESP32-S2, ESP32-S3, ESP32-C3, ESP32-C6 and ESP32-H2」です。
バージョン2系はESP-IDF v4を採用しており、バージョン3系はESP-IDF v5系になっています。この差は結構大きくて対応しているチップの種類が増えています。

上記がESP-IDFのバージョンとチップの対応表になります。これまではESP-IDF v4.4だったのですが、今回ESP-IDF v5.1.4に更新されました。これまで利用できなかったESP32-C2、C6、H2が利用可能になりました。ただしP5とC5はv5.3以降なのでまだ利用できません。
上記に過去のバージョンアップ履歴があるのですが長らくv4.4系が使われてきていました。今後のバージョンアップはわかりませんが、v5.3以降にバージョンアップ対応してくれると嬉しいですね。
バージョンアップの影響
ビルドシステムの変更
makeまわりが大幅に変更されています。ただしArduinoで利用する場合には見えないところなのであまり影響を受けないはずです。
またgccのバージョンが上がっています。これに伴いデフォルトの言語サポートが変更されています。これまでC言語はC11だったものがC17に、C++はC++11だったのものがC++20にあがりました。ESP-IDFだと内部的に変更が可能でしたがArduino環境だとデフォルトしか使えないのでこれは嬉しい変更です。
たとえばC++17で追加されたインライン変数とかはヘッダのみでstatic変数を宣言可能になります。個人的にはヘッダのみで動くライブラリが好きなのでかなり便利な機能です。
Arduinoでの独自拡張をESP-IDFの機能に統合
これまでESP-IDFとArduinoで同じような機能の関数がありましたが、動きとしては分かれており独自にAPIを拡張していました。そのため微妙に動きの違う関数などになっていましたが今回はArduinoはなるべくESP-IDFの関数を呼び出すように修正されています。
これの影響は大きく、ESP-IDFと設計が異なるAPIまわりはごそっと修正が入っています。analogRead関数なども影響を受けていますが、タイマーやI2Sなどの他、ESP-NOWなど通信系も差分が大きかったです。ただし、ほぼすべてのAPIが影響を受けているので、どこまで変わっているのかは個別に見てみる必要があります。
スケッチ例の差分
| # | # | # | # | # |
|---|---|---|---|---|
| 1 | ArduinoOTA | BasicOTA | BasicOTA.ino | |
| 2 | AsyncUDP | AsyncUDPClient | AsyncUDPClient.ino | |
| 3 | AsyncUDP | AsyncUDPMulticastServer | AsyncUDPMulticastServer.ino | |
| 4 | AsyncUDP | AsyncUDPServer | AsyncUDPServer.ino | |
| 5 | BLE | Beacon_Scanner | Beacon_Scanner.ino | |
| 6 | BLE | BLE5_extended_scan | BLE5_extended_scan.ino | |
| 7 | BLE | BLE5_multi_advertising | BLE5_multi_advertising.ino | |
| 8 | BLE | BLE5_periodic_advertising | BLE5_periodic_advertising.ino | |
| 9 | BLE | BLE5_periodic_sync | BLE5_periodic_sync.ino | |
| 10 | BLE | Client | Client.ino | |
| 11 | BLE | EddystoneTLM_Beacon | EddystoneTLM_Beacon.ino | |
| 12 | BLE | EddystoneURL_Beacon | EddystoneURL_Beacon.ino | |
| 13 | BLE | iBeacon | iBeacon.ino | |
| 14 | BLE | Notify | Notify.ino | |
| 15 | BLE | Scan | Scan.ino | |
| 16 | BLE | Server | Server.ino | |
| 17 | BLE | Server_multiconnect | Server_multiconnect.ino | |
| 18 | BLE | UART | UART.ino | |
| 19 | BLE | Write | Write.ino | |
| 20 | BluetoothSerial | bt_classic_device_discovery | bt_classic_device_discovery.ino | |
| 21 | BluetoothSerial | bt_remove_paired_devices | bt_remove_paired_devices.ino | |
| 22 | BluetoothSerial | DiscoverConnect | DiscoverConnect.ino | |
| 23 | BluetoothSerial | GetLocalMAC | GetLocalMAC.ino | |
| 24 | BluetoothSerial | SerialToSerialBT | SerialToSerialBT.ino | |
| 25 | BluetoothSerial | SerialToSerialBTM | SerialToSerialBTM.ino | |
| 26 | BluetoothSerial | SerialToSerialBT_Legacy | SerialToSerialBT_Legacy.ino | |
| 27 | BluetoothSerial | SerialToSerialBT_SSP | SerialToSerialBT_SSP.ino | |
| 28 | DNSServer | CaptivePortal | CaptivePortal.ino | |
| 29 | EEPROM | eeprom_class | eeprom_class.ino | |
| 30 | EEPROM | eeprom_extra | eeprom_extra.ino | |
| 31 | EEPROM | eeprom_write | eeprom_write.ino | |
| 32 | ESP32 | AnalogOut | LEDCFade | LEDCFade.ino |
| 33 | ESP32 | AnalogOut | ledcFrequency | ledcFrequency.ino |
| 34 | ESP32 | AnalogOut | LEDCSoftwareFade | LEDCSoftwareFade.ino |
| 35 | ESP32 | AnalogOut | ledcWrite_RGB | ledcWrite_RGB.ino |
| 36 | ESP32 | AnalogOut | SigmaDelta | SigmaDelta.ino |
| 37 | ESP32 | AnalogRead | AnalogRead.ino | |
| 38 | ESP32 | AnalogReadContinuous | AnalogReadContinuous.ino | |
| 39 | ESP32 | ArduinoStackSize | ArduinoStackSize.ino | |
| 40 | ESP32 | Camera | CameraWebServer | CameraWebServer.ino |
| 41 | ESP32 | ChipID | GetChipID | GetChipID.ino |
| 42 | ESP32 | CI | CIBoardsTest | CIBoardsTest.ino |
| 43 | ESP32 | DeepSleep | ExternalWakeUp | ExternalWakeUp.ino |
| 44 | ESP32 | DeepSleep | SmoothBlink_ULP_Code | SmoothBlink_ULP_Code.ino |
| 45 | ESP32 | DeepSleep | TimerWakeUp | TimerWakeUp.ino |
| 46 | ESP32 | DeepSleep | TouchWakeUp | TouchWakeUp.ino |
| 47 | ESP32 | FreeRTOS | BasicMultiThreading | BasicMultiThreading.ino |
| 48 | ESP32 | FreeRTOS | Mutex | Mutex.ino |
| 49 | ESP32 | FreeRTOS | Queue | Queue.ino |
| 50 | ESP32 | FreeRTOS | Semaphore | Semaphore.ino |
| 51 | ESP32 | GPIO | BlinkRGB | BlinkRGB.ino |
| 52 | ESP32 | GPIO | FunctionalInterrupt | FunctionalInterrupt.ino |
| 53 | ESP32 | GPIO | FunctionalInterruptStruct | FunctionalInterruptStruct.ino |
| 54 | ESP32 | GPIO | GPIOInterrupt | GPIOInterrupt.ino |
| 55 | ESP32 | HWCDC_Events | HWCDC_Events.ino | |
| 56 | ESP32 | MacAddress | GetMacAddress | GetMacAddress.ino |
| 57 | ESP32 | ResetReason | ResetReason | ResetReason.ino |
| 58 | ESP32 | ResetReason | ResetReason2 | ResetReason2.ino |
| 59 | ESP32 | RMT | RMTCallback | RMTCallback.ino |
| 60 | ESP32 | RMT | RMTLoopback | RMTLoopback.ino |
| 61 | ESP32 | RMT | RMTReadXJT | RMTReadXJT.ino |
| 62 | ESP32 | RMT | RMTWriteNeoPixel | RMTWriteNeoPixel.ino |
| 63 | ESP32 | RMT | RMT_CPUFreq_Test | RMT_CPUFreq_Test.ino |
| 64 | ESP32 | RMT | RMT_EndOfTransmissionState | RMT_EndOfTransmissionState.ino |
| 65 | ESP32 | RMT | RMT_LED_Blink | RMT_LED_Blink.ino |
| 66 | ESP32 | Serial | BaudRateDetect_Demo | BaudRateDetect_Demo.ino |
| 67 | ESP32 | Serial | OnReceiveError_BREAK_Demo | OnReceiveError_BREAK_Demo.ino |
| 68 | ESP32 | Serial | onReceiveExample | onReceiveExample.ino |
| 69 | ESP32 | Serial | OnReceive_Demo | OnReceive_Demo.ino |
| 70 | ESP32 | Serial | RS485_Echo_Demo | RS485_Echo_Demo.ino |
| 71 | ESP32 | Serial | RxFIFOFull_Demo | RxFIFOFull_Demo.ino |
| 72 | ESP32 | Serial | RxTimeout_Demo | RxTimeout_Demo.ino |
| 73 | ESP32 | Serial | Serial_All_CPU_Freqs | Serial_All_CPU_Freqs.ino |
| 74 | ESP32 | Serial | Serial_STD_Func_OnReceive | Serial_STD_Func_OnReceive.ino |
| 75 | ESP32 | Template | ExampleTemplate | ExampleTemplate.ino |
| 76 | ESP32 | Time | SimpleTime | SimpleTime.ino |
| 77 | ESP32 | Timer | RepeatTimer | RepeatTimer.ino |
| 78 | ESP32 | Timer | WatchdogTimer | WatchdogTimer.ino |
| 79 | ESP32 | Touch | TouchButton | TouchButton.ino |
| 80 | ESP32 | Touch | TouchButtonV2 | TouchButtonV2.ino |
| 81 | ESP32 | Touch | TouchInterrupt | TouchInterrupt.ino |
| 82 | ESP32 | Touch | TouchRead | TouchRead.ino |
| 83 | ESP32 | TWAI | TWAIreceive | TWAIreceive.ino |
| 84 | ESP32 | TWAI | TWAItransmit | TWAItransmit.ino |
| 85 | ESP32 | Utilities | HEXBuilder | HEXBuilder.ino |
| 86 | ESP32 | Utilities | MD5Builder | MD5Builder.ino |
| 87 | ESP32 | Utilities | SHA1Builder | SHA1Builder.ino |
| 88 | ESP32 | Zigbee | Zigbee_Light_Bulb | Zigbee_Light_Bulb.ino |
| 89 | ESP32 | Zigbee | Zigbee_Light_Switch | Zigbee_Light_Switch.ino |
| 90 | ESP32 | Zigbee | Zigbee_Temperature_Sensor | Zigbee_Temperature_Sensor.ino |
| 91 | ESP32 | Zigbee | Zigbee_Thermostat | Zigbee_Thermostat.ino |
| 92 | ESPmDNS | mDNS-SD_Extended | mDNS-SD_Extended.ino | |
| 93 | ESPmDNS | mDNS_Web_Server | mDNS_Web_Server.ino | |
| 94 | ESP_I2S | ES8388_loopback | ES8388_loopback.ino | |
| 95 | ESP_I2S | Record_to_WAV | Record_to_WAV.ino | |
| 96 | ESP_I2S | Simple_tone | Simple_tone.ino | |
| 97 | ESP_NOW | ESP_NOW_Broadcast_Master | ESP_NOW_Broadcast_Master.ino | |
| 98 | ESP_NOW | ESP_NOW_Broadcast_Slave | ESP_NOW_Broadcast_Slave.ino | |
| 99 | ESP_NOW | ESP_NOW_Network | ESP_NOW_Network.ino | |
| 100 | ESP_NOW | ESP_NOW_Serial | ESP_NOW_Serial.ino | |
| 101 | ESP_SR | Basic | Basic.ino | |
| 102 | Ethernet | ETH_LAN8720 | ETH_LAN8720.ino | |
| 103 | Ethernet | ETH_TLK110 | ETH_TLK110.ino | |
| 104 | Ethernet | ETH_W5500_Arduino_SPI | ETH_W5500_Arduino_SPI.ino | |
| 105 | Ethernet | ETH_W5500_IDF_SPI | ETH_W5500_IDF_SPI.ino | |
| 106 | FFat | FFat_Test | FFat_Test.ino | |
| 107 | FFat | FFat_time | FFat_time.ino | |
| 108 | HTTPClient | Authorization | Authorization.ino | |
| 109 | HTTPClient | BasicHttpClient | BasicHttpClient.ino | |
| 110 | HTTPClient | BasicHttpsClient | BasicHttpsClient.ino | |
| 111 | HTTPClient | HTTPClientEnterprise | HTTPClientEnterprise.ino | |
| 112 | HTTPClient | ReuseConnection | ReuseConnection.ino | |
| 113 | HTTPClient | StreamHttpClient | StreamHttpClient.ino | |
| 114 | HTTPUpdate | httpUpdate | httpUpdate.ino | |
| 115 | HTTPUpdate | httpUpdateSecure | httpUpdateSecure.ino | |
| 116 | HTTPUpdate | httpUpdateSPIFFS | httpUpdateSPIFFS.ino | |
| 117 | HTTPUpdateServer | WebUpdater | WebUpdater.ino | |
| 118 | Insights | DiagnosticsSmokeTest | DiagnosticsSmokeTest.ino | |
| 119 | Insights | MinimalDiagnostics | MinimalDiagnostics.ino | |
| 120 | LittleFS | LITTLEFS_test | LITTLEFS_test.ino | |
| 121 | LittleFS | LITTLEFS_time | LITTLEFS_time.ino | |
| 122 | NetBIOS | ESP_NBNST | ESP_NBNST.ino | |
| 123 | NetworkClientSecure | WiFiClientInsecure | WiFiClientInsecure.ino | |
| 124 | NetworkClientSecure | WiFiClientPSK | WiFiClientPSK.ino | |
| 125 | NetworkClientSecure | WiFiClientSecure | WiFiClientSecure.ino | |
| 126 | NetworkClientSecure | WiFiClientSecureEnterprise | WiFiClientSecureEnterprise.ino | |
| 127 | NetworkClientSecure | WiFiClientSecureProtocolUpgrade | WiFiClientSecureProtocolUpgrade.ino | |
| 128 | NetworkClientSecure | WiFiClientShowPeerCredentials | WiFiClientShowPeerCredentials.ino | |
| 129 | NetworkClientSecure | WiFiClientTrustOnFirstUse | WiFiClientTrustOnFirstUse.ino | |
| 130 | PPP | PPP_Basic | PPP_Basic.ino | |
| 131 | Preferences | Prefs2Struct | Prefs2Struct.ino | |
| 132 | Preferences | StartCounter | StartCounter.ino | |
| 133 | RainMaker | RMakerCustom | RMakerCustom.ino | |
| 134 | RainMaker | RMakerCustomAirCooler | RMakerCustomAirCooler.ino | |
| 135 | RainMaker | RMakerSonoffDualR3 | RMakerSonoffDualR3.ino | |
| 136 | RainMaker | RMakerSwitch | RMakerSwitch.ino | |
| 137 | SD | SD_Test | SD_Test.ino | |
| 138 | SD | SD_time | SD_time.ino | |
| 139 | SD_MMC | SDMMC_Test | SDMMC_Test.ino | |
| 140 | SD_MMC | SDMMC_time | SDMMC_time.ino | |
| 141 | SimpleBLE | SimpleBleDevice | SimpleBleDevice.ino | |
| 142 | SPI | SPI_Multiple_Buses | SPI_Multiple_Buses.ino | |
| 143 | SPIFFS | SPIFFS_Test | SPIFFS_Test.ino | |
| 144 | SPIFFS | SPIFFS_time | SPIFFS_time.ino | |
| 145 | TFLiteMicro | hello_world | hello_world.ino | |
| 146 | Ticker | Blinker | Blinker.ino | |
| 147 | Ticker | TickerBasic | TickerBasic.ino | |
| 148 | Ticker | TickerParameter | TickerParameter.ino | |
| 149 | Update | AWS_S3_OTA_Update | AWS_S3_OTA_Update.ino | |
| 150 | Update | HTTPS_OTA_Update | HTTPS_OTA_Update.ino | |
| 151 | Update | HTTP_Client_AES_OTA_Update | HTTP_Client_AES_OTA_Update.ino | |
| 152 | Update | HTTP_Server_AES_OTA_Update | HTTP_Server_AES_OTA_Update.ino | |
| 153 | Update | OTAWebUpdater | OTAWebUpdater.ino | |
| 154 | Update | SD_Update | SD_Update.ino | |
| 155 | USB | CompositeDevice | CompositeDevice.ino | |
| 156 | USB | ConsumerControl | ConsumerControl.ino | |
| 157 | USB | CustomHIDDevice | CustomHIDDevice.ino | |
| 158 | USB | FirmwareMSC | FirmwareMSC.ino | |
| 159 | USB | Gamepad | Gamepad.ino | |
| 160 | USB | HIDVendor | HIDVendor.ino | |
| 161 | USB | Keyboard | KeyboardLogout | KeyboardLogout.ino |
| 162 | USB | Keyboard | KeyboardMessage | KeyboardMessage.ino |
| 163 | USB | Keyboard | KeyboardReprogram | KeyboardReprogram.ino |
| 164 | USB | Keyboard | KeyboardSerial | KeyboardSerial.ino |
| 165 | USB | KeyboardAndMouseControl | KeyboardAndMouseControl.ino | |
| 166 | USB | MIDI | MidiController | MidiController.ino |
| 167 | USB | MIDI | MidiInterface | MidiInterface.ino |
| 168 | USB | MIDI | MidiMusicBox | MidiMusicBox.ino |
| 169 | USB | MIDI | ReceiveMidi | ReceiveMidi.ino |
| 170 | USB | Mouse | ButtonMouseControl | ButtonMouseControl.ino |
| 171 | USB | SystemControl | SystemControl.ino | |
| 172 | USB | USBMSC | USBMSC.ino | |
| 173 | USB | USBSerial | USBSerial.ino | |
| 174 | USB | USBVendor | USBVendor.ino | |
| 175 | WebServer | AdvancedWebServer | AdvancedWebServer.ino | |
| 176 | WebServer | FSBrowser | FSBrowser.ino | |
| 177 | WebServer | HelloServer | HelloServer.ino | |
| 178 | WebServer | HttpAdvancedAuth | HttpAdvancedAuth.ino | |
| 179 | WebServer | HttpAuthCallback | HttpAuthCallback.ino | |
| 180 | WebServer | HttpAuthCallbackInline | HttpAuthCallbackInline.ino | |
| 181 | WebServer | HttpBasicAuth | HttpBasicAuth.ino | |
| 182 | WebServer | HttpBasicAuthSHA1 | HttpBasicAuthSHA1.ino | |
| 183 | WebServer | HttpBasicAuthSHA1orBearerToken | HttpBasicAuthSHA1orBearerToken.ino | |
| 184 | WebServer | MultiHomedServers | MultiHomedServers.ino | |
| 185 | WebServer | PathArgServer | PathArgServer.ino | |
| 186 | WebServer | SDWebServer | SDWebServer.ino | |
| 187 | WebServer | SimpleAuthentification | SimpleAuthentification.ino | |
| 188 | WebServer | UploadHugeFile | UploadHugeFile.ino | |
| 189 | WebServer | WebServer | WebServer.ino | |
| 190 | WebServer | WebUpdate | WebUpdate.ino | |
| 191 | WiFi | FTM | FTM_Initiator | FTM_Initiator.ino |
| 192 | WiFi | FTM | FTM_Responder | FTM_Responder.ino |
| 193 | WiFi | SimpleWiFiServer | SimpleWiFiServer.ino | |
| 194 | WiFi | WiFiAccessPoint | WiFiAccessPoint.ino | |
| 195 | WiFi | WiFiBlueToothSwitch | WiFiBlueToothSwitch.ino | |
| 196 | WiFi | WiFiClient | WiFiClient.ino | |
| 197 | WiFi | WiFiClientBasic | WiFiClientBasic.ino | |
| 198 | WiFi | WiFiClientConnect | WiFiClientConnect.ino | |
| 199 | WiFi | WiFiClientEnterprise | WiFiClientEnterprise.ino | |
| 200 | WiFi | WiFiClientEvents | WiFiClientEvents.ino | |
| 201 | WiFi | WiFiClientStaticIP | WiFiClientStaticIP.ino | |
| 202 | WiFi | WiFiIPv6 | WiFiIPv6.ino | |
| 203 | WiFi | WiFiMulti | WiFiMulti.ino | |
| 204 | WiFi | WiFiMultiAdvanced | WiFiMultiAdvanced.ino | |
| 205 | WiFi | WiFiScan | WiFiScan.ino | |
| 206 | WiFi | WiFiScanAsync | WiFiScanAsync.ino | |
| 207 | WiFi | WiFiScanDualAntenna | WiFiScanDualAntenna.ino | |
| 208 | WiFi | WiFiSmartConfig | WiFiSmartConfig.ino | |
| 209 | WiFi | WiFiTelnetToSerial | WiFiTelnetToSerial.ino | |
| 210 | WiFi | WiFiUDPClient | WiFiUDPClient.ino | |
| 211 | WiFi | WPS | WPS.ino | |
| 212 | WiFiProv | WiFiProv | WiFiProv.ino | |
| 213 | Wire | WireMaster | WireMaster.ino | |
| 214 | Wire | WireScan | WireScan.ino | |
| 215 | Wire | WireSlave | WireSlave.ino |
上記が3.0.0に入っていたスケッチ例の一覧です。2.0.17との差分を確認してみます。
削除された項目
HallSensor
ホールセンサーはESP32に内蔵しているセンサーで、磁石などが近づいたことがわかります。ただし精度が怪しいのでデータシートから消された機能になります。今回のバージョンアップに伴いAPIからも削除されていました。
I2S
I2Sは大幅に作り直しが入っていますのでESP_I2Sに純粋なサウンド系は入っています。ただし、ADCまわりに関してはI2Sから削除されて、AnalogReadContinuousなどに移動しています。
追加された項目
Utilities
HEXやMD5、SHA1に対してのヘルパー関数などが追加されているようです。
- HEXBuilder::hex2bytes
- HEXBuilder::bytes2hex
- md5.add(password) -> .calculate() -> .toString()
- md5.addHexString(passwordAsHex)
- sha1.add(password)
- sha1.addHexString(passwordAsHex)
上記のようなものでよく使う変換が可能になっています。
Zigbee
ZigbeeはC6など新しいチップでESP-IDF5以降でないと対応していないため今回追加されています。
ESP_I2S
I2SからESP_I2Sに名前が変わっていますが、内部もかなり変更されているため過去との互換性はないようです。
ESP_NOW
こちらもESPNowからESP_NOWに名前が変わって、中身をかなり変わっています。
ESP_SR
マイクを利用しての音声入力をするライブラリです。
Ethernet
昔からサポートはしていましたがW5500のサンプルが追加されていました。
PPP
LTEモデムのSIM7600を利用してPPP接続するためのサンプルがありました。
TFLiteMicro
こちらESP-IDFでは昔からサポートされていましたがArduino環境では公式サポートがなかったのですが増えていました。とはいえhello_worldですのでサインカーブを出力するやつで、とくになにもできません。
Ticker
タイマー周りが変更あったので、サンプルも追加されていました。
MIDI
USBの中にMIDIが増えていました。中身はシリアル通信なのでシンプルなのですが、公式スケッチ例が増えたのは嬉しいです。
まとめ
まだあまりさわれていないので、気になったところは今後中身を確認してみたいと思います。あと地味にUSBシリアルまわりも変わっていました。前のバージョンは地味に状態によって定義される名前が変更されていたのですが、今回はSerial0とUSBSerialなど存在するシリアルが常に定義されており、Serialの別名をどれにするのかを状況によって変更しています。とりあえずSerialに出力しておけばコンパイルエラーにはならなくなりました。


コメント
https://github.com/espressif/arduino-esp32/blob/master/docs/en/migration_guides/2.x_to_3.0.rst#ledc
ではledcSetupとledcAttachPinのAPIが削除されたとあるので、M5Stack公式ライブラリのSpeaker.cppが更新されないとPWM機能を使用する際にエラーが出るかもしれないですね
そうですね
PWMのチャンネル指定がなくなって、自動指定に変わったので微妙に引数が変わっています
タイマー周りもいろいろ変わっていたり、赤外線リモコンなどで使うRMTも影響範囲が大きいみたいです
なのでM5Stackの場合には3系はまだ早く、M5Stack板のボードマネージャーも2系のままで更新されていないようでした