M5StickCPlus

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日 (土)

「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月23日 (木)

M5StickCPlus Arduino Install

2021/12/22.
初版

M5StickCPlus Arduino Install

M5StickCPlus Arduino Install

概要

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

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

電源操作:
・電源オン:電源ボタン(左側面)を2秒間押す
・電源オフ:電源ボタン(左側面)を6秒間押す

M5SrickCPlus_FactoryTestの書き込み方法

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

cd pio # platformio環境に入る source pio_env/bin/activate mkdir M5SCP cd M5SCP mkdir FactoryTest cd FactoryTest # ソースのダウンロード git clone https://github.com/m5stack/M5StickC-Plus.git cp -r M5StickC-Plus/examples/FactoryTest src gedit platformio.ini # 次節の内容のplatformio.iniを作成する # ビルド環境のクリーンアップ pio -t clean # M5CoreとPCをUSBで接続する # ビルド&書き込む pio -t upload

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

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

platformio.ini

M5StickCPlusのスケッチのビルドには
必要なライブラリの追加はあり得るが
基本的には以下のplatformio.iniを使用する。
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

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

sketch#1(ENVIII_HAT)

別のサンプルとして「M5StickC ENV Hat III (SHT30/QMP6988)」のHATをM5StickCPlusに接続して温度、湿度、気圧をLCDに表示するスケッチを動かす。

src/ENVIII_HAT.ino

/* ******************************************************************************* * Copyright (c) 2021 by M5Stack * Equipped with M5Core sample source code * 配套 M5Core 示例源代码 * Visit the website for more information:https://docs.m5stack.com/en/core/gray * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/gray * * describe:ENVIII_SHT30_QMP6988. 环境传感器 * date:2021/8/17 ******************************************************************************* Please connect to Port A(22、21),Read temperature, humidity and atmospheric pressure and display them on the display screen 请连接端口A(22、21),读取温度、湿度和大气压强并在显示屏上显示 */ //#include <M5Stack.h> #include <M5StickCPlus.h> #include "UNIT_ENV.h" SHT3X sht30; QMP6988 qmp6988; float tmp = 0.0; float hum = 0.0; float pressure = 0.0; void setup() { M5.begin(); Wire.begin(0,26); M5.Lcd.setRotation(3); M5.Lcd.fillScreen(BLACK); M5.lcd.setTextSize(2); M5.Lcd.setCursor(0, 0, 1); Wire.begin(0,26); // HAT ////M5.Power.begin(); //Init power 初始化电源模块 qmp6988.init(); ////M5.lcd.println(F("ENV Unit III test")); M5.lcd.println(F("ENV3 test")); } void loop() { pressure = qmp6988.calcPressure(); if(sht30.get()==0){ //Obtain the data of shT30. 获取sht30的数据 tmp = sht30.cTemp; //Store the temperature obtained from shT30. 将sht30获取到的温度存储 hum = sht30.humidity; //Store the humidity obtained from the SHT30. 将sht30获取到的湿度存储 }else{ tmp=0,hum=0; } M5.lcd.fillRect(0,20,100,60,BLACK); //Fill the screen with black (to clear the screen). 将屏幕填充黑色(用来清屏) M5.lcd.setCursor(0,20); /////M5.Lcd.printf("Temp: %2.1f \r\nHumi: %2.0f%% \r\nPressure:%2.0fPa\r\n", tmp, hum, pressure); M5.Lcd.printf("Temp:%2.1f\r\nHumi:%2.1f%%\r\n%4.1f hPa\r\n", tmp, hum, pressure/100); delay(2000); }

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/ttyUSB0):

........ 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

参考情報

M5StickC関連:
M5StickC非公式日本語リファレンス
M5StickCとM5StickC Plusの違い
M5StickCのトラブルシュート 動かないときに試すこと
【WiFi温度計】M5StackとM5Stick Cでコードを共通化する

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本入)

以上

続きを読む "M5StickCPlus Arduino Install"

| | コメント (0)