0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

M5Stack系のデバイスと M5Unified を組み合わせたシンプルな実装のお試しをやってみます。

M5Unified のドキュメント・参考情報

まずは、M5Unified のドキュメントや参考情報を集めてみます。
また、今回使う予定のシリアル通信まわりの情報も見かけたので、合わせて列挙してみました。

公式ドキュメント

●m5-docs: M5Unifiedライブラリの始め方
 https://docs.m5stack.com/ja/arduino/m5unified/helloworld

●m5-docs: M5Unifiedへの移植のポイント
 https://docs.m5stack.com/ja/arduino/m5unified/migration

公式のリポジトリ

●m5stack/M5Unified: Unified library for M5Stack series
 https://github.com/m5stack/M5Unified

シリアル通信関連

●Serial not working with M5Unified on AtomS3 | M5Stack Community
 https://community.m5stack.com/topic/5858/serial-not-working-with-m5unified-on-atoms3

実際に試していく

それでは、お試しを進めていきます。

今回の記事では、Arduino IDE を使って開発するのですが、この後に試す際には Arduino IDE の設定まわりは行っておいてください。

利用するデバイス

今回利用してみるデバイスは 2つで、以下を使います。

簡単なボタン押下のプログラムを試す

最初に、簡単なボタン押下のプログラムを試します。

#include <M5Unified.h>

void setup()
{
    auto cfg = M5.config();
    cfg.clear_display = true;
    M5.begin(cfg);
    M5.Lcd.setTextSize(2);
}

void loop()
{
    M5.update();

    if (M5.BtnA.isPressed()) {
        M5.Display.setCursor(0, 16);
        M5.Display.println("BtnA isPressed ");
    } else {
        M5.Display.setCursor(0, 16);
        M5.Lcd.println("Press BtnA");
    }
}

ボタン押下時にシリアル通信

ここにシリアル通信の処理を足してみます。

#include <M5Unified.h>

void setup()
{
    auto cfg = M5.config();
    cfg.clear_display = true;
    M5.begin(cfg);
    M5.Lcd.setTextSize(2);

    Serial.begin(115200);
}

void loop()
{
    M5.update();

    if (M5.BtnA.isPressed()) {
        M5.Display.setCursor(0, 16);
        M5.Display.println("BtnA isPressed ");
        Serial.println("test");
    } else {
        M5.Display.setCursor(0, 16);
        M5.Lcd.println("Press BtnA");
    }
    
    delay(100);
}

動作確認

上記の動作確認を行ったところ、問題なく動作しました。

449028526_794864992844381_2824586654350294133_n.jpg

449379652_511394977889941_209965090225810150_n.jpg

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?