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

More than 1 year has passed since last update.

ESP32 で microPython を導入してみた

Posted at

今まで ESP32 では Arduino 開発環境で使ってましたが、 microPython を使ってみました。
以下のページを元に試してみます。

環境

母艦

  • Ubuntu 22.04
  • python 3.10.6

デバイス

  • ESP32 / Lolin WEMOS 32

母艦の準備

esptool が必要らしい。

$ sudo pip install esptool

動作確認を兼ねて、デバイスの消去


$ esptool.py --chip esp32 --port /dev/ttyUSB0 erase_flash

タイミングよくリセットするとこのようになりました。

esptool.py v4.5
Serial port /dev/ttyUSB0
Connecting....
Chip is ESP32-D0WDQ6 (revision v1.0)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: 7c:9e:bd:e3:19:c8
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 13.1s
Hard resetting via RTS pin...

うまく動いているみたいです。

ファームウェアの書き込み

https://micropython.org/download/esp32/
こちらから、v1.19.1 (2022-06-18) .bin をダウンロードしました。

以下のようにして書き込みをします。

$ esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 460800 write_flash -z 0x1000 esp32-20220618-v1.19.1.bin 

REPL で操作

母艦から、picocom でアクセスしてみます。

$ picocom /dev/ttyUSB0 -b115200

エンターすると REPL のプロンプトが現れました。

>>>

計算を行わせてみました。普通の Python と同様にインタープリタが動作するようです。

>>> 1+2
3

Python構文もOKでした。

>>> print("a")
a

ESP32 ぽく GPIO を操作してみます。

>>> import machine

として、

>>> pin = machine.Pin(5, machine.Pin.OUT)

これを実行したらボード上のLEDが点灯。

>>> pin.on()

これで、LEDが消灯。

>>> pin.off()

これで、LEDが点灯しました。

WEMOS LOLIN32 のLEDは負論理かな?

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