LoginSignup
1
3

More than 5 years have passed since last update.

ESP32 ROM BASICでhello world & Lチカ

Last updated at Posted at 2017-02-10

ESP32でLチカシリーズ、第3弾はBasicでLチカ。Arduino IDE版ESP-IDF版もどうぞ。環境は、いずれもMac、OS X El Capitanです。

(追記:2019-02-20、公式ドキュメントに仕様が公開されていました。IOGETの使い方がわかりました。ただし使えないGPIOもある模様。POKEでGPIO出力レジスタの直接操作もできる。)

Arduino IDE版で書いた開発ボードを使います。

BASIC inside!

ESP32の弟分、ESP8266にもBASICが入ってて、盛り上がってるらしい。知らなかったけど。。いろいろな環境にポートされているんですね。最新版はここにあります。https://github.com/esp8266/Basic

ということで、当然のように(?)お兄ちゃんのESP32にもBasicが搭載されています!

元を辿ると、68000 Tiny Basic(Arduino) → Arduino Basic(C言語)→ TinyBasicPlus ということらしい。まぁ、その昔、電気屋さんの店頭で店員さんがいない隙にシャープMZ-80K、コモドールPET2001、タンデムラジオシャックTRS-80、日立ベーシックマスターなどを触ってましたが、すぐに機械語に行って、CP/MとかOS-9に行って、あとは、C言語、Unix、Macという道だったので、BASIC写経は、やったことがないです。懐かしい、というだけで、BASICでLチカ。おじさんにはオススメ。子ども向けには、たぶん、Python版をやります。
MicroPython on ESP32
micropython-esp32 on github

ちなみに、このROM BASIC、Arduino IDEやESP-IDFでプログラムを書き込んでも消えません。マジか。

ターミナルを準備

ターミナルは、Arduino IDEのシリアルモニターでも良いですが、やはり、気分を出すためにはターミナルアプリ。miniterm.pyを使います。screenコマンドでも良いです。

まずは、ポートを調べます。

ls /dev/tty.*
/dev/tty.SLAB_USBtoUART

そして、ターミナルコマンド。ボーレートをセットしないと文字化けの嵐になるので注意。

$ miniterm.py  /dev/tty.SLAB_USBtoUART 115200

コマンドから抜けたい時は、ctrl+]を押す。

あるいは、

$ screen  /dev/tty.SLAB_USBtoUART 115200

コマンドから抜けたい時は、ctrl+Aを押して、Kを押す。

入力待ちになります。

$ miniterm.py /dev/cu.SLAB_USBtoUART 115200
--- Miniterm on /dev/cu.SLAB_USBtoUART  115200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---

BASICを召喚(起動)

GPIO12を10KΩで3.3Vにプルアップして、リセット。(簡単)
IMG_2582.JPG

リセットすると、以下のようなエラーメッセージの繰り返しになります。

>ets Jun  8 2016 00:22:57

rst:0x10 (RTCWDT_RTC_RESET),boot:0x33 (SPI_FAST_FLASH_BOOT)
flash read err, 1000
Falling back to built-in command interpreter.
OK
>ets Jun  8 2016 00:22:57

rst:0x10 (RTCWDT_RTC_RESET),boot:0x33 (SPI_FAST_FLASH_BOOT)
flash read err, 1000
Falling back to built-in command interpreter.
OK

エンターキーを押すと、止まる。aboutを見ると、おお、いますな。

>about
ESP32 ROM Basic (c) 2016 Espressif Shanghai
Derived from TinyBasic Plus by Mike Field and Scott Lawrence

プログラムをポチポチと入力

間違えたら、同じ行番号で書く。間に入れたくなったら、間の行番号を使う。ちなみに、他のエディターで書いて一気にコピペでもいけますけど。いやいや、それでは気分が出ないので。

>10 IODIR 2,1
>
>20 IOSET 2,1
>
>30 DELAY 375
>
>40 IOSET 2,0
>
>50 DELAY 125
>
>60 GOTO 20
>
>25 PRINT "hello world!!  ";

実行!(論よりrun)

>run
hello world!!  hello world!!  hello world!!  hello world!!  hello world!!  hello world!!  hello world!!  hello world!!  hello world!!  hello world!!  hello world!!  hello world!!  hello world!!  hello world!!  hello world!!  hello world!!  hello world!!  hello world!!  hello world!!  hello world!!  hello world!!  hello world!!  hello world!!  hello world!!  hello world!!  hello world!!  hello world!!  hello world!!  break!
OK
>list
10 IODIR 2,1
20 IOSET 2,1
25 PRINT "hello world!!  ";
30 DELAY 375
40 IOSET 2,0
50 DELAY 125
60 GOTO 20
OK
>

FirefoxScreenSnapz013.png
(https://www.facebook.com/naohiro.tsuji/posts/1325315740872066)

helpで、使える命令が表示されます。

残念ながら、IOGETが動いてない。
(追記:2019-02-20、動いてました。ただ、全てのポートは使えないかも。下記参照)

>help
A very Basic ROM console. Available commands/functions:
LIST
NEW
RUN
NEXT
LET
IF
GOTO
GOSUB
RETURN
REM
FOR
INPUT
PRINT
PHEX
POKE
STOP
BYE
MEM
?
'
DELAY
END
RSEED
HELP
ABOUT
IOSET
IODIR
PEEK
ABS
RND
IOGET
USR
>

IOGETがあれば、もう少しいろいろ出来ますが。。INPUTも使えない。32KBytesフリーです。

>new
>
>mem
32560 bytes free.
>

(追記:2019-02-20、IOGETが動いてました。ただ、全てのポートは使えないかも。)

>iodir 23,0
>print ioget(23)
1

参考ページ

HACKADAY
macsbug
ESP-IDF Programming Guide
TOMER WELLER / A BLOB

(追記:2019-02-20、公式ドキュメントに仕様が公開されていました。)
ESP32 ROM console

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