0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

M5Stick Cの入門備忘録

Last updated at Posted at 2024-12-24

やったこと

  1. vscodeの拡張機能platformioを入れる
  2. プロジェクトを作る
  3. PIO Home から Libraries で m5stick と検索して「M5StickC by M5Stack An ESP32 Arduino board」を作成したプロジェクトにインストールする
  4. 以下、コード
main.cpp
#include <M5StickC.h>

// 液晶の位置
#define ROTATION_VERTICAL_UP (0)
#define ROTATION_HORIZONTAL_LEFT (1)
#define ROTATION_VERTICAL_DOWN (2)
#define ROTATION_HORIZONTAL_RIGHT (3)

void setup()
{
  M5.begin();
  Serial.begin(115200);

  pinMode(10, OUTPUT);

  // 液晶の初期化
  M5.Lcd.begin();                               // 画面初期化
  M5.Lcd.setRotation(ROTATION_HORIZONTAL_LEFT); // 画面向き設定(0~3で設定、4~7は反転)※初期値は1
  M5.Lcd.setTextWrap(true);                     // 画面端での改行の有無(true:有り[初期値], false:無し)※print関数のみ有効
  M5.Axp.ScreenBreath(12);                      // 液晶バックライト電圧設定 LCD backlight voltage setting.
  M5.Lcd.fillScreen(BLACK);                     // 画面の塗りつぶし Screen fill.

  // 描画の初期化
  M5.Lcd.setTextColor(WHITE);

  // シリアルモニタへの出力
  Serial.println("M5Stick C Start");
  Serial.print("Rotation Value: ");
  Serial.println(ROTATION_HORIZONTAL_LEFT);
  Serial.print("Resolution: ");
  Serial.print(M5.Lcd.width());
  Serial.print("x ");
  Serial.print(M5.Lcd.height());
  Serial.println("(px)");
  Serial.println("Hello World!"); // 改行ありで文字表示

  // M5Stick にある液晶への出力
  M5.Lcd.println("M5Stick C Start");
  M5.Lcd.print("Rotation Value: ");
  M5.Lcd.println(ROTATION_HORIZONTAL_LEFT);
  M5.Lcd.print("LCD Resolution: ");
  M5.Lcd.print(M5.Lcd.width());
  M5.Lcd.print("x");
  M5.Lcd.print(M5.Lcd.height());
  M5.Lcd.println("(px)");
  M5.Lcd.println("Hello World!"); // 改行ありで文字表示
}

void loop()
{
  M5.update(); // M5状態更新 M5 status update.

  // LEDの点灯
  digitalWrite(10, HIGH);
  delay(1000);

  // LEDの消灯
  digitalWrite(10, LOW);
  delay(1000);
}

つまずいたこと

  • ポート番号の確認
    • デバイスマネージャーでCOM番号をしっかり確認せよ
  • ライブラリ
    • M5StickC.h をインクルードすること
    • M5StickCPlus.h とは完全に別物なので注意
    • 誤って M5StickCPlus.h を入れた場合、M5StickC.h を入れなおした後に platformio.inilib_deps を書き換える
platformio.ini (書き換え前)
[env:m5stick-c]
platform = espressif32
board = m5stick-c
framework = arduino
lib_deps = 
	m5stack/M5StickCPlus@^0.1.0
	m5stack/M5StickC@^0.2.5
monitor_speed = 115200
upload_port = COM9
monitor_port = COM9
platformio.ini (書き換え前)
[env:m5stick-c]
platform = espressif32
board = m5stick-c
framework = arduino
lib_deps = m5stack/M5StickC@^0.2.5
monitor_speed = 115200
upload_port = COM9
monitor_port = COM9
  • Device unsupported エラー
C:\Users\takum\.platformio\penv\Scripts\platformio.exe run --target upload 
Processing uno_r4_wifi (platform: renesas-ra; board: uno_r4_wifi; framework: arduino)
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/renesas-ra/uno_r4_wifi.html
PLATFORM: Renesas RA (1.4.0) > Arduino Uno R4 WiFi
HARDWARE: RA4M1 48MHz, 32KB RAM, 256KB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, jlink)
PACKAGES:
 - framework-arduinorenesas-uno @ 1.1.0
 - tool-bossac @ 1.10901.0 (1.9.1)
 - tool-jlink @ 1.78811.0 (7.88.11)
 - tool-openocd @ 3.1200.0 (12.0)
 - toolchain-gccarmnoneeabi @ 1.70201.0 (7.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 21 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Checking size .pio\build\uno_r4_wifi\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   7.6% (used 2480 bytes from 32768 bytes)
Flash: [=         ]  13.0% (used 34040 bytes from 262144 bytes)
Configuring upload protocol...
AVAILABLE: cmsis-dap, jlink, sam-ba
CURRENT: upload_protocol = sam-ba
Looking for upload port...
Auto-detected: COM9
Forcing reset using 1200bps open/close on port COM9
Uploading .pio\build\uno_r4_wifi\firmware.bin
Device unsupported
*** [upload] Error 1
================================================================================================ [FAILED] Took 4.97 seconds ================================================================================================
  • 原因: vscodeのワークスペースで他のプロジェクトを開いていて,そのボード設定が使われてしまった
  • 解決策: vscodeのエクスプローラー画面にある関係ないワークスペースを右クリックで操作して外す
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?