« MicroPython(F767ZI)でStartwars(AsciiArt)を動かす | トップページ | micro:bit Arduino/MBED開発ツール(v2)(micro:bit-v2対応,linux版) »

2020年12月31日 (木)

python3/micro:bit-micropython/CircuitPython用エディタ(mu-editor)をインストールする(v2,microbit-v2対応)(linux版)

2020/12/31

Mu-editor micro:bit v2

Mu-editor micro:bit v2

概要

python3/micro:bit-micropython/CircuitPython用エディタ(mu-editor)をインストールする(v2,microbit-v2対応)(linux版)

この記事は「 python3/micro:bit-micropython/CircuitPython用エディタ(mu-editor)をインストールする(linux版) 」の第2版にあたり、micro:bit-v2の対応方法についてなどを追加している。
(ホストはubuntu20.04を想定している)

インストール方法

以下を実行する:

# 以下のライブラリをインストールする sudo apt -y install git python3-dev python3-setuptools python3-numpy python3-opengl \ libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsmpeg-dev \ libsdl1.2-dev libportmidi-dev libswscale-dev libavformat-dev libavcodec-dev \ libtiff5-dev libx11-6 libx11-dev fluid-soundfont-gm timgm6mb-soundfont \ xfonts-base xfonts-100dpi xfonts-75dpi xfonts-cyrillic fontconfig fonts-freefont-ttf libfreetype-dev # mu-editorのインストール pip3 install mu-editor # ショートカットを作成するためshortcutをインストールする pip installl shortcut # mu-editorのショートカットを作る shortcut mu-editor # この時点で、デスクトップにmu-editorのショートカット(アイコン)が作られる # そのショートカットをクリックするとmu-editorが起動する

micro:bit-v2の対応方法

mu-editor自身はmicro:bit-v2対応が未完で、そのままでは使用できない。 そのため以下の手順で対応する:

(1)以下のurlへchromeブラウザーでアクセスしてmu-editorのweb版を起動する。 https://python.microbit.org/v/2 (2)micro:bit-v2をホストに接続する (3)起動しているmu-editorでデバイスを接続して、そこにあるスクリプトを書き込む (4)以上で、micro:bit-v2に対応したmicropythonのファームウェアが書き込まれる

その後、通常のmu-editorを起動してスクリプトを書き込むことができる。

micro:bit-v2の最新のmicropythonを使う

以下の手順で最新のmu-editorを使用すると最新版のmicropythonが書き込める。

mkdir latest_mu cd latest_mu git clone https://github.com/bbcmicrobit/PythonEditor cd PythonEditor git submodule update --init --recursive # 以下のコマンドでmu-editor(のサーバー)を起動することができる。。 ./bin/show Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ... # http://localhost:8000/editor.htmlをchromeブラウザーでアクセスするとweb版と同じeditorが起動する (Web-USBの機能を使う関係上,chromeである必要がある) # 起動しているmu-editorでデバイスを接続して、そこにあるスクリプトを書き込む 以上で、micro:bit-v2に対応したmicropythonの最新版が書き込まれる

以上が完了すれば、通常のmu-editorを使用しても最新版のmicropythonが使える。

micro:bitのmicropythonのバージョン

REPLでバージョンを確認すると以下のようになっていた:

旧版 MP現行版(v1.5)

MicroPython v1.9.2-34-gd64154c73 on 2017-09-01; micro:bit v1.0.1 with nRF51822 Type "help()" for more information. >>> >> import gc >>> gc.collect() >>> gc.mem_free() 9136 >>>

v2 MP現行版(webからの書き込み)

MicroPython v1.13 on 2020-11-24; micro:bit v2.0.0-beta.1 with nRF52833 Type "help()" for more information. >>> >>> import gc >>> gc.collect() >>> gc.mem_free() 61344 >>>

v2 MP最新版(2020/12/31現在)

MicroPython v1.13 on 2020-12-21; micro:bit v2.0.0-beta.3 with nRF52833 Type "help()" for more information. >>> >>> import gc >>> gc.collect() >>> gc.mem_free() 63616 >>>

micro:bi-v2になってRAMが増えていることからフリーメモリが増えていることが分かる。

micro:bit-v2で追加された機能を使ったスクリプト例

music_button.py

from microbit import * import music pin0.set_touch_mode(pin0.CAPACITIVE) #pin0.set_touch_mode(pin0.RESISTIVE) pin1.set_touch_mode(pin1.CAPACITIVE) #pin1.set_touch_mode(pin1.RESISTIVE) pin2.set_touch_mode(pin2.CAPACITIVE) #pin2.set_touch_mode(pin2.RESISTIVE) while True: if pin_logo.is_touched(): music.play(music.BLUES) if pin0.is_touched(): music.play(music.NYAN) if pin1.is_touched(): music.play(music.ODE) if pin2.is_touched(): music.play(music.BLUES) if button_a.was_pressed(): music.play(music.NYAN) if button_b.was_pressed(): for x in range(2): music.play(["C4:4", "D4", "E4", "C4"]) for x in range(2): music.play(["E4:4", "F4", "G4:8"])

mic_test.py

from microbit import * while True: if microphone.current_event() == SoundEvent.LOUD: display.show(Image.SQUARE) elif microphone.current_event() == SoundEvent.QUIET: display.show(Image.SQUARE_SMALL)

speak_happy.py

from microbit import * import speech set_volume(100) speech.say("are you happy?")

send_smile.py

from microbit import * import radio radio.config(group=2) radio.on() while True: message = radio.receive() if message: display.show(Image.HAPPY) if button_a.is_pressed(): display.clear() radio.send('smile')

このスクリプトは新機能を使っていないがbluetoothの使用例として載せた。

ハードウェアの相違点

micro:bitのバージョンの違いは以下のようになる:

v1.5 Nordic Semiconductor nRF51822 256kB Flash, 16kB RAM v2.0 Nordic Semiconductor nRF52833 512kB Flash, 128kB RAM

詳細は以下を参照のこと:
micro:bit のバージョンアップについて

参照情報

Using Mu with micro:bit V2
How to install Mu with Python packaging on Windows, OSX and Linux

https://microbit-micropython.readthedocs.io/en/v2-docs/tutorials/hello.html

https://microbit-micropython.readthedocs.io/en/latest/tutorials/introduction.html

https://microbit-micropython.readthedocs.io/en/v2-docs/tutorials/radio.html

https://qiita.com/sat0ken/items/13bd03378c28b98a794e
micro:bit v2 で遊ぶ

https://qiita.com/inachi/items/a591707ab6bbcb1a467c
micro:bit v2 用 MicroPython の beta-3 が出たので試してみた

公式の技術情報
micro:bit developer community and technical resources
Working together on the latest BBC micro:bit
Guidance on using the latest micro:bit revision

以上

|

« MicroPython(F767ZI)でStartwars(AsciiArt)を動かす | トップページ | micro:bit Arduino/MBED開発ツール(v2)(micro:bit-v2対応,linux版) »

MCP2221」カテゴリの記事

M5Atom」カテゴリの記事

コメント

この記事へのコメントは終了しました。