6
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?

Elixir(AtomVM)でLチカ 〜 M5Stack CoreS3 〜

Last updated at Posted at 2025-11-28

ElixirのコードでM5Stack CoreS3を動かすことを目標にするコラムです
今回はExAtomVMを使います

開発環境

  • Ubuntu 24.04
  • elixir 1.17.1-otp-27
  • erlang 27.2.1

実行イメージ

回路

  • G8 LEDと220Ωの抵抗

image.png

前提知識

ESP32でファームを焼く知識
僕は下記の@mnishiguchiさんのコラムを参考にしました

環境構築

ESP32のファームを焼くツール
esptoolをインストール

$ python3 -m venv venv
$ source ~/venv/bin/activate
$ pip install esptool

AtomVMをM5Stack CoreS3に焼く

$ curl -LO https://github.com/atomvm/AtomVM/releases/download/v0.6.6/AtomVM-esp32s3-elixir-v0.6.6.img
$ esptool --chip auto --port /dev/ttyACM0 --baud 921600 erase-flash
$ esptool --chip auto --port /dev/ttyACM0 --baud 921600 write_flash 0x0 AtomVM-esp32s3-elixir-v0.6.6.img

Lチカのプロジェクト作成

プロジェクトを作成

$ mix new blinky

ソースを変更
exatomvmの追加
atomvm:を追加

基本はAtomVMのサンプルと同じ

mix.exs
defmodule Blinky.MixProject do
  use Mix.Project

  def project do
    [
      app: :Blinky,
      version: "0.1.0",
      elixir: "~> 1.13",
      start_permanent: Mix.env() == :prod,
      deps: deps(),
      atomvm: [
        start: Blinky,
        flash_offset: 0x250000
      ]
    ]
  end

  # Run "mix help compile.app" to learn about applications.
  def application do
    [
      extra_applications: [:logger]
    ]
  end

  # Run "mix help deps" to learn about dependencies.
  defp deps do
    [
      {:exatomvm, git: "https://github.com/atomvm/ExAtomVM/"}
    ]
  end
end

pin 8が重要です

lib/Blinky.ex
defmodule Blinky do
  @pin 8

  def start() do
    :gpio.set_pin_mode(@pin, :output)
    loop(@pin, :low)
  end

  defp loop(pin, level) do
    :io.format(~c"Setting pin ~p ~p~n", [pin, level])
    :gpio.digital_write(pin, level)
    Process.sleep(100)
    loop(pin, toggle(level))
  end

  defp toggle(:high), do: :low
  defp toggle(:low), do: :high

end

プログラムを焼く

$ mix atomvm.esp32.flash --port /dev/ttyACM0

焼くとLEDが点滅します

ハマったこと

M5Stack CoreS3 開発キット ポートB (G8)
では電源を落としてしまうと、次回からLEDが点滅いませんでした
予想ですが、grove経由(DNI BASE)だと電源供給の設定がないと動かないと思われます
未調査で今後の課題です

おまけ M5Stack Cores3を強制的に工場初期ファームにする方法

  • 電源を押しながらUSBを差す

  • 緑のLEDが光ったら離す

  • https://docs.m5stack.com/ja/core/CoreS3 にアクセス

  • 「Web Tools で CoreS3 工場出荷時ファームウェア書込みを実施」でブラウザから/dev/ttyACM0経由で書き込む

6
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
6
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?