Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

M5AtomS3をPlatformIOで動かしてみるメモ

Last updated at Posted at 2024-07-03

M5AtomS3を使ってみようと思います。PlatformIOでの開発が久々すぎるのでリハビリがてらメモです。


無事に動いてよかった

自分用メモなので結構雑です。

PlatformIo 始め方

復習も兼ねて

ボードのIDを探す

使いたいボードのIDを探します。

  • 利用できるボード一覧の確認
$ pio boards 
  • 設定を探してみる

今回はAtomS3を使いたいのでatomなどと入れて検索

$ pio boards atom

Platform: espressif32
=========================================================================================================
ID              MCU      Frequency    Flash    RAM    Name
--------------  -------  -----------  -------  -----  --------------
m5stack-atoms3  ESP32S3  240MHz       8MB      320KB  M5Stack AtomS3
m5stack-atom    ESP32    240MHz       4MB      320KB  M5Stack-ATOM

m5stack-atoms3というIDがあることがわかりました。

プロジェクトフォルダの作成と初期化

$ mkdir M5ATOMS3_HELLO
$ cd M5ATOMS3_HELLO 
$ pio init --board m5stack-atoms3
   
The following files/directories have been created in /Users/nobisuke/ds/2_playground/M5ATOMS3_HELLO
include - Put project header files here
lib - Put project specific (private) libraries here
src - Put project source files here
platformio.ini - Project Configuration File
Resolving m5stack-atoms3 dependencies...
Already up-to-date.
Project has been successfully initialized!

VSCodeで開くとこんな感じ。

$ code .

スクリーンショット 2024-07-04 0.22.27.png

hello world

srcフォルダ内にmain.cppを作成してビルド&書き込み

src/main.cpp
#include <Arduino.h>

void setup()
{
    Serial.begin(115200);
    Serial.println("hello platformio!");
}

void loop()
{
    Serial.println("hello");
    delay(1000);
}

スクリーンショット 2024-07-04 0.27.47.png

ライブラリ追加

M5Unifiedのライブラリを入れて描画してみる。

[env:m5stack-atoms3]
platform = espressif32
board = m5stack-atoms3
framework = arduino
lib_deps = m5stack/M5Unified@^0.1.16

コードはこちらの記事のものをそのまま使わせてもらいました。

src/main.cpp
#include <M5Unified.h> // M5Unifiedライブラリをプログラムで使用可能にします。

// グローバル変数(プログラム全体で使用する変数の定義をします。)
uint32_t count;


// setup関数は起動時に一度だけ実行されます。
// 主に初期化処理を記述します。
void setup() {

  auto cfg = M5.config();       // M5Stack初期設定用の構造体を代入
  // configを設定する場合はここで設定
  // 例
  // cfg.external_spk = true;

  M5.begin(cfg);                           // M5デバイスの初期化
  USBSerial.begin(115200);                 // シリアルモニターの初期化
  M5.Display.setTextSize(3);               // テキストサイズを変更
  M5.Display.print("Hello World!!");       // 画面にHello World!!と1行表示
  USBSerial.println("Hello World!!");         // シリアルモニターにHello World!!と1行表示
  count = 0;                               // countを初期化

}

// loop関数は起動している間ずっと繰り返し実行されます。
// センサーから値を取得したり、画面を書き換える動作等をおこないます。
void loop() {

  M5.Display.setCursor(0, 20);              // 文字の描画座標(カーソル位置)を設定
  M5.Display.printf("COUNT: %d\n", count);  // countを画面に表示
  USBSerial.printf("COUNT: %d\n", count);      // countをシリアルに表示
  count++;                                  // countを1増やす
  delay(1000);                              // 1秒待つ

}

ビルドして書き込むと上手く動きました。


手術前のアクアファインを背景に。

4
2
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

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?