M5Paper

2021年12月20日 (月)

M5Paper Clock

2021/12/20+
初版

M5Paper Colock

M5Paper Clock

概要

M5Paperのクロック(時計)をいくつか紹介する。
ホスト環境は、ubuntu20.04とする。
なお、platformioがインストール済みのものとする。

1. m5paper-dashboard

説明:
https://github.com/estshorter/m5paper-dashboard

ビルドと書き込み:

mkdie M5P cd M5P git clone https://github.com/estshorter/m5paper-dashboard.git cd m5paper-dashboard/ # Set your Wi-Fi parameters in src/WiFiInfo.h gedit src/WiFiInfo.h 以下を自分のWiFi完了に合わせる: constexpr auto SSID = "YOUR_SSID"; constexpr auto PASS = "YOUR_PASS"; # build&upload pio run -t clean pio run -t upload

以上でビルドと書き込みが終了する。

サポートデバイス:
以下をサポートしているが
 (1)CO2Mini(RaspberryPi経由)
 (2)ENV II Unit(@PORT-A)
 (3)LED Unit
手持ちが、「ENV III Unit」だったので
それを接続したが、問題無く、動作した。

操作:
Leftボタン:シャットダウン
Middleボタン:NTP同期
Rightボタン:画面リフレッシュ

2. M5Paper Weather Station

説明:
https://www.instructables.com/M5Paper-Weather-Station/ Take notes that:

The indoor temperature and humidity are read from a built-in SHT30 sensor. Time information is read from a RTC built-in sensor BM8563 and it can be synchronized with NTP Time Server. The other weather information like: pressure, wind, sunrise & sunset time, visibility, weather icon & description...are read from openweathermap.org

API_Key取得:
以下などを参考にAPI_Keyを取得する。
OpenWeatherMapのAPIから気象データを取得する方法
なお、私の場合、API Keyを取得する際、なぜか、オリジナル(のAPI_Key)ではなく 再生成で新しくAPI_Keyを作らないとAPI_Keyが有効ならなかった。

ビルドと書き込み:

cd M5P git clone https://github.com/tuenhidiy/m5paper-weatherstation.git cd m5paper-weatherstation 以下のように日本向けにパッチをおこなう: WiFiInto.h # 自分のWiFi環境に合わせる: constexpr auto SSID = "YOUR_SSID"; constexpr auto PASS = "YOUR_PASS"; #------------------------------------ main.cpp # 以下のように日本向けの修正をおこなう: #14行付近: // Change to your timezone //#define timezone 7 // JST #define timezone 9 #19行付近: // Set location and API key String Location = "Isehara,JP"; // Change to your location String API_Key = "取得したopenweathermap.orgのAPI_Key"; //String Location = "Vietnam,VN"; // Change to your location //String API_Key = "xxxxxxxxxxxxx"; #76行付近: //constexpr auto TIME_ZONE = "ICT-7"; constexpr auto TIME_ZONE = "JST-9"; #611行付近:(画面に表示される都市名になる) //gfx.printf("Ho Chi Minh City, VN\r\n"); gfx.printf("Isehara City Kanagawa, JP\r\n"); #------------------------------------ pio run -t clean pio run -t upload

以上で、ビルドと書き込みが完了する。

操作:
Leftボタン:シャットダウン
Middleボタン:NTP同期
Rightボタン:画面リフレッシュ

シャットダウン後の再起動は リセットボタンを押した後で 電源オンをするほうが確実のようだ。

platformio.ini

M5Paper-Weather-Stationのビルドには 以下のplatformio.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:m5paper] platform = espressif32 board = m5stack-fire framework = arduino board_build.flash_mode = qio board_build.f_flash = 80000000L upload_speed = 2000000 monitor_speed = 115200 build_flags = -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue ; -DCORE_DEBUG_LEVEL=4 lib_deps = m5stack/M5EPD@^0.1.1 https://github.com/lovyan03/LovyanGFX bblanchon/ArduinoJson@5.13.4 lib_ldf_mode = deep+

3. WeatherM5Paper

説明:
weather station, indoor data are from builtin temperature and humidity sensor, outdoor data are fetched from interet.
内蔵センサーで室内の温度、湿度、OpenWeatherMapのAPI経由で、外部の温度、湿度、風速、気圧を表示する。
注意:
「UPDATED:」で表示されている時刻は、現在の時刻ではなく、 画面をアップデートした時刻になる。
(つまり、時計としての機能は無い)

ビルドと書き込み:

# platformioの環境に入る cd M5P git clone https://github.com/VolosR/WeatherM5Paper.git cd WeatherM5Paper cp -r Weather src # src/back.jpgをM5PaperのSDにコピーする。 # (画面のバックグランドになる) gedit platformio.ini # 以下の内容のものを作成する:

platformio.ini

[env:m5paper] platform = espressif32 board = m5stack-fire framework = arduino board_build.flash_mode = qio board_build.f_flash = 80000000L upload_speed = 2000000 monitor_speed = 115200 build_flags = -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue ; -DCORE_DEBUG_LEVEL=4 lib_deps = m5stack/M5EPD@^0.1.1 ;https://github.com/lovyan03/LovyanGFX ;bblanchon/ArduinoJson@5.13.4 https://github.com/bblanchon/ArduinoJson.git https://github.com/taranais/NTPClient.git lib_ldf_mode = deep+

続き:

#パッチを当てる gedit src/Weather.ino #5行付近(typo修正) //#include "Orbitron44.h" #include "orbitron44.h" #19行付近(WiFi設定変更、日本向け修正) const char* ssid = "YourSSID"; const char* password = "YourPasswd"; String town="Isehara"; String Country="JP"; const String endpoint = "http://api.openweathermap.org/data/2.5/weather?q="+town+","+Country+"&units=metric&APPID="; const String key = "取得したOpenWeatherMapのAPI_Key"; #70行付近(JSTに変更する) timeClient.setTimeOffset(32400); // JST(GMT+9) #--------------------------------------- pio run -t clean pio run -t upload

以上で、ビルドと書き込みが終了する。

参考情報

platformio関連:
arduinoフレームワーク用platformio.ini集

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

M5Paper関連:
M5Paper 作業メモとリンク集
M5Paper_FactoryTest VS WeatherM5Paper
M5Paperの動作中の消費電力を削減する
M5Stack M5Paper発売
M5Paper で SD カードの JPEG 画像を表示
M5PaperにiPhoneから画像を送れるようにする
M5PaperでSDからテキストを読込んで表示する方法
M5Paperでデジタルモノクロフォトフレームを作る(前編)
初心者向けM5Stackの使い方 出荷時に簡単に戻す方法とプログラムの探し方+拡張ユニット
M5Stack製品の種類と特色紹介【最新 2020年12年 Ver】

M5Stackファミリ関連:
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本入)

以上

続きを読む "M5Paper Clock"

| | コメント (0)

2021年12月16日 (木)

M5Paper Arduino Install

2021/12/15
初版

M5Paper Arduino Install

M5Paper Arduino Install

概要

提供されているサンプルソースなどがplatformioベースの
Arduinoフレームワークなので、
それを使って「M5Paper V1.1」を動かす。
ホスト環境は、ubuntu20.04とする。
なお、platformioがインストール済みのものとする。

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

工場出荷時にArduinoスケッチであるM5Paper_FactoryTestが書き込まれており、見た目、AndroidなどのOSベースのアプリに見える。
これにより、WiFi設定、時間帯設定、言語設置、ハードウェアテスト、SDアクセスなどができる。

・時間帯は、UTCの時差で設定するので日本時間にするには、「+9」にする。
・SDのファイルアクセスでテキストとJPEGが表示できる。
# SDは32GBのものがアクセスできた。
# ただし、SDの初期化が不安定なようで、ときどきエラーになるようだが
# SDを挿入した後、電源オンで起動すると上手く行くようだ。

電源操作
・電源をオンする場合、PWRボタン(多機能ボタンを2秒長押し)を使う。
・デバイスをシャットダウンする必要がある場合、USB給電をしない状態で背面のリセットボタンを押す。

日本語を使用する場合、SDに以下のファイルを入れる必要がある。
https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/example/Font.ttf

ただし、使ってみると「設定」の「設」が正しく表示されないので 日本語を使う場合、別のttfファイルを使用したほうが良い。

たとえば、TakaoGothic.ttfを使う場合、 以下の手順を実行する。(Font.ttfにrenameする必要あり)

wget https://launchpad.net/takao-fonts/trunk/15.03/+download/TakaoFonts_00303.01.zip unzip TakaoFonts_00303.01.zip cd TakaoFonts_00303.01 ls *.ttf TakaoGothic.ttf TakaoMincho.ttf TakaoPGothic.ttf TakaoPMincho.ttf

言うまでのなく、別のスケッチを書き込むとM5Paper_FactoryTestが上書きされるので工場出荷状態に戻すためにM5Paper_FactoryTestを書き込む。

M5Paper_FactoryTestの書き込み方法

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

# platformio環境に入る source pio_env/bin/activate # ソースのダウンロード git clone https://github.com/m5stack/M5Paper_FactoryTest.git cd M5Paper_FactoryTest # ビルド環境のクリーンアップ pio run -t clean # M5PaperとPCをUSBで接続する # ビルド&書き込む pio run -t upload

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

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

platformio.ini

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

[env:m5stack-fire] platform = espressif32 board = m5stack-fire 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 = m5stack/M5EPD lib_ldf_mode = deep+

新たなプロジェクトをビルドしたい場合、 M5Paper_FactoryTestのディレクトリを、 まるごとコピーして、ディレクトリ名と src配下のスケッチを変更すれば良い。
platformio.iniが古いなどでビルドエラーを 起こした場合は、上のplatformio.iniを コピーして使用する。

sketch#1(Caluculater)

別のサンプルとして電卓のスケッチを挙げる:

以下を実行する:

# platformio環境に入る source pio_env/bin/activate # ソースのダウンロード git clone https://github.com/m5stack/M5EPD_Calculator.git cd M5EPD_Calculator # ビルド環境のクリーンアップ pio run -t clean # M5PaperとPCをUSBで接続する # ビルド&書き込む pio run -t upload

実行すると通常の電卓が動作する。

sketch#2(DISPLAY_URL_JPG)

src/DISPLAY_URL_JPG.ino

#include <M5EPD.h> #include <WiFi.h> #define MySSID "MySSID" #define MyPasswd "MyPasswd" M5EPD_Canvas canvas(&M5.EPD); void setup() { M5.begin(); M5.EPD.SetRotation(90); M5.EPD.Clear(true); WiFi.begin(MySSID, MyPasswd); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } canvas.createCanvas(540, 960); canvas.setTextSize(3); canvas.drawJpgUrl("https://m5stack.oss-cn-shenzhen.aliyuncs.com/image/example_pic/flower.jpg"); canvas.pushCanvas(0,0,UPDATE_MODE_GC16); } void loop() { }

以下は自分のWiFi環境に合わせて変更する:

#define MySSID "MySSID" #define MyPasswd "MyPasswd"

動作するとソース埋め込まれたURLのjpgをダウンロードして表示する。

sketch#3(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の内容でターゲットを切り替えることができる。

実行時のシリアル出力(/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集

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

M5Paper関連:
M5Paper 作業メモとリンク集
M5Paper_FactoryTest VS WeatherM5Paper
M5Paperの動作中の消費電力を削減する
M5Stack M5Paper発売
M5Paper で SD カードの JPEG 画像を表示
M5PaperにiPhoneから画像を送れるようにする
M5PaperでSDからテキストを読込んで表示する方法
M5Paperでデジタルモノクロフォトフレームを作る(前編)
初心者向けM5Stackの使い方 出荷時に簡単に戻す方法とプログラムの探し方+拡張ユニット
M5Stack製品の種類と特色紹介【最新 2020年12年 Ver】

M5Stackファミリ関連:
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本入)

以上

続きを読む "M5Paper Arduino Install"

| | コメント (0)