Raspberry Pi ZeroをOTGモードを使って、PCからMIDIデバイスとして認識できるように設定します。OTGはUSB On-The-Goの略です。PCがUSBのHost(親)とし、Raspberry Pi ZeroをFunction(子供側)にすることができます。普通のRaspberry Piは常にUSB Host(親)として機能し、このモードに対応していません。設定はLinuxの扱いに慣れていないとちょっと難しいかもしれません。以下の2つのファイルを書き換えます。
> pi@raspberrypi:~ $ sudo vi /boot/config.txt
私の場合、config.txtの一番最後は以下のようになりました。
... ... [pi4] # Run as fast as firmware / board allows arm_boost=1 [OTG] dtoverlay=dwc2
> pi@raspberrypi:~ $ sudo vi /boot/cmdline.txt
私の場合cmdline.txtを書き加えた結果、以下のようになりました。
console=serial0,115200 console=tty1 root=PARTUUID=fe7ff3ab-02 rootfstype=ext4 fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles cfg80211.ieee80211_regdom=JP rootwait modules-load=dwc2,g_midi quiet
コマンドラインで、以下の2つの命令を実行することでも書き換えられます。
> pi@raspberrypi:~ $ sudo sed -i -e '$ a dtoverlay=dwc2' /boot/config.txt > pi@raspberrypi:~ $ sudo sed -i s/rootwait/rootwait\ modules-load=dwc2,g_midi/ /boot/cmdline.txt
2つのファイルを書き換えたらrebootします。
> pi@raspberrypi:~ $ sudo reboot
Ubuntu 23.10をRaspberry Pi Zero2にインストールし、OTGを設定してみたところ、設定ファイルの場所が変わっていました。 ちなみに Ubuntuのバージョンは/etc/os-releaseをcatすることで確認できます。
> cat /etc/os-release PRETTY_NAME="Ubuntu 23.10" NAME="Ubuntu" VERSION_ID="23.10" VERSION="23.10 (Mantic Minotaur)" ...
config.txtとcmdline.txtの2つのファイルは、/boot/firmwareにあります。
> cd /boot/firmware > sudo vi config.txt
config.txtの最終行は以下の様に書かれていました。
[cm4] # Enable the USB2 outputs on the IO board (assuming your CM4 is plugged # into such a board) dtoverlay=dwc2,dr_mode=host
dr_mode=hostを削除し以下のように修正します。
[cm4] # Enable the USB2 outputs on the IO board (assuming your CM4 is plugged # into such a board) dtoverlay=dwc2
cmdline.txtの修正は上と同じです。rootwaitを探して、 rootwait modules-load=dwc2,g_midiと修正します。
PCとUSB接続します。Raspberry Pi Zero の中央のUSBと記載されている端子とつないで下さい。
PCでデバイスマネージャーを開くと、サウンド、ビデオ、および… の項目にMIDI functionが追加されています。
一方、Raspberry Pi Zeroでは、amidi -lコマンドを使って、f_midiという名前でMIDIデバイスが認識できます。
> pi@raspberrypi:~ $ amidi -l Dir Device Name IO hw:0,0 f_midi
Web MIDIを使って、MIDIの送受信をチェックします。PCのChromeで、このページを開きます。MIDI IN:/MIDI out:の両方にMIDI functionを設定します。
Raspberry Pi Zeroでも同じページを開きます。MIDI IN:/MIDI out:の両方にMIDI functionを設定します。
PC側のPushを押します。Raspberry Pi ZeroのブラウザでMIDIが受信できます。
Raspberry Pi Zero側のPushを押します。PCのブラウザでMIDIが受信できます。