Raspberry Pi Zero を USB ケーブル 1 本で遊ぶ

概要

Raspberry Pi Zero をディスプレイ、ネットワークアダプタなしで使用する方法です。 類似タイトルの記事がいくつかあったので、それらの記事に倣っています。 2016-11-25 版の Raspbian では ssh がデフォルト off となっているため、ssh を有効化する設定を追記しています。

確認環境

参考情報

解説

SDカードに Raspbian を書き込む

Raspbian Jessie Lite のイメージファイルをダウンロード。 4GB以上の容量のあるSDカードを用意する。

diskutil コマンド、dd コマンドを使用して、イメージファイルをSDカードに書き込む。環境により異なるため省略して記載する。

  • diskutil list でSDカードが接続されているデバイスを特定
  • sudo diskutil unmount /dev/<上記で調べたデバイス> でアンマウント
  • sudo dd bs=1m if=2016-11-25-raspbian-jessie-lite.img of=/dev/<上記で調べたデバイス> で書き込む

設定を変更する

SDカードへの書き込みが完了すると自動的にマウントされて Finder に boot が表示される。

config.txt, cmdline.txt を書き換える。

  • config.txt
    • dtoverlay=dwc2 を追記
  • cmdline.txt
    • ... rootwait modules-load=dwc2,g_ether quiet init=/usr/lib/raspi-config/init_resize.sh

ssh ファイルを作成する。2016-11-25 では ssh はデフォルトで off となっている。boot に ssh ファイルを置くことで on となる。

$ cd /Volumes/boot
$ touch ssh

Finder で boot を取り出す。以上でSDカードの準備は完了。

Raspberry Pi Zero を起動する

SDカードを挿してから、USBケーブルをPCと接続する。 接続するとOSが起動するので待つ。 電源はPCから供給される。 緑ランプの点滅が収まれば起動が完了していると思われる。 (USBケーブルは家にあった適当なケーブルを使ったら繋がった。 USBケーブルによっては動作しないとのことなので注意。 参考情報のサイトを参照。)

ssh で接続する

PCのターミナルを起動し、以下を実行する。password は raspberry

mac:~ nosix$ ssh pi@raspberrypi.local
The authenticity of host 'raspberrypi.local (169.254.225.196)' can't be established.
ECDSA key fingerprint is SHA256:<内緒>.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'raspberrypi.local,169.254.225.196' (ECDSA) to the list of known hosts.
pi@raspberrypi.local's password: 

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.

SSH is enabled and the default password for the 'pi' user has not been changed.
This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.

pi@raspberrypi:~ $ 

セキュリティリスクがあるので passwd コマンドで新しいパスワードに設定するように書かれている。