1.開発環境の設定:Arduino IDE 入門チュートリアルを参考に IDE をインストールし、使用する開発ボードに応じてボードマネージャーと必要なライブラリをインストールしてください。
2.使用ライブラリ:
3.使用するハードウェア製品:
M5Unifiedライブラリに含まれるDisplays
サンプルを参考に、本チュートリアルで使用するデバイスに合わせて設定を一部変更しました。使用する外部ディスプレイの解像度に応じて、13行目と14行目のコードを変更してください。
#include <Arduino.h>#include <M5AtomDisplay.h>#include <M5Unified.h> void setup() { auto cfg = M5.config(); // external display setting. (Pre-include required) cfg.external_display.atom_display = true; // default=true. use AtomDisplay // Set individual parameters for external displays. // (※ Use only the items you wish to change. Basically, it can be omitted.) cfg.atom_display.logical_width = 1920; cfg.atom_display.logical_height = 1200; // cfg.atom_display.output_width = 1920; // cfg.atom_display.output_height = 1080; // cfg.atom_display.refresh_rate = 60; // cfg.atom_display.scale_w = 2; // cfg.atom_display.scale_h = 2; // cfg.atom_display.pixel_clock = 74250000; // begin M5Unified. M5.begin(cfg); // Get the number of available displays int display_count = M5.getDisplayCount(); for (int i = 0; i < display_count; ++i) { // All displays are available in M5.Displays. // ※ Note that the order of which displays are numbered is the order in which they are detected, so the order may change. M5.Displays(i).clear(); int textsize = M5.Displays(i).height() / 120; if (textsize < 5) { textsize = 3; } M5.Displays(i).setTextSize(textsize); M5.Displays(i).printf("\n\nNo.%d\n\n", i); } // If an external display is to be used as the main display, it can be listed in order of priority. M5.setPrimaryDisplayType({ m5::board_t::board_M5AtomDisplay, // m5::board_t::board_M5ModuleDisplay, }); // The primary display can be used with M5.Display. M5.Display.print("primary display\n\n"); // Examine the indexes of a given type of display int index_atom_display = M5.getDisplayIndex(m5::board_t::board_M5AtomDisplay); if (index_atom_display >= 0) { M5.Displays(index_atom_display).print("This is Atom Display\n"); } M5.delay(2500);} void loop() { M5.delay(100); int x = rand() % M5.Displays(0).width(); int y = rand() % M5.Displays(0).height(); int r = (M5.Displays(0).width() >> 2) + 2; uint16_t c = rand(); M5.Displays(0).fillCircle(x, y, r, c); draw_function(&M5.Displays(1));} // When creating a function for drawing, it can be used universally by accepting a LovyanGFX type as an argument.void draw_function(LovyanGFX* gfx) { int x = rand() % gfx->width(); int y = rand() % gfx->height(); int r = (gfx->width() >> 6) + 2; uint16_t c = rand(); gfx->fillRect(x - r, y - r, r * 2, r * 2, c);}
1.ダウンロードモード:プログラムを書き込む前に、メインコントローラーをダウンロードモードに切り替える必要があります。デバイスによって手順が異なるため、詳細はArduino IDE 入門チュートリアルのページ下部にあるデバイス別の書き込み手順を参照してください。
AtomS3R の場合、リセットボタンを約2秒間長押しして、内部の緑色LEDが点灯したらボタンを離します。この状態でダウンロードモードに入り、書き込み待機状態になります。
AtomS3R と Atomic Display Base を組み合わせ、HDMIケーブルで外部モニターに接続します。その後、リセットボタンを短く一回押すと、AtomS3R の内蔵画面には多数のカラフルな円が表示されます。そして、外部ディスプレイには多数のカラフルな四角形が表示されます。実行結果は以下の通りです: