« M5Paper Arduino Install | トップページ | M5Paper Clock »

2021年12月18日 (土)

M5CoreInk Arduino Install

2021/12/18++
初版

M5CoreInk Arduino Install

M5CoreInk Arduino Install

概要

platformioベースのArduinoフレームワークで、
M5Stack CoreInk 開発キット(1.5インチ Einkディスプレイ)」を動かす。
ホスト環境は、ubuntu20.04とする。
なお、platformioがインストール済みのものとする。

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

工場出荷時にArduinoスケッチであるFactoryTestが書き込まれており、 まずは、それをビルド&書き込むことにする。

電源操作:
・電源をオンする場合、電源ボタン(右下側面の物理ボタン)を押す。
・デバイスをシャットダウンする必要がある場合、USB給電をしない状態で背面のリセットボタンを押す。 (シャットダウンすると、電子インクなので画面が消えずに表示が残るが薄くなるようだ)

FactoryTestの書き込み方法

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

# platformio環境に入る source pio_env/bin/activate # ソースのダウンロード git clone https://github.com/m5stack/M5-CoreInk.git cd M5-CoreInk cd examples/FactoryTest mkdir src cp *.* src/ # 次にあるplatformio.iniの内容のファイルを作成する。 gedit platformio.ini # ソースのパッチ gedit src/FactoryTest

以下のパッチをソースの先頭付近に置く。
(使用しているライブラリにtypoがあるので、それを修正する)

// lib typo fix #define GetDate GetData #define SetDate SetData

続き:

# ビルド環境のクリーンアップ pio run -t clean # M5PaperとPCをUSBで接続する # ビルド&書き込む pio run -t upload

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

なお、動作として、通常は時刻が表示されているが
LまたはRボタンを押すと「WIFI SCAN」モードになり
SSIDが表示される。

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

platformio.ini

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

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

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

sketch#1(RTC_BM8563)

別のサンプルとして内蔵RTCのスケッチを挙げる:

以下を実行する:

# platformio環境に入る source pio_env/bin/activate # ソース指定 cd M5-CoreInk/examples/RTC_BM8563 mkdir src cp *.ino src/ gedit platformio.ini #上と同じ内容のものを作成する。 gedit src/RTC_BM8563.ino

以下のパッチをソースの先頭に置く。

#include "M5CoreInk.h" // lib typo fix #define GetDate GetData #define SetDate SetData

続き:

# ビルド環境のクリーンアップ pio run -t clean # M5PaperとPCをUSBで接続する # ビルド&書き込む pio run -t upload

実行するとRTCの時刻が表示される。

sketch#2(MQTT)

cd M5-CoreInk/examples/Advanced/MQTT mkdir src cp *.ino gedit platformio.ini # 上と同じplatformio.iniを使用する。 gedit src/MQTT.ino

以下のところを自分の環境に合わせて変更する:

const char* ssid = "Explore-F"; const char* password = "xingchentansuo123";

続き:

pio run -t clean pio run -t upload

ここまでで、ビルド&書き込みが完了する。

実行画面(E-Ink):

MQTT Success connecting wifi Please see serial

シリアル出力(例):

... Publish message: hello world #63 Message arrived [M5Stack] hello world #63 Publish message: hello world #64 Message arrived [M5Stack] hello world #64 Publish message: hello world #65 Message arrived [M5Stack] hello world #65 Publish message: hello world #66 Message arrived [M5Stack] hello world #66 Publish message: hello world #67 Message arrived [M5Stack] hello world #67 Publish message: hello world #68 Message arrived [M5Stack] hello world #68 ...

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

sketch#4(RTC_NTP)

# platformio環境に入る source pio_env/bin/activate mkdir RTC_NTP gedit platformio.ini # 上と同じplatformio.iniを使用する mkdir src cd src wget https://github.com/kagurazakarasen/M5Stack/blob/master/M5CoreInk/RTC_NTP/RTC_NTP.ino gedit src/RTC_NTP.ino

このスケッチの場合、Arduino-IDEでサポートされているStringがplatformioにないので、 以下のように修正する:

修正前: const String SSID = "... const String WF_KEY = "... → 修正後: #include <string.h> const char SSID[] = "YourSSID"; const char WF_KEY[] = "YourPasswd"; // lib typo fix #define GetDate GetData #define SetDate SetData --------- 修正前: // Connect to an access point if(SSID.length() == 0 ){ → 修正後: // Connect to an access point //if(SSID.length() == 0 ){ if(strlen(SSID) == 0 ){

続き:

pio run -t clean pio run -t upload

ここまでで、ビルド&書き込みが完了する。

仕様としては、NTPで同期した時刻が表示される。

sketch#5(M5Stack CoreInk NTP Clock)

説明:
M5Stack CoreInk NTP Clock

以下の手順でソースをダウンロードする:

git clone https://github.com/hpsaturn/m5coreink-ntp-clock.git cd m5coreink-ntp-clock

もともとplatformioのプロジェクトだが 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 [wifi] ; ssid = *** ; password = *** ssid = ${sysenv.PIO_WIFI_SSID} password = ${sysenv.PIO_WIFI_PASSWORD} [env:M5CoreInk] platform = espressif32 board = m5stick-c framework = arduino upload_poert = /dev/ttyUSB0 monitor_speed = 115200 build_flags = '-DWIFI_SSID="${wifi.ssid}"' '-DWIFI_PASS="${wifi.password}"' lib_deps = m5stack/M5-CoreInk @ ^0.0.2 adafruit/Adafruit Unified Sensor @ 1.1.4 adafruit/Adafruit BMP280 Library @ ^2.1.0

ライブラリのバグ修正のため、
今までのスケッチと同様に
以下のパッチをsrc/main.cppをかける:

// lib typo fix #define GetDate GetData #define SetDate SetData

NTPを日本の設定にするために以下を修正する:

修正前: const char* NTP_SERVER = "ch.pool.ntp.org"; const char* TZ_INFO = "CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00"; // enter your time zone (https://remotemonitoringsystems.ca/time-zone-abbreviations.php) → 修正後: const char* NTP_SERVER = "ntp.nict.jp"; const char* TZ_INFO = "JST-9";

WiFiの設定をexportを使用しているので ビルド時に以下を実行する:

export PIO_WIFI_SSID="YourSSID" export PIO_WIFI_PASSWORD="YourPassword" pio run -t upload

なお、上のようにexportで設定するのが面倒であれば、
platformio.iniに以下のように設定を置くことができる:
# 文字列の両端の「"」が不要のことに注目
platformio.iniの一部:

[wifi] ssid = ssss password = pppp ;ssid = ${sysenv.PIO_WIFI_SSID} ;password = ${sysenv.PIO_WIFI_PASSWORD} ...

実行時:
USBシリアル接続して、Middleボタンを押しながら resetボタンを押すと 以下のようなメッセージが表示され WiFiが接続できたことが確認できる。 この時、ビープが鳴ればNTPが正常動作したことになる。

initializing.....OK 09:19:48 [WiFi] connecting to SSID..... connected! [NTP] sync.......now 1639787623 [NTP] in: 2021/12/18 09:33:43 [NTP] Sat 18-12-21 09:33:43 [NTP] 18/12/21-9:33:43 Day of Week 6 [BATT] Voltage 4.29 Switch Mode to INK_PARTIAL_MODE

また、USBケーブルを外してバッテリ動作の場合、
Middleボタンを押しながら電源オンにすると
ビープが鳴りNTPが正常動作したことを表す。
Middleボタンを無しで電源オンした場合、
NTP同期無しで起動する。

注意

ライブラリがバージョンアップして修正完了したら 以下のパッチは外すこと:

// lib typo fix #define GetDate GetData #define SetDate SetData

参考情報

M5CoreInk関連:
M5 CoreInkとEnvHat,TVOC/eCO2 ガスセンサユニット(SGP30)で環境モニタを作る
M5Stack CoreInk発売
M5StickC ENV Hat III (SHT30/QMP6988)
M5StickC ENV II Hat(SHT30/BMP280/BMM150搭載)

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

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

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 | トップページ | M5Paper Clock »

PlatformIO」カテゴリの記事

M5CoreInk」カテゴリの記事

コメント

この記事へのコメントは終了しました。