PlatformIO

2022年8月18日 (木)

NuEVI/NuRADのビルド


🚧🚧🚧🚧 githubに移行中 🚧🚧🚧🚧

以下をクリックしてください:
NuEVI/NuRADのビルド

目次は以下をクリックしてください:
Welcome to xshige’s beta notes

githubのblogではコメントできないので
コメントする場合は、ここに書き込んでください。


続きを読む "NuEVI/NuRADのビルド"

| | コメント (0)

2022年2月 3日 (木)

Wio_ExtFlashLoad(WriteSampleMenu.ino)スケッチをplatformioでビルドする

2022/2/3
初版

Wio_ExtFlashLoad sketch build by platformio

Wio_ExtFlashLoad sketch build by platformio

概要

Wio Ext Flash Load」、 「External Flash Loader library for Wio Terminal」 にあるWio_ExtFlashLoad(WriteSampleMenu.ino)スケッチをplatformioでビルドする。
arduinoのサンプル・スケッチとして提供されているものだが、plaformioビルド環境でビルドする。
Wio_ExtFlashLoadは、アプリを起動するメニューになっており、
SDカードにビルドした.binを起き、それを選択して起動する。

WriteSampleMenu.ino

以下の手順をダウンロード/ビルド/書き込みする:

# platformioの環境に入る # プロジェクト・ディレクトリを作成する mkdir Wio_ExtFlashLoad cd Wio_ExtFlashLoad mkdir src cd src wget https://raw.githubusercontent.com/ciniml/ExtFlashLoader/master/examples/WriteSampleMenu/WriteSampleMenu.ino wget https://raw.githubusercontent.com/ciniml/ExtFlashLoader/master/examples/WriteSampleMenu/menu_data.h cd .. gedit platformio.ini # 後節にあるplatformio.iniの内容を作成する # ビルド&書き込み pio run -t upload

以上で、実行すると、メニューが表示されるようになる。

platformio.ini

wio-terminal用:

[env:seeed_wio_terminal] platform = atmelsam board = seeed_wio_terminal framework = arduino build_flags = -DWIO_TERMINAL upload_protocol = sam-ba monitor_speed = 115200 lib_ldf_mode = deep+ lib_deps = https://github.com/Seeed-Studio/Seeed_Arduino_mbedtls/archive/dev.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcUnified/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcBLE/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcWiFi/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_FreeRTOS/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_FS/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_SFUD/archive/master.zip # https://github.com/Seeed-Studio/Seeed_Arduino_LCD/archive/master.zip # arduino-libraries/NTPClient@^3.1.0 # ciniml/ExtFlashLoader@^0.1.2

アプリ用.binを作成する

アプリ用SDの詳細は「External Flash Loader library for Wio Terminal」に記述されているので、その中に入れる.binの作成方法について説明する。

「pio run」でビルドすると
以下に.binができる:

.pio/build/seeed_wio_terminal/firmware.bin

これをfirmware.binをapp.binにリネームしてSDにコピーする。

これだけでメニューから起動できる。
ただ、このままだとアプリ起動後、
メニューに戻ることができないので
setup()にボタンAを押しながらリセットしたときに
メニューに戻るコードを埋め込む。

(1)TFT_eSPI対応アプリの場合、「External Flash Loader library for Wio Terminal」の「アプリケーションのメニューアプリ対応」を参照のこと。

(2)LGFX対応アプリの場合は
以下のコードを埋め込む:

以下のヘッダーを追加する: /////////////////////////////////////////// // application menu header #include <cstdint> #include <ExtFlashLoader.h> /////////////////////////////////////////// 変更前: void setup() { lcd.init(); ------------------- → 変更後: void setup() { //// goto application menu /////////////// lcd.init(); pinMode(WIO_KEY_A, INPUT_PULLUP); if( digitalRead(WIO_KEY_A) == LOW) { lcd.print("Launching QSPI application\r\n"); // for LGFX ExtFlashLoader::ExtFlashLoader loader; } ////////////////////////////////////////// // //lcd.init();

platformio.iniには
以下のライブラリを追加する:

lib_deps = ... <省略> ... # ciniml/ExtFlashLoader@^0.1.2

参照情報

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

LovyanGFX関連:
LovyanGFX - Display (LCD / OLED / EPD) graphics library (for ESP32 SPI, I2C, 8bitParallel / ESP8266 SPI, I2C / ATSAMD51 SPI) - M5Stack / M5StickC / TTGO T-Watch / ODROID-GO / ESP-WROVER-KIT / WioTerminal / and more...
LovyanGFX LCD Graphics driver
LovyanGFX-Display ライブラリを使用したスケッチをplatformioでビルドする

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対応)

以上

続きを読む "Wio_ExtFlashLoad(WriteSampleMenu.ino)スケッチをplatformioでビルドする"

| | コメント (0)

2022年1月31日 (月)

uncannyeyesスケッチをplatformioでビルドする

2022/1/30
初版

uncannyeyes sketch build by platformio

uncannyeyes sketch build by platformio

概要

M5Stack Electronic Animated Eyes」、 「M5StickC Electronic Animated Eyes」のuncannyeyesスケッチをplatformioでビルドする。
両目バージョンは、M5Core2/M5Stack-Fireで共通ソース化する。
片目バージョンは、M5StickC/M5stickCPlusで共通ソース化する。
platformio.iniの内容で、対応ボードを切り替えることになる。

両目バージョン

M5Stack-Fireは、オリジナルのソースで動作するが、
M5Core2でも動作するように共通化する。

以下の手順をダウンロード/ビルド/書き込みする:

# platformioの環境に入る # プロジェクト・ディレクトリを作成する mkdir M5Stack_uncannyEyes cd M5Stack_uncannyEyes wget https://macsbug.files.wordpress.com/2019/05/m5stack_uncannyeyes.zip_-1.pdf mv m5stack_uncannyeyes.zip_-1.pdf m5stack_uncannyeyes.zip unzip m5stack_uncannyeyes.zip mv M5Stack_uncannyEyes src cd src mv screenshotToConsole.ino screenshotToConsole.ino.bu gedit M5Stack_uncannyEyes.ino # M5Core2のために以下のパッチをかける

パッチ内容:

#56行目付近: #include <M5Stack.h> → #ifndef M5C2 #include <M5Stack.h> #endif #ifdef M5C2 #include <M5Core2.h> #endif ------------------------------------- #88行目付近: #define WINK_L_PIN 39 // Pin for LEFT eye wink button #define BLINK_PIN 38 // Pin for blink button (BOTH eyes) #define WINK_R_PIN 37 // Pin for RIGHT eye wink button → #ifndef M5C2 #define WINK_L_PIN 39 // Pin for LEFT eye wink button #define BLINK_PIN 38 // Pin for blink button (BOTH eyes) #define WINK_R_PIN 37 // Pin for RIGHT eye wink button #endif #ifdef M5C2 // M5Core2 #define WINK_L_PIN 32 // Pin for LEFT eye wink button #define BLINK_PIN 32 // Pin for blink button (BOTH eyes) #define WINK_R_PIN 33 // Pin for RIGHT eye wink button // for eyes enable status int eyesStatus = 3; // 1:left 2:right 3:both #endif ------------------------------------- #122行目: M5.Speaker.begin(); → #ifndef M5C2 M5.Speaker.begin(); #endif #129行目付近: pinMode(37, INPUT);pinMode(38, INPUT);pinMode(39, INPUT); → #ifndef M5C2 pinMode(37, INPUT);pinMode(38, INPUT);pinMode(39, INPUT); #endif #ifdef M5C2 pinMode(32, INPUT);pinMode(33, INPUT); #endif ------------------------------------- #153行目付近: if (e == 0){ M5.Lcd.setAddrWindow ( 1,0,128,128);} // set left window if (e == 1){ M5.Lcd.setAddrWindow (191,0,128,128);} // set right window → #ifndef M5C2 if (e == 0){ M5.Lcd.setAddrWindow ( 1,0,128,128);} // set left window if (e == 1){ M5.Lcd.setAddrWindow (191,0,128,128);} // set right window #endif #ifdef M5C2 switch(eyesStatus) { case 3: // both if (e == 0){ M5.Lcd.setAddrWindow ( 1,0,128,128);} // set left window if (e == 1){ M5.Lcd.setAddrWindow (191,0,128,128);} // set right window break; case 1: // left M5.Lcd.fillRect(191,0,128,128,TFT_BLACK); // clear oposite side if (e == 0){ M5.Lcd.setAddrWindow ( 1,0,128,128);} // set left window break; case 2: // right M5.Lcd.fillRect(1,0,128,128,TFT_BLACK); // clear oposite side if (e == 1){ M5.Lcd.setAddrWindow (191,0,128,128);} // set right window break; default: break; }; #endif ------------------------------------- #423行付近: //screenshotToConsole(); } → //screenshotToConsole(); #ifdef M5C2 //<<============================================ // touch button int keyCode = 0; TouchPoint_t pos = M5.Touch.getPressPoint(); if (pos.y > 240) { // Yが240以上はボタンのエリア if (pos.x < 109) { keyCode = 1; // Left Button } else if (pos.x > 218) { keyCode = 3; // Mid Button } else if (pos.x >= 109 && pos.x <= 218) { keyCode = 2; // Right Button } if (keyCode != 0) { // ボタンを押した場合には75ミリ秒振動モーターを動かす M5.Axp.SetLDOEnable(3, true); delay(75); M5.Axp.SetLDOEnable(3, false); //Serial.println(keyCode); // for Debug } if (keyCode == 1) eyesStatus = 1; // Left Button if (keyCode == 3) eyesStatus = 2; // Mid Button if (keyCode == 2) eyesStatus = 3; // Right Button } //Serial.println(eyesStatus); // for Debug //>>=========================================== #endif } -------------------------------------

続き:

cd .. # platformioの設定ファイルをダウンロードする wget https://raw.githubusercontent.com/espressif/arduino-esp32/master/tools/partitions/default_16MB.csv gedit platformio.ini # 後節にあるplatformio.iniの内容をビルドするボードに応じて作成する # ビルド&書き込み pio run -t upload

動作説明:
1.オリジナル版(M5Stack版)
オリジナルのものは、左ボタン、右ボタンを押すと、それぞれの目を瞑る(消える)。
中央ボタンを押すと両目を瞑る(消える)。
2.M5Core2版
オリジナルと同じ操作性は実装が難しかったので、
下の3つのタッチボタンで表示モードの切り替えにした。
左ボタン、右ボタンを押すとそれぞれの片目を表示するモードになり
中央ボタンは両目を表示するモードになる。

片目バージョン

M5StickCは、オリジナルのソースで動作するが、
M5StickCPlusでも動作するように共通化する。

以下の手順をダウンロード/ビルド/書き込みする:

以下のダウンロードurlがあるが、NOT_FOUNDになり使用できない。 https://macsbug.files.wordpress.com/2019/05/m5stickc_uncannyeyes_left.zip_.pdf https://macsbug.files.wordpress.com/2019/05/m5stickc_uncannyeyes_right.zip_.pdf そこで両目バージョンのプロジェクトを流用する: (1)両目バージョンのプロジェクト・ディレクトリをコピーして  片目バージョンのプロジェクト・ディレクトリ「M5SCx_uncannyEyes」を作成する。 (2)「M5StickC Electronic Animated Eyes」(https://macsbug.wordpress.com/2019/05/08/m5stickc-electronic-animated-eyes/)の末尾のスケッチ・ソースをコピーして、 プロジェクト・ディレクトリのM5Stack_uncannyEyes.inoの内容を差し替える。 (3)以下のようにパッチをかける: 変更前: #include <M5StickC.h> → 変更後: #ifdef M5STICK_C #include <M5StickC.h> #endif #ifdef M5STICK_CP #include <M5StickCPlus.h> #endif (4)platformio.iniをM5StickC,M5StickCPlus用に差し替える。 (5)「pio run -t upload」でビルド&書き込みする。

動作説明:
正面の[M5]ボタンを押すと目を瞑る(消える)

platformio.ini

上のスケッチをビルドするには、ボードに応じて、
以下の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 tobozo/M5Stack-SD-Updater@^1.1.8 lib_ldf_mode = deep+

M5Stack-Fire用:

[env:m5stack-fire] platform = espressif32 board = m5stack-fire framework = arduino monitor_speed = 115200 lib_ldf_mode = deep+ upload_speed = 2000000 upload_protocol = esptool board_build.partitions = default_16MB.csv build_flags = -DM5STACK_FIRE -DCORE_DEBUG_LEVEL=4 -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue lib_deps = m5stack/M5Stack@^0.3.9 ;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 tobozo/M5Stack-SD-Updater@^1.1.8

M5StickC用:

[env:M5StickC] platform = espressif32 board = m5stick-c framework = arduino build_flags = -DM5STICK_C monitor_speed = 115200 lib_ldf_mode = deep+ lib_deps = m5stack/M5StickC@^0.2.5 ;m5stack/M5StickCPlus @ ^0.0.5 tinyu-zhao/FFT @ ^0.0.1 ;https://github.com/earlephilhower/ESP8266Audio.git earlephilhower/ESP8266Audio@^1.9.5

M5StickCPlus用:

[env:M5StickCPlus] platform = espressif32 board = m5stick-c framework = arduino build_flags = -DM5STICK_CP monitor_speed = 115200 lib_ldf_mode = deep+ lib_deps = ;m5stack/M5StickC@^0.2.5 m5stack/M5StickCPlus @ ^0.0.5 tinyu-zhao/FFT @ ^0.0.1 ;https://github.com/earlephilhower/ESP8266Audio.git earlephilhower/ESP8266Audio@^1.9.5

参照情報

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

M5Core2関連:
M5Stack Core2のタッチパネル研究
M5Stack Core2のGPIO調査
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編)

その他;
Wio Electronic Animated Eyes

以上

続きを読む "uncannyeyesスケッチをplatformioでビルドする"

| | コメント (0)

2022年1月30日 (日)

LovyanGFX-Display ライブラリを使用したスケッチをplatformioでビルドする

2022/1/30
初版

LovyanGFX sketch build by platformio

LovyanGFX sketch build by platformio

概要

LovyanGFX - Display (LCD / OLED / EPD) graphics library」ライブラリを使用したスケッチを platformioでビルドする。
arduinoのサンプル・スケッチとして提供されているものだが、plaformioビルド環境では、エラーを出てビルドできないことがある。
それを解決したplatformio.iniを提供する。
対応ボードは、M5Core2,M5Stack-Fire,Wio-Terminalとなる。
スケッチのソースは共通で、platformio.iniの内容で、対応ボードを切り替えることになる。

arduino_misaki.ino

以下の手順をダウンロード/ビルド/書き込みする:

# platformioの環境に入る # プロジェクト・ディレクトリを作成する mkdir arduino_misaki cd arduino_misaki mkdir src cd src wget https://raw.githubusercontent.com/lovyan03/LovyanGFX/master/examples/HowToUse/4_unicode_fonts/arduino_misaki/arduino_misaki.ino cd .. # platformioの設定ファイルをダウンロードする(M5Stack系のみ) wget https://raw.githubusercontent.com/espressif/arduino-esp32/master/tools/partitions/default_16MB.csv gedit platformio.ini # 後節にあるplatformio.iniの内容をビルドするボードに応じて作成する # ビルド&書き込み pio run -t upload

efont.ino

以下の手順をダウンロード/ビルド/書き込みする:

# platformioの環境に入る # プロジェクト・ディレクトリを作成する mkdir efont cd efont mkdir src cd src wget https://raw.githubusercontent.com/lovyan03/LovyanGFX/master/examples/HowToUse/4_unicode_fonts/efont/efont.ino cd .. # platformioの設定ファイルをダウンロードする(M5Stack系のみ) wget https://raw.githubusercontent.com/espressif/arduino-esp32/master/tools/partitions/default_16MB.csv gedit platformio.ini # 後節にあるplatformio.iniの内容をビルドするボードに応じて作成する # ビルド&書き込み pio run -t upload

LongTextScroll.ino

以下の手順をダウンロード/ビルド/書き込みする:

# platformioの環境に入る # プロジェクト・ディレクトリを作成する mkdir LongTextScroll cd LongTextScroll mkdir src cd src wget https://raw.githubusercontent.com/lovyan03/LovyanGFX/master/examples/Standard/LongTextScroll/LongTextScroll.ino cd .. # platformioの設定ファイルをダウンロードする(M5Stack系のみ) wget https://raw.githubusercontent.com/espressif/arduino-esp32/master/tools/partitions/default_16MB.csv gedit platformio.ini # 後節にあるplatformio.iniの内容をビルドするボードに応じて作成する # ビルド&書き込み pio run -t upload

5_images.ino

以下の手順をダウンロード/ビルド/書き込みする:

# platformioの環境に入る # プロジェクト・ディレクトリを作成する mkdir 5_images cd 5_images mkdir src cd src wget https://raw.githubusercontent.com/lovyan03/LovyanGFX/master/examples/HowToUse/5_images/5_images.ino wget https://raw.githubusercontent.com/lovyan03/LovyanGFX/master/examples/HowToUse/5_images/image.h cd .. # platformioの設定ファイルをダウンロードする(M5Stack系のみ) wget https://raw.githubusercontent.com/espressif/arduino-esp32/master/tools/partitions/default_16MB.csv gedit platformio.ini # 後節にあるplatformio.iniの内容をビルドするボードに応じて作成する # ビルド&書き込み pio run -t upload

ClockSample.ino

以下の手順をダウンロード/ビルド/書き込みする:

# platformioの環境に入る # プロジェクト・ディレクトリを作成する mkdir ClockSample cd ClockSample mkdir src cd src wget https://raw.githubusercontent.com/lovyan03/LovyanGFX/master/examples/Sprite/ClockSample/ClockSample.ino gedit ClockSample.ino # 以下のようにパッチをかける 修正前: #define LGFX_USE_V1 #include <LovyanGFX.hpp> → 修正後: #define LGFX_AUTODETECT //#define LGFX_USE_V1 #include <LovyanGFX.hpp> cd .. # platformioの設定ファイルをダウンロードする(M5Stack系のみ) wget https://raw.githubusercontent.com/espressif/arduino-esp32/master/tools/partitions/default_16MB.csv gedit platformio.ini # 後節にあるplatformio.iniの内容をビルドするボードに応じて作成する # ビルド&書き込み pio run -t upload

platformio.ini

上のスケッチをビルドするには、ボードに応じて、
以下の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 = m5stack/M5Core2@^0.1.0 ;https://github.com/m5stack/M5Core2.git https://github.com/FastLED/FastLED ;https://github.com/m5stack/M5Core2/blob/master/examples/core2_for_aws/ArduinoECCX08.zip ;tobozo/ESP32-Chimera-Core@^1.4.0 lovyan03/LovyanGFX@^0.4.13 https://github.com/tanakamasayuki/efont.git https://github.com/Tamakichi/Arduino-misakiUTF16.git # 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 tobozo/M5Stack-SD-Updater@^1.1.8 ;lib_ldf_mode = deep+ lib_ldf_mode = deep

重要:
通常の設定と異なり「lib_ldf_mode = deep」(末尾に「+」が無い)にしないとビルドエラーになる。

M5Stack-Fire用:

[env:m5stack-fire] platform = espressif32 board = m5stack-fire framework = arduino monitor_speed = 115200 upload_speed = 2000000 upload_protocol = esptool board_build.partitions = default_16MB.csv build_flags = -DM5STACK_FIRE -DCORE_DEBUG_LEVEL=4 -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue lib_deps = m5stack/M5Stack@^0.3.9 ;tobozo/ESP32-Chimera-Core@^1.4.0 lovyan03/LovyanGFX@^0.4.13 https://github.com/tanakamasayuki/efont.git https://github.com/Tamakichi/Arduino-misakiUTF16.git # 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 tobozo/M5Stack-SD-Updater@^1.1.8 ;lib_ldf_mode = deep+ lib_ldf_mode = deep

重要:
通常の設定と異なり「lib_ldf_mode = deep」(末尾に「+」が無い)にしないとビルドエラーになる。

Wio-Terminal用:

[env:seeed_wio_terminal] platform = atmelsam board = seeed_wio_terminal framework = arduino build_flags = -DWIO_TERMINAL upload_protocol = sam-ba monitor_speed = 115200 lib_deps = https://github.com/Seeed-Studio/Seeed_Arduino_mbedtls/archive/dev.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcUnified/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcBLE/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcWiFi/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_FreeRTOS/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_FS/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_SFUD/archive/master.zip # # RTC adafruit/RTClib@^2.0.2 ;neironx/RTCLib@^1.6.0 ;powerbroker2/SafeString@^4.1.14 ;seeed-studio/Seeed Arduino RTC@^2.0.0 # # display libs (* Select Only ONE *) ;https://github.com/Seeed-Studio/Seeed_Arduino_LCD/archive/master.zip ;moononournation/GFX Library for Arduino@^1.1.8 lovyan03/LovyanGFX@^0.4.13 https://github.com/tanakamasayuki/efont.git https://github.com/Tamakichi/Arduino-misakiUTF16.git # # network related ;arduino-libraries/NTPClient@^3.1.0 ;knolleary/PubSubClient@^2.8 # # sensor related adafruit/Adafruit Unified Sensor@^1.1.4 adafruit/Adafruit BME280 Library@^2.2.2 adafruit/Adafruit DPS310@^1.1.1 ;wemos/WEMOS SHT3x@^1.0.0 https://github.com/Seeed-Studio/Grove_SHT31_Temp_Humi_Sensor.git # lib_ldf_mode = deep+

参照情報

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

LovyanGFX関連:
LovyanGFX - Display (LCD / OLED / EPD) graphics library (for ESP32 SPI, I2C, 8bitParallel / ESP8266 SPI, I2C / ATSAMD51 SPI) - M5Stack / M5StickC / TTGO T-Watch / ODROID-GO / ESP-WROVER-KIT / WioTerminal / and more...
LovyanGFX LCD Graphics driver

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対応)

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

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編)

以上

続きを読む "LovyanGFX-Display ライブラリを使用したスケッチをplatformioでビルドする"

| | コメント (0)

2022年1月24日 (月)

Wio-Terminal/M5Core2のWiFiAnallyzer

2022/1/24
初版

WiFiAnalyzer for WioT/M5Core2

WiFiAnalyzer for WioT/M5Core2

概要

Wio-Terminal用とM5Core2用のWiFiAnallyzerを紹介する。
Arduinoのスケッチになっているが、platformioでビルドする。

Wio-Terminal用

以下の手順でビルト&書き込みする:

# platformio環境に入る mkdir WioWiFiAnalyzer cd WioWiFiAnalyzer mkdir src cd src # ソースをダウンロードする wget https://raw.githubusercontent.com/moononournation/Arduino_GFX/master/examples/WiFiAnalyzer/WioWiFiAnalyzer/WioWiFiAnalyzer.ino cd .. gedit platormio.ini # 次節のplatformio.iniの内容を作成する

platformio.ini(wio-terminal用)

Wio-Terminal用

[env:seeed_wio_terminal] platform = atmelsam board = seeed_wio_terminal framework = arduino ;build_flags = -DWIO_TERMINAL upload_protocol = sam-ba monitor_speed = 115200 lib_ldf_mode = deep+ lib_deps = https://github.com/Seeed-Studio/Seeed_Arduino_mbedtls/archive/dev.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcUnified/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcBLE/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcWiFi/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_FreeRTOS/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_FS/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_SFUD/archive/master.zip # # RTC adafruit/RTClib@^2.0.2 ;powerbroker2/SafeString@^4.1.14 ;seeed-studio/Seeed Arduino RTC@^2.0.0 # # display libs (* Select Only ONE *) ;https://github.com/Seeed-Studio/Seeed_Arduino_LCD/archive/master.zip moononournation/GFX Library for Arduino@^1.1.8 ;lovyan03/LovyanGFX@^0.4.10 https://github.com/tanakamasayuki/efont.git https://github.com/Tamakichi/Arduino-misakiUTF16.git # # network related ;arduino-libraries/NTPClient@^3.1.0 ;knolleary/PubSubClient@^2.8 # # sensor related adafruit/Adafruit Unified Sensor@^1.1.4 adafruit/Adafruit BME280 Library@^2.2.2 adafruit/Adafruit DPS310@^1.1.1 ;wemos/WEMOS SHT3x@^1.0.0 https://github.com/Seeed-Studio/Grove_SHT31_Temp_Humi_Sensor.git #

注意:
display系のライブラリが複数登録されているとビルトでエラーが出なくても正常に実行されない現象があった。
ヘッダーが異なっているので問題がないと思っていたが、必要なライブラリ以外はコメントアウトする必要がるようだ。
ダウンロードした(ローカルな)ライブラリをいったんクリアするためには「sudo rm -r .pio」を実行する。
その後、「pio run -t upload」でビルト&書き込みを行なう。

M5Core2用

以下の手順でビルド&書き込みを行なう:

# platformio環境に入る mkdir Core2WiFiAnalyzer cd Core2WiFiAnalyzer mkdir src cd src # ソースをダウンロードする gedit main.ino 以下のurlからソースコードをコピー&ペーストする: https://macsbug.wordpress.com/2018/04/30/m5stack-wifianalyzer/ M5STACK WiFiAnalyzer cd .. # platformioの設定ファイルをダウンロードする wget https://raw.githubusercontent.com/espressif/arduino-esp32/master/tools/partitions/default_16MB.csv gedit platormio.ini # 次節のplatformio.iniの内容を作成する

パッチ

M5Stack用をM5Core2用に変更するためにソースを以下のように変更する。

src/main.ino

#9行当たりを以下のように変更する:(M5StackUpdaterは使用しない) //#include <M5Stack.h> #include <M5Core2.h> //#include "M5StackUpdater.h" // SD Update #27行当たりをコメントアウトする:(M5StackUpdaterは使用しない) // if(digitalRead(BUTTON_A_PIN) == 0){ // SD Update // updateFromFS(SD); ESP.restart(); // SD Update // } // SD Update

platformio.ini(M5Core2用)

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 ;tobozo/M5Stack-SD-Updater@^1.1.8 lib_ldf_mode = deep+

参考情報

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

WiFiAnalyzer関連:
Dual Band WiFi Analyzer with Wio Terminal
M5STACK WiFiAnalyzer

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編)

以上

続きを読む "Wio-Terminal/M5Core2のWiFiAnallyzer"

| | コメント (0)

2022年1月20日 (木)

Wio-TerminalでMQTTを動かす

2022/1/20
初版

Wio-Terminal MQTT

Wio-Terminal MQTT

概要

Wio-TerminalでMQTTを動かす。
MQTT on Wio Terminal」の記事のコードを利用して、Wio-TerminalでMQTTを動かす。
ビルド環境としては、platformioを使用する。
ここでは、Wio-TerminalをPublisher(送信側)、PCやiPhoneをSubscriber(受信側)にする。

Publisher(送信側)

当該の「MQTT on Wio Terminal」の記事のコードにある[ボタン]でコードをコピーまたはダウンロードして platformioのプロジェクト(ディレクトリ)のsrc配下に置く。
# ダウンロードしたものは、ファイルタイプが「.c」になっているので、「.ino」にする。

src配下に置いたコードに以下のパッチを当てる:

src/WioTerminal_MQTT_Example.ino

#6行目付近を以下のように変更する。(新しいファームを使用する) //#include <AtWiFi.h> // old firmware #include <rpcWiFi.h> #22行目付近を自分のWiFi環境に合わせて変更する。 // Update these with values suitable for your network. const char* ssid = "***"; // WiFi Name const char* password = "***"; // WiFi Password const char* mqtt_server = "broker.mqtt-dashboard.com"; // MQTT Broker URL

plaformio.iniは以下のものにする: platformio.ini

; PlatformIO Project Configuration File ; ; Build options: build flags, source filter ; Upload options: custom upload port, speed and extra flags ; Library options: dependencies, extra library storages ; Advanced options: extra scripting ; ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html [env:seeed_wio_terminal] platform = atmelsam board = seeed_wio_terminal framework = arduino build_flags = -DWIO_TERMINAL upload_protocol = sam-ba monitor_speed = 115200 lib_ldf_mode = deep+ lib_deps = https://github.com/Seeed-Studio/Seeed_Arduino_mbedtls/archive/dev.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcUnified/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcBLE/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcWiFi/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_FreeRTOS/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_FS/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_SFUD/archive/master.zip # https://github.com/Seeed-Studio/Seeed_Arduino_LCD/archive/master.zip # arduino-libraries/NTPClient@^3.1.0 # powerbroker2/SafeString@^4.1.14 seeed-studio/Seeed Arduino RTC@^2.0.0 # lovyan03/LovyanGFX@^0.4.10 https://github.com/tanakamasayuki/efont.git https://github.com/Tamakichi/Arduino-misakiUTF16.git # adafruit/Adafruit Unified Sensor@^1.1.4 adafruit/Adafruit BME280 Library@^2.2.2 adafruit/Adafruit DPS310@^1.1.1 adafruit/RTClib@^2.0.2 ;neironx/RTCLib@^1.6.0 ;wemos/WEMOS SHT3x@^1.0.0 https://github.com/Seeed-Studio/Grove_SHT31_Temp_Humi_Sensor.git # knolleary/PubSubClient@^2.8

以下のコマンドラインでビルドと書き込みを行う:

pio run -t upload #通信ソフトを起動する bt -L 1

USBシリアルからは、publishしているメッセージが表示される。

Subscriber(受信側)

Subscriberとしては、Andoroid,iPhone,PCが使用できるが、ここでは、PCとiPhoneを取り上げる:

PCの場合:
以下のurlにwebブラウザーでアクセスする。
http://www.hivemq.com/demos/websocket-client/
websocket client

[Connect]をクリックして、broker-serverに接続して Subscriptionsの[Add New Topic Subuscription]をクリックして Wio-TerminalのPublisherで使用しているTopicの「WTout」を入力して Subscribeする。
そうすると、Wio-Terminalからのメッセージが表示される。 以下、表示例:

Messages 2022-01-20 09:02:49 Topic: WTout Qos: 0 Wio Terminal #6241 2022-01-20 09:02:47 Topic: WTout Qos: 0 Wio Terminal #6240 2022-01-20 09:02:45 Topic: WTout Qos: 0 Wio Terminal #6239 2022-01-20 09:02:42 Topic: WTout Qos: 0 Wio Terminal #6238   ...

iPhoneの場合:
アプリとしてMQTTtoolかEasyMQTTをインストールして 以下の情報を設定する:

MQTTtool設定情報:

HOST broker.mqtt-dashboard.com Port 1883 Client ID アプリ側で自動設定されるので特に入力は無い Username/Passwaordは不要。 SubscribeのTopicは「WTout」を設定する。

EasyMQTT設定情報:

HOST broker.mqtt-dashboard.com Port 1883 Client ID Wio Terminal MQTT Username/Passwaordは不要。 SubscribeのTopicは「WTout」を設定する。

broker-serverの設定情報

MQTT connection settings

Connection Name: Public MQTT Broker Client ID: Wio Terminal MQTT(任意) Broker Web/IP address: broker.mqtt-dashboard.com TCP Port: 1883 Websocket Port: 8000

以下をアクセスするとMQTTのアクセス状況が表示される:
http://broker.mqtt-dashboard.com/
HIVEMQ MQTT Dashboard

参考情報

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

Wio-Terminal関連:
wio-terminal firmware update(v2) (linux)
nixieクロックにNTPクライアントの機能を追加する(v2,rpcファーム対応)

MQTT関連:
Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(MQTT編)
10 Free Public MQTT Brokers(Private & Public)

platformio関連:
arduinoフレームワーク用platformio.ini集
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編)
Building Core2 FactoryDemo in PlatformIO
VSCodeとPlatformIOでM5Stack Core2開発
M5Stack Core2とVSCode + PlatformIOとでM5Stackプログラミングを始めてみた。
Arduino勉強会/37-RaspberryPi Picoをはじめよう - デバッガー

Arduino-IDE関連:
Raspberry Pi PicoでI2C/SPI通信
Arduino IDE environment - M5Paper
Arduino IDEのインストールと設定 (Windows, Mac, Linux対応)

以上

続きを読む "Wio-TerminalでMQTTを動かす"

| | コメント (0)

2022年1月17日 (月)

wio-terminalでGROVEを使う

2022/1/17
初版

WIOT_TWO_GROVES

WIOT_TWO_GROVES

概要

wio-terminalでGROVEを使う。
Wio Terminal」はGROVEソケットを2つ持っている。 wio-terminalで、正面のボタンを下にして
右側のGROVEはアナログ入力/デジタル用ポート、
左側のGROVEはI2C用ポートになる。

参照:
Wio Terminal Wio Terminalをはじめよう

ここでは、右側のGROVEソケット(アナログ入力/デジタル・ポート)、左側のGROVE(I2Cポート)を使ったスケッチを紹介する。

アナログ入力ポートのスケッチ例

右側のGROVEにUNIT_ANGLE「M5Stack用回転角ユニット」を接続したスケッチを紹介する。

src/UNIT_ANGLE_wiot.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 读取角度计的角度,并转换为数字量显示 */ //#include <M5Atom.h> //int sensorPin = 32; // set the input pin for the potentiometer. 设置角度计的输入引脚 int sensorPin = 0; // for grove of wio-terminal 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(); //Init M5Atom. 初始化 M5Atom Serial.begin(115200); pinMode(sensorPin, INPUT); //Sets the specified pin to input mode. 设置指定引脚为输入模式 //dacWrite(25, 0); } void loop() { // cur_sensorValue = analogRead(sensorPin); // read the value from the sensor. 读取当前传感器的值 cur_sensorValue = (500*analogRead(sensorPin))/330; // scalling for wio-terminal 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); }

本スケッチはM5ATOMのものをwio-terminal用に変更したものである、

デジタル出力ポートとしてのスケッチ例

右側のGROVEに「GROVE - 7セグメント4桁ディスプレイ」を接続したスケッチを紹介する。

src/NumberFlow_wiot.ino

/* * TM1637.cpp * A library for the 4 digit display * * Copyright (c) 2012 seeed technology inc. * Website : www.seeed.cc * Author : Frankie.Chu * Create Time: 9 April,2012 * Change Log : * * The MIT License (MIT) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include "TM1637.h" /* #define CLK 2//pins definitions for TM1637 and can be changed to other ports #define DIO 3 */ /* // for MAKER PI RP2040 #define CLK 27 //pins definitions for TM1637 and can be changed to other ports #define DIO 26 */ // wio-terminal #define CLK 0 #define DIO 1 TM1637 tm1637(CLK,DIO); void setup() { tm1637.init(); tm1637.set(BRIGHT_TYPICAL);//BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7; } void loop() { int8_t NumTab[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};//0~9,A,b,C,d,E,F int8_t ListDisp[4]; unsigned char i = 0; unsigned char count = 0; delay(150); while(1) { i = count; count ++; if(count == sizeof(NumTab)) count = 0; for(unsigned char BitSelect = 0;BitSelect < 4;BitSelect ++) { ListDisp[BitSelect] = NumTab[i]; i ++; if(i == sizeof(NumTab)) i = 0; } tm1637.display(0,ListDisp[0]); tm1637.display(1,ListDisp[1]); tm1637.display(2,ListDisp[2]); tm1637.display(3,ListDisp[3]); delay(1000); //(300); } }

I2Cポートのスケッチ例#1

左側のGROVEにM5Stack用「M5Stack用大気圧センサーユニット【M5STACK-U090】」を接続したスケッチになる。
本ユニットはBMP280を使用しており、BMP280のAdafruitのライブラリが使用できる。
以下は提供されているスケッチにピン割当、デバイスアドレスの変更をしたものである。

src/bmp280_sensortest_wiot.ino

/*************************************************************************** This is a library for the BMP280 humidity, temperature & pressure sensor This example shows how to take Sensor Events instead of direct readings Designed specifically to work with the Adafruit BMP280 Breakout ----> http://www.adafruit.com/products/2651 These sensors use I2C or SPI to communicate, 2 or 4 pins are required to interface. Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! Written by Limor Fried & Kevin Townsend for Adafruit Industries. BSD license, all text above must be included in any redistribution ***************************************************************************/ #include <Wire.h> #include <SPI.h> #include <Adafruit_BMP280.h> Adafruit_BMP280 bmp; // use I2C interface Adafruit_Sensor *bmp_temp = bmp.getTemperatureSensor(); Adafruit_Sensor *bmp_pressure = bmp.getPressureSensor(); void setup() { Serial.begin(9600); while ( !Serial ) delay(100); // wait for native usb Serial.println(F("BMP280 Sensor event test")); /******************** // MAKER // GROVE#4 for I2C#0 Wire.setSDA(16); Wire.setSCL(17); Wire.begin(); **********************/ unsigned status; //status = bmp.begin(BMP280_ADDRESS_ALT, BMP280_CHIPID); status = bmp.begin(0x76); // for BPS UNIT of M5Stack if (!status) { Serial.println(F("Could not find a valid BMP280 sensor, check wiring or " "try a different address!")); Serial.print("SensorID was: 0x"); Serial.println(bmp.sensorID(),16); Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n"); Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n"); Serial.print(" ID of 0x60 represents a BME 280.\n"); Serial.print(" ID of 0x61 represents a BME 680.\n"); while (1) delay(10); } /* Default settings from datasheet. */ bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */ Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */ Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */ Adafruit_BMP280::FILTER_X16, /* Filtering. */ Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */ bmp_temp->printSensorDetails(); } void loop() { sensors_event_t temp_event, pressure_event; bmp_temp->getEvent(&temp_event); bmp_pressure->getEvent(&pressure_event); Serial.print(F("Temperature = ")); Serial.print(temp_event.temperature); Serial.println(" *C"); Serial.print(F("Pressure = ")); Serial.print(pressure_event.pressure); Serial.println(" hPa"); Serial.println(); delay(2000); }

シリアル出力例:

BMP280 Sensor event test ------------------------------------ Sensor: BMP280 Type: Ambient Temp (C) Driver Ver: 1 Unique ID: 280 Min Value: -40.00 Max Value: 85.00 Resolution: 0.01 ------------------------------------ Temperature = 22.55 *C Pressure = 1010.33 hPa Temperature = 22.59 *C Pressure = 1010.26 hPa Temperature = 22.60 *C Pressure = 1010.27 hPa Temperature = 22.62 *C Pressure = 1010.28 hPa Temperature = 22.65 *C Pressure = 1010.28 hPa Temperature = 22.68 *C Pressure = 1010.29 hPa

I2Cポートのスケッチ例#2

Qwiic - 小型OLEDモジュールをQwiic->Grove変換ケーブル経由で左側のGROVEに接続する。

src/Example10_MultiDemo_v13.ino

/* SFE_MicroOLED Library Demo Paul Clark @ SparkFun Electronics Original Creation Date: December 11th, 2020 This sketch uses the MicroOLED library to show all the functionality built into the library using the begin function defined in version v1.3 of the library - which allows different TwoWire ports and custom I2C addresses to be used. If you are using the standard Micro OLED display, its I2C address will be 0x3D or 0x3C depending on how you have the D/C or ADDR jumper configured. Hardware Connections: This example assumes you are using Qwiic. See the SPI examples for a detailed breakdown of connection info. Want to support open source hardware? Buy a board from SparkFun! https://www.sparkfun.com/products/13003 https://www.sparkfun.com/products/14532 This code is beerware; if you see me (or any other SparkFun employee) at the local, and you've found our code helpful, please buy us a round! Distributed as-is; no warranty is given. */ #include <Wire.h> #include <SFE_MicroOLED.h> //Click here to get the library: http://librarymanager/All#SparkFun_Micro_OLED #define PIN_RESET 9 /* // This is the old way of instantiating oled. You can still do it this way if you want to. #define DC_JUMPER 1 MicroOLED oled(PIN_RESET, DC_JUMPER); // I2C declaration */ // From version v1.3, we can also instantiate oled like this (but only for I2C) MicroOLED oled(PIN_RESET); // The TwoWire I2C port is passed to .begin instead void setup() { delay(100); Wire.begin(); // <-- Change this to (e.g.) Qwiic.begin(); as required //Wire.setClock(400000); // Uncomment this line to increase the I2C bus speed to 400kHz /* // This is the old way of initializing the OLED. // You can still do it this way if you want to - but only // if you instantiated oled using: MicroOLED oled(PIN_RESET, DC_JUMPER) oled.begin(); // Initialize the OLED */ // This is the new way of initializing the OLED. // We can pass a different I2C address and TwoWire port oled.begin(0x3D, Wire); // Initialize the OLED /* // This is the new way of initializing the OLED. // We can pass a different I2C address and TwoWire port oled.begin(0x3C, Qwiic); // Initialize the OLED */ oled.clear(ALL); // Clear the display's internal memory oled.display(); // Display what's in the buffer (splashscreen) delay(1000); // Delay 1000 ms oled.clear(PAGE); // Clear the buffer. randomSeed(analogRead(A0) + analogRead(A1)); } void pixelExample() { printTitle("Pixels", 1); for (int i = 0; i < 512; i++) { oled.pixel(random(oled.getLCDWidth()), random(oled.getLCDHeight())); oled.display(); } } void lineExample() { int middleX = oled.getLCDWidth() / 2; int middleY = oled.getLCDHeight() / 2; int xEnd, yEnd; int lineWidth = min(middleX, middleY); printTitle("Lines!", 1); for (int i = 0; i < 3; i++) { for (int deg = 0; deg < 360; deg += 15) { xEnd = lineWidth * cos(deg * PI / 180.0); yEnd = lineWidth * sin(deg * PI / 180.0); oled.line(middleX, middleY, middleX + xEnd, middleY + yEnd); oled.display(); delay(10); } for (int deg = 0; deg < 360; deg += 15) { xEnd = lineWidth * cos(deg * PI / 180.0); yEnd = lineWidth * sin(deg * PI / 180.0); oled.line(middleX, middleY, middleX + xEnd, middleY + yEnd, BLACK, NORM); oled.display(); delay(10); } } } void shapeExample() { printTitle("Shapes!", 0); // Silly pong demo. It takes a lot of work to fake pong... int paddleW = 3; // Paddle width int paddleH = 15; // Paddle height // Paddle 0 (left) position coordinates int paddle0_Y = (oled.getLCDHeight() / 2) - (paddleH / 2); int paddle0_X = 2; // Paddle 1 (right) position coordinates int paddle1_Y = (oled.getLCDHeight() / 2) - (paddleH / 2); int paddle1_X = oled.getLCDWidth() - 3 - paddleW; int ball_rad = 2; // Ball radius // Ball position coordinates int ball_X = paddle0_X + paddleW + ball_rad; int ball_Y = random(1 + ball_rad, oled.getLCDHeight() - ball_rad); //paddle0_Y + ball_rad; int ballVelocityX = 1; // Ball left/right velocity int ballVelocityY = 1; // Ball up/down velocity int paddle0Velocity = -1; // Paddle 0 velocity int paddle1Velocity = 1; // Paddle 1 velocity //while(ball_X >= paddle0_X + paddleW - 1) while ((ball_X - ball_rad > 1) && (ball_X + ball_rad < oled.getLCDWidth() - 2)) { // Increment ball's position ball_X += ballVelocityX; ball_Y += ballVelocityY; // Check if the ball is colliding with the left paddle if (ball_X - ball_rad < paddle0_X + paddleW) { // Check if ball is within paddle's height if ((ball_Y > paddle0_Y) && (ball_Y < paddle0_Y + paddleH)) { ball_X++; // Move ball over one to the right ballVelocityX = -ballVelocityX; // Change velocity } } // Check if the ball hit the right paddle if (ball_X + ball_rad > paddle1_X) { // Check if ball is within paddle's height if ((ball_Y > paddle1_Y) && (ball_Y < paddle1_Y + paddleH)) { ball_X--; // Move ball over one to the left ballVelocityX = -ballVelocityX; // change velocity } } // Check if the ball hit the top or bottom if ((ball_Y <= ball_rad) || (ball_Y >= (oled.getLCDHeight() - ball_rad - 1))) { // Change up/down velocity direction ballVelocityY = -ballVelocityY; } // Move the paddles up and down paddle0_Y += paddle0Velocity; paddle1_Y += paddle1Velocity; // Change paddle 0's direction if it hit top/bottom if ((paddle0_Y <= 1) || (paddle0_Y > oled.getLCDHeight() - 2 - paddleH)) { paddle0Velocity = -paddle0Velocity; } // Change paddle 1's direction if it hit top/bottom if ((paddle1_Y <= 1) || (paddle1_Y > oled.getLCDHeight() - 2 - paddleH)) { paddle1Velocity = -paddle1Velocity; } // Draw the Pong Field oled.clear(PAGE); // Clear the page // Draw an outline of the screen: oled.rect(0, 0, oled.getLCDWidth() - 1, oled.getLCDHeight()); // Draw the center line oled.rectFill(oled.getLCDWidth() / 2 - 1, 0, 2, oled.getLCDHeight()); // Draw the Paddles: oled.rectFill(paddle0_X, paddle0_Y, paddleW, paddleH); oled.rectFill(paddle1_X, paddle1_Y, paddleW, paddleH); // Draw the ball: oled.circle(ball_X, ball_Y, ball_rad); // Actually draw everything on the screen: oled.display(); delay(25); // Delay for visibility } delay(1000); } void textExamples() { printTitle("Text!", 1); // Demonstrate font 0. 5x8 font oled.clear(PAGE); // Clear the screen oled.setFontType(0); // Set font to type 0 oled.setCursor(0, 0); // Set cursor to top-left // There are 255 possible characters in the font 0 type. // Lets run through all of them and print them out! for (int i = 0; i <= 255; i++) { // You can write byte values and they'll be mapped to // their ASCII equivalent character. oled.write(i); // Write a byte out as a character oled.display(); // Draw on the screen delay(10); // Wait 10ms // We can only display 60 font 0 characters at a time. // Every 60 characters, pause for a moment. Then clear // the page and start over. if ((i % 60 == 0) && (i != 0)) { delay(500); // Delay 500 ms oled.clear(PAGE); // Clear the page oled.setCursor(0, 0); // Set cursor to top-left } } delay(500); // Wait 500ms before next example // Demonstrate font 1. 8x16. Let's use the print function // to display every character defined in this font. oled.setFontType(1); // Set font to type 1 oled.clear(PAGE); // Clear the page oled.setCursor(0, 0); // Set cursor to top-left // Print can be used to print a string to the screen: oled.print(" !\"#$%&'()*+,-./01234"); oled.display(); // Refresh the display delay(1000); // Delay a second and repeat oled.clear(PAGE); oled.setCursor(0, 0); oled.print("56789:;<=>?@ABCDEFGHI"); oled.display(); delay(1000); oled.clear(PAGE); oled.setCursor(0, 0); oled.print("JKLMNOPQRSTUVWXYZ[\\]^"); oled.display(); delay(1000); oled.clear(PAGE); oled.setCursor(0, 0); oled.print("_`abcdefghijklmnopqrs"); oled.display(); delay(1000); oled.clear(PAGE); oled.setCursor(0, 0); oled.print("tuvwxyz{|}~"); oled.display(); delay(1000); // Demonstrate font 2. 10x16. Only numbers and '.' are defined. // This font looks like 7-segment displays. // Lets use this big-ish font to display readings from the // analog pins. for (int i = 0; i < 25; i++) { oled.clear(PAGE); // Clear the display oled.setCursor(0, 0); // Set cursor to top-left oled.setFontType(0); // Smallest font oled.print("A0: "); // Print "A0" oled.setFontType(2); // 7-segment font oled.print(analogRead(A0)); // Print a0 reading oled.setCursor(0, 16); // Set cursor to top-middle-left oled.setFontType(0); // Repeat oled.print("A1: "); oled.setFontType(2); oled.print(analogRead(A1)); oled.setCursor(0, 32); oled.setFontType(0); oled.print("A2: "); oled.setFontType(2); oled.print(analogRead(A2)); oled.display(); delay(100); } // Demonstrate font 3. 12x48. Stopwatch demo. oled.setFontType(3); // Use the biggest font int ms = 0; int s = 0; while (s <= 5) { oled.clear(PAGE); // Clear the display oled.setCursor(0, 0); // Set cursor to top-left if (s < 10) oled.print("00"); // Print "00" if s is 1 digit else if (s < 100) oled.print("0"); // Print "0" if s is 2 digits oled.print(s); // Print s's value oled.print(":"); // Print ":" oled.print(ms); // Print ms value oled.display(); // Draw on the screen ms++; // Increment ms if (ms >= 10) // If ms is >= 10 { ms = 0; // Set ms back to 0 s++; // and increment s } } } void loop() { //pixelExample(); // Run the pixel example function lineExample(); // Then the line example function shapeExample(); // Then the shape example textExamples(); // Finally the text example } // Center and print a small title // This function is quick and dirty. Only works for titles one // line long. void printTitle(String title, int font) { int middleX = oled.getLCDWidth() / 2; int middleY = oled.getLCDHeight() / 2; oled.clear(PAGE); oled.setFontType(font); // Try to set the cursor in the middle of the screen oled.setCursor(middleX - (oled.getFontWidth() * (title.length() / 2)), middleY - (oled.getFontHeight() / 2)); // Print the title: oled.print(title); oled.display(); delay(1500); oled.clear(PAGE); }

提供されているスケッチが変更無しで動作した。

platformio.ini

以上のスケッチには、以下のplatformio.iniでビルドできる。

wio-terminal用:
platformio.ini

[env:seeed_wio_terminal] platform = atmelsam board = seeed_wio_terminal framework = arduino build_flags = -DWIO_TERMINAL upload_protocol = sam-ba monitor_speed = 115200 lib_ldf_mode = deep+ lib_deps = https://github.com/Seeed-Studio/Seeed_Arduino_mbedtls/archive/dev.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcUnified/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcBLE/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcWiFi/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_FreeRTOS/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_FS/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_SFUD/archive/master.zip # https://github.com/Seeed-Studio/Seeed_Arduino_LCD/archive/master.zip # arduino-libraries/NTPClient@^3.1.0 # powerbroker2/SafeString@^4.1.14 seeed-studio/Seeed Arduino RTC@^2.0.0 # lovyan03/LovyanGFX@^0.4.10 # adafruit/Adafruit Unified Sensor@^1.1.4 adafruit/Adafruit BME280 Library@^2.2.2 adafruit/Adafruit DPS310@^1.1.1 https://github.com/Seeed-Studio/Grove_SHT31_Temp_Humi_Sensor.git # seeed-studio/Grove 4-Digit Display@^1.0.0

参考情報

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

GROVE使用スケッチ関連:
MAKER_PI_RP2040でI2Cを使う(Arduino編)

platformio関連:

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

Arduino-IDE関連:
Raspberry Pi PicoでI2C/SPI通信
Arduino IDE environment - M5Paper
Arduino IDEのインストールと設定 (Windows, Mac, Linux対応)

以上

続きを読む "wio-terminalでGROVEを使う"

| | コメント (0)

2022年1月 2日 (日)

WebRadio「Arduino Web Radio Player」を動かす

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

2022/1/1
初版

WebRadio for M5StickCPlus

WebRadio for M5StickCPlus

概要

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

プロジェクト作成

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

# platformio環境に入る cd m5WebRadio mkdir m5WebRadio cd src # ソースをダウンロードする https://www.hackster.io/tommyho/arduino-web-radio-player-c4cb23 のCodeのところにある「m5WebRadio.ino」をコピーして、src配下に置く。 cd .. gedit platormio.ini # 次節のplatformio.iniの内容を作成する

パッチ

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

src/m5WebRadio.ino

#2行あたりを以下のように修正する: //#include <M5StickC.h> #ifdef M5STICK_CP #include <M5StickCPlus.h> #endif #28行あたりを自分のWiFi環境に合わせて変更する: // Enter your WiFi, Station, button settings here: const char *SSID = "XXXXXXXX"; const char *PASSWORD = "XXXXXXXX";

platformio.ini

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 ;https://github.com/earlephilhower/ESP8266Audio.git earlephilhower/ESP8266Audio@^1.9.5

動作

起動するとWiFiでネットワークに接続し、設定されているURLのインターネットラジオが動作する。
操作性など:
(「Arduino Web Radio Player」から抜粋)
Features in this version 2020-12c
・Support up to 256kbps MP3 stream with adjustable 16kb buffer (NEW)
・Small and portable: It runs on the built-in battery
・Play or Pause: Press BTN-A to trigger streaming.
・Multiple channels: Press BTN-B while paused to change the radio channel.
・Volume control: Press BTN-B while playing to change the volume.
・Volume meter.
・Metadata supported.
・Ready to use in 10 minutes.
・Attach to a pico buzzer, SPK-Hat, or an external speaker via a modified stereo cable.

参考情報

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 Speaker Hat(PAM8303搭載)
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「Arduino Web Radio Player」を動かす"

| | コメント (0)

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)

より以前の記事一覧