M5Core2

2022年1月 1日 (土)

WebRadio「M5Stack-Core2-MediaPlayer」を動かす。

2022/1/6
platformio.iniのライブラリの表現を
バージョン付きのものに変更した。

2022/1/1
初版

WebRadio for M5Core2

WebRadio for M5Core2

概要

WebRadio「M5Stack-Core2-MediaPlayer」を動かす。
Arduinoのスケッチになっているが、platformioでビルドする。
ターゲットは、M5Core2になっている。
直接関係ない話だが、同じスケッチが、なぜかArduino-IDEではエラーになりコンパイルできなかった。
(なにかしらの環境の問題のようだ)

プロジェクト作成

以下の手順でplatformioのプロジェクトを作成する:

# platformio環境に入る mkdir Core2_Media_Player cd Core2_Media_Player mkdir sc cd src # ソースをダウンロードする wget https://raw.githubusercontent.com/bwbguard/M5Stack-Core2-MediaPlayer/main/Core2_Media_Player.ino cd .. # platformioの設定ファイルをダウンロードする wget https://raw.githubusercontent.com/espressif/arduino-esp32/master/tools/partitions/default_16MB.csv gedit platormio.ini # 次節のplatformio.iniの内容を作成する

パッチ

ソースを以下のように変更する。

src/Core2_Media_Player.ino

#40行あたりを自分のWiFi環境に合わせて変更する: const char *SSID = "ENTER_SSID_HERE"; const char *PASSWORD = "ENTER_WIFI_PASSWORD_HERE";

platformio.ini

M5Core2用

[env:m5core2] platform = espressif32 board = m5stack-core2 framework = arduino upload_speed = 2000000 monitor_speed = 115200 board_build.partitions = default_16MB.csv build_flags = -DM5C2 -DCORE_DEBUG_LEVEL=4 -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue lib_deps = https://github.com/m5stack/M5Core2.git https://github.com/FastLED/FastLED ;https://github.com/m5stack/M5Core2/blob/master/examples/core2_for_aws/ArduinoECCX08.zip lovyan03/LovyanGFX adafruit/Adafruit BMP280 Library @ ^2.5.0 adafruit/Adafruit Unified Sensor @ ^1.1.4 m5stack/UNIT_ENV @ ^0.0.2 ;https://github.com/earlephilhower/ESP8266Audio.git earlephilhower/ESP8266Audio@^1.9.5 lib_ldf_mode = deep+

動作

起動するとWiFiでネットワークに接続し、設定されているURLのインターネットラジオが動作する。
タッチボタンは左から[Vulume],[Station],[Mute]になっている。

参考情報

terminal関連:
Bootterm – a developer-friendly serial terminal program

ESP8266Audio関連:
ESP8266Audio - supports ESP8266 & ESP32 & Raspberry Pi RP2040
M5Stack-Core2-MediaPlayer
Arduino Web Radio Player(M5StickC)

M5Atom関連:
M5Atomの細かい仕様
Grove端子(HY2.0-4P、PH2.0-4P)について調べてみた

M5StickC/Plus関連:
M5StickCのIOについて調べてみた
Arduino(M5StickC)でefont Unicodeフォント表示 完結編

M5Core2関連:
M5Stack Core2を使ってみました。

platformio関連:
arduinoフレームワーク用platformio.ini集
Building Core2 FactoryDemo in PlatformIO
VSCodeとPlatformIOでM5Stack Core2開発
M5Stack Core2とVSCode + PlatformIOとでM5Stackプログラミングを始めてみた。

Arduino-IDE関連:
Arduino IDE environment - M5Paper
Arduino IDEのインストールと設定 (Windows, Mac, Linux対応)

M5Stackファミリ関連:
M5Core2 Arduino Install
M5Paper Arduino Install
M5CoreInk Arduino Install
M5Stamp-PICO Arduino Install
M5Stamp-C3 Arduino Install
Wio-Terminal/ESP8622/ESP32ボードを共通のスケッチで動かす(NTP-CLIENT編)
Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(STARWARS編)
Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(MQTT編)
Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(REST-API編)
Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(OSC編)

以上

続きを読む "WebRadio「M5Stack-Core2-MediaPlayer」を動かす。"

| | コメント (0)

「M5Stack用回転角ユニット」を動かす

2022/1/1
初版

UNIT_ANGLE

UNIT_ANGLE

概要

UNIT_ANGLE「M5Stack用回転角ユニット」を動かす。
ソースは共通化しており、ターゲットのM5Atom,M5StickCPlus,M5Core2をplatformio.iniの内容で切り替えてビルドする。
直接関係ない話だが、M5Atom用に提供されているUNIT_ANGLEのサンプル・スケッチは、なぜかArduino-IDEではエラーになりコンパイルできなかった。
(なにかしらの環境の問題のようだ)

ソース

src/main.ino

/* ******************************************************************************* * Copyright (c) 2021 by M5Stack * Equipped with Atom-Lite/Matrix sample source code * 配套 Atom-Lite/Matrix 示例源代码 * Visit the website for more information:https://docs.m5stack.com/en/products * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products * * describe:Angle. 角度计 * date:2021/8/9 ******************************************************************************* Description: Read the Angle of the angometer and convert it to digital display 读取角度计的角度,并转换为数字量显示 */ #ifdef M5ATOM #include <M5Atom.h> #endif #ifdef M5STICK_CP #include <M5StickCPlus.h> #endif #ifdef M5C2 #include <M5Core2.h> #endif #ifdef M5ATOM int sensorPin = 32; // set the input pin for the potentiometer. 设置角度计的输入引脚 #endif #ifdef M5STICK_CP int sensorPin = 33; #endif #ifdef M5C2 int sensorPin = 33; #endif int last_sensorValue = 100; // Stores the value last read by the sensor. 存储传感器上次读取到的值 int cur_sensorValue = 0; // Stores the value currently read by the sensor. 存储传感器当前读取到的值 void setup() { M5.begin(); pinMode(sensorPin, INPUT); dacWrite(25, 0); #ifdef M5STICK_CP M5.Lcd.setRotation(3); M5.Lcd.setCursor(0, 10, 2); M5.Lcd.print("The value of ANGLE: "); #endif #ifdef M5C2 M5.Lcd.setTextSize(2); //Set the font size to 2. 设置字体大小为2 M5.Lcd.print("the value of ANGLE: "); #endif } void loop() { // read the value from the sensor: cur_sensorValue = analogRead(sensorPin); #ifdef M5ATOM if(abs(cur_sensorValue - last_sensorValue) > 10){ //If the difference is more than 10. 如果差值超过10 Serial.print("the value of ANGLE: "); Serial.println(cur_sensorValue); last_sensorValue = cur_sensorValue; } delay(200); #endif #ifdef M5STICK_CP M5.Lcd.setCursor(80, 50, 6); if(abs(cur_sensorValue - last_sensorValue) > 10){//debaunce M5.Lcd.fillRect(100, 50, 100, 40, BLACK); M5.Lcd.print(cur_sensorValue); last_sensorValue = cur_sensorValue; } delay(50); #endif #ifdef M5C2 M5.Lcd.setCursor(0, 25); if(abs(cur_sensorValue - last_sensorValue) > 10){//debaunce M5.Lcd.fillRect(0, 25, 100, 25, BLACK); M5.Lcd.print(cur_sensorValue); last_sensorValue = cur_sensorValue; } delay(50); #endif }

platformio.ini

M5Atom用

[env:M5ATOM] platform = espressif32 board = m5stick-c framework = arduino build_flags = -DM5ATOM upload_poert = /dev/ttyUSB0 monitor_speed = 115200 lib_deps = m5stack/M5Atom @ ^0.0.7 fastled/FastLED @ ^3.4.0 adafruit/Adafruit NeoPixel @ ^1.10.3 lib_ldf_mode = deep+

M5StickCPlus用

[env:M5StickCPlus] platform = espressif32 board = m5stick-c framework = arduino build_flags = -DM5STICK_CP monitor_speed = 115200 lib_ldf_mode = deep+ lib_deps = m5stack/M5StickCPlus @ ^0.0.5 tinyu-zhao/FFT @ ^0.0.1 m5stack/UNIT_ENV @ ^0.0.2 adafruit/Adafruit BMP280 Library @ ^2.5.0 adafruit/Adafruit Unified Sensor @ ^1.1.4 adafruit/Adafruit NeoPixel @ ^1.10.3

M5Core2用

[env:m5core2] platform = espressif32 board = m5stack-core2 framework = arduino upload_speed = 2000000 monitor_speed = 115200 board_build.partitions = default_16MB.csv build_flags = -DM5C2 -DCORE_DEBUG_LEVEL=4 -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue lib_deps = https://github.com/m5stack/M5Core2.git https://github.com/FastLED/FastLED ;https://github.com/m5stack/M5Core2/blob/master/examples/core2_for_aws/ArduinoECCX08.zip lovyan03/LovyanGFX adafruit/Adafruit BMP280 Library @ ^2.5.0 adafruit/Adafruit Unified Sensor @ ^1.1.4 m5stack/UNIT_ENV @ ^0.0.2 adafruit/Adafruit NeoPixel @ ^1.10.3 lib_ldf_mode = deep+

動作

実態はポテンショメーターなのでアナログで読み込んだ値がLCDに表示される。
(M5Atomではシリアルに出力される)

M5Atomの出力例(シリアル出力):

$ bt -L 1 No port specified, using ttyUSB0 (last registered). Use -l to list ports. Trying port ttyUSB0... Connected to ttyUSB0 at 115200 bps. Escape character is 'Ctrl-]'. Use escape followed by '?' for help. the value of ANGLE: 2739 the value of ANGLE: 2704 the value of ANGLE: 2717 <省略> the value of ANGLE: 706 the value of ANGLE: 1059 the value of ANGLE: 2411 the value of ANGLE: 4095 the value of ANGLE: 4049 the value of ANGLE: 4095 ...

参考情報

terminal関連:
Bootterm – a developer-friendly serial terminal program

M5Atom関連:
M5Atomの細かい仕様
Grove端子(HY2.0-4P、PH2.0-4P)について調べてみた

M5StickC/Plus関連:
M5StickCのIOについて調べてみた
Arduino(M5StickC)でefont Unicodeフォント表示 完結編

M5Core2関連:
M5Stack Core2を使ってみました。

platformio関連:
arduinoフレームワーク用platformio.ini集
Building Core2 FactoryDemo in PlatformIO
VSCodeとPlatformIOでM5Stack Core2開発
M5Stack Core2とVSCode + PlatformIOとでM5Stackプログラミングを始めてみた。

Arduino-IDE関連:
Arduino IDE environment - M5Paper
Arduino IDEのインストールと設定 (Windows, Mac, Linux対応)

M5Stackファミリ関連:
M5Core2 Arduino Install
M5Paper Arduino Install
M5CoreInk Arduino Install
M5Stamp-PICO Arduino Install
M5Stamp-C3 Arduino Install
Wio-Terminal/ESP8622/ESP32ボードを共通のスケッチで動かす(NTP-CLIENT編)
Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(STARWARS編)
Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(MQTT編)
Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(REST-API編)
Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(OSC編)

以上

続きを読む "「M5Stack用回転角ユニット」を動かす"

| | コメント (0)

2021年12月25日 (土)

NTPによる時刻設定(M5StickC_Plus, M5CoreInk, M5Core2)

2021/12/26
サポートボードとしてM5Core2を追加した。

2021/12/25
初版

NTPによる時刻設定(M5StickC_Plus, M5CoreInk, M5Core2)

NTPによる時刻設定(M5StickC_Plus, M5CoreInk, M5Core2)

概要

M5StickC_Plus, M5CoreInk, M5Core2は、RTC内蔵されており電源オフでも時刻を保存している。ここでは、NTPに時刻設定するスケッチを紹介する。
M5StickCのRTCをNTPサーバーからセットする」のスケッチを参考にして、M5StickC_Plus, M5CoreInk,M5Core2用に修正する。ソースは共通になっており、platformio.iniの内容で切り替えてビルドする。

ソース

以下のようにソースを修正する:
src/main.ino

//#define M5CI //#define M5C2 //#define M5STICK_CP #ifdef M5STICK_CP //#include <M5StickC.h> #include <M5StickCPlus.h> #endif #ifdef M5C2 #include <M5Core2.h> #endif #ifdef M5CI #include "M5CoreInk.h" #endif #include <WiFi.h> #include "time.h" #ifdef M5CI Ink_Sprite InkPageSprite(&M5.M5Ink); char titleStrbuff[64]; char ntpStrbuff[64]; char dateStrbuff[64]; char weekStrbuff[64]; char timeStrbuff[64]; #endif const char* ssid = "your_ssid"; const char* password = "your_password"; const char* ntpServer = "ntp.jst.mfeed.ad.jp"; RTC_TimeTypeDef RTC_TimeStruct; RTC_DateTypeDef RTC_DateStruct; void setup() { #ifdef M5CI M5.begin(); if( !M5.M5Ink.isInit()) { Serial.printf("Ink Init faild"); } M5.M5Ink.clear(); delay(1000); //creat ink refresh Sprite if( InkPageSprite.creatSprite(0,0,200,200,true) != 0 ) { Serial.printf("Ink Sprite creat faild"); } #endif #ifndef M5CI // put your setup code here, to run once: M5.begin(); M5.Lcd.setRotation(3); M5.Lcd.fillScreen(BLACK); M5.Lcd.setTextSize(1); M5.Lcd.setCursor(40, 0, 2); M5.Lcd.println("RTC NTP TEST"); #endif // connect to WiFi Serial.printf("Connecting to %s ", ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(" CONNECTED"); // Set ntp time to local configTime(9 * 3600, 0, ntpServer); // Get local time struct tm timeInfo; if (getLocalTime(&timeInfo)) { #ifndef M5CI M5.Lcd.print(" NTP : "); M5.Lcd.println(ntpServer); #endif // Set RTC time RTC_TimeTypeDef TimeStruct; TimeStruct.Hours = timeInfo.tm_hour; TimeStruct.Minutes = timeInfo.tm_min; TimeStruct.Seconds = timeInfo.tm_sec; #ifndef M5CI M5.Rtc.SetTime(&TimeStruct); #endif #ifdef M5CI M5.rtc.SetTime(&TimeStruct); #endif RTC_DateTypeDef DateStruct; DateStruct.WeekDay = timeInfo.tm_wday; DateStruct.Month = timeInfo.tm_mon + 1; DateStruct.Date = timeInfo.tm_mday; DateStruct.Year = timeInfo.tm_year + 1900; #ifdef M5STICK_CP M5.Rtc.SetData(&DateStruct); #endif #ifdef M5C2 M5.Rtc.SetDate(&DateStruct); #endif #ifdef M5CI M5.rtc.SetData(&DateStruct); #endif } //disconnect WiFi WiFi.disconnect(true); WiFi.mode(WIFI_OFF); } void loop() { static const char *wd[7] = {"Sun","Mon","Tue","Wed","Thr","Fri","Sat"}; #ifndef M5CI // put your main code here, to run repeatedly: M5.Rtc.GetTime(&RTC_TimeStruct); #ifdef M5STICK_CP M5.Rtc.GetData(&RTC_DateStruct); #endif #ifdef M5C2 M5.Rtc.GetDate(&RTC_DateStruct); #endif M5.Lcd.setCursor(0, 30); M5.Lcd.printf(" Date: %04d-%02d-%02d\n", RTC_DateStruct.Year, RTC_DateStruct.Month, RTC_DateStruct.Date); M5.Lcd.printf(" Week: %s\n", wd[RTC_DateStruct.WeekDay]); M5.Lcd.printf(" Time: %02d : %02d : %02d\n", RTC_TimeStruct.Hours, RTC_TimeStruct.Minutes, RTC_TimeStruct.Seconds); #endif #ifdef M5CI // put your main code here, to run repeatedly: M5.rtc.GetTime(&RTC_TimeStruct); M5.rtc.GetData(&RTC_DateStruct); sprintf(titleStrbuff,"RTC NTP TEST"); sprintf(ntpStrbuff,"NTP:%s", ntpServer); sprintf(dateStrbuff,"Date: %04d-%02d-%02d", RTC_DateStruct.Year, RTC_DateStruct.Month, RTC_DateStruct.Date); sprintf(weekStrbuff,"Week: %s", wd[RTC_DateStruct.WeekDay]); sprintf(timeStrbuff,"Time: %02d : %02d : %02d", RTC_TimeStruct.Hours, RTC_TimeStruct.Minutes, RTC_TimeStruct.Seconds); InkPageSprite.clear(); InkPageSprite.drawString(5,5,titleStrbuff); InkPageSprite.drawString(5,20,ntpStrbuff); InkPageSprite.drawString(5,35,dateStrbuff); InkPageSprite.drawString(5,50,weekStrbuff); InkPageSprite.drawString(5,65,timeStrbuff); InkPageSprite.pushSprite(); #endif delay(500); }

以下は、自分の環境に合わせて修正すること:

const char* ssid = "your_ssid"; const char* password = "your_password"; const char* ntpServer = "ntp.jst.mfeed.ad.jp";

platformio.ini

M5StickC_Plus, M5CoreInk. M5Core2用は以下のようになり、ビルドのターゲットに合わせて内容を変更してビルドする。

M5StickC_Plus用:
platformio.ini

[env:M5StickCPlus] platform = espressif32 board = m5stick-c framework = arduino build_flags = -DM5STICK_CP monitor_speed = 115200 lib_ldf_mode = deep+ lib_deps = m5stack/M5StickCPlus @ ^0.0.5 tinyu-zhao/FFT @ ^0.0.1 m5stack/UNIT_ENV @ ^0.0.2 adafruit/Adafruit BMP280 Library @ ^2.5.0 adafruit/Adafruit Unified Sensor @ ^1.1.4

M5CoreInk用:
platformio.ini

[env:M5CoreInk] platform = espressif32 board = m5stick-c framework = arduino build_flags = -DM5CI upload_poert = /dev/ttyUSB0 monitor_speed = 115200 lib_deps = m5stack/M5-CoreInk @ ^0.0.2 knolleary/PubSubClient @ ^2.8 m5stack/UNIT_ENV @ ^0.0.2 lib_ldf_mode = deep+

M5Core2用:
platformio.ini

[env:m5core2] platform = espressif32 board = m5stack-core2 framework = arduino upload_speed = 2000000 monitor_speed = 115200 board_build.partitions = default_16MB.csv build_flags = -DM5C2 -DCORE_DEBUG_LEVEL=4 -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue lib_deps = https://github.com/m5stack/M5Core2.git https://github.com/FastLED/FastLED ;https://github.com/m5stack/M5Core2/blob/master/examples/core2_for_aws/ArduinoECCX08.zip lovyan03/LovyanGFX adafruit/Adafruit BMP280 Library @ ^2.5.0 adafruit/Adafruit Unified Sensor @ ^1.1.4 m5stack/UNIT_ENV @ ^0.0.2 lib_ldf_mode = deep+

なお、ファイルとして、default_16MB.csvが必要になる。
以下の手順でダウンロードすること:

wget https://github.com/espressif/arduino-esp32/blob/master/tools/partitions/default_16MB.csv

動作

ビルドして起動するとNTP同期した時刻が表示される。
一回動かせば時刻が設定されるので、他のスケッチを書き込んでも、設定された時刻が保存される。

参考情報

platformio関連:
arduinoフレームワーク用platformio.ini集
Building Core2 FactoryDemo in PlatformIO
VSCodeとPlatformIOでM5Stack Core2開発
M5Stack Core2とVSCode + PlatformIOとでM5Stackプログラミングを始めてみた。

Arduino-IDE関連:
Arduino IDE environment - M5Paper
Arduino IDEのインストールと設定 (Windows, Mac, Linux対応)

M5Stackファミリ関連:
M5Core2 Arduino Install
M5Paper Arduino Install
M5CoreInk Arduino Install
M5Stamp-PICO Arduino Install
M5Stamp-C3 Arduino Install
Wio-Terminal/ESP8622/ESP32ボードを共通のスケッチで動かす(NTP-CLIENT編)
Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(STARWARS編)
Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(MQTT編)
Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(REST-API編)
Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(OSC編)

その他:
スルーホール用テストワイヤ TT-200 (10本入)

以上

続きを読む "NTPによる時刻設定(M5StickC_Plus, M5CoreInk, M5Core2)"

| | コメント (0)

2021年12月22日 (水)

M5Core2 Arduino Install

2022/1/29
誤記修正:

修正前: wget https://github.com/espressif/arduino-esp32/blob/master/tools/partitions/default_16MB.csv → 修正後: wget https://raw.githubusercontent.com/espressif/arduino-esp32/master/tools/partitions/default_16MB.csv

2021/12/22
初版

M5Core2 Arduino Install

M5Core2 Arduino Install

概要

platformioベースのArduinoフレームワークを使って
M5Stack Core2 IoT開発キット」を動かす。
ホスト環境は、ubuntu20.04とする。
なお、platformioがインストール済みのものとする。

linuxのplatformioのインストールについては以下を参照のこと。
arduinoフレームワーク用platformio.ini集

電源操作:
・電源オン:ボタン(左側面)のを押す。
・電源オフ:6秒間ボタン(左側面)を長押しする。
・リスタート:底にあるリセットボタンを押す。

M5Core2_FactoryTestの書き込み方法

まず、FactoryTestの書き込み方法について説明する。
以下を実行する:

# ソースをダウンロードする cd Downloads/ git clone https://github.com/m5stack/M5-ProductExampleCodes.git cd pio # platformio環境に入る source pio_env/bin/activate mkdir core2 cd core2 mkdir FactoryTest cd FactoryTest # default_16MB.csvをダウンロードする wget https://raw.githubusercontent.com/espressif/arduino-esp32/master/tools/partitions/default_16MB.csv # ソースをコピーする cp -r ~/Downloads/M5-ProductExampleCodes/Core/M5Core2/Arduino/Core2_Factory_test src gedit platformio.ini # 次節の内容のplatformio.iniを作成する # ビルド環境のクリーンアップ pio -t clean # M5CoreとPCをUSBで接続する # ビルド&書き込む pio -t upload

以上で書き込みが完了する。

なお、シリアルデバイスは通常「/dev/ttyACM0」になる。

platformio.ini

M5Core2のスケッチのビルドには
必要なライブラリの追加はあり得るが
基本的には以下のplatformio.iniを使用する。
platformio.ini

[env:m5core2] platform = espressif32 board = m5stack-core2 framework = arduino upload_speed = 2000000 monitor_speed = 115200 board_build.partitions = default_16MB.csv build_flags = -DCORE_DEBUG_LEVEL=4 -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue lib_deps = https://github.com/m5stack/M5Core2.git https://github.com/FastLED/FastLED ;https://github.com/m5stack/M5Core2/blob/master/examples/core2_for_aws/ArduinoECCX08.zip lovyan03/LovyanGFX adafruit/Adafruit BME280 Library@^2.1.2 adafruit/Adafruit Unified Sensor@^1.1 m5stack/UNIT_ENV @ ^0.0.2 lib_ldf_mode = deep+

新たなプロジェクトをビルドしたい場合、 FactoryTestのディレクトリを、 まるごとコピーして、ディレクトリ名と src配下のスケッチを変更すれば良い。

sketch#1(UNIT_ENV_III)

別のサンプルとして「M5Stack用温湿度気圧センサユニット Ver.3(ENV Ⅲ)」をPORT-Aに接続して温度、湿度、気圧をシリアルに出力するスケッチを動かす。

src/UNIT_ENV_III.ino

#include "Wire.h" #include "UNIT_ENV.h" SHT3X sht30; QMP6988 qmp6988; void setup() { Serial.begin(115200); Wire.begin(32, 33); // Core2 PORT-A qmp6988.init(); } void loop() { if (sht30.get() != 0) { return; } Serial.printf("Temperature: %2.2f℃ Humidity: %0.2f%% Pressure: %4.1f hPa\r\n", sht30.cTemp, sht30.humidity, qmp6988.calcPressure()/100); delay(1);//000); }

M5Stack系ボードで汎用的に使用できるようにシリアル出力のみにしている。 たぶん、依存している部分は「Wire.begin(32, 33);」と思われる。

platformio.iniは上のものが、そのまま使用できる。
(必要なライブラリは登録済み)

sketch#2(b3NTP)

b3NTP.ino

// select board ////#define WIO_TERMINAL ////#define ESP8266 ////#define ESP32 ////#define M5ATOM //------------------ // NTP Client for Wio-Terminal/ESP8266/ESP32 #ifdef M5ATOM #include "M5Atom.h" #define ESP32 #endif #ifdef WIO_TERMAL //#include <AtWiFi.h> #include <rpcWiFi.h> #endif #ifdef ESP8266 #include <ESP8266WiFi.h> #endif #ifdef ESP32 #include <WiFi.h> #endif #include <time.h> #define WIFI_SSID "your_wifi_ssid" #define WIFI_PASSWORD "your_wifi_password" void setup() { Serial.begin(115200); delay(100); Serial.print("\r\n\nReset:\r\n"); WiFi.begin(WIFI_SSID, WIFI_PASSWORD); while(WiFi.status() != WL_CONNECTED) { Serial.print('.'); delay(500); } Serial.println(); Serial.printf("Connected, IP address: "); Serial.println(WiFi.localIP()); configTzTime("JST-9", "ntp.nict.jp", "ntp.jst.mfeed.ad.jp"); // 2.7.0以降, esp32コンパチ } void loop() { time_t t; struct tm *tm; static const char *wd[7] = {"Sun","Mon","Tue","Wed","Thr","Fri","Sat"}; t = time(NULL); tm = localtime(&t); /***** Serial.printf("ESP8266/Arduino ver%s : %04d/%02d/%02d(%s) %02d:%02d:%02d\n", __STR(ARDUINO_ESP8266_GIT_DESC), tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, wd[tm->tm_wday], tm->tm_hour, tm->tm_min, tm->tm_sec); ****/ Serial.printf("Arduino NTP: %04d/%02d/%02d(%s) %02d:%02d:%02d\r\n", tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, wd[tm->tm_wday], tm->tm_hour, tm->tm_min, tm->tm_sec); delay(1000); }

以下はwifi環境に応じて変更すること:

#define WIFI_SSID "your_wifi_ssid" #define WIFI_PASSWORD "your_wifi_password"

本ソースは、WIO_TERMINAL、ESP8266、ESP32、M5ATOMで共通になっており、platformio.iniの内容でターゲットを切り替えることができる。

platformio.iniは、上のものが、そのまま使用できる。

実行時のシリアル出力(/dev/ttyACM0):

........ Connected, IP address: 192.168.1.15 Arduino NTP: 1970/01/01(Thr) 09:00:04 Arduino NTP: 1970/01/01(Thr) 09:00:05 Arduino NTP: 1970/01/01(Thr) 09:00:06 Arduino NTP: 1970/01/01(Thr) 09:00:07 Arduino NTP: 1970/01/01(Thr) 09:00:08 Arduino NTP: 2021/12/11(Sat) 16:55:59 ← ここでNTPによって時刻が同期している Arduino NTP: 2021/12/11(Sat) 16:56:00 Arduino NTP: 2021/12/11(Sat) 16:56:01

参考情報

platformio関連:
arduinoフレームワーク用platformio.ini集
Building Core2 FactoryDemo in PlatformIO
VSCodeとPlatformIOでM5Stack Core2開発
M5Stack Core2とVSCode + PlatformIOとでM5Stackプログラミングを始めてみた。

Arduino-IDE関連:
Arduino IDE environment - M5Paper
Arduino IDEのインストールと設定 (Windows, Mac, Linux対応)

M5Stackファミリ関連:
M5Paper Arduino Install
M5CoreInk Arduino Install
M5Stamp-PICO Arduino Install
M5Stamp-C3 Arduino Install
Wio-Terminal/ESP8622/ESP32ボードを共通のスケッチで動かす(NTP-CLIENT編)
Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(STARWARS編)
Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(MQTT編)
Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(REST-API編)
Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(OSC編)

その他:
スルーホール用テストワイヤ TT-200 (10本入)

以上

続きを読む "M5Core2 Arduino Install"

| | コメント (0)