LoginSignup
0
0

More than 1 year has passed since last update.

Raspberrypi PicoでMicroPythonを使ってみたメモ2

Last updated at Posted at 2021-05-08

はじめに

Windows環境でTeratermを使って取り急ぎLチカを実行してみたが、これではPicoを起動する度にコピペが必要なため、作成したコードを起動時に自動で立ち上げることができない。この動作はマイコンとしてはどうよ、ということで対応する方法を調査した

自動起動する方法

ネット上で先人の知恵を借りると、作成したコードをmain.pyなるファイル名でMicroPythonに送り込めば、起動即実行が可能ということがわかった。Thonnyを使えばこのあたりはよしなにやってくれるらしい(さすが開発環境)。またpythonで書かれた専用のファイル転送ツールもあるようだ。
PythonなしのWindows環境に固執していると、なかなか対応が難しい状況に思えてきた。

開発母艦を"普通のRaspberryPi"に変更

少し悩んだ結果、手元にある普通のラズパイ(Linux)を開発環境に用いることに変更。最初からこっちを使った方が良かった。Windowsからsshでログインして使うことに。

rshellをインストール

pythonで動くrshellというツールが便利そうなのでインストール

pip3 install rshell

PicoをラズパイのUSB端子に接続し、以下のコマンドを入力すると、MicroPython側のファイルシステム(?)にアクセスできる

rshell --buffer-size=512 -p /dev/ttyACM0

以下のようなメッセージが表示されてコマンド入力状態に

Using buffer-size of 512
Connecting to /dev/ttyACM0 (buffer-size 512)...
Trying to connect to REPL  connected
Retrieving sysname ... rp2
Testing if ubinascii.unhexlify exists ... Y
Retrieving root directories ... 
Setting time ... May 08, 2021 11:45:58
Evaluating board_name ... pyboard
Retrieving time epoch ... Jan 01, 1970
Welcome to rshell. Use Control-D (or the exit command) to exit rshell.
/home/pi> 

rshell環境でmain.pyをMicroPython側にコピーする

MicroPythonのファイルシステムに移動するには/pyboardにcdする。ここには何も置いていないことがわかる。

/home/pi> cd /pyboard/
/pyboard> ls
/pyboard> ls -al

使えるコマンドを確認し、母艦ラズパイで作成したmain.pyをMicroPython側(/piboard以下)にコピーする

/pyboard> help

Documented commands (type help <topic>):
========================================
args    cat  connect  date  edit  filesize  help  mkdir  rm     shell
boards  cd   cp       echo  exit  filetype  ls    repl   rsync

Use Control-D (or the exit command) to exit rshell.
/pyboard> cp /home/py/main.py .
/pyboard>

Ctrl-Dでrshellを抜け、Picoを再起動するとmain.py(Lチカ)が自動実行された(目的達成)。

0
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
0
0