<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Raspberry Pi &#8211; sozorablog</title>
	<atom:link href="https://sozorablog.com/category/raspberry-pi/feed/" rel="self" type="application/rss+xml" />
	<link>https://sozorablog.com</link>
	<description>Raspberry Piで電子工作をはじめよう</description>
	<lastBuildDate>Fri, 17 Apr 2026 08:50:47 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://sozorablog.com/wp-content/uploads/2025/04/cropped-ChatGPT-Image-2025年4月5日-15_25_36-32x32.png</url>
	<title>Raspberry Pi &#8211; sozorablog</title>
	<link>https://sozorablog.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Raspberry PiとWhisplay HATで音声ガジェットを作ろう</title>
		<link>https://sozorablog.com/whisplay-hat/</link>
					<comments>https://sozorablog.com/whisplay-hat/#respond</comments>
		
		<dc:creator><![CDATA[そぞら]]></dc:creator>
		<pubDate>Thu, 16 Apr 2026 11:17:29 +0000</pubDate>
				<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[関連製品]]></category>
		<guid isPermaLink="false">https://sozorablog.com/?p=16651</guid>

					<description><![CDATA[PiSugarから音声と表示を一体で扱える拡張ボード「Whisplay HAT」が登場しました。Raspberry Piに差し込むだけで、マイクとスピーカーによる音声入出力、LCD表示、ボタン操作までをまとめて利用できま [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p><a href="https://www.pisugar.com/">PiSugar</a>から音声と表示を一体で扱える拡張ボード「Whisplay HAT」が登場しました。<a href="https://sozorablog.com/raspberry-pi/">Raspberry Pi</a>に差し込むだけで、マイクとスピーカーによる音声入出力、LCD表示、ボタン操作までをまとめて利用できます。</p>



<figure class="wp-block-image size-full is-resized"><img fetchpriority="high" decoding="async" width="714" height="694" src="https://sozorablog.com/wp-content/uploads/2026/04/IMG_0742.jpeg" alt="" class="wp-image-16798" style="aspect-ratio:1.0288522288522288;width:514px;height:auto"/><figcaption class="wp-element-caption">Raspberry Piと音声で会話できる</figcaption></figure>



<p>今までになかったコンセプトの製品で、昨今のAIブームとも相性が良く、音声インターフェースを使ったガジェットを手軽に作れる点が魅力です。</p>



<p>この記事では、Whisplay HATを使い、AIチャットボットとニュース読み上げガジェットの作り方を解説します。ラズパイの可能性がさらに広がる感覚をつかめるはずです。</p>



<p>私が購入した時点では、Amazonで在庫がなく、<a href="https://www.pisugar.com/products/whisplay-hat-for-pi-zero-2w-audio-display">公式サイト</a>から購入しました。</p>



<!-- START MoshimoAffiliateEasyLink -->
<script type="text/javascript">
(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;
b[a]=b[a]||function(){arguments.currentScript=c.currentScript
||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};
c.getElementById(a)||(d=c.createElement(f),d.src=g,
d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})
(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");
msmaflink({"n":"Raspberry Pi Zero W\/2W用Whisplay HAT – オーディオ+ディスプレイ拡張ボード。","b":"PI PISUGAR","t":"","d":"https:\/\/m.media-amazon.com","c_p":"\/images\/I","p":["\/31ZWzMEzvgL._SL500_.jpg","\/41167B9024L._SL500_.jpg","\/21FWfK7GKUL._SL500_.jpg","\/31F9K0E1oML._SL500_.jpg","\/31A-oMe1qrL._SL500_.jpg","\/51glNP3UJEL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0FPG8S6K6","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":1,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0FPG8S6K6","a_id":3038653,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":0}],"eid":"oKnZh","s":"s"});
</script>
<div id="msmaflink-oKnZh">リンク</div>
<!-- MoshimoAffiliateEasyLink END -->



<h2 class="wp-block-heading">Whisplay HATは音声アシスタントに特化</h2>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="450" src="https://sozorablog.com/wp-content/uploads/2026/04/pico-6.jpg" alt="" class="wp-image-16802" srcset="https://sozorablog.com/wp-content/uploads/2026/04/pico-6.jpg 800w, https://sozorablog.com/wp-content/uploads/2026/04/pico-6-320x180.jpg 320w, https://sozorablog.com/wp-content/uploads/2026/04/pico-6-224x126.jpg 224w" sizes="(max-width: 800px) 100vw, 800px" /><figcaption class="wp-element-caption">Whisplay HATの裏面</figcaption></figure>



<p>Whisplay HATは、<a href="https://sozorablog.com/raspberry-pi-zero-2-w/">Raspberry Pi Zero 2 W</a>や<a href="https://sozorablog.com/pi5/">Raspberry Pi 5</a>に対応した、音声と表示をまとめて扱える拡張ボードです。Raspberry Piに取り付けることで、以下の機能が使えるようになります。</p>



<div class="wp-block-sbd-list"><ul class="sbd-list sbd-list-border"><li>音声の入出力（マイク・スピーカー）</li><li>LCD画面の表示</li><li>ボタン入力の取得</li><li>RGB LEDの制御</li></ul></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="583" src="https://sozorablog.com/wp-content/uploads/2026/04/IMG_0626-1.jpeg" alt="" class="wp-image-16800" style="width:638px;height:auto"/><figcaption class="wp-element-caption">Raspberry Pi 5でも使用可能</figcaption></figure>



<p>Raspberry PiのGPIOにそのまま差し込むだけで利用できる便利な設計です。複雑な配線を行う手間がなく、使い始められます。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="489" src="https://sozorablog.com/wp-content/uploads/2026/04/IMG_0745.jpeg" alt="" class="wp-image-16816"/><figcaption class="wp-element-caption">Raspberry Pi Zero 2 Wとのサイズ比較</figcaption></figure>



<p>Raspberry Pi Zero 2 Wと同サイズなので、一体感のあるスマートな見た目に仕上がる点が気に入っています。</p>



<h2 class="wp-block-heading">Whisplay HATの使用準備</h2>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/04/スクリーンショット-2026-04-12-20.17.09-1.png" alt="" style="width:766px;height:auto"/></figure>



<p><a href="https://sozorablog.com/raspberrypi_initial_setting/">Raspberry Pi OS</a>はTrixieのデスクトップ版を選択しました。</p>



<h3 class="wp-block-heading">Whisplay HATの取り付け</h3>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="554" src="https://sozorablog.com/wp-content/uploads/2026/04/IMG_0634.jpeg" alt="" class="wp-image-16799"/></figure>



<p>Raspberry PiのGPIOピンに差し込みます。この際、LCD部分を押さえないように注意しましょう。</p>



<h3 class="wp-block-heading">Whisplay HATの初期設定</h3>



<p>Raspberry Piを起動して、Whisplay HATの使用準備をします。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/pico-1-6.jpg" alt=""/></figure>



<p>Whisplay HATのプログラムをダウンロードします。<code>--depth 1</code>は最新版だけを取得する指定です。以下を入力したあとにEnterキーを押すと実行されます<strong>。</strong></p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>git clone https://github.com/PiSugar/Whisplay.git --depth 1</code></pre></div>



<p>フォルダを移動します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>cd Whisplay/Driver</code></pre></div>



<p>以下を実行すると、音声チップの設定や、I2C・I2Sといった通信機能の有効化が自動で行われます。先頭のyesは、途中で表示される確認メッセージに対して自動的に「yes」と答えるためのものです。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>yes | sudo bash install_wm8960_drive.sh</code></pre></div>



<p>Raspberry Piを再起動して、設定を反映させます。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo reboot</code></pre></div>



<h3 class="wp-block-heading">Whisplay HATの動作確認</h3>



<p>再起動したら、Whisplay HATの動作を確認するためのテストプログラムを実行してみましょう。以下のコマンドでtest.pyを起動します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>cd /home/pi/Whisplay/example && python3 test.py</code></pre></div>



<p><br>プログラムを起動すると、data/test.pngの画像がLCDに表示されます。Whisplay HATの右側面に付いている白いボタンを押すと、サンプルの音声が再生され、画面とLEDの色が赤・緑・青の順に切り替わります。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/04/IMG_0624.jpeg" alt="" style="aspect-ratio:0.8222213491533414;width:283px;height:auto"/></figure>



<p>この動作により、画面表示、音声再生、LED制御、ボタン入力といった機能が正常に動いているかを確認できます。<a href="https://github.com/PiSugar/Whisplay/blob/main/example/test.py">テストコード</a>の中身を確認することで、Whisplay HATの動かし方が理解でき、オリジナルのプロジェクトを作る際のヒントにもなります。</p>



<h4 class="wp-block-heading">音量の調整</h4>



<p>スピーカーの音量は、デスクトップ画面右上のスピーカーのアイコンをクリックして変更できます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/04/pico.jpg" alt="" style="width:548px;height:auto"/></figure>



<h2 class="wp-block-heading">AIチャットボットを動かす</h2>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="748" height="788" src="https://sozorablog.com/wp-content/uploads/2026/04/IMG_0744.jpg" alt="" class="wp-image-16803" style="aspect-ratio:0.9492530988452167;width:560px;height:auto"/><figcaption class="wp-element-caption">音声で会話できる</figcaption></figure>



<p>メーカーが公開している音声チャットボット「Whisplay AI Chatbot」を使うことで、会話デバイスを簡単に構築できます。ボタンを押して話しかけると、AIが音声で返答する仕組みです。</p>



<p>Whisplay AI Chatbotは、複数のAIサービスに対応しています。クラウド型ではOpenAIやGeminiなどが使えます。ローカル型ではOllamaやWhisper、Piperなどを使ってオフライン動作も可能です。</p>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>ここでは、最も簡単に設定できるOpenAIのサービスを使って設定します。</p>
</div></div>



<p>まずは<a href="https://github.com/PiSugar/whisplay-ai-chatbot">GitHub</a>に公開されているソースコード（プログラム一式）をダウンロードします。<code>whisplay-ai-chatbot</code>フォルダが作成され、その中にソースコードが保存されます。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>git clone https://github.com/PiSugar/whisplay-ai-chatbot.git</code></pre></div>



<p>ダウンロードしたフォルダへ移動します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>cd whisplay-ai-chatbot</code></pre></div>



<p>プログラムを動かすために必要なソフトをまとめてインストールします。以下を実行すると、音声処理やAIの動作に必要なライブラリ、Node.jsやPython関連のパッケージが自動でインストールされます。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>bash install_dependencies.sh</code></pre></div>



<p>設定ファイル（.bashrc）の内容を反映します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>source ~/.bashrc</code></pre></div>



<p><code>.env.template</code>をコピーして<code>.env</code>というファイルを作成します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>cp .env.template .env</code></pre></div>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>チャットボットは、設定が書かれた<code>.env</code>というファイルを読み込んで動きます。</p>
</div></div>



<p>次のコマンドで<code>.env</code>を開きます。nanoはターミナル上でテキストファイルを編集できるシンプルなエディタです。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>nano .env</code></pre></div>



<h3 class="wp-block-heading">APIキーを準備する</h3>



<p>ここでは詳細を説明しませんが、以下の手順でOpenAIのAPIキーを作成します。事前に<a href="https://openai.com/ja-JP/api/pricing/">API利用料金</a>も確認しておきましょう。使用するモデルはデフォルトで<span class="sbd-text-red">gpt-4o</span>が設定されています。</p>



<ol class="wp-block-list">
<li><a href="https://platform.openai.com/overview">管理画面（APIプラットフォーム）</a>を開く</li>



<li>アカウントを作成またはログインする</li>



<li>金額を選んでクレジットを購入（$5 creditsで十分）</li>



<li><a href="https://platform.openai.com/overview">OpenAI developer platform</a>の画面右上の歯車マークをクリック</li>



<li>「API keys」ページに移動する </li>



<li>「Create new secret key」をクリックしてAPIキーを発行する </li>



<li>表示されたキーをコピーして保存する</li>
</ol>



<h3 class="wp-block-heading">APIキーを設定する</h3>



<p>テンプレートはデフォルトで音声認識・会話処理・音声出力のすべてをOpenAIで行う設定になっています。.envの下の方までスクロールして、OpenAIのAPIキーを入力します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>OPENAI_API_KEY=ここに自分のAPIキー</code></pre></div>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/04/pico-1.jpg" alt=""/></figure>



<p><code>nano .env</code>で編集したあと、Ctrlキーを押しながらOを押して保存します。画面下にファイル名が表示されるので、そのままEnterキーを押すと保存が確定します。その後、Ctrlキーを押しながらXを押すとnanoが終了します。</p>



<p>プロジェクトをビルドします。依存パッケージの準備や必要なファイルの生成が行われ、チャットボットを起動できる状態になります。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>bash build.sh</code></pre></div>



<h3 class="wp-block-heading">チャットボットを動かしてみる</h3>



<p>以下のコマンドでチャットボットが起動します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>bash run_chatbot.sh</code></pre></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/04/IMG_0729.jpeg" alt="" style="aspect-ratio:1.2441987897269737;width:469px;height:auto"/></figure>



<p>起動後は、Whisplay HATの右側面に付いている白いボタンを押している間に話しかけます。話し終えたらボタンを離すと、音声がOpenAIに送信され、内容が解析されます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/04/IMG_0730.jpeg" alt="" style="width:491px;height:auto"/></figure>



<p>その後、AIが返答を生成し、その内容が音声として再生されます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/04/IMG_0731.jpeg" alt="" style="aspect-ratio:1.2779953014878622;width:495px;height:auto"/></figure>



<p>終了する場合は、ターミナルでCtrlキーとCを押すと停止します。</p>



<p>Raspberry Piを再起動したあとは、以下のコマンドでチャットボットを起動できます。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>cd ~/whisplay-ai-chatbot && bash run_chatbot.sh</code></pre></div>



<h2 class="wp-block-heading">ニュースを読み上げるガジェットを作ろう</h2>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="583" src="https://sozorablog.com/wp-content/uploads/2026/04/IMG_0741.jpeg" alt="" class="wp-image-16784" style="width:668px;height:auto"/><figcaption class="wp-element-caption">最新ニュースを音声とテキスト表示で教えてくれる</figcaption></figure>



<p>ここからはWhisplay HATの独自の使い方を紹介します。API料金を気にせず使える方法として、<span class="sbd-text-bg-yellow">ローカル環境だけで音声を生成する構成</span>を考えました。今回はインターネットからニュースを取得し、その見出しを音声で読み上げるガジェットを作成します。</p>



<h3 class="wp-block-heading">テキストをしゃべらせてみよう</h3>



<p>OpenJTalkをインストールします。OpenJTalkは、名古屋工業大学を中心に開発された、日本語の文章を音声に変換して読み上げるオープンソースの音声合成エンジンです。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo apt install -y open-jtalk open-jtalk-mecab-naist-jdic hts-voice-nitech-jp-atr503-m001</code></pre></div>



<p>音声対話ソフトMMDAgentのサンプルに含まれる音声を取得します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>wget https://downloads.sourceforge.net/project/mmdagent/MMDAgent_Example/MMDAgent_Example-1.8/MMDAgent_Example-1.8.zip</code></pre></div>



<p>ZIP形式のファイル「MMDAgent_Example-1.8.zip」を解凍します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>unzip MMDAgent_Example-1.8.zip</code></pre></div>



<p>meiフォルダをシステムの音声データ用ディレクトリ（/usr/share/hts-voice/）にコピーします。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo cp -r MMDAgent_Example-1.8/Voice/mei /usr/share/hts-voice/</code></pre></div>



<p>Thonnyを開いて、Pythonのプログラムを実行します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/04/pico-2.jpg" alt="" style="width:555px;height:auto"/></figure>



<p>以下のコードをコピーペーストして実行してみましょう。Whisplay HATのスピーカーから「こんにちは」の音声が流れるはずです。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/04/pico-3.jpg" alt="" style="aspect-ratio:1.5444307750544146;width:564px;height:auto"/></figure>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>import subprocess

def speak_japanese(text, voice=&quot;normal&quot;, speed=0.8):
    # voiceで選択できる種類
    # &quot;normal&quot;   : 標準
    # &quot;happy&quot;    : 明るい
    # &quot;angry&quot;    : 怒り
    # &quot;sad&quot;      : 悲しい
    # &quot;bashful&quot;  : 照れ
    voice_path = f&quot;/usr/share/hts-voice/mei/mei_{voice}.htsvoice&quot;

    subprocess.run(
        [
            &quot;open_jtalk&quot;,
            &quot;-x&quot;, &quot;/var/lib/mecab/dic/open-jtalk/naist-jdic&quot;,
            &quot;-m&quot;, voice_path,
            &quot;-r&quot;, str(speed),
            &quot;-ow&quot;, &quot;/tmp/test.wav&quot;
        ],
        input=text,
        text=True
    )

    subprocess.run([&quot;aplay&quot;, &quot;/tmp/test.wav&quot;])

speak_japanese(&quot;こんにちは&quot;, &quot;happy&quot;)</code></pre></div>



<h4 class="wp-block-heading">エラーが出る場合</h4>



<p>Whisplay HATのテストプログラム実行後の場合などは、音声デバイス（/dev/snd）が解放されず、以下のエラーが出ることがあります。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="591" height="119" src="https://sozorablog.com/wp-content/uploads/2026/04/スクリーンショット-2026-04-17-4.58.17.png" alt="" class="wp-image-16847" style="width:814px;height:auto"/></figure>



<p>この場合は、以下のコマンドで使用中のプロセスを強制終了してデバイスを解放します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo fuser -k /dev/snd/*</code></pre></div>



<h4 class="wp-block-heading">プログラムの解説</h4>



<p>日本語テキストをOpenJTalkで音声に変換し、/tmp/test.wavに保存してから再生する処理です。読み上げる内容はtextに入れた文字で決まり、voiceで声の種類（normal・happyなど）を選べます。speedで話す速さを調整でき、数値が小さいほどゆっくり、大きいほど速くなります。</p>



<p>最後の<code>speak_japanese("こんにちは", "happy")</code>は、「こんにちは」を明るい声で再生する指定です。</p>



<h3 class="wp-block-heading">ニュースを取得してみよう</h3>



<p><a href="https://www.nhk.or.jp/toppage/rss/index.html">NHKのRSS</a>を使い、ニュースの見出しを取得する手順を確認します。RSSはニュースサイトが更新情報を公開している仕組みで、その中に含まれる見出しデータを読み取ることでニュースの見出しを取得できます。</p>



<p>仮想環境を作成</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>python3 -m venv venv --system-site-packages</code></pre></div>



<p>仮想環境を有効化</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>source venv/bin/activate</code></pre></div>



<p>RSSはXML形式なので、解析用ライブラリをインストールします。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>pip install feedparser</code></pre></div>



<p>Thonnyを仮想環境に切り替える</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="450" src="https://sozorablog.com/wp-content/uploads/2026/04/pico.png" alt="" class="wp-image-16751" style="width:601px;height:auto" srcset="https://sozorablog.com/wp-content/uploads/2026/04/pico.png 800w, https://sozorablog.com/wp-content/uploads/2026/04/pico-320x180.png 320w, https://sozorablog.com/wp-content/uploads/2026/04/pico-224x126.png 224w" sizes="(max-width: 800px) 100vw, 800px" /></figure>



<p>「Python executable」の右側にある「…」ボタンをクリックして、使用するPython（仮想環境のpython）を選択します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="672" src="https://sozorablog.com/wp-content/uploads/2026/04/pico-1.png" alt="" class="wp-image-16752" style="aspect-ratio:1.1904925938684119;width:370px;height:auto"/></figure>



<p>ホームをクリック。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="493" src="https://sozorablog.com/wp-content/uploads/2026/04/pico-2.png" alt="" class="wp-image-16753" style="aspect-ratio:1.6227630345277404;width:487px;height:auto"/></figure>



<p>venvを選択</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="524" src="https://sozorablog.com/wp-content/uploads/2026/04/pico-3.png" alt="" class="wp-image-16754" style="width:513px;height:auto"/></figure>



<p>binを選択。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="391" height="255" src="https://sozorablog.com/wp-content/uploads/2026/04/スクリーンショット-2026-04-13-20.13.05.png" alt="" class="wp-image-16755"/></figure>



<p>pythonを選択。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="286" height="296" src="https://sozorablog.com/wp-content/uploads/2026/04/スクリーンショット-2026-04-13-20.13.57.png" alt="" class="wp-image-16756"/></figure>



<p>OKをクリック。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="674" src="https://sozorablog.com/wp-content/uploads/2026/04/pico-4.png" alt="" class="wp-image-16757" style="aspect-ratio:1.1869554393826238;width:304px;height:auto"/></figure>



<p>仮想環境に切り替えたら、Thonnyで以下を実行します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>import feedparser

url = &quot;https://www.nhk.or.jp/rss/news/cat0.xml&quot;

feed = feedparser.parse(url)

for entry in feed.entries[:5]:
    print(entry.title)</code></pre></div>



<p>このコードは、インターネット上のニュースを取得して表示するプログラムです。まず、NHKが公開しているRSSのURLからニュース情報を読み込みます。URLに含まれる<code>cat0</code>はニュースのカテゴリを表しており、主要ニュース（総合）の見出しを取得できます。この数値を変更すれば、さまざまなジャンルのニュースに切り替え可能です。</p>



<figure class="wp-block-table wp-block-sbd-table wp-block-sbd-table-horizontal"><table class="has-fixed-layout"><tbody><tr><td>cat番号</td><td>ジャンル</td></tr><tr><td>cat0</td><td>主要ニュース</td></tr><tr><td>cat1</td><td>社会</td></tr><tr><td>cat2</td><td>文化・エンタメ</td></tr><tr><td>cat3</td><td>科学・医療</td></tr><tr><td>cat4</td><td>政治</td></tr><tr><td>cat5</td><td>経済</td></tr><tr><td>cat6</td><td>国際</td></tr><tr><td>cat7</td><td>スポーツ</td></tr></tbody></table></figure>



<p><code>eedparser.parse(url)</code>でデータを取得すると、その中にニュースの一覧が含まれます。<code>feed.entries</code>には記事ごとの情報が入っており、<code>[:5]</code>とすることで最初の5件だけを取り出しています。</p>



<h3 class="wp-block-heading">動画とアイコンを準備する</h3>



<p>ニュースの取得方法がわかったら、画面表示の準備をします。ニュースの文字を表示するだけでは味気ないので、アイコンと背景動画で気分を盛り上げることにしました。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="373" src="https://sozorablog.com/wp-content/uploads/2026/04/スクリーンショット-2026-04-14-18.12.21.jpg" alt="" class="wp-image-16771"/><figcaption class="wp-element-caption"><a href="https://pixabay.com/ja/videos/%e3%83%9e%e3%83%88%e3%83%aa%e3%83%83%e3%82%af%e3%82%b9-%e3%83%80%e3%82%a6%e3%83%b3%e3%83%ad%e3%83%bc%e3%83%89-75043/">Pixabay</a></figcaption></figure>



<p>映画マトリックス風の動画は、<a href="https://pixabay.com/ja/videos/%e3%83%9e%e3%83%88%e3%83%aa%e3%83%83%e3%82%af%e3%82%b9-%e3%83%80%e3%82%a6%e3%83%b3%e3%83%ad%e3%83%bc%e3%83%89-75043/">Pixabay</a>で公開されているものをダウンロードして使用します。Pixabayは著作権フリーの画像、動画、音声などを共有するサイトです。サイズは<strong>640×360</strong>のものをダウンロードしました。</p>



<p>スピーカーのアイコン画像は以下からダウンロードできます。私がCanvaで作成したものです。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="90" height="90" src="https://sozorablog.com/wp-content/uploads/2026/04/icon_speaker.png" alt="" class="wp-image-16777"/><figcaption class="wp-element-caption">icon_speaker.png</figcaption></figure>


<div class='w3eden'><!-- WPDM Link Template: Default Template -->

<div class="link-template-default card mb-2">
    <div class="card-body">
        <div class="media">
            <div class="mr-3 img-48"><img decoding="async" class="wpdm_icon" alt="アイコン" src="https://sozorablog.com/wp-content/plugins/download-manager/assets/file-type-icons/png.svg" /></div>
            <div class="media-body">
                <h3 class="package-title"><a href='https://sozorablog.com/download/%e3%82%b9%e3%83%94%e3%83%bc%e3%82%ab%e3%83%bc%e3%82%a2%e3%82%a4%e3%82%b3%e3%83%b3/'>スピーカーアイコン</a></h3>
                <div class="text-muted text-small"><i class="fas fa-copy"></i> 1 ファイル <i class="fas fa-hdd ml-3"></i> 4.69 KB</div>
            </div>
            <div class="ml-3">
                <a class='wpdm-download-link download-on-click btn btn-primary ' rel='nofollow' href='#' data-downloadurl="https://sozorablog.com/download/%e3%82%b9%e3%83%94%e3%83%bc%e3%82%ab%e3%83%bc%e3%82%a2%e3%82%a4%e3%82%b3%e3%83%b3/?wpdmdl=16773&refresh=69e5655ba41d11776641371">ダウンロード</a>
            </div>
        </div>
    </div>
</div>

</div>



<p>動画とアイコンはRaspberry Piの「/home/pi」ディレクトリに保存します。動画のファイル名は<span class="sbd-text-red">matrix.mp4</span>に必ず変更してください。スクリプトから参照できなくなります。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="614" src="https://sozorablog.com/wp-content/uploads/2026/04/pico-5.png" alt="" class="wp-image-16781" style="width:414px;height:auto"/></figure>



<p>Pythonで画像や映像を扱えるOpenCVライブラリをインストールします。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo apt install -y python3-opencv</code></pre></div>



<h3 class="wp-block-heading">日本語フォントの準備</h3>



<p>LCDにニュースをテキスト表示するために、日本語対応のフォント（Noto）をインストールします。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo apt install -y fonts-noto-cjk</code></pre></div>



<h3 class="wp-block-heading">完成したプログラム</h3>



<p>以下はWhisplay HATを使い、RSSから取得したニュースを音声で読み上げながらテキスト表示するプログラムです。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>import cv2
import time
import sys
import os
import numpy as np
from PIL import Image, ImageDraw, ImageFont
import subprocess
import feedparser
import unicodedata
import threading

mode = 0
speech_ready = False

sys.path.append(os.path.abspath(&quot;/home/pi/Whisplay/Driver&quot;))
from WhisPlay import WhisPlayBoard

# =========================
# TTS
# =========================
def speak(text, voice=&quot;normal&quot;, speed=0.9):

    voice_path = f&quot;/usr/share/hts-voice/mei/mei_{voice}.htsvoice&quot;

    subprocess.run(
        [
            &quot;open_jtalk&quot;,
            &quot;-x&quot;, &quot;/var/lib/mecab/dic/open-jtalk/naist-jdic&quot;,
            &quot;-m&quot;, voice_path,
            &quot;-r&quot;, str(speed),
            &quot;-ow&quot;, &quot;/tmp/test.wav&quot;
        ],
        input=text,
        text=True
    )

    subprocess.run([&quot;aplay&quot;, &quot;/tmp/test.wav&quot;])
    
# =========================
# Init
# =========================
board = WhisPlayBoard()
board.set_backlight(100)

VIDEO_PATH = &quot;/home/pi/matrix.mp4&quot;

font = ImageFont.truetype(
    &quot;/usr/share/fonts/truetype/noto/NotoSansCJK-Regular.ttc&quot;, 26
)

show_text = False
current_text = &quot;&quot;

# RSS source list (expandable)
RSS_FEEDS = [
    &quot;https://www3.nhk.or.jp/rss/news/cat5.xml&quot;
    #&quot;https://news.yahoo.co.jp/rss/topics/it.xml&quot;
]

def fetch_news():
    headlines = []

    for url in RSS_FEEDS:
        feed = feedparser.parse(url)
        for entry in feed.entries:
            headlines.append(entry.title)

    return headlines

def get_headlines(n=1):
    news = fetch_news()
    return news[:n]

# =========================
# Overlay icon
# =========================
def overlay_icon(frame, icon_path, x, y, size=None):
    base = Image.fromarray(frame).convert(&quot;RGBA&quot;)
    icon = Image.open(icon_path).convert(&quot;RGBA&quot;)

    if size:
        icon = icon.resize(size)

    datas = icon.getdata()
    new_data = []
    for item in datas:
        if item[0] &gt; 240 and item[1] &gt; 240 and item[2] &gt; 240:
            new_data.append((255, 255, 255, 0))
        else:
            new_data.append(item)
    icon.putdata(new_data)

    base.paste(icon, (x, y), icon)
    return np.array(base.convert(&quot;RGB&quot;))


# =========================
# Button handler
# =========================
def on_button():
    global show_text, current_text, mode, speech_ready

    if mode == 0:
        mode = 1
        show_text = False
        speech_ready = False

        headlines = get_headlines(3)

        for text in headlines:
            current_text = text
            print(text)
            
            speech_ready = True
            show_text = True
            speak(text)

    else:
        mode = 0
        show_text = False
        current_text = &quot;&quot;

board.on_button_press(on_button)

# =========================
# Image processing
# =========================
def zoom_center(frame, zoom=1.2):
    h, w, _ = frame.shape
    new_w = int(w / zoom)
    new_h = int(h / zoom)
    x1 = (w - new_w) // 2
    y1 = (h - new_h) // 2
    cropped = frame[y1:y1+new_h, x1:x1+new_w]
    return cv2.resize(cropped, (w, h))

def frame_to_rgb565(frame):
    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
    r = (frame[:, :, 0] &gt;&gt; 3).astype(&#39;uint16&#39;)
    g = (frame[:, :, 1] &gt;&gt; 2).astype(&#39;uint16&#39;)
    b = (frame[:, :, 2] &gt;&gt; 3).astype(&#39;uint16&#39;)
    rgb565 = (r &lt;&lt; 11) | (g &lt;&lt; 5) | b
    high = (rgb565 &gt;&gt; 8).astype(&#39;uint8&#39;)
    low = (rgb565 & 0xFF).astype(&#39;uint8&#39;)
    return np.dstack((high, low)).flatten().tolist()

def resize_and_crop(frame):
    h, w, _ = frame.shape
    screen_w = board.LCD_WIDTH
    screen_h = board.LCD_HEIGHT
    aspect = w / h
    screen_aspect = screen_w / screen_h

    if aspect &gt; screen_aspect:
        new_h = screen_h
        new_w = int(new_h * aspect)
        frame = cv2.resize(frame, (new_w, new_h))
        x = (new_w - screen_w) // 2
        frame = frame[:, x:x + screen_w]
    else:
        new_w = screen_w
        new_h = int(new_w / aspect)
        frame = cv2.resize(frame, (new_w, new_h))
        y = (new_h - screen_h) // 2
        frame = frame[y:y + screen_h, :]

    return frame

def split_text(text, max_width=18):
    lines = []
    current = &quot;&quot;
    width = 0

    for ch in text:
        w = 2 if unicodedata.east_asian_width(ch) in &quot;FWA&quot; else 1

        if width + w &gt; max_width:
            lines.append(current)
            current = ch
            width = w
        else:
            current += ch
            width += w

    if current:
        lines.append(current)

    return lines

# =========================
# Draw text
# =========================
def draw_text(frame, text, x, y):
    pil_img = Image.fromarray(frame)
    draw = ImageDraw.Draw(pil_img)

    lines = split_text(text, max_width=18)

    for i, line in enumerate(lines):
        draw.text((x, y + i * 40), line, font=font, fill=(180, 255, 255))

    return np.array(pil_img)

# =========================
# Main loop
# =========================
cap = cv2.VideoCapture(VIDEO_PATH)

if not cap.isOpened():
    print(&quot;Failed to open video&quot;)
    sys.exit()

try:
    while True:
        ret, frame = cap.read()

        if not ret:
            cap.set(cv2.CAP_PROP_POS_FRAMES, 0)
            continue
        frame = cv2.resize(frame, (160, 120))
        frame = resize_and_crop(frame)
        frame = zoom_center(frame, 1.5)

        if show_text and speech_ready:
            frame = overlay_icon(
                frame,
                &quot;/home/pi/icon_speaker.png&quot;,
                75,
                0
            )

            frame = draw_text(frame, current_text, 5, 110)

        rgb565 = frame_to_rgb565(frame)

        board.draw_image(
            0, 0,
            board.LCD_WIDTH,
            board.LCD_HEIGHT,
            rgb565
        )

        time.sleep(0.08)

except KeyboardInterrupt:
    pass

finally:
    cap.release()
    board.cleanup()
</code></pre></div>



<p>ボタンを押すとRSSからニュースを3件取得し、見出しを順番に処理します。取得件数は<code>get_headlines(3)</code>で指定しており、この数値を変更することで取得するニュースの件数を調整できます。取得したテキストはOpen JTalkで音声に変換され、スピーカーから再生されます。表示処理ではOpenCVで動画を再生し、その上にPillowでテキストとアイコンを重ねて描画します。</p>



<p>再度ボタンを押すと表示がリセットされ、ニュースの表示が終了します。その後にもう一度ボタンを押すことで、最新のニュースを再取得できます。つまり、ボタン操作のたびに最新のニュースを取得できる仕様にしました。</p>



<h2 class="wp-block-heading">ローカル環境でチャットボットを動かす</h2>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="750" height="922" src="https://sozorablog.com/wp-content/uploads/2026/04/IMG_0747.jpeg" alt="" class="wp-image-16813" style="aspect-ratio:0.8134532655455612;width:377px;height:auto"/></figure>



<p>Raspberry Pi上で音声入力からAIの応答生成、音声出力までを一通り動かすことで、ローカル環境だけで会話できるチャットボットを構築してみました。マイクで入力した音声をテキストに変換し、LLMで応答を生成し、その結果を音声として再生する仕組みです。</p>



<p>今回の構成ではRaspberry Pi 5と<a href="https://sozorablog.com/ai-hat-2/">AI HAT＋2</a>を使用しています。処理性能の関係からRaspberry Pi Zero 2での動作は現実的ではありません。</p>



<figure class="wp-block-embed is-type-rich is-provider-twitter wp-block-embed-twitter"><div class="wp-block-embed__wrapper">
<blockquote class="twitter-tweet" data-width="500" data-dnt="true"><p lang="ja" dir="ltr">Raspberry Pi AI HAT+ 2で、音声対話型チャットボットを作ってみました。<br><br>すべてローカルで動いています。精度が課題ではあるけど、音声認識→文章生成→音声合成がこの速さ動くのは驚きです。 <a href="https://t.co/tgGoQ6Yhv2">pic.twitter.com/tgGoQ6Yhv2</a></p>&mdash; そぞら@Raspberry Pi 電子工作 (@sozoraemon) <a href="https://twitter.com/sozoraemon/status/2041460961673097486?ref_src=twsrc%5Etfw">April 7, 2026</a></blockquote><script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
</div></figure>



<p>認識精度や返答内容はまだ高いとは言えず、意図しない変換や不自然な応答になることもありますが、ローカル環境でここまでの処理が実現できる点は大きな魅力です。今後のモデルや音声認識技術の進化によって、より自然な会話ができるようになることが期待されます。</p>



<div class="wp-block-sbd-background-block sbd-bg-color sbd-inner-block-init is-style-yellow">
<p>実際の構築手順や設定方法については、以下の記事の後半部分で詳しく解説しています。<br><a href="https://sozorablog.com/ai-hat-2/#toc19"><strong>»【生成AIに特化】Raspberry Pi AI HAT+ 2レビュー</strong></a></p>
</div>



<h2 class="wp-block-heading">音声インターフェースが変えるラズパイ活用</h2>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/04/IMG_0623.jpeg" alt="" style="width:377px;height:auto"/></figure>



<p>以前から音声で操作・応答できるデバイス制作に興味があったものの、なかなかコンパクトなスピーカーが見つからずに二の足を踏んでいました。Whisplay HATはLCD、ボタンまで一体化されており、この1枚で表示と音声の両方を手軽に扱える点が大きな魅力です。</p>



<p>ニュースの取得と音声読み上げを組み合わせることで、実用的なガジェットも無理なく作れました。</p>



<p>今後はエッジAIの進化により、音声インターフェースを活用する場面はさらに増えていくことが予想されます。これまでクラウドに依存していた処理も、ローカルで完結できるケースが増えてきました。Raspberry Piの可能性を広げる一歩として、ぜひ体験してみてはいかがでしょうか。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sozorablog.com/whisplay-hat/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【生成AIに特化】Raspberry Pi AI HAT+ 2レビュー</title>
		<link>https://sozorablog.com/ai-hat-2/</link>
					<comments>https://sozorablog.com/ai-hat-2/#comments</comments>
		
		<dc:creator><![CDATA[そぞら]]></dc:creator>
		<pubDate>Thu, 15 Jan 2026 09:00:40 +0000</pubDate>
				<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[関連製品]]></category>
		<guid isPermaLink="false">https://sozorablog.com/?p=16076</guid>

					<description><![CDATA[Raspberry Piで生成AIを動かす。これまで何度か試しましたが、短い文章であれば数秒で生成できても、長文になると待ち時間が気になることも。ラズパイで動くこと自体は興味深いものの、実用面では一歩足りない印象がありま [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p><a href="https://sozorablog.com/raspberry-pi/">Raspberry Pi</a>で生成AIを動かす。これまで何度か試しましたが、短い文章であれば数秒で生成できても、長文になると待ち時間が気になることも。ラズパイで動くこと自体は興味深いものの、実用面では一歩足りない印象がありました。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="3019" height="2220" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0251.jpg" alt="" class="wp-image-16469"/></figure>



<p>そんな中で登場したのが、<a href="https://sozorablog.com/pi5/">Raspberry Pi 5</a>に取り付けて使う<a href="https://www.raspberrypi.com/products/ai-hat-plus-2/">Raspberry Pi AI HAT+ 2</a>です。従来の<a href="https://www.switch-science.com/products/9998?srsltid=AfmBOoqP4Mexlcwv7c7tslBvIu9QIIhGU8HMUvFcI_mVVQ-zrUqGT8rz">AI HAT+</a>が画像認識などの推論AIを得意としてきたのに対し、本製品はLLM（大規模言語モデル）やVLM（視覚言語モデル）といった<span class="sbd-text-red">生成AIの実行を主目的に設計</span>されています。</p>



<figure class="wp-block-video"><video controls src="https://sozorablog.com/wp-content/uploads/2026/01/画面収録-2026-01-15-10.23.27.mov"></video><figcaption class="wp-element-caption">高速な文章生成が可能</figcaption></figure>



<p>今回、<a href="https://www.raspberrypi.com/">Raspberry Pi Ltd</a>さまより製品の提供をいただき、実機を試用する機会を賜りました。本記事では実際に触ってみて分かった処理時間の感覚や使い勝手を中心に、AI HAT+ 2の可能性に迫ります。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="327" src="https://sozorablog.com/wp-content/uploads/2026/01/スクリーンショット-2026-03-24-6.25.42.jpg" alt="" class="wp-image-16531"/><figcaption class="wp-element-caption">バナナの熟し具合を推測</figcaption></figure>



<h2 class="wp-block-heading">AI HAT+ 2 は Raspberry Pi 5 専用の拡張ボード</h2>



<figure class="wp-block-image size-full"><img decoding="async" width="775" height="612" src="https://sozorablog.com/wp-content/uploads/2026/01/AI_HAT2.jpg" alt="" class="wp-image-16462"/></figure>



<p>近年、クラウドに頼らずデバイス単体でAI処理を行うエッジAIが注目されています。通信遅延やプライバシーの問題を避けられる点から、Raspberry PiにはAI処理を担うプラットフォームとしての期待が高まっています。AI HAT+ 2 は、その流れの中で登場した拡張ボードです。</p>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p><a href="https://hailo.ai/lp/the-worlds-best-performing-ai-processor-for-edge-devices/?utm_term=hailo&amp;utm_campaign=brand_phrase_ww&amp;utm_source=adwords&amp;utm_medium=ppc&amp;hsa_acc=6640877786&amp;hsa_cam=20270381401&amp;hsa_grp=149790458563&amp;hsa_ad=753850024499&amp;hsa_src=g&amp;hsa_tgt=kwd-104989908&amp;hsa_kw=hailo&amp;hsa_mt=e&amp;hsa_net=adwords&amp;hsa_ver=3&amp;gad_source=1&amp;gad_campaignid=20270381401&amp;gbraid=0AAAAACSXbO0q0844SBlHbe06ZdeIRQmYk&amp;gclid=EAIaIQobChMIzM6qxf-PkgMVjxp7Bx0yeyxyEAAYASAAEgLo_fD_BwE">Hailo</a>は、エッジデバイス向けに高性能かつ低消費電力のAIアクセラレータを開発している半導体メーカーです。</p>
</div></div>



<h3 class="wp-block-heading">従来の AI HAT+ との違い</h3>



<figure class="wp-block-table wp-block-sbd-table wp-block-sbd-table-vertical"><table class="has-fixed-layout"><thead><tr><th>項目</th><th>AI HAT+<br><img decoding="async" width="100" height="87" class="wp-image-16244" style="width: 100px;" src="https://sozorablog.com/wp-content/uploads/2026/01/AI_HAT.png" alt=""></th><th><span class="sbd-text-red">AI HAT+ 2</span><br><img decoding="async" width="97" height="97" class="wp-image-16260" style="width: 97px;" src="https://sozorablog.com/wp-content/uploads/2026/01/ChatGPT-Image-2026年1月11日-09_26_24.png" alt=""></th></tr></thead><tbody><tr><td>搭載チップ</td><td>Hailo-8 / Hailo-8L</td><td>Hailo-10H</td></tr><tr><td>処理性能</td><td>13 TOPS / 26 TOPS</td><td><span class="sbd-table-bg-circle">40 TOPS</span></td></tr><tr><td>対応機種</td><td>Raspberry Pi 5</td><td>Raspberry Pi 5</td></tr><tr><td>専用オンボードRAM</td><td>なし</td><td><span class="sbd-table-bg-circle">8GB 搭載</span></td></tr><tr><td>価格</td><td>13 TOPS：$70<br>26 TOPS：$110</td><td>$130</td></tr><tr><td>販売ページ</td><td><span class="sbd-table-btn"><a href="https://www.switch-science.com/products/9998?srsltid=AfmBOoqP4Mexlcwv7c7tslBvIu9QIIhGU8HMUvFcI_mVVQ-zrUqGT8rz" target="_blank" rel="noreferrer noopener">詳細を見る</a></span></td><td><span class="sbd-table-btn"><a href="https://www.switch-science.com/collections/ai/products/10916?srsltid=AfmBOoqwd2BeEPvRZmxKclvQw9atHfz2acsnye0up28y2ySwzpnDt1fi">詳細を見る</a></span></td></tr></tbody></table></figure>



<p>AI HAT+ 2は<a href="https://sozorablog.com/pi5/">Raspberry Pi 5</a>の上部に取り付け、PCIe（PCI Express）で接続して高速にデータ通信を行う拡張ボードです。</p>



<p>AI HAT+ 2は、従来モデルの単なる上位版ではありません。推論AIを高速に処理するための製品から、<span class="sbd-text-red">生成AIを扱うための製品へと役割が分かれた</span>と考えるのが適切です。</p>



<p>従来のAI HAT+ が推論処理でRaspberry Pi本体のメモリを使用するのに対して、AI HAT+ 2は<span class="sbd-text-bg-yellow">8GBの専用オンボードRAMを搭載</span>しており、AI処理用のメモリが独立しています。そのため、メモリ競合が起きにくく、AI処理そのものが安定して高速に動作します。</p>



<h3 class="wp-block-heading">Hailo-10H を搭載した AI アクセラレーター</h3>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0244.jpg" alt="" class="wp-image-4"/></figure>



<p>従来の AI HAT+ が採用していた Hailo-8 / 8L は、画像認識などの推論AIを主用途としていました。一方、AI HAT+ 2 の<a href="https://hailo.ai/ja/products/ai-accelerators/hailo-10h-ai-accelerator/#hailo-10-overview">Hailo-10H</a> は、<span class="sbd-text-bg-yellow">より大規模で複雑なAI処理を扱うことを前提に設計されたチップ</span>です。AI HAT+ 2 は、このチップの特性を生かすための構成になっています。</p>



<h2 class="wp-block-heading">AI HAT+ 2の取り付け</h2>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0237.jpg" alt="" class="wp-image-4" style="aspect-ratio:1.3778706171826942;width:584px;height:auto"/><figcaption class="wp-element-caption">カメラとActive Coolerを取り付け</figcaption></figure>



<p>今回、Raspberry Pi本体は<a href="https://www.switch-science.com/products/9250">Raspberry Pi 5</a>を使用しました。</p>



<!-- START MoshimoAffiliateEasyLink -->
<script type="text/javascript">
(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;
b[a]=b[a]||function(){arguments.currentScript=c.currentScript
||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};
c.getElementById(a)||(d=c.createElement(f),d.src=g,
d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})
(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");
msmaflink({"n":"Raspberrypi5 8G ラズベリーパイ5 技適取得済マーク入り商品","b":"Raspberry Pi","t":"","d":"https:\/\/m.media-amazon.com","c_p":"\/images\/I","p":["\/31ulVhoF7LL._SL500_.jpg","\/31Paz5taW5L._SL500_.jpg","\/31wPYoxjgCL._SL500_.jpg","\/31ArwA0xXgL._SL500_.jpg","\/31wPYoxjgCL._SL500_.jpg","\/314jAZZTefL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0CQZHN2K4","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":1,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0CQZHN2K4","a_id":3038653,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1}],"eid":"6dQw8","s":"s"});
</script>
<div id="msmaflink-6dQw8">リンク</div>
<!-- MoshimoAffiliateEasyLink END -->



<p>カメラを使用する場合はこの段階で取り付けておきます。僕は<a href="https://raspberry-pi.ksyic.com/main/index/pdp.id/908/pdp.open/908">Raspberry Pi Camera Module 3</a>を使用しました。<a href="https://www.switch-science.com/products/9253?pr_prod_strat=jac&amp;pr_rec_id=600fa0a5e&amp;pr_rec_pid=7821219463366&amp;pr_ref_pid=8373989703878&amp;pr_seq=uniform">Raspberry Pi Active Cooler</a>（別売り）を装着します。AI HAT+ 2は十分な性能を発揮するため、Active Coolerと一緒に使うことが推奨されています。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0238.jpg" alt="" class="wp-image-4" style="aspect-ratio:1.3895523159636063;width:549px;height:auto"/><figcaption class="wp-element-caption">スペーサーとGPIOピン延長用ヘッダの取付</figcaption></figure>



<p>付属のネジでスペーサーを取り付け、GPIOピン延長用ヘッダをRaspberry PiのGPIOピンに差し込みます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0239.jpg" alt="" class="wp-image-4" style="aspect-ratio:1.3840074144633525;width:544px;height:auto"/><figcaption class="wp-element-caption">ヒートシンクの取り付け</figcaption></figure>



<p>AI HAT+ 2本体にチップを冷却するためのヒートシンクを取り付けます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0240.jpg" alt="" class="wp-image-4" style="aspect-ratio:0.8579613463349239;width:480px;height:auto"/></figure>



<p>フラットケーブルをRaspberry Pi側のPCIeポートに入れつつ、GPIOピン延長用ヘッダに差し込みます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0241.jpg" alt="" class="wp-image-4" style="aspect-ratio:1.2794421182992275;width:487px;height:auto"/></figure>



<p>スペーサー部分をネジで固定したら取付完了です。</p>



<h3 class="wp-block-heading">GPIOピンを使用する場合</h3>



<p>キットに付属しているスペーサーを使うと、GPIOピンが隠れてしまい、電子パーツをピンに接続できなくなります。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="3019" height="2373" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0254.jpg" alt="" class="wp-image-16475"/></figure>



<p>そこで、別売りのM2.5×11mmのスペーサーに交換することで、GPIOピンの先端を外に出せます。</p>



<!-- START MoshimoAffiliateEasyLink -->
<script type="text/javascript">
(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;
b[a]=b[a]||function(){arguments.currentScript=c.currentScript
||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};
c.getElementById(a)||(d=c.createElement(f),d.src=g,
d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})
(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");
msmaflink({"n":"Entaniya 六角スペーサー M2.5 長さ11mm (メス-メス) 真鍮 10本入り 【HBF25046-11】","b":"Entaniya","t":"XBF25046","d":"https:\/\/m.media-amazon.com","c_p":"\/images\/I","p":["\/41LMofwfEKL._SL500_.jpg","\/318w89qjVeL._SL500_.jpg","\/41Asi16eWHL._SL500_.jpg","\/41J9-E1mf2L._SL500_.jpg","\/51JeQcvKd2L._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0D7HPP8ZM","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":1,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0D7HPP8ZM","a_id":3038653,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"id":2,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/Entaniya%20%E5%85%AD%E8%A7%92%E3%82%B9%E3%83%9A%E3%83%BC%E3%82%B5%E3%83%BC%20M2.5%20%E9%95%B7%E3%81%9511mm%20(%E3%83%A1%E3%82%B9-%E3%83%A1%E3%82%B9)%20%E7%9C%9F%E9%8D%AE%2010%E6%9C%AC%E5%85%A5%E3%82%8A%20%E3%80%90HBF25046-11%E3%80%91\/","a_id":3038654,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":2}],"eid":"pJ0du","s":"s"});
</script>
<div id="msmaflink-pJ0du">リンク</div>
<!-- MoshimoAffiliateEasyLink END -->



<p>ただし、この方法ではRaspberry PiとAI HAT+ 2の間隔が狭くなり、Active Coolerが基板に接触するおそれがあります。そのため、<span class="sbd-text-red">Active Coolerは取り外して使用する</span>方が無難です。</p>



<h2 class="wp-block-heading">セットアップ手順</h2>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0245.jpg" alt="" class="wp-image-4" style="aspect-ratio:1.5505465662945979;width:685px;height:auto"/><figcaption class="wp-element-caption">microSDカードは64GB以上を推奨します</figcaption></figure>



<p>AI HAT+ 2を使う場合、32GBのmicroSDカードでは途中で容量が足りなくなりました。ファイルサイズの大きいモデルを複数ダウンロードしていくため、余裕を持って使うなら<span class="sbd-text-bg-yellow">64GB以上のmicroSDカード</span>をおすすめします。<br></p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/スクリーンショット-2026-01-11-7.04.15.png" alt="" class="wp-image-4"/><figcaption class="wp-element-caption">Raspberry Pi OS(64-bit)を使用</figcaption></figure>



<p>Raspberry Pi OS Trixie を<span class="sbd-text-bg-yellow">新しくインストールした状態</span>から作業を進めます。別の用途で使っていた環境では、過去の設定などが影響し、AI HAT+ 2 がうまく動作しないことがあるようです。</p>



<p>準備ができたら、Hailo関連のソフトをインストールするための設定を行います。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/pico-1-6.jpg" alt="" class="wp-image-4"/></figure>



<p>以下のコマンドは途中で分けず、<span class="sbd-text-bg-yellow">最初から最後までの行を一度に実行</span>します。aptが参照するソフト配布先の一覧にHailo用のパッケージ配布先が追加されます。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo tee /etc/apt/sources.list.d/hailo.sources &lt;&lt;EOF
Types: deb
URIs: https://hailo:chahy5Zo@extranet.raspberrypi.org/hailo
Suites: trixie
Components: main
Signed-By: /usr/share/keyrings/raspberrypi-archive-keyring.pgp
EOF
</code></pre></div>



<p>ここで使っているEOFは、「ここまでを書き込む」という区切りを示す目印です。 &lt;&lt;EOF から始まり、最後に書かれた EOFまでの内容が保存されます。</p>



<p>次に、Raspberry Piに登録した内容を反映し、システムを最新の状態に更新します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo apt update</code></pre></div>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>Raspberry Pi では<span class="sbd-text-red">apt</span>という管理システムを使ってソフトを管理しています。</p>
</div></div>



<p>必要な更新をまとめて適用します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo apt full-upgrade -y</code></pre></div>



<p>Raspberry Piを再起動し、更新内容を反映させます。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo reboot</code></pre></div>



<h3 class="wp-block-heading">Dockerのインストール</h3>



<p>ブラウザから生成AIを操作するためのWebUI（Webベースの操作画面）を使うには、Dockerのインストールが必須です。WebUIの土台となる Dockerを、Hailoを入れる前に準備しておきます。</p>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>Dockerは必要なソフトや設定をまとめて用意し、Raspberry Pi OSの違いに影響されずにプログラムを実行するための仕組みです。</p>
</div></div>



<div class="wp-block-sbd-checkpoint-block"><p class="sbd-checkpoint-title">チェックポイント</p><div class="sbd-checkpoint-content sbd-inner-block-init"><p>Raspberry Pi OS TrixieではPython 3.13 が使われていますが、WebUIはこのバージョンに対応していません。そのため、Python環境に依存しないDockerを使ってWebUIを動かします。</p></div></div>



<p>まず、環境の競合を防ぐため、すでに入っている Docker 関連パッケージを削除します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo apt remove $(dpkg --get-selections docker.io docker-compose docker-doc podman-docker containerd runc | cut -f1)</code></pre></div>



<p>Dockerを正しくインストールするため、公式リポジトリを追加します。HTTPS通信に必要な証明書と、データ取得用のツール（curl）をインストールします。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo apt install ca-certificates curl</code></pre></div>



<p>リポジトリの署名キーを保存するためのディレクトリを作成します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo install -m 0755 -d /etc/apt/keyrings</code></pre></div>



<p>Dockerの公式署名キーをダウンロードして保存します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc</code></pre></div>



<p>保存した署名キーをシステムから読み取れるように設定します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo chmod a+r /etc/apt/keyrings/docker.asc</code></pre></div>



<p>Docker の配布先を <code>apt</code> に登録します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo tee /etc/apt/sources.list.d/docker.sources &lt;&lt;EOF
Types: deb
URIs: https://download.docker.com/linux/debian
Suites: $(. /etc/os-release && echo &quot;$VERSION_CODENAME&quot;)
Components: stable
Signed-By: /etc/apt/keyrings/docker.asc
EOF</code></pre></div>



<p>パッケージ一覧を更新します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo apt update</code></pre></div>



<p>Docker 本体と関連ツールをインストールします。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin</code></pre></div>



<p>Docker を起動します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo systemctl start docker</code></pre></div>



<p>Docker が正しく動作するかを確認します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo docker run hello-world</code></pre></div>



<p>「Hello from Docker!」を含むメッセージが表示されれば、Dockerのセットアップは完了です。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="634" height="345" src="https://sozorablog.com/wp-content/uploads/2026/01/スクリーンショット-2026-01-16-10.45.10.png" alt="" class="wp-image-16433"/></figure>



<h3 class="wp-block-heading">Hailo-10Hドライバとランタイムの導入</h3>



<p>Hailo-10HをOSから利用できるようにします。ドライバを自動で再構築する仕組み（DKMS）を導入します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo apt install dkms</code></pre></div>



<p>Hailo-10H を使用するためのドライバとランタイム一式をインストールします。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo apt install -y hailo-h10-all</code></pre></div>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>この処理は7分かかりました。</p>
</div></div>



<p>再起動します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo reboot</code></pre></div>



<h3 class="wp-block-heading">Hailo Gen-AI Model Zooのインストール</h3>



<p>Hailoが提供する<strong>Gen-AI Model Zoo</strong>を導入します。Gen-AI Model ZooはCLIやREST APIから利用できる、事前学習済みの生成AIモデルを集めたライブラリです。</p>



<p>この手順は<span class="sbd-text-red">内容が更新される可能性がある</span>ため、<a href="https://github.com/hailo-ai/hailo_model_zoo_genai">公式の手順</a>に従ってインストールします。2026年1月11日時点では以下のコマンドを1行づつ実行してインストールしました。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo apt install -y libssl-dev
git clone https://github.com/hailo-ai/hailo_model_zoo_genai.git
cd /home/pi/hailo_model_zoo_genai
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build .
mkdir -p ~/.local/bin
cp ./src/apps/server/hailo-ollama ~/.local/bin/
mkdir -p ~/.config/hailo-ollama/
cp ../config/hailo-ollama.json ~/.config/hailo-ollama/
mkdir -p ~/.local/share/hailo-ollama
cp -r ../models/ ~/.local/share/hailo-ollama
echo &#39;export PATH=&quot;$HOME/.local/bin:$PATH&quot;&#39; &gt;&gt; ~/.bashrc
source ~/.bashrc</code></pre></div>



<h3 class="wp-block-heading">hailo-ollamaサーバーの起動</h3>



<p>LLMのリクエストを受け付けるサーバーを起動します。hailo-ollamaは、Hailo-10H上でLLMやVLMを動かすためのサーバープログラムです。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>hailo-ollama</code></pre></div>



<div class="wp-block-sbd-checkpoint-block"><p class="sbd-checkpoint-title">チェックポイント</p><div class="sbd-checkpoint-content sbd-inner-block-init"><p>私の場合、ここで<code>hailo-ollama</code>を実行した際にコマンドが見つからないと表示されました。<code>hailo-ollama</code> 本体を <code>~/.local/bin</code> に配置していましたが、そのパスが反映されていなかったため、コマンドとして認識されなかったためです。</p><p>解決方法として、「echo &#8216;export PATH=&#8221;$HOME/.local/bin:$PATH&#8221;&#8216; &gt;&gt; ~/.bashrc」を実行して、 PATH を追加したあと、「source ~/.bashrc」を実行して設定を読み込み直すことで、<code>hailo-ollama</code> を実行できるようになりました。</p></div></div>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/スクリーンショット-2026-01-11-13.22.32.png" alt="" class="wp-image-4"/></figure>



<p><span class="sbd-text-red">新しいターミナルを開き</span>、次を実行します。使用可能な LLMモデルの一覧が表示されます。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>curl --silent http://localhost:8000/hailo/v1/list</code></pre></div>



<p>上記で表示された使用可能なモデルを以下にまとめました。</p>



<figure class="wp-block-table wp-block-sbd-table wp-block-sbd-table-horizontal"><table class="has-fixed-layout"><tbody><tr><td>モデル名</td><td>特徴</td><td>用途</td><td>開発元</td></tr><tr><td>DeepSeek-R1:1.5B</td><td>大規模モデルの思考パターンを小型に凝縮したモデル</td><td>推論・汎用生成</td><td>DeepSeek</td></tr><tr><td>Llama3.2:1b</td><td>シンプルで軽量、基本的な文章生成向け</td><td>一般生成・会話</td><td>Meta</td></tr><tr><td>qwen2.5-coder:1.5b</td><td>コード生成や解析に強い専門モデル</td><td>コード生成</td><td>Alibaba Cloud</td></tr><tr><td>qwen2.5:1.5b</td><td>Qwen2.5の基本版、小〜中規模の生成タスク向け</td><td>汎用言語生成・会話</td><td>Alibaba Cloud</td></tr><tr><td><span class="sbd-text-red">qwen2:1.5b</span></td><td><span class="sbd-table-bg-circle">Qwenシリーズの前世代で、バランスの取れた生成能力</span></td><td>一般生成・会話</td><td>Alibaba Cloud</td></tr></tbody></table></figure>



<p>私が実際に使ってみたところ、<span class="sbd-text-red">qwen2:1.5b</span>モデルが<span class="sbd-text-bg-yellow">日本語のやり取りにおいて</span>最も安定しており、回答精度が高いと感じました<strong>。</strong>他のモデルでは、日本語で質問しても英語で返ってきたり、不自然な日本語になったりすることが多いです。</p>



<h2 class="wp-block-heading">LLMを動かしてみる</h2>



<p>Qwen2 1.5Bモデルをダウンロードします。モデル名は先ほど表示された一覧にあるものへ変更できます。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>curl --silent http://localhost:8000/api/pull \
     -H &#39;Content-Type: application/json&#39; \
     -d &#39;{ &quot;model&quot;: &quot;qwen2:1.5b&quot;, &quot;stream&quot; : true }&#39;</code></pre></div>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>ダウンロードは10分程度かかります。</p>
</div></div>



<p>以下のコマンドを実行すると、LLMに直接質問できます。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>curl --silent http://localhost:8000/api/chat \
     -H &#39;Content-Type: application/json&#39; \
     -d &#39;{&quot;model&quot;: &quot;qwen2:1.5b&quot;, &quot;messages&quot;: [{&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;Translate to French: The cat is on the table.&quot;}]}&#39;</code></pre></div>



<p>エラーが出ずに結果が返ってくれば、LLMの実行は成功です。</p>



<h3 class="wp-block-heading">WebUI（ChatGPT風UI）で動かす</h3>



<p>WebUIのDockerイメージを取得します。以下のコマンドでChatGPTのような画面を表示するためのプログラム一式をインターネットから取得します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo docker pull ghcr.io/open-webui/open-webui:main</code></pre></div>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>このダウンロードも10分以上かかります。</p>
</div></div>



<p>WebUIコンテナを起動します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo docker run -d \
  -e OLLAMA_BASE_URL=http://127.0.0.1:8000 \
  -v open-webui:/app/backend/data \
  --name open-webui \
  --network=host \
  --restart always \
  ghcr.io/open-webui/open-webui:main</code></pre></div>



<div class="wp-block-sbd-checkpoint-block"><p class="sbd-checkpoint-title">チェックポイント</p><div class="sbd-checkpoint-content sbd-inner-block-init"><p>このコマンドを実行する前に、別のターミナルでhailo-ollamaが起動していることを確認してください。</p></div></div>



<p>初回起動は数分かかります。次のコマンドで起動状況を確認できます。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo docker logs open-webui -f</code></pre></div>



<p>起動完了したら、Raspberry Piのブラウザで次のURLを開きます。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>http://127.0.0.1:8080</code></pre></div>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/スクリーンショット-2026-01-13-12.35.40.png" alt="" class="wp-image-4"/></figure>



<p>ChatGPTのような画面が表示されます<strong>。</strong></p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/スクリーンショット-2026-01-11-14.45.18.png" alt="" class="wp-image-4" style="width:607px;height:auto"/></figure>



<p>「はじめる」をクリックします。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/スクリーンショット-2026-01-11-14.49.05.png" alt="" class="wp-image-4"/></figure>



<p>WebUIの初回起動時には、ローカルで使用するユーザー情報の登録が必要です。これは外部サービスへのサインインではなく、Raspberry Pi上でWebUIを管理するための設定です。</p>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>登録した情報は<span class="sbd-text-red">Raspberry Pi本体内に保存</span>され、以後はそのユーザーでログインします。</p>
</div></div>



<p>ログインすると、ChatGPTで馴染みのある画面が登場しました。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/スクリーンショット-2026-01-11-14.56.20.png" alt=""/></figure>



<p>「あなたは誰ですか」の質問に回答してくれました。回答完了までの時間は7秒でした。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/スクリーンショット-2026-01-11-15.03.49.png" alt=""/></figure>



<p>ブログに掲載するスクリーンショットでは、明るい画面のままだと文字やUIが見にくいため、ダークモードに切り替えました。</p>



<p>「Qwen2 1.5B」以外のモデルを使用したい場合は、以下の手順でダウンロードします。</p>



<div class="wp-block-sbd-checkpoint-block"><p class="sbd-checkpoint-title">qwen2.5:1.5bをWebUIで使えるようにする手順</p><div class="sbd-checkpoint-content sbd-inner-block-init"><p>①ターミナルを開き、<code>hailo-ollama</code>を実行。</p><p>②別のターミナルで、次を実行。<br><code>curl --silent http://localhost:8000/api/pull -H 'Content-Type: application/json' -d '{ "model": "qwen2.5:1.5b", "stream": true }'</code></p><p>③<code>sudo docker start open-webui</code>を実行</p><p>④ブラウザで<code>http://127.0.0.1:8080</code>にアクセスし、モデル一覧からqwen2.5:1.5bを選択</p></div></div>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/スクリーンショット-2026-01-11-16.39.33.png" alt="" class="wp-image-4"/><figcaption class="wp-element-caption">モデル一覧からqwen2.5:1.5bを選択</figcaption></figure>



<p>Raspberry Piの再起動後など、次回以降は以下の手順でWebUIを立ち上げます。</p>



<div class="wp-block-sbd-checkpoint-block"><p class="sbd-checkpoint-title">再起動後の実行手順</p><div class="sbd-checkpoint-content sbd-inner-block-init"><p>①再起動後はターミナルを2つ開き、1つ目で<code>hailo-ollama</code>を実行してLLMサーバーを起動。</p><p>②もう1つのターミナルで<code>sudo docker start open-webui</code>を実行。</p><p>③ブラウザで<code>http://127.0.0.1:8080</code>にアクセスすればWebUIを利用できます。</p></div></div>



<h3 class="wp-block-heading">PythonからLLMを動かす</h3>



<p>ローカルLLMは、Pythonから制御することで電子工作やアプリに組み込みやすくなります。ここでは、PythonからローカルLLMを動かすための基本的な流れを説明します。</p>



<p>PythonからローカルLLMを使う前に、ターミナルから<span class="sbd-text-red">hailo-ollama</span>を実行しておく必要があります。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/スクリーンショット-2026-01-13-11.17.26.png" alt="" class="wp-image-4"/></figure>



<p>以下のコードはPythonからローカルLLMを呼び出し、回答を生成途中から受け取りつつ最終結果もまとめて取得するためのコードです。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>import requests
import json
import time

# ローカルで起動しているLLMのAPIエンドポイント
url = &quot;http://localhost:8000/api/chat&quot;

# ユーザーの質問
question = &quot;おすすめの気分転換の方法を教えてください。&quot;

payload = {
    # 使用するLLMモデルを指定
    &quot;model&quot;: &quot;qwen2:1.5b&quot;,
    # &quot;model&quot;: &quot;qwen2.5:1.5b&quot;,
    # &quot;model&quot;: &quot;llama3.2:1b&quot;,
    # &quot;model&quot;: &quot;deepseek_r1:1.5b&quot;,

    # LLMに送る会話内容を指定
    &quot;messages&quot;: [
        {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: question}
    ]
}

# 質問内容を表示
print(f&quot;質問: {question}\n&quot;)

# 思考開始時刻を記録
think_start_time = time.time()
print(&quot;思考開始\n&quot;)

# LLM APIにPOSTリクエストを送信（ストリーミング）
res = requests.post(url, json=payload, stream=True)

answer_started = False        # 回答開始検知フラグ
final_answer = &quot;&quot;             # 回答全文を格納する変数

for line in res.iter_lines():
    if not line:
        continue

    data = json.loads(line.decode(&quot;utf-8&quot;))
    content = data.get(&quot;message&quot;, {}).get(&quot;content&quot;, &quot;&quot;)

    # 回答が初めて返ってきた瞬間
    if content and not answer_started:
        print(&quot;回答開始\n&quot;)
        answer_started = True

    # 回答内容を逐次表示しつつ、変数に蓄積
    if content:
        print(content, end=&quot;&quot;, flush=True)
        final_answer += content

    # 回答終了を検知
    if data.get(&quot;done&quot;):
        elapsed = time.time() - think_start_time
        print(f&quot;\n\n処理時間: {elapsed:.2f}秒&quot;)
        break
</code></pre></div>



<p>13～16行目で使用するLLMモデルを変更できますが、Raspberry Piにダウンロードしたモデルのみ利用できます。</p>



<p>ローカルLLMに質問を送信し、返ってくる文章をその場で表示しながら、同時に後続処理用として1つの変数に保存する構成になっています。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/スクリーンショット-2026-01-15-12.48.17.png" alt="" class="wp-image-4"/><figcaption class="wp-element-caption">出力結果</figcaption></figure>



<h2 class="wp-block-heading">VLMで画像を説明してもらう</h2>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/pico-1-7.jpg" alt="" style="width:800px;height:auto"/><figcaption class="wp-element-caption">カメラの映像を文章で説明できる</figcaption></figure>



<p>VLMを使うと、<span class="sbd-text-red">画像をもとに状況や特徴を言葉で表現させる</span>ことができます。保存した写真だけでなくカメラ映像もそのまま渡せるため、精度次第ではリアルタイムの状況に応じた判断や提案にも使えそうです。実際に試しながら、回答の精度や処理にかかる時間を確認していきます。</p>



<p>Hailoデバイスが認識されていることを確認する。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>hailortcli scan</code></pre></div>



<p>以下のようにデバイスアドレスが表示されれば、Hailoデバイスは正しく認識されています。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/スクリーンショット-2026-01-14-10.09.35.png" alt="" class="wp-image-4"/></figure>



<p>hailo-apps リポジトリを取得します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>git clone https://github.com/hailo-ai/hailo-apps.git</code></pre></div>



<p>hailo-appsディレクトリに移動</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>cd hailo-apps</code></pre></div>



<p>venvという名前のPython仮想環境を作成します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>python3 -m venv venv --system-site-packages</code></pre></div>



<p>仮想環境を有効化します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>source venv/bin/activate</code></pre></div>



<p>PortAudioをOS側にインストールします。これをしないと、PyAudioのビルドでエラーが出てしまいます。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo apt update
sudo apt install -y portaudio19-dev</code></pre></div>



<p>hailo-appsが定義しているGenAI用の追加依存関係をまとめてインストールします。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>pip install -e &quot;.[gen-ai]&quot;</code></pre></div>



<p>モデルのダウンロードや保存時に権限エラーが発生するのを防ぐため、事前にディレクトリを作成し、所有者を<code>pi</code>に変更します。まず、<code>/usr/local/hailo</code>ディレクトリを作成します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo mkdir -p /usr/local/hailo</code></pre></div>



<p>以下を実行して、<code>/usr/local/hailo</code>以下のファイルとディレクトリの所有者をユーザー<code>pi</code>とグループ<code>pi</code>に変更します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo chown -R pi:pi /usr/local/hailo</code></pre></div>



<h3 class="wp-block-heading">保存した画像を説明させる</h3>



<p>simple_vlm_chat を実行します。初回実行時はVLMモデル（Qwen2-VL-2B-Instruct for hailo10h）のダウンロードが行われるため、時間がかかります。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>python -m hailo_apps.python.gen_ai_apps.simple_vlm_chat.simple_vlm_chat</code></pre></div>



<p>このコマンドは、リポジトリ内の doc/images/barcode-example.png という画像を使って、HailoのVision Language Modelを試すデモを実行します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/barcode-example.jpg" alt="" style="aspect-ratio:0.9968924798011187;width:265px;height:auto"/><figcaption class="wp-element-caption">barcode-example.png</figcaption></figure>



<p><br>この画像に対して “How many people in the image?”（この画像には何人の人が写っていますか？） という質問を行います。</p>



<p>「There is one person in the image.（この画像には1人の人物が写っています）」<br>と回答されました。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/スクリーンショット-2026-01-14-11.11.48.png" alt=""/><figcaption class="wp-element-caption">VLMからの回答を表示</figcaption></figure>



<p>VLMモデルには Alibaba Cloud開発の<span class="sbd-text-bg-yellow">Qwen2-VL-2B-Instruct</span>が使われており、これが Hailo-10H 向けに最適化された形で提供されています。</p>



<p>「/home/pi/hailo-apps/hailo_apps/python/gen_ai_apps/simple_vlm_chat/simple_vlm_chat.py」のコードの一部を変更することで、渡す画像や質問の変更ができます。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="359" src="https://sozorablog.com/wp-content/uploads/2026/01/pico-1-9.jpg" alt="" class="wp-image-16458"/></figure>



<p>質問を日本語に変えてみました。ざっくりとした回答ですが、赤い帽子と白いマスクが認識されており、悪くない結果です。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/スクリーンショット-2026-01-14-11.35.05.png" alt="" style="width:621px;height:auto"/></figure>



<h3 class="wp-block-heading">カメラの映像を説明させる</h3>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0242.jpg" alt="" style="aspect-ratio:1.1815943908389563;width:676px;height:auto"/></figure>



<p>以下を実行すると、Raspberry Piカメラの映像についてVLMに質問できます。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>python -m hailo_apps.python.gen_ai_apps.vlm_chat.vlm_chat --input rpi</code></pre></div>



<p>Raspberry Piカメラが起動し、ライブ映像が画面に表示されます。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/スクリーンショット-2026-01-14-12.26.17.jpg" alt=""/></figure>



<p>Enterキーを押すと、その時点の映像が静止画として取得されます。静止した画像に対してターミナル上で質問を入力すると、VLMが画像を解析して回答を返します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/スクリーンショット-2026-01-14-12.25.02.png" alt="" class="wp-image-4" style="width:807px;height:auto"/></figure>



<p>応答が始まるまでにかかる時間は<span class="sbd-text-red">約2秒</span>で、その速さに驚きました。「日本語で答えてください」を質問に含めると日本語で回答が返ってきます。</p>



<p>プログラムをそのまま実行すると、カメラ映像中の<span class="sbd-text-bg-yellow">オレンジ色の部分が青色に変換されてしまう不具合があった</span>ため、「/home/pi/hailo-apps/hailo_apps/python/gen_ai_apps/vlm_chat/vlm_chat.py」の105行目をコメントアウト（行の先頭に#をつけて無効化）し、その下の行に「get_frame = lambda: picam2.capture_array()」を追加しました。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="270" src="https://sozorablog.com/wp-content/uploads/2026/01/スクリーンショット-2026-01-17-8.48.34.jpg" alt="" class="wp-image-16473"/><figcaption class="wp-element-caption">vlm_chat.pyの変更箇所</figcaption></figure>



<p>不要な色の変換処理を無効にし、カメラで取得した画像をそのまま使うように変更することで、正しい色で表示されるようになりました。</p>



<div class="wp-block-sbd-checkpoint-block"><p class="sbd-checkpoint-title">Raspberry Pi再起動後の実行手順</p><div class="sbd-checkpoint-content sbd-inner-block-init"><p>「cd hailo-apps」でディレクトリに移動</p><p>「source venv/bin/activate」でPythonの仮想環境を有効化</p><p>Pythonスクリプトを実行</p></div></div>



<p>今回使用したVLMでは、<span class="sbd-text-red">日本語で質問した場合に誤った物体名を返す</span>ことがあり、ミカンの映像を「にんにく」と回答する例が見られました。一方、同じ画像に対して英語で質問すると、「orange」と正しく認識され、英語で回答させた方が精度が高いようです。</p>



<h3 class="wp-block-heading">PythonからVLMを動かす</h3>



<p>以下はカメラで取得した画像をHailoのVLMで解析し、内容をテキストとして生成するPythonプログラムです。日本語で回答させると精度が悪いので、英語のVLM回答をローカルLLMのQwen2:1.5bで日本語に翻訳する処理も行います。</p>



<div class="wp-block-sbd-background-block sbd-bg-color sbd-inner-block-init is-style-yellow">
<p>Qwen2:1.5bをダウンロードして、フォルダに配置する方法は<a href="#qwen">LLMを「Qwen2 1.5B」に変更する</a>で解説しています。</p>
</div>



<p>以下はカメラで取得した映像をHailoで解析して内容を英語で説明し、その結果を日本語に翻訳して表示するプログラムです。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>import subprocess
import time

# エラー回避のための強制開放（前回プロセスの残骸対策）
subprocess.run(
    &quot;sudo fuser -k /dev/video* /dev/media* /dev/v4l-subdev*&quot;,
    shell=True,
    stdout=subprocess.DEVNULL,
    stderr=subprocess.DEVNULL
)
time.sleep(1)

import sys
import time
import signal
import os
import cv2
from typing import Optional

from hailo_apps.python.gen_ai_apps.vlm_chat.backend import Backend
from hailo_apps.python.core.common.core import (
    get_standalone_parser,
    handle_list_models_flag,
    resolve_hef_path,
)
from hailo_apps.python.core.common.defines import (
    VLM_CHAT_APP,
    HAILO10H_ARCH,
)
from hailo_platform import VDevice
from hailo_platform.genai import LLM

def translate_to_japanese(text: str) -&gt; str:
    vdevice_llm = VDevice()
    llm = LLM(vdevice_llm, &quot;/home/pi/models/Qwen2-1.5B-Instruct.hef&quot;)
    
    prompt = f&quot;以下の英文を自然で正しい日本語の表現で翻訳してください。難しい漢字を使わないこと\n\n{text}&quot;    
    #print(prompt)

    messages = [
        {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: prompt}
    ]

    result = &quot;&quot;
    for chunk in llm.generate(messages):
        result += chunk

    llm.release()
    return result.replace(&quot;&lt;|im_end|&gt;&quot;, &quot;&quot;).strip()

# =========================
# 設定
# =========================
WAIT_SECONDS = 3  # 撮影までの待機時間

QUESTION = &quot;&quot;&quot;
Look at the camera image carefully.
Describe what is happening in the image.
Be concise and clear.
Mention the main subject and important details.
&quot;&quot;&quot;
MAX_TOKENS = 30
TEMPERATURE = 0.1
SEED = 42

# 画像説明用のシステムプロンプト
SYSTEM_PROMPT = &quot;&quot;&quot;
You see images from a camera.
You describe the image clearly and objectively.
Focus on what is visible.
&quot;&quot;&quot;
INFERENCE_TIMEOUT = 60
WINDOW_NAME = &quot;Captured Frame&quot;

def extract_model_name(hef_path: str) -&gt; str:
    # hefファイル名からモデル名を取得
    return os.path.splitext(os.path.basename(hef_path))[0]

class OneShotVLMApp:
    def __init__(self, hef_path: str):
        self.hef_path = hef_path
        self.backend: Optional[Backend] = None
        self.running = True
        signal.signal(signal.SIGINT, self._signal_handler)

    def _signal_handler(self, sig, frame):
        self.running = False

    def _init_camera(self):
        from picamera2 import Picamera2
        from libcamera import controls

        picam2 = Picamera2()
        config = picam2.create_preview_configuration(
            main={&quot;size&quot;: (320, 240), &quot;format&quot;: &quot;RGB888&quot;}
        )
        picam2.configure(config)
        picam2.start()
        
        # オートフォーカス設定
        picam2.set_controls({
            &quot;AfMode&quot;: controls.AfModeEnum.Continuous,
            &quot;AfSpeed&quot;: controls.AfSpeedEnum.Fast,
        })
        return picam2

    def _init_backend(self):
        # Hailo VLMバックエンド初期化
        self.backend = Backend(
            hef_path=self.hef_path,
            max_tokens=MAX_TOKENS,
            temperature=TEMPERATURE,
            seed=SEED,
            system_prompt=SYSTEM_PROMPT,
        )

    def run(self):
        
        picam2 = self._init_camera()
        self._init_backend()

        cv2.namedWindow(WINDOW_NAME, cv2.WINDOW_AUTOSIZE)

        # ---------- ライブ表示 ----------
        while self.running:

            start_time = time.time()
            captured_frame = None
            
            while self.running and captured_frame is None:
                frame = picam2.capture_array()
                rgb_frame = Backend.convert_resize_image(frame)
                bgr_frame = cv2.cvtColor(rgb_frame, cv2.COLOR_RGB2BGR)

                cv2.imshow(WINDOW_NAME, bgr_frame)
                
                # 指定時間経過で撮影
                if (time.time() - start_time) &gt;= WAIT_SECONDS:
                    captured_frame = cv2.cvtColor(rgb_frame, cv2.COLOR_RGB2BGR)
                    break

                if cv2.waitKey(1) & 0xFF == ord(&quot;q&quot;):
                    self.running = False
                    break
                
            if not self.running:
                break
        
            loop_start = time.perf_counter()
            t0 = time.perf_counter()
                    
            # VLM推論を実行（画像→テキスト生成）
            result = self.backend.vlm_inference(
                captured_frame,
                QUESTION,
                INFERENCE_TIMEOUT,
            )
            t1 = time.perf_counter()
            inference_time = t1 - t0
            
            answer_text = result.get(&quot;answer&quot;, &quot;回答を取得できませんでした&quot;)

            model_name = extract_model_name(self.hef_path)

            print(&quot;\n=====================================\n&quot;)
            print(&quot;---------- 実行情報 ----------&quot;)
            print(f&quot;モデル名   ：{model_name}&quot;)
            print(f&quot;VLM推論時間   ：{inference_time:.2f}秒&quot;)
            print(&quot;------------------------------\n&quot;)
                    
            # Hailoデバイス解放
            self.backend.close()
                             
            # 翻訳 -----------------------------------------------
            t2 = time.perf_counter()

            translated_text = translate_to_japanese(answer_text)
            print(translated_text)
            
            t3 = time.perf_counter()
            llm_time = t3 - t2            
                    
            total_time = time.perf_counter() - loop_start # トータル時間計算
                    
            print(&quot;\n---------- 処理時間 ----------&quot;)
            print(f&quot;LLM推論時間   ：{llm_time:.2f}秒&quot;)
            print(f&quot;トータル時間 ：{total_time:.2f}秒&quot;)
            print(&quot;------------------------------\n&quot;)

            self._init_backend()
            time.sleep(1)

            if cv2.waitKey(30) & 0xFF == ord(&quot;q&quot;):
                break

if __name__ == &quot;__main__&quot;:
    parser = get_standalone_parser()
    handle_list_models_flag(parser, VLM_CHAT_APP)
    options = parser.parse_args()

    hef_path = resolve_hef_path(
        options.hef_path if hasattr(options, &quot;hef_path&quot;) else None,
        app_name=VLM_CHAT_APP,
        arch=HAILO10H_ARCH,
    )

    if hef_path is None:
        sys.exit(1)

    OneShotVLMApp(str(hef_path)).run()
    sys.exit(0)
</code></pre></div>



<p>VLMからLLMへ処理を切り替える際に、プロセスの起動やメモリ確保、モデルのロードが行われるため時間がかかります。結果、VLMの推論自体は速くても、全体の処理時間は長くなります。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="459" src="https://sozorablog.com/wp-content/uploads/2026/01/スクリーンショット-2026-03-18-9.00.19.jpg" alt="" class="wp-image-16512"/><figcaption class="wp-element-caption">実行結果</figcaption></figure>



<h2 class="wp-block-heading">VLM作例紹介</h2>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="590" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0556.jpeg" alt="" class="wp-image-16515"/></figure>



<p>ローカルVLMを使って、カメラに映った物や人物をひたすら褒めてくれる装置を作りました。使用したのは<a href="https://www.raspberrypi.com/products/touch-display-2/">Touch Display 2</a>の5インチモデルです。カメラを固定できるスタンドは、3Dプリンターで自作しました。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="819" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0565.jpeg" alt="" class="wp-image-16516" style="aspect-ratio:0.9768097951814027;width:490px;height:auto"/></figure>



<p>背景で流れている映画マトリックス風の動画は、<a href="https://pixabay.com/ja/videos/%e3%83%9e%e3%83%88%e3%83%aa%e3%83%83%e3%82%af%e3%82%b9-%e3%83%80%e3%82%a6%e3%83%b3%e3%83%ad%e3%83%bc%e3%83%89-75043/">Pixabay</a>で公開されているものを使用しました。これがあるだけで、近未来感が増します。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="300" height="214" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0560-1.gif" alt="" class="wp-image-16522"/></figure>



<p>英語のVLM回答をローカルLLMで日本語に翻訳させているので、英文と日本語文が交互に流れます。日本語回答までの処理時間は合計で30秒くらいです。</p>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>繰り返し動かしても、API利用料金を気にせずに済むところが良いですね。</p>
</div></div>



<h2 class="wp-block-heading">テキストをしゃべらせる</h2>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="583" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0626.jpeg" alt="" class="wp-image-16545"/><figcaption class="wp-element-caption">AI HAT ＋2の上部に取り付けた<a href="https://sozorablog.com/whisplay-hat/">Whisplay Hat</a></figcaption></figure>



<p>音声合成（TTS）はRaspberry PiのCPUで動作します。PiperはONNX Runtimeという仕組みで動いており、これはCPUやGPU向けに作られているため、Hailo（Raspberry Pi AI HAT+ 2）では動かないようです。</p>



<p>音声を出力させるためにスピーカーが必要です。今回は<a href="https://sozorablog.com/whisplay-hat/">PiSugar Whisplay Hat</a>を使用します。コンパクトですが、スピーカーとマイクが搭載されています。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="450" src="https://sozorablog.com/wp-content/uploads/2026/04/pico-6.jpg" alt="" class="wp-image-16802" style="width:455px;height:auto" srcset="https://sozorablog.com/wp-content/uploads/2026/04/pico-6.jpg 800w, https://sozorablog.com/wp-content/uploads/2026/04/pico-6-320x180.jpg 320w, https://sozorablog.com/wp-content/uploads/2026/04/pico-6-224x126.jpg 224w" sizes="(max-width: 800px) 100vw, 800px" /><figcaption class="wp-element-caption">Whisplay HATの裏面</figcaption></figure>



<p>以下を1行ずつ実行すると、Whisplay HATのスピーカーとマイクが使える状態になります。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>git clone https://github.com/PiSugar/Whisplay.git --depth 1
cd Whisplay/Driver
sudo bash install_wm8960_drive.sh
sudo reboot</code></pre></div>



<h3 class="wp-block-heading">Piperで音声を再生する</h3>



<p>音声合成エンジンであるPiperのTTSモデルをダウンロードします。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>hailo-audio-troubleshoot --install-tts</code></pre></div>



<p>以下を実行すると、「Hello, how are you today?」というテキストが音声に変換され、スピーカーから再生されます。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>python -c &quot;from hailo_apps.python.gen_ai_apps.gen_ai_utils.voice_processing.text_to_speech import TextToSpeechProcessor as T; t=T(); t.queue_text(&#39;Hello, how are you today?&#39;); t.wait_for_completion()&quot;</code></pre></div>



<h3 class="wp-block-heading">OpenJTalkで日本語音声を再生する</h3>



<p>Piperでは日本語対応しているモデルを使用できないようです。そこで、OpenJTalkをインストールすることにしました。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo apt install -y open-jtalk open-jtalk-mecab-naist-jdic hts-voice-nitech-jp-atr503-m001</code></pre></div>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>OpenJTalkは、名古屋工業大学を中心に開発された、日本語の文章を音声に変換して読み上げるオープンソースの音声合成エンジンです。</p>
</div></div>



<p>OpenJTalkで日本語を音声合成するための辞書と音声モデルをインストールします。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo apt install -y open-jtalk-mecab-naist-jdic hts-voice-nitech-jp-atr503-m001</code></pre></div>



<p>以下で日本語がしゃべれます。「こんにちは」というテキストを音声に変換してWAVファイルに保存し、その音声を再生しています。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>echo &quot;こんにちは&quot; | open_jtalk -x /var/lib/mecab/dic/open-jtalk/naist-jdic -m /usr/share/hts-voice/nitech-jp-atr503-m001/nitech_jp_atr503_m001.htsvoice -ow /tmp/test.wav && aplay /tmp/test.wav</code></pre></div>



<p>女性の声のモデルもインストールしてみます。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>wget https://downloads.sourceforge.net/project/mmdagent/MMDAgent_Example/MMDAgent_Example-1.8/MMDAgent_Example-1.8.zip</code></pre></div>



<p>ZIP形式のファイル「MMDAgent_Example-1.8.zip」を解凍します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>unzip MMDAgent_Example-1.8.zip</code></pre></div>



<p>meiフォルダをシステムの音声データ用ディレクトリ（/usr/share/hts-voice/）にコピーします。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo cp -r MMDAgent_Example-1.8/Voice/mei /usr/share/hts-voice/</code></pre></div>



<p>Pythonからは以下のように再生します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>import subprocess

def speak_japanese(text, voice=&quot;normal&quot;, speed=0.8):
    # voiceで選択できる種類
    # &quot;normal&quot;   : 標準
    # &quot;happy&quot;    : 明るい
    # &quot;angry&quot;    : 怒り
    # &quot;sad&quot;      : 悲しい
    # &quot;bashful&quot;  : 照れ
    voice_path = f&quot;/usr/share/hts-voice/mei/mei_{voice}.htsvoice&quot;

    subprocess.run(
        [
            &quot;open_jtalk&quot;,
            &quot;-x&quot;, &quot;/var/lib/mecab/dic/open-jtalk/naist-jdic&quot;,
            &quot;-m&quot;, voice_path,
            &quot;-r&quot;, str(speed),
            &quot;-ow&quot;, &quot;/tmp/test.wav&quot;
        ],
        input=text,
        text=True
    )

    subprocess.run([&quot;aplay&quot;, &quot;/tmp/test.wav&quot;])

speak_japanese(&quot;こんにちは&quot;, &quot;happy&quot;)</code></pre></div>



<p>日本語テキストをOpenJTalkで音声に変換し、/tmp/test.wavに保存してから再生する処理です。読み上げる内容はtextに入れた文字で決まり、voiceで声の種類（normal・happyなど）を選べます。speedで話す速さを調整でき、数値が小さいほどゆっくり、大きいほど速くなります。<br><br>最後の<code>speak_japanese("こんにちは", "happy")</code>は、「こんにちは」を明るい声で再生する指定です。</p>



<h2 class="wp-block-heading">AIと音声で会話する</h2>



<p>hailo-appsのvoice_assistant.pyを使うことで、マイク入力から音声認識・LLM処理・音声出力まで一連の流れを実行できます。</p>



<p>引き続き、<a href="https://www.pisugar.com/products/whisplay-hat-for-pi-zero-2w-audio-display">PiSugar Whisplay Hat</a>をスピーカー・マイクとして使用します。</p>



<p>hailo-appsディレクトリに移動し、仮想環境venvを有効化。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>cd hailo-apps && source venv/bin/activate</code></pre></div>



<p>voice_assistant.pyを起動します。初回実行時は音声認識モデルのダウンロードが行われるため、10分程度かかります。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>python -m hailo_apps.python.gen_ai_apps.voice_assistant.voice_assistant</code></pre></div>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p><code>-m</code>は指定したモジュールをパッケージとして実行するためのオプションです。</p>
</div></div>



<p>起動すると待機状態になり、SPACEキーを押すと録音が始まります。話し終わったらもう一度SPACEキーを押すと録音が止まり、その内容がテキストに変換されてAIの応答が表示・音声再生されます。会話の履歴をリセットしたいときはCキー、アプリを終了したいときはQキーを押します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="162" src="https://sozorablog.com/wp-content/uploads/2026/01/pico-1.png" alt="" class="wp-image-16562" style="width:840px;height:auto"/></figure>



<p>デフォルトの構成では日本語で会話できないので、以下に変更します。</p>



<p>マイク → 音声認識（日本語） → LLM（qwen2:1.5b） → TTS（open_jtalk）</p>



<h3 class="wp-block-heading">日本語の音声を認識できるようにする</h3>



<p>音声認識を日本語で動作させるための設定を追加します。</p>



<p>/home/pi/hailo-apps/hailo_apps/python/gen_ai_apps/voice_assistant/voice_assistant.pyを開いて、language=&#8221;ja&#8221;を追加します。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="475" src="https://sozorablog.com/wp-content/uploads/2026/01/pico-2-2.jpg" alt="" class="wp-image-16567"/></figure>



<p>これにより、音声入力が日本語として処理されるようになります。認識精度は決して高くはありませんが、処理の速さには驚きました。</p>



<p>以下の投稿は日本語音声認識をWhisplayHATのボタン操作で動くようにして、結果をLCDに表示させたものです。</p>



<figure class="wp-block-embed is-type-rich is-provider-twitter wp-block-embed-twitter"><div class="wp-block-embed__wrapper">
<blockquote class="twitter-tweet" data-width="500" data-dnt="true"><p lang="ja" dir="ltr">Raspberry Pi AI HAT+ 2を使った音声認識。<br><br>短い言葉なら、短時間で正確に認識できる。長文や一般用語以外は苦手。日本語より英語の方が精度は良さそう。とはいえ、ローカルでこの処理速度は、なかなか良い。 <a href="https://t.co/RelJFBglK5">pic.twitter.com/RelJFBglK5</a></p>&mdash; そぞら@Raspberry Pi 電子工作 (@sozoraemon) <a href="https://twitter.com/sozoraemon/status/2040729870947561658?ref_src=twsrc%5Etfw">April 5, 2026</a></blockquote><script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
</div></figure>



<h3 class="wp-block-heading" id="qwen">LLMを「Qwen2 1.5B」に変更する</h3>



<p>認識した音声を回答させる際にデフォルトのモデルでは回答が安定しません。そこで、比較的日本語に強いqwen2:1.5bモデルを使用します。</p>



<p><a href="https://hailo.ai/products/hailo-software/model-explorer/generative-ai/qwen2-1-5b/">https://hailo.ai/products/hailo-software/model-explorer/generative-ai/qwen2-1-5b/</a>のページ下部から<span class="sbd-text-bg-yellow">Compiled Model</span>をダウンロードします。ファイルサイズが大きいため、かなり時間がかかります。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="530" src="https://sozorablog.com/wp-content/uploads/2026/01/pico-3.png" alt="" class="wp-image-16571" style="width:507px;height:auto"/><figcaption class="wp-element-caption"><a href="https://hailo.ai/products/hailo-software/model-explorer/generative-ai/qwen2-1-5b/">Hailo公式のダウンロードページ</a></figcaption></figure>



<p>モデルを保存するフォルダを作成</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>mkdir -p /home/pi/models</code></pre></div>



<p>ダウンロードしたモデルを移動</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>mv /home/pi/ダウンロード/Qwen2-1.5B-Instruct.hef /home/pi/models/</code></pre></div>



<p>/home/pi/hailo-apps/hailo_apps/python/gen_ai_apps/voice_assistant/voice_assistant.pyを開いて、モデルのパスを変更します。</p>



<p>以下の行にmodel_path = &#8220;/home/pi/models/Qwen2-1.5B-Instruct.hef&#8221;を追加します。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="450" src="https://sozorablog.com/wp-content/uploads/2026/01/pico-4-1.jpg" alt="" class="wp-image-16574" srcset="https://sozorablog.com/wp-content/uploads/2026/01/pico-4-1.jpg 800w, https://sozorablog.com/wp-content/uploads/2026/01/pico-4-1-320x180.jpg 320w, https://sozorablog.com/wp-content/uploads/2026/01/pico-4-1-224x126.jpg 224w" sizes="(max-width: 800px) 100vw, 800px" /></figure>



<p>日本語で回答してもらうために、import文の下に以下を追加します。from hailo_apps.python.core.common.defines import LLM_PROMPT_PREFIX, SHARED_VDEVICE_GROUP_ID, HAILO10H_ARCH, VOICE_ASSISTANT_APP, VOICE_ASSISTANT_MODEL_NAMEの行より下に記述します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>LLM_PROMPT_PREFIX = &quot;日本語で答えてください。\n&quot;</code></pre></div>



<h3 class="wp-block-heading">TTSを日本語対応させる</h3>



<p>先ほどインストールしたOpenJTalkを使用するために日本語TTS用ファイルを作成します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>nano ~/hailo-apps/hailo_apps/python/gen_ai_apps/voice_assistant/tts_openjtalk.py</code></pre></div>



<p>tts_openjtalk.pyに、以下のコードを保存します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>import subprocess

def speak_japanese(text, voice=&quot;normal&quot;, speed=0.8):
    voice_path = f&quot;/usr/share/hts-voice/mei/mei_{voice}.htsvoice&quot;

    subprocess.run(
        [
            &quot;open_jtalk&quot;,
            &quot;-x&quot;, &quot;/var/lib/mecab/dic/open-jtalk/naist-jdic&quot;,
            &quot;-m&quot;, voice_path,
            &quot;-r&quot;, str(speed),
            &quot;-ow&quot;, &quot;/tmp/test.wav&quot;
        ],
        input=text,
        text=True
    )

    subprocess.run(
        [&quot;aplay&quot;, &quot;/tmp/test.wav&quot;],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL
    )</code></pre></div>



<p>voice_assistant.pyの先頭付近に以下を追加</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>from .tts_openjtalk import speak_japanese</code></pre></div>



<p>speak_japanese(response_text)を追加</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="388" src="https://sozorablog.com/wp-content/uploads/2026/01/pico-4-2.jpg" alt="" class="wp-image-16582"/></figure>



<p>response_text = &#8220;&#8221;を追加</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="386" src="https://sozorablog.com/wp-content/uploads/2026/01/pico-4-3.jpg" alt="" class="wp-image-16585"/></figure>



<p>以下を追加</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>def collect_callback(chunk: str):
    nonlocal response_text
    response_text += chunk</code></pre></div>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="450" src="https://sozorablog.com/wp-content/uploads/2026/01/pico-1-1-1.jpg" alt="" class="wp-image-16588" srcset="https://sozorablog.com/wp-content/uploads/2026/01/pico-1-1-1.jpg 800w, https://sozorablog.com/wp-content/uploads/2026/01/pico-1-1-1-320x180.jpg 320w, https://sozorablog.com/wp-content/uploads/2026/01/pico-1-1-1-224x126.jpg 224w" sizes="(max-width: 800px) 100vw, 800px" /></figure>



<p>&#8221;token_callback=tts_callback&#8221;を&#8221;token_callback=collect_callback&#8221;に変更</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="450" src="https://sozorablog.com/wp-content/uploads/2026/01/pico-4-4.jpg" alt="" class="wp-image-16589" srcset="https://sozorablog.com/wp-content/uploads/2026/01/pico-4-4.jpg 800w, https://sozorablog.com/wp-content/uploads/2026/01/pico-4-4-320x180.jpg 320w, https://sozorablog.com/wp-content/uploads/2026/01/pico-4-4-224x126.jpg 224w" sizes="(max-width: 800px) 100vw, 800px" /></figure>



<p>voice_assistant.pyを以下のコマンドで実行します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>python -m hailo_apps.python.gen_ai_apps.voice_assistant.voice_assistant --no-tts</code></pre></div>



<p>日本語の音声を認識し、日本語で返答を生成し、そのまま音声として再生できるようになりました。</p>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>一連の流れがすべてRaspberry Pi上で動作しており、実際に声でやり取りできる体験はとても新鮮です。</p>
</div></div>



<p>認識精度や返答内容については、<span class="sbd-text-red">意図しない変換や不自然な応答になる</span>こともあります。それでも、この速度で会話のようなやり取りが成立するのは、触っていて面白さを感じられるレベルです。</p>



<p>現時点では英語と比べて日本語の精度が低い傾向があり、初期のChatGPTと似た印象を受けます。今後のモデルや音声認識の進化によって、より自然で正確な会話ができるようになることが期待されます。</p>



<p>以下の投稿はvoice_assistantをWhisplayHATのボタン操作で動くようにして、結果をLCDに表示させたものです。</p>



<figure class="wp-block-embed is-type-rich is-provider-twitter wp-block-embed-twitter"><div class="wp-block-embed__wrapper">
<blockquote class="twitter-tweet" data-width="500" data-dnt="true"><p lang="ja" dir="ltr">Raspberry Pi AI HAT+ 2で、音声対話型チャットボットを作ってみました。<br><br>すべてローカルで動いています。精度が課題ではあるけど、音声認識→文章生成→音声合成がこの速さ動くのは驚きです。 <a href="https://t.co/tgGoQ6Yhv2">pic.twitter.com/tgGoQ6Yhv2</a></p>&mdash; そぞら@Raspberry Pi 電子工作 (@sozoraemon) <a href="https://twitter.com/sozoraemon/status/2041460961673097486?ref_src=twsrc%5Etfw">April 7, 2026</a></blockquote><script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
</div></figure>



<h2 class="wp-block-heading">まとめ</h2>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0249.jpg" alt="" style="aspect-ratio:1.2631640781033389;width:527px;height:auto"/></figure>



<p>Raspberry Pi AI HAT+ 2を使ってみると、Raspberry Pi上でも<span class="sbd-text-bg-yellow">LLMの回答が数秒で返ってくる</span>ことがわかり、エッジAIとしての可能性にワクワクしました。カメラを使った生成AIでは、さまざまなシチュエーションや質問を次々に試してみたくなるような楽しさがあります。API利用料金を気にせず実行できるため、プロンプトや処理の調整を気軽に繰り返せる点も大きな利点です。</p>



<p>一方で、<span class="sbd-text-red">日本語の回答精度が安定しない</span>場面があり、現時点では用途を選びながら使う必要があると感じました。ただ、この点はAI HAT+ 2自体の問題ではなく、モデルやソフトウェアの進化によって改善される余地があり、今後に期待したい部分です。</p>



<p>生成AIを単体で使うだけでなく、電子工作やセンサー、カメラと組み合わせることで、Raspberry Piならではの使い方に広げられそうです。実際にいろいろ試してみて、面白い形になったものがあれば、この記事に追記していきます。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sozorablog.com/ai-hat-2/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		<enclosure url="https://sozorablog.com/wp-content/uploads/2026/01/画面収録-2026-01-15-10.23.27.mov" length="229866" type="video/quicktime" />

			</item>
		<item>
		<title>【レビュー】ハードケース型Raspberry Pi学習キットCrowPiを使ってみた</title>
		<link>https://sozorablog.com/crowpi/</link>
					<comments>https://sozorablog.com/crowpi/#respond</comments>
		
		<dc:creator><![CDATA[そぞら]]></dc:creator>
		<pubDate>Sun, 11 Jan 2026 10:13:34 +0000</pubDate>
				<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[関連製品]]></category>
		<guid isPermaLink="false">https://sozorablog.com/?p=16081</guid>

					<description><![CDATA[Raspberry Piの学習キットは数あれど、見た目のインパクトがここまで強烈な製品はまずないでしょう。ハードケース型のオールインワン学習キット「CrowPi」が以前から気になっており、レビュー記事がほとんど見当たらな [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p><a href="https://sozorablog.com/raspberry-pi/">Raspberry Pi</a>の学習キットは数あれど、見た目のインパクトがここまで強烈な製品はまずないでしょう。ハードケース型のオールインワン学習キット「CrowPi」が以前から気になっており、レビュー記事がほとんど見当たらないこともあって、半ば使命感のような気持ちで購入を決意しました。</p>



<!-- START MoshimoAffiliateEasyLink -->
<script type="text/javascript">
(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;
b[a]=b[a]||function(){arguments.currentScript=c.currentScript
||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};
c.getElementById(a)||(d=c.createElement(f),d.src=g,
d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})
(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");
msmaflink({"n":"ELECROW Raspberry Pi 5 8GBキット用 Pi 5 8GB シングルボードコンピューター付き Crowpi Pi 5 ケースキット 9インチディスプレイ付き Raspberry Pi 5 ラーニングプログラミングキット(8GB RAM)対応","b":"Elecrow","t":"","d":"https:\/\/m.media-amazon.com","c_p":"\/images\/I","p":["\/410FwKdoR5L._SL500_.jpg","\/51SgAgmc4HL._SL500_.jpg","\/51ZjF8UoB8L._SL500_.jpg","\/51jroFvN0LL._SL500_.jpg","\/51feD1Y3g7L._SL500_.jpg","\/41LJlUjd2YL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0D4LPCKCF","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":1,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0D4LPCKCF","a_id":3038653,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"id":2,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/ELECROW%20Raspberry%20Pi%205%208GB%E3%82%AD%E3%83%83%E3%83%88%E7%94%A8%20Pi%205%208GB%20%E3%82%B7%E3%83%B3%E3%82%B0%E3%83%AB%E3%83%9C%E3%83%BC%E3%83%89%E3%82%B3%E3%83%B3%E3%83%94%E3%83%A5%E3%83%BC%E3%82%BF%E3%83%BC%E4%BB%98%E3%81%8D%20Crowpi%20Pi%205%20%E3%82%B1%E3%83%BC%E3%82%B9%E3%82%AD%E3%83%83%E3%83%88%209%E3%82%A4%E3%83%B3%E3%83%81%E3%83%87%E3%82%A3%E3%82%B9%E3%83%97%E3%83%AC%E3%82%A4%E4%BB%98%E3%81%8D%20Raspberry%20Pi%205%20%E3%83%A9%E3%83%BC%E3%83%8B%E3%83%B3%E3%82%B0%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0%E3%82%AD%E3%83%83%E3%83%88(8GB%20RAM)%E5%AF%BE%E5%BF%9C\/","a_id":3038654,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":2}],"eid":"U496C","s":"s"});
</script>
<div id="msmaflink-U496C">リンク</div>
<!-- MoshimoAffiliateEasyLink END -->



<p>スパイグッズのようなケースを開くと、9インチタッチディスプレイと電子工作で定番のLCDやセンサー、スイッチ類が整然と配置されています。メカ好きな方なら、この外観だけで心をつかまれるはずです。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0209.jpg" alt="" class="wp-image-4"/></figure>



<p>本記事ではCrowPiの外観の魅力を入口に、実際に動かして感じた楽しさや、初心者でも無理なく始められるかといった点から、<strong>高額なこの製品に購入する価値があるのか</strong>をレビューしていきます。</p>



<h2 class="wp-block-heading">公式サイトから購入</h2>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0165.jpg" alt="" class="wp-image-4" style="aspect-ratio:0.9930727454095393;width:663px;height:auto"/></figure>



<p><a href="https://www.elecrow.com/crowpi-compact-raspberry-pi-educational-kit.html">Elecrowの公式サイト</a>から購入したCrowPi。注文から到着までは7日間でした。購入したタイミングでは5ドルオフのクーポンが配布されており、送料込みで約36,000円。価格は購入時の為替レートによって前後します。CrowPiは<a href="https://ja.aliexpress.com/item/1005006958783387.html?spm=a2g0o.productlist.main.4.2434db28kXL4yS&amp;algo_pvid=48729ff9-d98b-4ac3-8916-f683819cf87d&amp;algo_exp_id=48729ff9-d98b-4ac3-8916-f683819cf87d-3&amp;pdp_ext_f=%7B%22order%22%3A%223%22%2C%22eval%22%3A%221%22%2C%22fromPage%22%3A%22search%22%7D&amp;pdp_npi=6%40dis%21JPY%2155053%2140170%21%21%21344.00%21251.00%21%402140ec5d17676441857174406e38c8%2112000038859699847%21sea%21JP%210%21ABX%211%210%21n_tag%3A-29910%3Bd%3A5c23aefc%3Bm03_new_user%3A-29895%3BpisId%3A5000000197845725&amp;curPageLogUid=6evfMaUbcAP5&amp;utparam-url=scene%3Asearch%7Cquery_from%3A%7Cx_object_id%3A1005006958783387%7C_p_origin_prod%3A">AliExpress</a>でも購入可能です。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/12/image.png" alt="" class="wp-image-4" style="width:315px;height:auto"/><figcaption class="wp-element-caption">出典：<a href="https://www.elecrow.com/crowpi-compact-raspberry-pi-educational-kit.html">CrowPi販売ページ</a></figcaption></figure>



<p>購入時にACアダプターの<span class="sbd-text-red">電源プラグの規格</span>を選択します。USプラグは日本のコンセントと形状が同じであるため、そのまま使用できます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0202.jpg" alt="" class="wp-image-4" style="aspect-ratio:1.374769844517185;width:430px;height:auto"/><figcaption class="wp-element-caption">付属のACアダプター（USプラグを選択）</figcaption></figure>



<h2 class="wp-block-heading">CrowPiの基本情報</h2>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0181.jpg" alt="" class="wp-image-4"/></figure>



<p>CrowPiを手がけている<a href="https://www.elecrow.com/">Elecrow</a>は、中国・深圳を拠点に、電子工作やRaspberry Pi関連の製品を多く展開しています。</p>



<h3 class="wp-block-heading">ハードケース型デザインと作り</h3>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/pico-2.jpg" alt="" class="wp-image-4"/><figcaption class="wp-element-caption">Basic KitはRaspberry Pi本体が別売り</figcaption></figure>



<p>ハードケース型の筐体に9インチのタッチディスプレイや各種センサー、操作用の基板が組み込まれており、ケースを開いた状態で使う前提の構成になっています。</p>



<p>CrowPiには、<strong>Basic Kit</strong>と<strong>Advanced Kit</strong>の2種類があります。私が購入したBasic KitはRaspberry Pi本体が付属しない構成で、すでに本体を持っている人向けです。Advanced KitはRaspberry Pi 5（8GB）が同梱され、その分価格が上がります。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0193.jpg" alt="" class="wp-image-4" style="aspect-ratio:1.006685142878544;width:465px;height:auto"/></figure>



<p>CrowPiで使用できるモデルは<a href="https://sozorablog.com/pi5/">Raspberry Pi 5</a>または<a href="https://sozorablog.com/raspberry-pi-4-revue/">Raspberry Pi 4</a>となっています。</p>



<h3 class="wp-block-heading">搭載されているパーツ</h3>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/12/image-1.jpg" alt="" class="wp-image-4"/><figcaption class="wp-element-caption">出典：<a href="https://www.elecrow.com/crowpi-compact-raspberry-pi-educational-kit.html">CrowPi販売ページ</a></figcaption></figure>



<p>ケース内には9インチのタッチディスプレイをはじめ、カメラ、LEDマトリクス、ブザー、各種ボタン、温度・湿度センサー、距離センサー、モーター制御系、ブレッドボードなどがまとめられています。</p>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>配線を個別に行わなくても、多くのセンサーや入出力デバイスをすぐ試せるよう設計されているのが特徴です。</p>
</div></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0207.jpg" alt="" class="wp-image-4" style="aspect-ratio:0.9422476951659831;width:509px;height:auto"/><figcaption class="wp-element-caption">ステッピングモーターを動かしている様子</figcaption></figure>



<p>モーターなどの一部のパーツはCrowPi側の専用コネクタに挿して使用します。コネクタは向きを間違えて挿せない形状になっているため、接続で迷うことはありません。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/スクリーンショット-2026-01-06-18.10.01.jpg" alt="" class="wp-image-4" style="width:526px;height:auto"/><figcaption class="wp-element-caption">出典：<a href="https://www.elecrow.com/crowpi-compact-raspberry-pi-educational-kit.html">CrowPi販売ページ</a></figcaption></figure>



<p>本体のほかに、電源アダプターとOSを書き込んだmicroSDカードが付属しており、Raspberry Piを用意すればすぐに起動できます。加えて、モーター類やIRリモコン、RFIDカード、GPIOケーブルなど、Raspberry Piでの入出力や制御を試すための基本パーツがひと通りそろっています。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0219.jpg" alt="" class="wp-image-4" style="aspect-ratio:1.2056561035232904;width:524px;height:auto"/></figure>



<p>ユーザーマニュアルは英語ですが、<a href="https://www.elecrow.com/download/product/SES14002K/CrowPi_User_Manual_New.pdf">PDF版</a>をダウンロードして<a href="https://translate.google.co.jp/?hl=ja&amp;sl=en&amp;tl=ja&amp;op=docs">Google翻訳</a>を利用すれば、日本語で内容を把握できます。</p>



<h2 class="wp-block-heading">使用開始までの準備</h2>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0197-1.jpg" alt="" class="wp-image-4" style="width:466px;height:auto"/><figcaption class="wp-element-caption">付属のmicroSDカード（CrowPi用OS書き込み済）</figcaption></figure>



<p>CrowPiは付属のmicroSDカードをRaspberry Piにセットするだけで、そのまま起動して使い始めることができます。ただし私の環境では、付属カードを使った場合、Webページの表示や VNC操作、パッケージのインストールが非常に遅く感じられました。そこで付属のmicroSDカードにCrowPi専用OSイメージを書き直して起動したところ、動作が明らかに軽くなりました。</p>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p><span class="sbd-text-red">まずは付属のmicroSDカードでそのまま起動し</span>、重さを感じた場合は、次の手順でOSイメージを書き直してみると良いと思います。</p>
</div></div>



<h3 class="wp-block-heading">CrowPi専用OSイメージをダウンロード</h3>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/スクリーンショット-2026-01-06-4.11.55.png" alt="" class="wp-image-4"/></figure>



<p>通常はこの手順を省略し、下の<a href="#microSD">microSDカードの取り付け</a>から始めて問題ありません。<span class="sbd-text-bg-yellow">OSを書き直す場合は</span>、<a href="https://drive.google.com/drive/u/0/folders/1omz8i4UVU-chItRekNViZEYqbhsLtCnn">公式サイト</a>からRaspberry Pi 5用イメージのファイルをPCにダウンロードします。</p>



<h3 class="wp-block-heading">microSDカードにOSイメージを書き込み</h3>



<p>PCにmicroSDカードをセットします。カードリーダーもキットに付属していました。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0218.jpg" alt="" class="wp-image-4" style="aspect-ratio:1.16404304614252;width:349px;height:auto"/></figure>



<p><a href="https://www.raspberrypi.com/software/">Raspberry Pi Imager</a>というソフトを使って、microSDにOSイメージを書き込みます。OSの選択画面で、「カスタムイメージを使う」をクリック後して、ダウンロードしたimgファイルを選択します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/12/スクリーンショット-2025-12-31-12.52.42.png" alt="" class="wp-image-4" style="width:498px;height:auto"/><figcaption class="wp-element-caption">Raspberry Pi Imagerの操作画面</figcaption></figure>



<p>OSイメージの書き込みは1時間かかりました。</p>



<h3 class="wp-block-heading" id="microSD">microSDカードの取り付け</h3>



<p>書き込みが完了したら、microSDをRaspberry Piにセットします。今回使用したのはRaspberry Pi 5の8GBモデルです。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0198.jpg" alt="" class="wp-image-4" style="aspect-ratio:1.2369480683831482;width:463px;height:auto"/></figure>



<h3 class="wp-block-heading">Raspberry PiをCrowPiに取り付け</h3>



<p>Raspberry Piに電源やHDMIのケーブルを接続して、CrowPiに固定します。ドライバーはキットに付属しています。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0199.jpg" alt="" class="wp-image-4" style="aspect-ratio:0.984651171309779;width:462px;height:auto"/></figure>



<p>キーボードとマウスUSBポートを接続。Basic Kitにはキーボードとマウスが付属しないので、手持ちのものを使用しました。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0212.jpg" alt="" class="wp-image-4" style="aspect-ratio:0.9943953238873886;width:440px;height:auto"/></figure>



<p>フラットケーブルはGPIOピンへの取り付け前に、山折りに曲げておくと接続しやすいです。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0200.jpg" alt="" class="wp-image-4" style="width:289px;height:auto"/></figure>



<h2 class="wp-block-heading">実際に動かしてみる</h2>



<p>ここからは、CrowPiを実際に起動し、基本的な使い方を一通り試していきます。</p>



<h3 class="wp-block-heading">電源を接続して起動</h3>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0203.jpg" alt="" class="wp-image-4" style="aspect-ratio:0.8017508799140965;width:516px;height:auto"/></figure>



<p>CrowPiに電源ケーブルを接続すると、Raspberry Piやディスプレイを含むシステムが起動します。CrowPiの電源スイッチはありません。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0204.jpg" alt="" class="wp-image-4" style="aspect-ratio:0.9287367839126529;width:579px;height:auto"/></figure>



<p>Raspberry Piが起動すると、ディスプレイにデスクトップ画面が表示され、すぐに操作を始められます。CrowPiを動かすためのソフトウェアは最初から入っており、必要な設定も済んだ状態になっていました。</p>



<h3 class="wp-block-heading">センサーやモジュールをPythonで操作する</h3>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/スクリーンショット-2026-01-07-18.37.42.png" alt="" class="wp-image-4"/><figcaption class="wp-element-caption">温湿度センサーから取得した数値を表示</figcaption></figure>



<p>まずはデモコードを動かして、ディスプレイやセンサーなどのデバイスを動かしてみましょう。<a href="https://www.elecrow.com/download/product/SES14002K/CrowPi_Python_Lessons_bookworm_version.pdf">公式チュートリアル</a>の通りに進めていけば問題ありませんが、以下の手順だとコマンド入力不要で簡単にプログラムを実行できます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/pico-3.jpg" alt="" class="wp-image-4" style="width:526px;height:auto"/></figure>



<p>デスクトップの「CrowPi」フォルダを開いて「Examples」を開きます。</p>



<p>「Examples」には各デバイスを動かすための基本的なコードが、あらかじめ保存されています。ファイル名を見れば、どのデバイス用のコードかがわかりようになっています。</p>



<h4 class="wp-block-heading">マトリクスLEDの動作確認</h4>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/pico-2-1.jpg" alt="" class="wp-image-4" style="width:476px;height:auto"/></figure>



<p>ここでは例として「matrix_demo.py」（マトリクスLEDのデモコード）を右クリックして、Thonnyで開きます。ThonnyはPython初心者向けに作られた統合開発環境で、コードの編集と実行を一つの画面で行えます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/pico-4.jpg" alt="" class="wp-image-4" style="width:491px;height:auto"/></figure>



<p>実行ボタンを押すと、マトリクスLEDに「Hello World」がスクロール表示されました。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/1v6uw-cq1pf.gif" alt="" class="wp-image-4" style="width:184px;height:auto"/></figure>



<p>使用する部品によっては、以下の物理スイッチの切り替えが必要なものもあります。これは、Raspberry Piが使える<a href="https://sozorablog.com/gpio_pinout/">GPIOピン</a>の数に限りがあり、複数の部品で同じピンを共有しているためです。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0215.jpg" alt="" class="wp-image-4"/></figure>



<h4 class="wp-block-heading">RFIDリーダーの動作確認</h4>



<p>RFIDリーダー（MFRC522）を使うと、カードやタグに書き込まれたIDの読み取りや、文字データの読み書きができます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0216.jpg" alt="" class="wp-image-4" style="aspect-ratio:1.3759987008769081;width:399px;height:auto"/></figure>



<p>デモコードを実行して、RFIDタグをリーダーに近づけます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0217.jpg" alt="" class="wp-image-4" style="aspect-ratio:1.0565633537076708;width:397px;height:auto"/></figure>



<p>読み取りに成功すると、タグのIDがThonnyのShell画面に表示されます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2026/01/pico.png" alt="" class="wp-image-4" style="width:506px;height:auto"/></figure>



<p>RFIDは本来、通信や制御などの複雑な処理が必要な仕組みです。しかし、このプログラムでは、そうした面倒な処理をまとめて引き受けてくれる仕組み（ライブラリ）を使っているため、わずか<span class="sbd-text-bg-yellow">8行のコード</span>でタグの読み取りができ、すぐに動作を確認できます。</p>



<h4 class="wp-block-heading">RFIDリーダーの活用方法を模索</h4>



<p>この仕組みを応用して、RFIDタグをかざすことでCrowPiを使える<span class="sbd-text-bg-yellow">認証機能</span>を実装してみました。Raspberry Piの起動時にプログラムが自動で立ち上がるように設定し、RFIDタグ認証が成功したときだけデスクトップ画面が開く仕組みです。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="308" src="https://sozorablog.com/wp-content/uploads/2026/01/pico-1-5.jpg" alt="" class="wp-image-16250"/></figure>



<p>待機中の画面には映画「マトリックス」をイメージした動画を表示し、タグをかざすとサイバーパンク調の認証完了画面に切り替わります。このとき、7セグメントLEDやマトリクスLEDも同時に点灯させ、演出を盛り上げます。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="150" height="200" src="https://sozorablog.com/wp-content/uploads/2026/01/Videotogif.gif" alt="" class="wp-image-16332"/></figure>



<h3 class="wp-block-heading">Scratchでプログラミングもできる</h3>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="688" height="474" src="https://sozorablog.com/wp-content/uploads/2026/01/スクリーンショット-2026-01-07-16.17.15.jpg" alt="" class="wp-image-16209" style="width:454px;height:auto"/></figure>



<p>CrowPiはPythonだけでなく、Scratchを使ったプログラミングにも対応しています。画面上でブロックを組み合わせるだけなので、コードを書く必要はありません。操作は直感的で、プログラミングが初めてでも動かしやすいように設計されています。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="468" src="https://sozorablog.com/wp-content/uploads/2026/01/スクリーンショット-2026-01-07-16.24.45-1.jpg" alt="" class="wp-image-16211"/><figcaption class="wp-element-caption">ブザーを鳴らすプログラムを作成</figcaption></figure>



<p>ブザーが鳴る、LEDが光るといった動作を、画面を見ながら確認できます。処理の流れを視覚的に理解しやすく、「なぜ動いたのか」が分かりやすい点が特徴です。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="649" src="https://sozorablog.com/wp-content/uploads/2026/01/pico-1-3.jpg" alt="" class="wp-image-16214" style="width:516px;height:auto"/></figure>



<p>一方で、すべてのパーツをScratchで制御できるわけではありません。カメラを使った画像処理や、複雑な制御が必要なパーツは、Scratchでは扱えません。そうした処理はPython向けです。CrowPiは、Scratchで基礎を学び、必要に応じてPythonに進める構成になっています。</p>



<h3 class="wp-block-heading">マインクラフトでも遊べる</h3>



<p>CrowPiではRaspberry Pi向けに用意された<strong>Minecraft Pi Edition</strong>を使って遊ぶこともできます。Raspberry Piで快適に動作するよう調整された特別版で、シンプルな構成が特徴です。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="392" height="240" src="https://sozorablog.com/wp-content/uploads/2026/01/スクリーンショット-2026-01-06-5.57.48.png" alt="" class="wp-image-16152" style="width:392px;height:auto"/></figure>



<p>「Minecraft Pi」はスタートメニューのゲームから起動できます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="500" src="https://sozorablog.com/wp-content/uploads/2026/01/スクリーンショット-2026-01-06-10.25.56.jpg" alt="" class="wp-image-16154" style="width:454px;height:auto"/></figure>



<p>Minecraft Pi EditionはPythonと連携できる点が特徴です。コードを書いてブロックを配置したり、ゲーム内の情報を取得したりできます。まずはゲームとして遊び、興味が出てきたらプログラミングにも踏み込める構成です。</p>



<h2 class="wp-block-heading">デモコードを応用して遊ぶ</h2>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="450" src="https://sozorablog.com/wp-content/uploads/2026/01/pico-1-1.jpg" alt="" class="wp-image-16140" style="width:708px;height:auto" srcset="https://sozorablog.com/wp-content/uploads/2026/01/pico-1-1.jpg 800w, https://sozorablog.com/wp-content/uploads/2026/01/pico-1-1-320x180.jpg 320w, https://sozorablog.com/wp-content/uploads/2026/01/pico-1-1-224x126.jpg 224w" sizes="(max-width: 800px) 100vw, 800px" /></figure>



<p>用意されているデモコードをそのまま動かすだけでなく、少し手を加えながら遊んでみます。</p>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>コードを組み合わせることで、独自の使い方を生み出すのが電子工作の醍醐味です。</p>
</div></div>



<p>ここでは、カメラで顔を検出し、その結果を複数の表示デバイスに同時に出す構成を試しました。</p>



<h3 class="wp-block-heading">顔認識した結果を表示デバイスで可視化</h3>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="365" src="https://sozorablog.com/wp-content/uploads/2025/09/pico-29-1.jpg" alt="" class="wp-image-15813" style="width:581px;height:auto"/></figure>



<p>以下のコマンドをターミナルで実行して、PythonからOpenCVという画像処理ライブラリを使えるようにします。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo apt install python3-opencv</code></pre></div>



<p>OpenCVで顔認識などを行うための<strong> </strong>学習済みデータ一式をインストールします。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo apt install -y opencv-data</code></pre></div>



<p>以下のプログラムはカメラ映像から顔を検出し、そのステータスを7セグメントLEDやLEDマトリクス、LCDに表示するものです。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>import cv2
import smbus
from ht16k33segment_python import HT16K33Segment
from luma.led_matrix.device import max7219
from luma.core.interface.serial import spi, noop
from luma.core.legacy import show_message
from luma.core.legacy.font import proportional, CP437_FONT
import HD44780MCP
import MCP230XX
import threading
import time

# -----------------------------
# Haar Cascade configuration
# -----------------------------
HAAR_FILE = &quot;/usr/share/opencv4/haarcascades/haarcascade_frontalface_default.xml&quot;
cascade = cv2.CascadeClassifier(HAAR_FILE)

if cascade.empty():
    raise RuntimeError(&quot;Failed to load Haar Cascade XML file&quot;)

# -----------------------------
# 7-segment display (HT16K33) configuration
# -----------------------------
i2c = smbus.SMBus(1)
led = HT16K33Segment(i2c)
led.set_brightness(10)

# Initialize MCP
i2cAddr = 0x21
MCP = MCP230XX.MCP230XX(&#39;MCP23008&#39;, i2cAddr)

# Backlight ON
blPin = 7
MCP.set_mode(blPin, &#39;output&#39;)
MCP.output(blPin, True)

# Initialize LCD (16x2)
LCD = HD44780MCP.HD44780(MCP, 1, -1, 2, [3,4,5,6], rows = 2, characters = 16, mode = 0, font = 0)

LCD.clear_display()
LCD.cursor(False)

def display_count(value):
    &quot;&quot;&quot;Display a count value (0?9999) on the 7-segment LED.&quot;&quot;&quot;
    value = max(0, min(9999, value))
    bcd = int(str(value), 16)

    led.set_number((bcd & 0xF000) &gt;&gt; 12, 0)
    led.set_number((bcd & 0x0F00) &gt;&gt; 8, 1)
    led.set_number((bcd & 0x00F0) &gt;&gt; 4, 2)
    led.set_number((bcd & 0x000F), 3)
    led.update()
    
def show_detect_message():
    &quot;&quot;&quot;Show &#39;detect&#39; message on MAX7219 LED matrix.&quot;&quot;&quot;
    serial = spi(port=0, device=1, gpio=noop())
    device = max7219(
        serial,
        cascaded=1,
        block_orientation=90,
        rotate=0
    )

    show_message(
        device,
        &quot;detect&quot;,
        fill=&quot;white&quot;,
        font=proportional(CP437_FONT),
        scroll_delay=0.05
    )    

def lcd_show_detect():
    LCD.clear_display()
    LCD.set_cursor(0, 0)
    LCD.display_string(&quot;detect!&quot;)

# -----------------------------
# Camera configuration
# -----------------------------
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*&#39;MJPG&#39;))
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 800)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 600)

detect_count = 0
prev_detected = False
lcd_active = False

cooldown_frames = 20
cooldown_counter = 0

display_count(detect_count)

# -----------------------------
# Main loop
# -----------------------------
while True:
    ret, frame = cap.read()
    if not ret:
        break

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    faces = cascade.detectMultiScale(
        gray,
        scaleFactor=1.2,
        minNeighbors=5,
        minSize=(80, 80)
    )

    detected = len(faces) &gt; 0

    # Case 1: detection starts (False -&gt; True) and cooldown is over
    if detected and not prev_detected and cooldown_counter == 0:
        detect_count += 1
        display_count(detect_count)     # 7-segment update
        lcd_show_detect()               # LCD update
        #lcd_active = True
        # Run MAX7219 message in a separate thread
        threading.Thread(
            target=show_detect_message,
            daemon=True
        ).start()            

    # Case 2: detection ends (True -&gt; False), start cooldown
    if not detected and prev_detected:
        cooldown_counter = cooldown_frames
        
    if cooldown_counter == 0 and not detected:
        LCD.clear_display()
        #lcd_active = False        

    # Decrease cooldown after detection has ended
    if cooldown_counter &gt; 0:
        cooldown_counter -= 1

    prev_detected = detected

    for (x, y, w, h) in faces:
        cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 2)

    cv2.imshow(&quot;Face Detection Counter&quot;, frame)

    if cv2.waitKey(1) & 0xFF == ord(&quot;q&quot;):
        break

# -----------------------------
# Cleanup
# -----------------------------
cap.release()
cv2.destroyAllWindows()
led.clear()
led.update()
</code></pre></div>



<p>コードを実行するとウィンドウにはカメラ映像が映し出され、検出された顔には赤い枠が描画されます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="450" src="https://sozorablog.com/wp-content/uploads/2026/01/pico.jpg" alt="" class="wp-image-16118" style="width:452px;height:auto" srcset="https://sozorablog.com/wp-content/uploads/2026/01/pico.jpg 800w, https://sozorablog.com/wp-content/uploads/2026/01/pico-320x180.jpg 320w, https://sozorablog.com/wp-content/uploads/2026/01/pico-224x126.jpg 224w" sizes="(max-width: 800px) 100vw, 800px" /></figure>



<p>顔が検出された回数を数え、その数値を7セグメントLEDに表示します。さらに、顔を検出した瞬間には、LCDに「detect!」という文字を表示し、LEDマトリクスには「detect」という文字が流れるようにしています。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="409" src="https://sozorablog.com/wp-content/uploads/2026/01/pico-1.jpg" alt="" class="wp-image-16139" style="width:800px;height:auto"/></figure>



<p>同じ顔を連続して検出した場合に回数が増えすぎないよう、少し待ち時間を入れる工夫もしています。</p>



<p>画像処理の結果を複数の表示方法で見せることで、「認識した情報をどう表現するか」まで踏み込めるのが面白い点です。デモコードを組み合わせることで、CrowPiを使った遊び方の幅が広がります。</p>



<h2 class="wp-block-heading">CrowPiはどんな人向けか</h2>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="3018" height="3175" src="https://sozorablog.com/wp-content/uploads/2026/01/IMG_0221.jpg" alt="" class="wp-image-16207" style="aspect-ratio:0.9505445929697999;width:452px;height:auto"/></figure>



<p>Raspberry Piや電子工作に興味はあるものの、</p>



<div class="wp-block-sbd-list"><ul class="sbd-list sbd-list-border"><li>何を買えばいいのか分からない</li><li>部品や配線の扱いが不安</li><li>プログラミングに自信がない</li></ul></div>



<p><br>といった理由で、これまで踏み出せなかった人に適しています。</p>



<p>ケースを開くと、何かすごいことができそうなワクワク感があり、実際に約20種類のパーツを手軽に動かすことができます。Raspberry Piの使い方に慣れるという意味でも有用です。</p>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>ただし、入門用としては<span class="sbd-text-red">価格が高め</span>なのは気になるところ。</p>
</div></div>



<p>パーツはあらかじめ固定されており、構成を自由に組み替えたり、発展させたりする余地は限られています。そのため、すでに電子工作に慣れていて、自分で部品を選び構成を考えたい人には向きません。</p>



<p>CrowPiはソフトウェアの設計やマニュアルのわかりやすさも含め、全体としてよく作り込まれている印象を受けました。コンセプトに惹かれる部分があれば、自分の用途に合うかを考えたうえで検討してみるとよいでしょう。</p>



<!-- START MoshimoAffiliateEasyLink -->
<script type="text/javascript">
(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;
b[a]=b[a]||function(){arguments.currentScript=c.currentScript
||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};
c.getElementById(a)||(d=c.createElement(f),d.src=g,
d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})
(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");
msmaflink({"n":"ELECROW Raspberry Pi 5 8GBキット用 Pi 5 8GB シングルボードコンピューター付き Crowpi Pi 5 ケースキット 9インチディスプレイ付き Raspberry Pi 5 ラーニングプログラミングキット(8GB RAM)対応","b":"Elecrow","t":"","d":"https:\/\/m.media-amazon.com","c_p":"\/images\/I","p":["\/410FwKdoR5L._SL500_.jpg","\/51SgAgmc4HL._SL500_.jpg","\/51ZjF8UoB8L._SL500_.jpg","\/51jroFvN0LL._SL500_.jpg","\/51feD1Y3g7L._SL500_.jpg","\/41LJlUjd2YL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0D4LPCKCF","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":1,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0D4LPCKCF","a_id":3038653,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"id":2,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/ELECROW%20Raspberry%20Pi%205%208GB%E3%82%AD%E3%83%83%E3%83%88%E7%94%A8%20Pi%205%208GB%20%E3%82%B7%E3%83%B3%E3%82%B0%E3%83%AB%E3%83%9C%E3%83%BC%E3%83%89%E3%82%B3%E3%83%B3%E3%83%94%E3%83%A5%E3%83%BC%E3%82%BF%E3%83%BC%E4%BB%98%E3%81%8D%20Crowpi%20Pi%205%20%E3%82%B1%E3%83%BC%E3%82%B9%E3%82%AD%E3%83%83%E3%83%88%209%E3%82%A4%E3%83%B3%E3%83%81%E3%83%87%E3%82%A3%E3%82%B9%E3%83%97%E3%83%AC%E3%82%A4%E4%BB%98%E3%81%8D%20Raspberry%20Pi%205%20%E3%83%A9%E3%83%BC%E3%83%8B%E3%83%B3%E3%82%B0%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0%E3%82%AD%E3%83%83%E3%83%88(8GB%20RAM)%E5%AF%BE%E5%BF%9C\/","a_id":3038654,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":2}],"eid":"U496C","s":"s"});
</script>
<div id="msmaflink-U496C">リンク</div>
<!-- MoshimoAffiliateEasyLink END -->



<p><br><br><br><br></p>
]]></content:encoded>
					
					<wfw:commentRss>https://sozorablog.com/crowpi/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>光るキーボード＆SSD搭載！Raspberry Pi 500+ を徹底検証</title>
		<link>https://sozorablog.com/raspberry-pi-500-plus/</link>
					<comments>https://sozorablog.com/raspberry-pi-500-plus/#respond</comments>
		
		<dc:creator><![CDATA[そぞら]]></dc:creator>
		<pubDate>Thu, 25 Sep 2025 07:19:56 +0000</pubDate>
				<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[ラズパイを買う]]></category>
		<guid isPermaLink="false">https://sozorablog.com/?p=15757</guid>

					<description><![CDATA[Raspberry Piとキーボードが一体になったRaspberry Pi 500に上位モデルが登場しました。NVMe SSDと光るメカニカルキーボードを備えたプレミアム仕様のRaspberry Pi 500+です。 1 [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p><a href="https://sozorablog.com/raspberry-pi/">Raspberry Pi</a>とキーボードが一体になった<a href="https://sozorablog.com/raspberry-pi-500/">Raspberry Pi 500</a>に上位モデルが登場しました<strong>。</strong>NVMe SSDと光るメカニカルキーボードを備えたプレミアム仕様の<span class="sbd-text-red">Raspberry Pi 500+</span>です。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="600" src="https://sozorablog.com/wp-content/uploads/2025/09/IMG_9710.jpeg" alt="" class="wp-image-15776"/><figcaption class="wp-element-caption">Raspberry Pi 500+（UK配列キーボード版）</figcaption></figure>



<p><span class="sbd-text-red">16GB RAM</span>を搭載したことで、複雑なタスクも快適にこなせます。<span class="sbd-text-red">標準装備のNVMe SSD</span>により起動やデータアクセスは高速化され、光るキーボードは点灯パターンの変更やプログラミングによるカスタマイズにも対応。Raspberry Pi シリーズに新たな魅力を加える存在となっています。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="280" height="200" src="https://sozorablog.com/wp-content/uploads/2025/09/Videotogif-2-2.gif" alt="" class="wp-image-15912"/><figcaption class="wp-element-caption">ショートカットキーで点灯のオンオフや切替が可能</figcaption></figure>



<p>本記事ではRaspberry Pi 500との違いを探りつつ、SSDの快適さやLEDキーボードのカスタマイズ性を中心にレビューしていきます。</p>



<div class="wp-block-sbd-checkpoint-block"><p class="sbd-checkpoint-title">チェックポイント</p><div class="sbd-checkpoint-content sbd-inner-block-init"><p>日本語版キーボードの国内での発売は準備ができ次第とのことです。今回の検証には、<a href="https://www.raspberrypi.com/">Raspberry Pi Ltd</a>様より提供いただいたRaspberry Pi 500+（<strong>UK配列キーボード版</strong>）を使用しています。技適特例申請を行ったうえで検証をしました。</p></div></div>



<h2 class="wp-block-heading">Raspberry Pi 500+の基本構成</h2>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="597" src="https://sozorablog.com/wp-content/uploads/2025/09/IMG_9668.jpeg" alt="" class="wp-image-15884"/><figcaption class="wp-element-caption">Raspberry Pi 500+（UK配列キーボード版）のパッケージ</figcaption></figure>



<p>Raspberry Pi 500+ の進化は、従来モデルのRaspberry Pi 500と比較するとわかりやすいです。ここでは、両者の仕様を比較しながら、その特徴と強化されたポイントを見ていきます。</p>



<h3 class="wp-block-heading">Raspberry Pi 500との比較</h3>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="662" src="https://sozorablog.com/wp-content/uploads/2025/09/pico-27.jpg" alt="" class="wp-image-15872" style="width:474px;height:auto"/></figure>



<figure class="wp-block-table wp-block-sbd-table wp-block-sbd-table-vertical"><table><thead><tr><th></th><th>Raspberry Pi 500+</th><th><a href="https://sozorablog.com/raspberry-pi-500/">Raspberry Pi 500</a></th></tr></thead><tbody><tr><td>SoC</td><td>Broadcom BCM2712</td><td>Broadcom BCM2712</td></tr><tr><td>CPU</td><td>Cortex-A76(ARM v8) 64-bit SoC @ 2.4GHz × 4</td><td>Cortex-A76(ARM v8) 64-bit SoC @ 2.4GHz × 4</td></tr><tr><td>メモリ</td><td><span class="sbd-table-bg-circle">16GB</span></td><td>8GB</td></tr><tr><td>ストレージ</td><td><span class="sbd-table-bg-circle">256GB NVMe SSD <br>＋ microSD スロット</span></td><td>microSD スロットのみ</td></tr><tr><td>有線LAN</td><td>1000 Base-T</td><td>1000 Base-T</td></tr><tr><td>無線LAN</td><td>IEEE 802.11b/g/n/ac</td><td>IEEE 802.11b/g/n/ac</td></tr><tr><td>Bluetooth</td><td>Bluetooth 5.0</td><td>Bluetooth 5.0</td></tr><tr><td>サイズ</td><td>312 × 123.06 × 35.76 mm</td><td>286 × 122 × 23mm</td></tr><tr><td>重量</td><td>613g</td><td>377g</td></tr><tr><td>生産国</td><td>イギリス</td><td>イギリス</td></tr><tr><td>価格</td><td><a href="https://www.switch-science.com/products/10696">スイッチサイエンス</a>：¥39,600</td><td><a href="https://raspberry-pi.ksyic.com/main/index/pdp.id/1156/pdp.open/1156/">KSY</a>：¥17,600<br><a href="https://akizukidenshi.com/catalog/g/g130200/">秋月電子</a>：¥17,800<br><a href="https://www.switch-science.com/products/10054">スイッチサイエンス</a>：¥18,480</td></tr></tbody></table></figure>



<p>Raspberry Pi 500+は、16GB RAM と <a href="https://www.raspberrypi.com/products/ssd/">256GB  Raspberry Pi SSD</a>、そしてLED付きのメカニカルキーボードを搭載した上位モデルです。CPUはシリーズ最上位である<a href="https://sozorablog.com/pi5/">Raspberry Pi 5</a>と同等の性能を持ち、日常利用から開発用途まで幅広く対応できます。<a href="https://sozorablog.com/raspberry-pi-500/">Raspberry Pi 500</a>と比べると本体サイズがやや大きく、重量も増しています。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="236" src="https://sozorablog.com/wp-content/uploads/2025/08/image.png" alt="" class="wp-image-15559" style="width:840px;height:auto"/><figcaption class="wp-element-caption">出典：<a href="https://datasheets.raspberrypi.com/pi500/raspberry-pi-500-product-brief.pdf">Raspberry Pi 500 Product Brief</a>より引用</figcaption></figure>



<p>キーボード背面のインターフェースはRaspberry Pi 500と同じ構成です。SSD搭載で使用頻度は少ないかもしれませんが、microSDカードスロットも備えています。<a href="https://sozorablog.com/gpio_pinout/">GPIO端子</a>も搭載されており、LEDやセンサーなどの電子工作パーツを直接接続できます。</p>



<h3 class="wp-block-heading"><span class="sbd-table-bg-double-circle">256GB NVMe SSD</span>搭載</h3>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="615" src="https://sozorablog.com/wp-content/uploads/2025/09/IMG_9738.jpeg" alt="" class="wp-image-15840"/><figcaption class="wp-element-caption">本体内部に搭載されたNVMe SSD</figcaption></figure>



<p>NVMe SSDにはRaspberry Pi OSがインストールされているため、起動時にはそれを読み込んで動作します。NVMe SSDは、一般的なRaspberry Piで使われるmicroSDと比べて次のような利点があります。</p>



<div class="wp-block-sbd-list"><ul class="sbd-list sbd-list-border"><li>大容量で多くのデータを保存できる</li><li>読み書きが高速</li><li>耐久性が高く長期間の使用に強い</li></ul></div>



<p>さらに、付属のヘラ状の工具を使って本体を上下に分割すれば、SSDを交換して容量を増やすことも可能です。</p>



<h3 class="wp-block-heading">光るメカニカルキーボード</h3>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="450" src="https://sozorablog.com/wp-content/uploads/2025/09/pico-25.jpg" alt="" class="wp-image-15846" srcset="https://sozorablog.com/wp-content/uploads/2025/09/pico-25.jpg 800w, https://sozorablog.com/wp-content/uploads/2025/09/pico-25-320x180.jpg 320w, https://sozorablog.com/wp-content/uploads/2025/09/pico-25-224x126.jpg 224w" sizes="(max-width: 800px) 100vw, 800px" /><figcaption class="wp-element-caption">Raspberry Pi 500とのキーの高さの比較</figcaption></figure>



<p>キーボードには<a href="https://www.gateron.co/products/gateron-low-profile-mechanical-switch-set">Gateron Blue KS-33<strong> </strong>Low Profile</a>が採用されており、カチッとしたクリック感のある打鍵を楽しめます。キーには高さがあり、ストロークも大きめなので、しっかりとした操作感を得られるのが特徴です。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="378" src="https://sozorablog.com/wp-content/uploads/2025/09/pico-29-3.jpg" alt="" class="wp-image-15830"/><figcaption class="wp-element-caption">交換可能なキーキャップ</figcaption></figure>



<p>キーキャップを外すための工具も付属しており、標準のキーキャップから好きなデザインのものに交換もできます。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="691" src="https://sozorablog.com/wp-content/uploads/2025/09/IMG_9705.jpeg" alt="" class="wp-image-15775"/></figure>



<p>さらに、キーの下には鮮やかに発光するフルカラーLEDが内蔵されており、その制御には<a href="https://sozorablog.com/raspberry-pi-pico/">Raspberry Pi Pico</a>にも搭載されているマイクロコントローラチップの<a href="https://www.raspberrypi.com/products/rp2040/">RP2040</a>が使われています。あらかじめ用意された6パターンの点灯モードに加え、自分で<span class="sbd-text-red">プログラミングして色や光り方を変えられる</span>ため、電子工作でおなじみの RGB LED 制御をキーボード上で体験できる点も大きな魅力です。</p>



<h2 class="wp-block-heading">Raspberry Pi 500+を分解</h2>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="626" src="https://sozorablog.com/wp-content/uploads/2025/09/IMG_9735.jpeg" alt="" class="wp-image-15833"/></figure>



<p>Raspberry Pi 500+の内部構造を確かめるため、分解して中身をチェックしてみました。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="602" src="https://sozorablog.com/wp-content/uploads/2025/09/IMG_9742.jpeg" alt="" class="wp-image-15836" style="width:417px;height:auto"/></figure>



<p>はじめに、キーボード裏側にある5カ所のネジをドライバーで外します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="759" src="https://sozorablog.com/wp-content/uploads/2025/09/IMG_9731.jpeg" alt="" class="wp-image-15834" style="width:415px;height:auto"/></figure>



<p>本体に付属しているプラスチック製のヘラで周囲のツメを外します。</p>



<h3 class="wp-block-heading">ファンレスで高性能を実現するヒートシンク</h3>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="602" src="https://sozorablog.com/wp-content/uploads/2025/09/IMG_9734.jpeg" alt="" class="wp-image-15835"/></figure>



<p>中を開けるとキーボードとメイン基板がリボンケーブルで接続されているので、そこも外します。基板の上には、大きな金属製のプレートが取り付けられていて、これが<span class="sbd-text-red">ヒートシンクとして機能</span>しています。</p>



<div class="wp-block-sbd-background-block sbd-bg-color sbd-inner-block-init is-style-yellow">
<p>ヒートシンクの冷却性能については、以下の記事で検証を行っています。<br><strong><a href="https://sozorablog.com/raspberry-pi-500/">≫ Raspberry Pi 500【レビュー】分解で見えた秘密と活用アイデア</a></strong></p>
</div>



<p>このヒートシンクはRaspberry Pi財団が特に設計に注力した部分であり、<span class="sbd-text-red">冷却ファンなしでも高い性能を発揮</span>します。高負荷の作業でも安定した動作が期待でき、静音性にも優れている点が大きな魅力です。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="715" src="https://sozorablog.com/wp-content/uploads/2025/09/pico-24.jpg" alt="" class="wp-image-15839" style="width:452px;height:auto"/></figure>



<p>キーボード側の基板には<a href="https://sozorablog.com/raspberry-pi-pico/">Raspberry Pi Pico</a>にも搭載されているマイコンチップの<a href="https://www.raspberrypi.com/products/rp2040/">RP2040</a>が実装されています。</p>



<h3 class="wp-block-heading">メイン基板に搭載されたNVMe SSD</h3>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="584" src="https://sozorablog.com/wp-content/uploads/2025/09/IMG_9739.jpeg" alt="" class="wp-image-15838"/></figure>



<p>メイン基板はキーボード接続部とNVMe SSDを除けばRaspberry Pi 500とほぼ同じ構造です。基板の右側には、Raspberry Piのロゴが印字された公式ブランドの<a href="https://www.raspberrypi.com/products/ssd/">Raspberry Pi SSD</a>が搭載されています。</p>



<p>基板には「2242」「2260」「2280」といったサイズ表記のスロット位置が刻まれています。標準で装着されているのは短い「2230」サイズですが、基板の穴位置を利用すれば、より長いタイプのSSDも取り付け可能です。</p>



<h2 class="wp-block-heading">Raspberry Pi 500+を起動</h2>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="771" src="https://sozorablog.com/wp-content/uploads/2025/09/pico-26-1.jpg" alt="" class="wp-image-15866" style="width:453px;height:auto"/></figure>



<p>起動にあたり周辺機器を準備します。</p>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>マウスやケーブル、電源は付属していません。</p>
</div></div>



<p>まずマウスをUSBポートに接続し、micro HDMIケーブルでモニターとつなぎます。HDMIポートは2つありますが、背面から見て左側の「HDMI 0」に接続するのが基本です。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="350" height="200" src="https://sozorablog.com/wp-content/uploads/2025/09/Videotogif-3-1.gif" alt="" class="wp-image-15888"/><figcaption class="wp-element-caption">起動時のLEDアニメーション</figcaption></figure>



<p>別売りの<a href="https://www.switch-science.com/products/9811">電源ACアダプター</a>をUSB Type-Cポートに差し込むと、自動で電源が入り起動が始まります。</p>



<h3 class="wp-block-heading">OSインストール不要ですぐに使える</h3>



<p>Raspberry Pi 500+は、必要な機器を接続すればすぐに使い始められます。内蔵のNVMe SSDには<span class="sbd-text-red">Raspberry Pi OSがプリインストールされており</span>、起動から初期設定まで迷うことなく進められます。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="756" src="https://sozorablog.com/wp-content/uploads/2025/09/IMG_9686.jpeg" alt="" class="wp-image-15779"/></figure>



<p>起動すると、Raspberry Pi OSの初期設定ウィザードが立ち上がります。言語や地域、Wi-Fiの接続、ユーザー名の設定などを順に進めていきます。必要に応じて画面の表示調整やOSアップデートも行いますが、画面の指示に従えば問題ありません。</p>



<div class="wp-block-sbd-background-block sbd-bg-color sbd-inner-block-init is-style-yellow">
<p>Raspberry Pi OSの設定方法は、以下の記事で詳しく解説しています。<br><strong><a href="https://sozorablog.com/raspberrypi_initial_setting/">≫【2025年最新版】OSインストールから初期設定まで｜セットアップ手順のすべて</a></strong></p>
</div>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="450" src="https://sozorablog.com/wp-content/uploads/2025/08/image-1.jpg" alt="" class="wp-image-15562" srcset="https://sozorablog.com/wp-content/uploads/2025/08/image-1.jpg 800w, https://sozorablog.com/wp-content/uploads/2025/08/image-1-320x180.jpg 320w, https://sozorablog.com/wp-content/uploads/2025/08/image-1-224x126.jpg 224w" sizes="(max-width: 800px) 100vw, 800px" /><figcaption class="wp-element-caption">Raspberry Pi OSのデスクトップ画面</figcaption></figure>



<p>初期設定が終わるとデスクトップ画面が表示され、すぐにブラウザを使ったり、Pythonでプログラミングを始めたりできます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="583" height="507" src="https://sozorablog.com/wp-content/uploads/2025/08/image-1.png" alt="" class="wp-image-15587" style="width:473px;height:auto"/><figcaption class="wp-element-caption">豊富なアプリケーションが入っている</figcaption></figure>



<h3 class="wp-block-heading">起動時間の比較</h3>



<p>Raspberry Pi 500 と 500+ の起動時間を実際に計測すると、500は25秒、500+は<span class="sbd-text-red">22秒</span>でした。差は3秒ほどで、大きく体感できるほどではありません。</p>



<figure class="wp-block-table wp-block-sbd-table wp-block-sbd-table-horizontal"><table><tbody><tr><td>モデル名</td><td>起動時間</td></tr><tr><td>Raspberry Pi 500</td><td>25秒</td></tr><tr><td>Raspberry Pi 500+</td><td>22秒</td></tr></tbody></table></figure>



<p>ただし、500+にはNVMe SSDが搭載されており、ストレージアクセスの安定性や信頼性、耐久性の面ではmicroSDよりも優れています。起動時間そのものの差は小さいものの、日常的に使用するうえで<span class="sbd-text-red">信頼できるストレージ</span>を使える安心感があります。</p>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>私の経験上、Raspberry Piが起動しなくなる原因の多くは、microSDの書き込み回数による寿命に起因していました。</p>
</div></div>



<h2 class="wp-block-heading">変更可能なLEDライトの点灯パターン</h2>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="507" src="https://sozorablog.com/wp-content/uploads/2025/09/IMG_9704.jpeg" alt="" class="wp-image-15811"/></figure>



<p>Raspberry Pi 500+ の大きな特長のひとつが、キーボードに内蔵されたLEDイルミネーションです。光り方を切り替えたり、好みに合わせてカスタマイズしたりできるので、学習や作業だけでなく「遊び心」をプラスできます。</p>



<h3 class="wp-block-heading">Fn+F4キーで切り替え</h3>



<p>出荷時点で <strong>8種類のプリセット（0〜7）</strong> が用意されており、<strong>Fn+F4キーを押すことで順番に切り替え可能</strong>です。プリセットには単色点灯やグラデーション、アニメーション効果などが含まれていて、本体を再起動しても最後に選んだ設定が自動で復元されます。</p>



<figure class="wp-block-table wp-block-sbd-table wp-block-sbd-table-horizontal"><table><tbody><tr><td>プリセット番号</td><td>特徴</td></tr><tr><td>0</td><td>消灯（電源ボタンのみ点灯）</td></tr><tr><td>1</td><td>すべてのキーが白色に点灯</td></tr><tr><td>2</td><td>すべてのキーが赤色に点灯</td></tr><tr><td>3</td><td>すべてのキーがレインボーのグラデーションカラーに点灯（固定）</td></tr><tr><td>4</td><td>レインボーカラーの回転アニメーション</td></tr><tr><td>5</td><td>押したキーが青色に点灯。連打すると周囲のLEDも点灯し色が変化</td></tr><tr><td>6</td><td>押したキーが赤色に点灯。</td></tr><tr><td>7</td><td>一時的なエフェクトが保存される特別枠。再起動で消える<br><span class="sbd-text-red">Fn+F4の切り替えサイクルではスキップされる</span></td></tr></tbody></table></figure>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="1067" src="https://sozorablog.com/wp-content/uploads/2025/09/IMG_9685.jpeg" alt="" class="wp-image-15778" style="width:451px;height:auto"/><figcaption class="wp-element-caption">どのプリセットでも常時点灯する電源ボタン</figcaption></figure>



<p>右上の電源ボタンのキーは、どのプリセットでも緑色に点灯します。電源を切ると赤に変わり、従来の Raspberry Pi に搭載されていたステータス LED の役割を担っているようです。</p>



<h3 class="wp-block-heading">コマンドやPythonで自在にLEDを制御</h3>



<p>キーボードの光り方を自由に変えるには、追加のソフトをインストールする必要があります。まずターミナルを開きます。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="365" src="https://sozorablog.com/wp-content/uploads/2025/09/pico-29-1.jpg" alt="" class="wp-image-15813"/></figure>



<p>下記のコマンドをターミナルに入力してEnterキーを押します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo apt install rpi-keyboard-config</code></pre></div>



<p>これでキーボードのLEDやキー設定を変更できるソフトがインストールされます。</p>



<h4 class="wp-block-heading">コマンドでLEDを操作</h4>



<p>インストール後はターミナルからLEDを直接操作可能です。全体を赤にするには以下のコマンドを実行します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>rpi-keyboard-config leds set --colour red  </code></pre></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="871" src="https://sozorablog.com/wp-content/uploads/2025/09/IMG_9703.jpeg" alt="" class="wp-image-15774" style="width:453px;height:auto"/></figure>



<p>LED操作に関する主なコマンドを以下に示します。</p>



<figure class="wp-block-table wp-block-sbd-table wp-block-sbd-table-horizontal"><table class="has-fixed-layout"><tbody><tr><td>コマンド</td><td>内容</td><td class="has-text-align-left" data-align="left">使用例</td></tr><tr><td>rpi-keyboard-config preset index &lt;番号&gt;</td><td>特定のプリセットに切り替える</td><td class="has-text-align-left" data-align="left">rpi-keyboard-config preset index 2<br>(プリセット2に切り替え)</td></tr><tr><td>rpi-keyboard-config leds set &#8211;colour &lt;色&gt;</td><td>キーボード全体を指定した色に点灯</td><td class="has-text-align-left" data-align="left"><code>--colour red</code>（赤）<br><code>--colour "#FF0000"</code>（RGB指定）<br><code>--colour "128,255,255"</code>（HSV指定）</td></tr><tr><td>rpi-keyboard-config led set &lt;番号&gt; &#8211;colour &lt;色&gt;</td><td>指定したLEDを個別に光らせる（番号指定）</td><td class="has-text-align-left" data-align="left"><code>led set 5 --colour blue</code><br>（LED5を青）</td></tr><tr><td>rpi-keyboard-config led set &lt;行&gt;,&lt;列&gt; &#8211;colour &lt;色&gt;</td><td>指定したキーの位置を光らせる（行・列指定）</td><td class="has-text-align-left" data-align="left"><code>led set 2,3 --colour green</code><br>（[2,3]のキーを緑）</td></tr><tr><td>rpi-keyboard-config leds clear</td><td>すべてのLEDを消灯する</td><td class="has-text-align-left" data-align="left">－</td></tr></tbody></table></figure>



<h4 class="wp-block-heading">光るキーボードでゲームもできる</h4>



<p>Raspberry Pi 500+ のLEDキーボードには、ミニゲームとして「Flappy Bird」が用意されています。ターミナルで以下のコマンドを実行したあと、「ESCキー」と「ENTERキー」を同時に押し続け、カウントが0になるまで待ちます。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>rpi-keyboard-config game</code></pre></div>



<p>するとキーボードがアンロックされ、ゲームがスタートします。キーボード全体のLEDが画面のように光り、鳥や障害物が光の点で表示されます。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="536" src="https://sozorablog.com/wp-content/uploads/2025/09/IMG_9723.jpeg" alt="" class="wp-image-15814"/></figure>



<p>操作はスペースキーを押して鳥（緑色のLEDで表示）をジャンプさせるだけです。水色のパイプを避けながら進むと、スコアが最上段のキーに表示されます。シンプルなゲームですが、LEDとキーボードだけでゲームが作れることに可能性を感じます。</p>



<h4 class="wp-block-heading">PythonでLEDを操作</h4>



<figure class="wp-block-image size-full"><img decoding="async" width="645" height="446" src="https://sozorablog.com/wp-content/uploads/2025/09/IMG_9726.jpeg" alt="" class="wp-image-15816"/><figcaption class="wp-element-caption">ピンク色で数字の「2」を表現</figcaption></figure>



<p>プログラミング言語Pythonを使って、LEDを操作することもできます。Thonnyというソフトでプログラムを書き、実際に動かしてみましょう。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="556" src="https://sozorablog.com/wp-content/uploads/2025/09/pico-29-2.jpg" alt="" class="wp-image-15817" style="width:430px;height:auto"/><figcaption class="wp-element-caption">Thonnyの起動</figcaption></figure>



<p>Thonnyでは画面上部の大きな白いスペースにプログラムを入力し、「▶（再生マーク）」をクリックすることで実行できます。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="639" height="234" src="https://sozorablog.com/wp-content/uploads/2025/09/image-2.png" alt="" class="wp-image-15818"/></figure>



<p>以下はLEDキーボードで特定のキー位置を指定して光らせるコードです。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>from RPiKeyboardConfig import RPiKeyboardConfig

# キーボード制御を初期化
keyboard = RPiKeyboardConfig()

# LEDを直接制御するモードに切り替え
keyboard.set_led_direct_effect()

# 行0・列0のLEDを「ピンク」で点灯（Hue=213）
keyboard.set_led_by_matrix(matrix=[0, 0], colour=(213, 255, 255))

# 設定を反映して実際に光らせる
keyboard.send_leds()
</code></pre></div>



<p>keyboard.set_led_by_matrix(matrix=[0, 0], colour=(213, 255, 255))で、光らせる位置と色を指定します。<code>matrix=[0, 0]</code> はキーボードの一番左上のキーを意味します。たとえば <code>[1, 3]</code> にすると「上から2行目・左から4列目」にあるキーが光る仕組みです。</p>



<p>ただし、すべての座標にLEDがあるわけではなく、行や列によっては「抜けている」場所があります。指定した座標にLEDが存在しない場合はエラーになります。ターミナルで「rpi-keyboard-config leds get」を実行するとLEDの番号と対応する行・列の座標が一覧表示され、実際に指定できる位置を確認できます。</p>



<p><code>colour=(213, 255, 255)</code> は、光の色をHSVという形式で指定しています。</p>



<div class="wp-block-sbd-list"><ul class="sbd-list sbd-list-border"><li>最初の <strong>213</strong> は「色合い」を決める値で、213ではピンク寄りの色。0 にすると赤、42 前後で黄色、85 なら緑、170 で青といったように数値を変えることでさまざまな色に変更可能</li><li>次の <strong>255</strong> は「鮮やかさ（彩度）」を表し、255 が最もはっきりした色</li><li>最後の <strong>255</strong> は「明るさ（輝度）」で、最大値に設定されているため明るく光る</li></ul></div>



<p>最後に <code>keyboard.send_leds()</code> を実行すると、指定した内容が反映されて、LEDが実際に光ります。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="730" src="https://sozorablog.com/wp-content/uploads/2025/09/IMG_9727.jpeg" alt="" class="wp-image-15820" style="width:395px;height:auto"/></figure>



<h3 class="wp-block-heading">LEDキーボードで時刻を表示してみた</h3>



<p>LEDを自由に制御できるとなると、文字を表示してみたくなるものです。以下のコードではLEDキーボードを使って、時刻をスクロール表示する仕組みを作ってみました。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>import time
from RPiKeyboardConfig import RPiKeyboardConfig

font_5x4 = {
    &quot;0&quot;: [&quot;0110&quot;,&quot;1001&quot;,&quot;1001&quot;,&quot;1001&quot;,&quot;0100&quot;],
    &quot;1&quot;: [&quot;0010&quot;,&quot;0010&quot;,&quot;0010&quot;,&quot;0010&quot;,&quot;0010&quot;],
    &quot;2&quot;: [&quot;0110&quot;,&quot;1001&quot;,&quot;0010&quot;,&quot;0100&quot;,&quot;1111&quot;],
    &quot;3&quot;: [&quot;1110&quot;,&quot;0001&quot;,&quot;0110&quot;,&quot;0001&quot;,&quot;1110&quot;],
    &quot;4&quot;: [&quot;1001&quot;,&quot;1001&quot;,&quot;1111&quot;,&quot;0001&quot;,&quot;0001&quot;],
    &quot;5&quot;: [&quot;1111&quot;,&quot;1000&quot;,&quot;1110&quot;,&quot;0001&quot;,&quot;1110&quot;],
    &quot;6&quot;: [&quot;0111&quot;,&quot;1000&quot;,&quot;1110&quot;,&quot;1001&quot;,&quot;0110&quot;],
    &quot;7&quot;: [&quot;1111&quot;,&quot;0001&quot;,&quot;0010&quot;,&quot;0100&quot;,&quot;0100&quot;],
    &quot;8&quot;: [&quot;0110&quot;,&quot;1001&quot;,&quot;0110&quot;,&quot;1001&quot;,&quot;0110&quot;],
    &quot;9&quot;: [&quot;0110&quot;,&quot;1001&quot;,&quot;0111&quot;,&quot;0001&quot;,&quot;1110&quot;],
    &quot;:&quot;: [&quot;000&quot;,&quot;010&quot;,&quot;000&quot;,&quot;010&quot;,&quot;000&quot;],
}

keyboard = RPiKeyboardConfig()
keyboard.set_led_direct_effect()

current_brightness = keyboard.get_brightness()
print(f&quot;Current brightness: {current_brightness}&quot;)

rows = 5
max_col = 16
scroll_area_cols = 16

def build_message(numbers, space=1):
    message = [&quot;&quot;] * rows
    for num in numbers:
        digit = font_5x4[num]
        for r in range(rows):
            message[r] += digit[r] + &quot;0&quot; * space
    return message

while True:
    current_time = time.strftime(&quot;%H:%M&quot;).lstrip(&quot;0&quot;)
    message = build_message(current_time, space=2)
    msg_width = len(message[0])

    for shift in range(msg_width + scroll_area_cols):
        for r in range(rows):
            for c in range(scroll_area_cols):
                try:
                    keyboard.set_led_by_matrix(matrix=[r, c], colour=(0, 0, 0))
                except ValueError:
                    pass

        for r in range(rows):
            for c in range(scroll_area_cols):
                src_col = shift + c - scroll_area_cols
                if 0 &lt;= src_col &lt; msg_width:
                    if message[r][src_col] == &quot;1&quot;:
                        try:
                            keyboard.set_led_by_matrix(matrix=[r, c], colour=(213, 255, 255))
                        except ValueError:
                            pass

        keyboard.send_leds()
        time.sleep(0.15)</code></pre></div>



<p>数字を5×4のドットフォントとして定義し、それを組み合わせて現在時刻を「hh:mm」の形に変換します。はじめに文字列を作り、左から右へ少しずつずらして表示することで、文字が横に流れていくように見せています。存在しないLED座標を指定するとエラーになるため、例外処理を追加しました。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="350" height="200" src="https://sozorablog.com/wp-content/uploads/2025/09/Videotogif-3.gif" alt="" class="wp-image-15825"/><figcaption class="wp-element-caption">時刻「7:42」をスクロール表示</figcaption></figure>



<p>使えるドット数が限られており、キーの配置も不規則なため文字は見づらいですが、ギリギリ読める程度にはなったかな？と、自分的には満足です。</p>



<h2 class="wp-block-heading">GPIOピンに透明OLEDを接続</h2>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="539" src="https://sozorablog.com/wp-content/uploads/2025/09/IMG_9716.jpeg" alt="" class="wp-image-15796"/></figure>



<p>Raspberry Pi 500はキーボード一体型ながら、他のRaspberry Piと同様に<a href="https://sozorablog.com/gpio_pinout/">GPIO端子</a>を備えています。これにより、センサーやLEDといった電子パーツを接続して、電子工作やハードウェア制御の学習にも活用できます。</p>



<p>今回は<a href="https://sozorablog.com/pi-transparent-oled/">透明OLEDディスプレイ</a>を使って近未来的な時計表示を作成します。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="555" height="446" src="https://sozorablog.com/wp-content/uploads/2025/09/image-1.png" alt="" class="wp-image-15799"/></figure>



<p>ディスプレイのスタンドは<a href="https://sozorablog.com/ankermake-m5c/">3Dプリンター</a>で作成しました。</p>



<h3 class="wp-block-heading">Raspberry Piとディスプレイの配線</h3>



<p>Raspberry Pi 500+とディスプレイの接続は次のようになります。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="450" src="https://sozorablog.com/wp-content/uploads/2025/09/pico-29.jpg" alt="" class="wp-image-15789" srcset="https://sozorablog.com/wp-content/uploads/2025/09/pico-29.jpg 800w, https://sozorablog.com/wp-content/uploads/2025/09/pico-29-320x180.jpg 320w, https://sozorablog.com/wp-content/uploads/2025/09/pico-29-224x126.jpg 224w" sizes="(max-width: 800px) 100vw, 800px" /></figure>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="730" src="https://sozorablog.com/wp-content/uploads/2025/09/IMG_9719.jpeg" alt="" class="wp-image-15797" style="width:467px;height:auto"/></figure>



<h3 class="wp-block-heading">SPIを有効にする</h3>



<p>LCDを使うには、SPIインターフェースを有効にする必要があります。SPIはRaspberry Piとディスプレイがデータを通信するための仕組みです。</p>



<p>デスクトップ左上の「ラズベリーマーク（メニュー）」をクリックし、設定」→「Raspberry Piの設定」を選びます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="640" height="430" src="https://sozorablog.com/wp-content/uploads/2025/09/image.png" alt="" class="wp-image-15790" style="width:435px;height:auto"/></figure>



<p>「インターフェイス」タブを開き、「SPI」の項目を「有効」に切り替えます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-1.png" alt="" style="width:487px;height:auto"/><figcaption class="wp-element-caption">SPIが有効になっている状態</figcaption></figure>



<p>以下のコマンドで、日本語フォントの「Takaoフォント」をインストールしました。これはプログラムでディスプレイにテキストを表示するために必要です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo apt install -y fonts-takao</code></pre></div>



<h3 class="wp-block-heading">Pythonスクリプト</h3>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="579" src="https://sozorablog.com/wp-content/uploads/2025/09/IMG_9718.jpeg" alt="" class="wp-image-15794" style="width:427px;height:auto"/></figure>



<p>以下のプログラムは透明OLEDディスプレイに、現在の時刻と立体的に回転するピラミッドのアニメーションを表示するものです。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>import spidev
import lgpio
from PIL import Image, ImageDraw, ImageFont
from math import sin, cos, radians
import datetime
import time

spi = spidev.SpiDev()
spi.open(0, 0)
spi.max_speed_hz = 8000000

DC = 25
RESET = 27

h = lgpio.gpiochip_open(0)
lgpio.gpio_claim_output(h, DC)
lgpio.gpio_claim_output(h, RESET)

WIDTH = 128
HEIGHT = 64

def hardware_reset():
    lgpio.gpio_write(h, RESET, 0)
    time.sleep(0.05)
    lgpio.gpio_write(h, RESET, 1)
    time.sleep(0.05)

def send_cmd(cmd):
    lgpio.gpio_write(h, DC, 0)
    spi.writebytes([cmd])

def send_data(data):
    lgpio.gpio_write(h, DC, 1)
    spi.writebytes(data if isinstance(data, list) else [data])

def init_display():
    hardware_reset() 
    cmds = [
        0xAE, 0xD5, 0x80, 0xA8, 0x3F, 0xD3, 0x00,
        0x40, 0x8D, 0x14, 0x20, 0x00, 0xA1, 0xC8,
        0xDA, 0x12, 0x81, 0xCF, 0xD9, 0xF1, 0xDB,
        0x40, 0xA4, 0xA6, 0xAF
    ]
    for cmd in cmds:
        send_cmd(cmd)

def set_addressing():
    send_cmd(0x21)
    send_cmd(0)
    send_cmd(WIDTH - 1)
    send_cmd(0x22)
    send_cmd(0)
    send_cmd((HEIGHT // 8) - 1)

def display_image(image):
    set_addressing()
    pixels = list(image.getdata())
    buffer = []
    for page in range(HEIGHT // 8):
        for x in range(WIDTH):
            byte = 0
            for bit in range(8):
                pixel = pixels[x + (page * 8 + bit) * WIDTH]
                if pixel == 0:
                    byte |= (1 &lt;&lt; bit)
            buffer.append(byte)
    for b in buffer:
        send_data(b)

init_display()

font1 = ImageFont.truetype(&quot;/usr/share/fonts/truetype/takao-gothic/TakaoGothic.ttf&quot;, 12)
font2 = ImageFont.truetype(&quot;/usr/share/fonts/truetype/takao-gothic/TakaoGothic.ttf&quot;, 14)
font3 = ImageFont.truetype(&quot;/usr/share/fonts/truetype/takao-gothic/TakaoGothic.ttf&quot;, 24)

scale_factor = 0.7
x_offset = 25
X_CENTER = 64
Y_CENTER = 28
pyramid = ((0, -20, 0), (-20, 20, -20), (20, 20, -20), (0, 20, 20))

try:
    while True:
        for angle in range(0, 361, 10):
            dt_now = datetime.datetime.now()
            date1 = dt_now.strftime(&#39;%m/%d&#39;)
            weekday = dt_now.strftime(&#39;%a&#39;).upper()
            time1 = dt_now.strftime(&#39;%H:%M&#39;)
            second = dt_now.strftime(&#39;%S&#39;)

            f = [[0.0 for _ in range(3)] for _ in range(4)]
            r = radians(angle)

            for i in range(4):
                x1 = pyramid[i][2] * sin(r) + pyramid[i][0] * cos(r)
                ya = pyramid[i][1]
                z1 = pyramid[i][2] * cos(r) - pyramid[i][0] * sin(r)
                y2 = ya * cos(r) - z1 * sin(r)
                z2 = ya * sin(r) + z1 * cos(r)
                x3 = (x1 * cos(r) - y2 * sin(r)) * scale_factor + x_offset
                y3 = (x1 * sin(r) + y2 * cos(r)) * scale_factor + Y_CENTER
                f[i][0] = x3
                f[i][1] = y3

            image = Image.new(&quot;1&quot;, (WIDTH, HEIGHT), 255)
            draw = ImageDraw.Draw(image)

            for i in range(3):
                draw.line((f[0][0], f[0][1], f[i + 1][0], f[i + 1][1]), fill=0)
                draw.line((f[i + 1][0], f[i + 1][1], f[(i + 1) % 3 + 1][0], f[(i + 1) % 3 + 1][1]), fill=0)

            draw.text((55, 8), date1, font=font2, fill=0)
            draw.text((103, 8), weekday, font=font2, fill=0)
            draw.text((50, 29), time1, font=font3, fill=0)
            draw.text((114, 39), second, font=font1, fill=0)

            display_image(image)
            time.sleep(0.1)

except KeyboardInterrupt:
    pass


</code></pre></div>



<p>最初に必要なライブラリを読み込み、SPIを使ってディスプレイと通信できるように設定します。</p>



<p>描画部分では、年月日や曜日、時刻をフォントで表示するだけでなく、三角形を組み合わせたピラミッドの線を描き、角度を少しずつ変化させることで3Dアニメーションとして動かしています。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="785" src="https://sozorablog.com/wp-content/uploads/2025/09/IMG_9715.jpeg" alt="" class="wp-image-15798" style="width:427px;height:auto"/></figure>



<p>キーボードのLEDと組み合わせることで、さらに近未来的な雰囲気が際立ちました。</p>



<h2 class="wp-block-heading">まとめ</h2>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="825" src="https://sozorablog.com/wp-content/uploads/2025/09/IMG_9702.jpeg" alt="" class="wp-image-15773" style="width:483px;height:auto"/></figure>



<p>Raspberry Pi 500+ は、NVMe SSD搭載で安定性を高め、光るメカニカルキーボードによって「使用する喜び」を強く打ち出したプレミアムモデルです。起動時のLEDアニメーションは、電源を入れるたびにワクワクさせてくれます。さらに光り方をプログラムで変えられるため、書いたコードの成果がすぐに目に見える形で反映され、体験的な学びにつながります。</p>



<p>一方で、価格は39,600円と高めで、初心者が気軽に気軽に手に取れるモデルではありません。従来の「安価で気軽に使えるコンピュータ」というイメージから離れつつあるのも事実です。個人的には光るキーボードは大歓迎ですが、SSDはオプション扱いでも良かったのではと感じました。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="355" src="https://sozorablog.com/wp-content/uploads/2025/09/pico-26-2.jpg" alt="" class="wp-image-15906"/><figcaption class="wp-element-caption">直近で発売されたRaspberry Pi公式製品</figcaption></figure>



<p>総じて Raspberry Pi 500+ は、「手頃さ」よりも「体験価値」を重視する方向へシフトした象徴的なモデルといえます。<a href="https://sozorablog.com/pi5/">Raspberry Pi 5</a>の16GBモデルなども含め、シリーズ全体が高性能・高価格帯へと向かいつつあるのが最近の傾向です。Raspberry Pi が今後どのような進化を見せるのか、引き続き注目です。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sozorablog.com/raspberry-pi-500-plus/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Raspberry Pi 500【レビュー】分解で見えた秘密と活用アイデア</title>
		<link>https://sozorablog.com/raspberry-pi-500/</link>
					<comments>https://sozorablog.com/raspberry-pi-500/#respond</comments>
		
		<dc:creator><![CDATA[そぞら]]></dc:creator>
		<pubDate>Fri, 08 Aug 2025 22:32:56 +0000</pubDate>
				<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[ラズパイを買う]]></category>
		<guid isPermaLink="false">https://sozorablog.com/?p=15508</guid>

					<description><![CDATA[Raspberry Piといえば、小さな基板にケーブルをつないで使うというイメージを持っている人が多いかもしれません。そんなイメージを覆すように、最上位モデルのRaspberry Pi 5と同等のスペックを備えたキーボー [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p><a href="https://sozorablog.com/raspberry-pi/">Raspberry Pi</a>といえば、小さな基板にケーブルをつないで使うというイメージを持っている人が多いかもしれません。そんなイメージを覆すように、最上位モデルの<a href="https://sozorablog.com/pi5/">Raspberry Pi 5</a>と同等のスペックを備えた<span class="sbd-text-red">キーボード一体型</span>モデルの<span class="sbd-text-bg-yellow">Raspberry Pi 500</span>が登場しました。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="908" src="https://sozorablog.com/wp-content/uploads/2025/08/IMG_9359.jpeg" alt="" class="wp-image-15533" style="width:446px;height:auto"/></figure>



<p>基板むき出しのRaspberry Piシリーズは、「マニア向け」の印象が強く、初心者にはとっつきにくいのも事実。一方、Raspberry Pi 500はキーボードの中に本体を内蔵することで、見慣れたパソコンに近い形となっており、「キーボードがないと不便では？」という不安も解消しています。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="755" src="https://sozorablog.com/wp-content/uploads/2025/08/IMG_9473.jpeg" alt="" class="wp-image-15612" style="width:445px;height:auto"/></figure>



<p>この記事ではRaspberry Pi 500を分解し、中身をチェックしつつ、向いているユーザー層についても掘り下げていきます。</p>



<!-- START MoshimoAffiliateEasyLink -->
<script type="text/javascript">
(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;
b[a]=b[a]||function(){arguments.currentScript=c.currentScript
||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};
c.getElementById(a)||(d=c.createElement(f),d.src=g,
d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})
(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");
msmaflink({"n":"Raspberry pi 500 日本語キーボード","b":"Raspberry Pi","t":"","d":"https:\/\/m.media-amazon.com","c_p":"\/images\/I","p":["\/21JC7iBMqiL._SL500_.jpg","\/41FcWyDS-nL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0FJXJSWZ8","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":1,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0FJXJSWZ8","a_id":3038653,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"id":4,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/Raspberry%20pi%20500%20%E6%97%A5%E6%9C%AC%E8%AA%9E%E3%82%AD%E3%83%BC%E3%83%9C%E3%83%BC%E3%83%89\/","a_id":3038654,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":2}],"eid":"5oDBD","s":"s"});
</script>
<div id="msmaflink-5oDBD">リンク</div>
<!-- MoshimoAffiliateEasyLink END -->



<h2 class="wp-block-heading">Raspberry Pi 500の基本構成</h2>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="485" src="https://sozorablog.com/wp-content/uploads/2025/08/pico-2025-08-07T120245.494.jpg" alt="" class="wp-image-15592"/><figcaption class="wp-element-caption">先代モデルとの比較</figcaption></figure>



<p><a href="https://sozorablog.com/raspberry-pi-400-explanation/">Raspberry Pi 400</a>の後継モデルとして登場したRaspberry Pi 500。プロセッサ性能の向上に加え、筐体カラーは従来の赤と白から白一色へと変更され、シンプルで洗練されたデザインに仕上がっています。</p>



<figure class="wp-block-table wp-block-sbd-table wp-block-sbd-table-vertical"><table><tbody><tr><td>SoC</td><td>Broadcom BCM2712</td></tr><tr><td>CPU</td><td>Cortex-A76(ARM v8) 64-bit SoC @ 2.4GHz × 4</td></tr><tr><td>メモリ</td><td>8GB</td></tr><tr><td>有線LAN</td><td>1000 Base-T</td></tr><tr><td>無線LAN</td><td>IEEE 802.11b/g/n/ac</td></tr><tr><td>Bluetooth</td><td>Bluetooth 5.0</td></tr><tr><td>消費電力</td><td>2.6W</td></tr><tr><td>サイズ</td><td>286 × 122 × 23mm</td></tr><tr><td>生産国</td><td>イギリス</td></tr><tr><td>価格</td><td><a href="https://raspberry-pi.ksyic.com/main/index/pdp.id/1156/pdp.open/1156/">KSY</a>：¥17,600<br><a href="https://akizukidenshi.com/catalog/g/g130200/">秋月電子</a>：¥17,800<br><a href="https://www.switch-science.com/products/10054">スイッチサイエンス</a>：¥18,480</td></tr></tbody></table></figure>



<p>次の図は、Raspberry Pi 500 の背面ポートの配置を示しています。2つのmicro HDMIポートを搭載しており、デュアルディスプレイにも対応。GPIO端子も搭載されており、LEDやセンサーなどの電子工作パーツを直接接続できます。一方で、Raspberry Pi 5にあるカメラコネクタやPCIeインタフェースは搭載されていません。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="236" src="https://sozorablog.com/wp-content/uploads/2025/08/image.png" alt="" class="wp-image-15559" style="width:840px;height:auto"/><figcaption class="wp-element-caption">出典：<a href="https://datasheets.raspberrypi.com/pi500/raspberry-pi-500-product-brief.pdf">Raspberry Pi 500 Product Brief</a>より引用</figcaption></figure>



<p>日本語キーボード版は技適の取得に時間を要したため、海外発売から約8か月遅れて登場しました。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="848" src="https://sozorablog.com/wp-content/uploads/2025/08/IMG_9363.jpeg" alt="" class="wp-image-15534" style="width:501px;height:auto"/><figcaption class="wp-element-caption">本体裏面にある技適シール</figcaption></figure>



<p>技適マークは本体裏面に貼付されています。</p>



<h3 class="wp-block-heading">新たに採用された電源ボタン</h3>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="754" src="https://sozorablog.com/wp-content/uploads/2025/08/IMG_9471.jpeg" alt="" class="wp-image-15605" style="width:490px;height:auto"/></figure>



<p>Raspberry Pi 500には、前モデルのPi 400にはなかった電源ボタンが搭載されました。ボタンを1回押すとシャットダウンダイアログが表示され、<span class="sbd-text-red">Enterキーを押す</span>ことで安全に電源を切ることができます。Raspberry Pi 5のように2回押しで即シャットダウンする機能はないため、誤操作で電源が切れてしまう心配はありません。</p>



<p>シャットダウン後は、電源ボタンを1回押すだけで起動可能で、快適さと誤操作防止を両立させた工夫が見て取れます。</p>



<h3 class="wp-block-heading">OS書き込み済みのmicroSDカードが付属</h3>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="600" src="https://sozorablog.com/wp-content/uploads/2025/08/IMG_9361.jpeg" alt="" class="wp-image-15531"/><figcaption class="wp-element-caption">あらかじめ本体にセットされているmicroSDカード</figcaption></figure>



<p>Raspberry Pi 500には、Raspberry Pi OSがあらかじめ書き込まれたmicroSDカードがセットされています。これにより、電源を接続してディスプレイをつなぐだけですぐに起動することができます。OSのダウンロードや書き込みといった<a href="https://sozorablog.com/raspberrypi_initial_setting/">使用準備</a>が不要なため、初心者にとっては大きな安心材料です。</p>



<h3 class="wp-block-heading">「電源アダプター」「HDMIケーブル」「マウス」は別売り</h3>



<p>なお、Raspberry Pi 500には「マウス」「電源アダプター」「HDMIケーブル」は付属していません。これらは別途用意する必要があります。<br>ディスプレイ出力にはmicro HDMI端子を使用するため、<a href="https://akizukidenshi.com/catalog/g/g115002">micro HDMI to HDMIケーブル</a>を忘れずに準備しましょう。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="453" height="785" src="https://sozorablog.com/wp-content/uploads/2022/03/HDMI-type-D.jpg" alt="Micro HDMI" class="wp-image-4969" style="width:173px;height:290px" srcset="https://sozorablog.com/wp-content/uploads/2022/03/HDMI-type-D.jpg 453w, https://sozorablog.com/wp-content/uploads/2022/03/HDMI-type-D-173x300.jpg 173w" sizes="(max-width: 453px) 100vw, 453px" /></figure>



<p><br>また、電源はUSB Type-C給電で、<strong>5V/5A出力対応の電源アダプター</strong>が推奨されています。Raspberry Pi公式電源アダプターは<a href="https://www.switch-science.com/products/9811">スイッチサイエンス</a>や<a href="https://akizukidenshi.com/catalog/g/g130329">秋月電子</a>などで購入できます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="743" src="https://sozorablog.com/wp-content/uploads/2025/08/IMG_9472.jpeg" alt="" class="wp-image-15606" style="width:461px;height:auto"/><figcaption class="wp-element-caption">Raspberry Pi公式電源アダプター</figcaption></figure>



<h2 class="wp-block-heading">Raspberry Pi 500を分解</h2>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="450" src="https://sozorablog.com/wp-content/uploads/2025/08/pico-2025-08-09T075312.125.jpg" alt="" class="wp-image-15637" srcset="https://sozorablog.com/wp-content/uploads/2025/08/pico-2025-08-09T075312.125.jpg 800w, https://sozorablog.com/wp-content/uploads/2025/08/pico-2025-08-09T075312.125-320x180.jpg 320w, https://sozorablog.com/wp-content/uploads/2025/08/pico-2025-08-09T075312.125-224x126.jpg 224w" sizes="(max-width: 800px) 100vw, 800px" /><figcaption class="wp-element-caption">Pi 500の内部基板とPi 5の比較</figcaption></figure>



<p>Raspberry Pi 500の内部構造を確かめるため、分解して中身をチェックしてみました。冷却性能や基板の配置などに注目です。</p>



<p>まずは周囲のツメをマイナスドライバーで慎重に外していきます。ただし、この作業は筐体に傷が入りやすいため、あまりおすすめはできません。分解は自己責任で行うようにしてください。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="664" src="https://sozorablog.com/wp-content/uploads/2025/08/IMG_9366.jpeg" alt="" class="wp-image-15535"/></figure>



<p>中を開けると、キーボードと基板はリボンケーブルで接続されており、キーボード側には「日本」と書かれたシールが貼られていました。基板の上には、大きな金属製のプレートが取り付けられていて、これがヒートシンクとして機能しているようです。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="1067" src="https://sozorablog.com/wp-content/uploads/2025/08/IMG_9371.jpeg" alt="" class="wp-image-15536" style="width:439px;height:auto"/></figure>



<p>Raspberry Pi 5では、熱対策のためにヒートシンクやファンを後付けするのが一般的でしたが、Raspberry Pi 500では最初から放熱性能に配慮した設計になっています。キーボード内部でファンなしでも安定動作できる秘密は、このヒートシンクにあるようです。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="691" src="https://sozorablog.com/wp-content/uploads/2025/08/IMG_9373.jpeg" alt="" class="wp-image-15538"/></figure>



<p>ヒートシンクを固定している4本のネジを外すと、ようやく基板が姿を現します。内部の主な構成は、キーボード、基板、ヒートシンクの3つだけで、シンプルかつ無駄のない設計にまとまっています。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="506" src="https://sozorablog.com/wp-content/uploads/2025/08/IMG_9368.jpeg" alt="" class="wp-image-15537"/></figure>



<p>細長い形状の基板は、Raspberry Pi 5をそのまま流用しているわけではなく、<strong>Raspberry Pi 500専用に設計されたもの</strong>です。キーボード一体型という構造に最適化されており、内部まで抜かりなく作り込まれている印象を受けます。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="449" src="https://sozorablog.com/wp-content/uploads/2025/08/IMG_9376-2.jpeg" alt="" class="wp-image-15639" srcset="https://sozorablog.com/wp-content/uploads/2025/08/IMG_9376-2.jpeg 800w, https://sozorablog.com/wp-content/uploads/2025/08/IMG_9376-2-320x180.jpeg 320w, https://sozorablog.com/wp-content/uploads/2025/08/IMG_9376-2-224x126.jpeg 224w" sizes="(max-width: 800px) 100vw, 800px" /></figure>



<p>興味深いのは「2230」「2242」「2260」「2280」と刻まれたM.2（NVMe SSD）用のパッド（はんだ付け用のランド）がある点です。ソケットや固定用のネジ台座は取り付けられておらず、パッドだけがある状態です。将来的にNVMeストレージ対応モデルを想定して設計されている可能性がありますが、現行モデルではその機能は使えません。</p>



<h3 class="wp-block-heading">驚異的なRaspberry Pi 500の冷却性能</h3>



<p>前項で紹介したとおり、Raspberry Pi 500には大型の金属プレートが内蔵されており、ヒートシンクとしての役割を果たしています。このプレートがどの程度の効果を発揮するのか、実際に検証してみました。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="415" src="https://sozorablog.com/wp-content/uploads/2025/08/pico-2025-08-08T102501.331.jpg" alt="" class="wp-image-15602"/><figcaption class="wp-element-caption">同スペックのモデルでCPU温度を比較</figcaption></figure>



<p>比較対象は、ほぼ同じ性能を持つRaspberry Pi 5の8GBモデルです。1秒ごとにCPU温度を測定して1分間の平均を出すPythonスクリプトを実行し、同じ条件でテストを実施。その結果、Raspberry Pi 500の方が<span class="sbd-text-bg-yellow">約20℃も低い温度</span>で動作していることが分かりました。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="384" src="https://sozorablog.com/wp-content/uploads/2025/08/pico-2025-08-07T122046.462.jpg" alt="" class="wp-image-15593"/></figure>



<p>冷却ファンを搭載せずにここまで温度を抑えられるのは、Raspberry Pi 500独自の設計によるものです。高負荷の作業でも安定した動作が期待でき、静音性にも優れているのが大きな魅力です。</p>



<p>以下は検証用に使用したプログラムです。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>import time

temps = []

for _ in range(60):
    try:
        with open(&quot;/sys/class/thermal/thermal_zone0/temp&quot;, &quot;r&quot;) as f:
            temp = int(f.read()) / 1000.0  # 単位はミリ度 → 度に変換
            temps.append(temp)
            print(f&quot;現在の温度: {temp:.2f}℃&quot;)
    except Exception as e:
        print(&quot;温度の読み取りに失敗しました:&quot;, e)
    time.sleep(1)

average = sum(temps) / len(temps) if temps else 0
print(f&quot;\n1分間の平均温度: {average:.2f}℃&quot;)
</code></pre></div>



<p><code>/sys/class/thermal/thermal_zone0/temp</code> から1秒ごとに温度を取得し、60秒後に平均温度を表示する機能を有しています。</p>



<h2 class="wp-block-heading">Raspberry Pi 500を起動</h2>



<p>Raspberry Pi 500は、必要な機器を接続すればすぐに使い始められます。あらかじめmicroSDカード入りのため、起動から初期設定までの流れもシンプルで、初めての方でも安心です。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="671" src="https://sozorablog.com/wp-content/uploads/2025/08/IMG_9470.jpeg" alt="" class="wp-image-15596"/></figure>



<p>まずはマウスをUSBポートに接続し、micro HDMIケーブルでモニターとつなぎます。HDMIポートは2つありますが、背面から見て左側の「HDMI 0」に接続するのが基本です。<br>その後、電源アダプターをUSB Type-Cポートに差し込むと、自動で電源が入り起動が始まります。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="836" src="https://sozorablog.com/wp-content/uploads/2025/08/IMG_9378.jpeg" alt="" class="wp-image-15560" style="width:434px;height:auto"/></figure>



<p>起動すると、Raspberry Pi OSの初期設定ウィザードが立ち上がります。言語や地域、Wi-Fiの接続、ユーザー名の設定などを順に進めていきます。必要に応じて画面の表示調整やOSアップデートも行いますが、画面の指示に従えば問題ありません。</p>



<div class="wp-block-sbd-background-block sbd-bg-color sbd-inner-block-init is-style-yellow">
<p>Raspberry Pi OSの設定方法は、以下の記事で詳しく解説しています。<br><strong><a href="https://sozorablog.com/raspberrypi_initial_setting/">≫【2025年最新版】OSインストールから初期設定まで｜セットアップ手順のすべて</a></strong></p>
</div>



<p>初期設定が終わるとデスクトップ画面が表示され、すぐにブラウザを使ったり、Pythonでプログラミングを始めたりできます。スムーズにラズパイの世界に入っていけるのは、Raspberry Pi 500ならではの魅力です。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="450" src="https://sozorablog.com/wp-content/uploads/2025/08/image-1.jpg" alt="" class="wp-image-15562" srcset="https://sozorablog.com/wp-content/uploads/2025/08/image-1.jpg 800w, https://sozorablog.com/wp-content/uploads/2025/08/image-1-320x180.jpg 320w, https://sozorablog.com/wp-content/uploads/2025/08/image-1-224x126.jpg 224w" sizes="(max-width: 800px) 100vw, 800px" /><figcaption class="wp-element-caption">Raspberry Pi OSのデスクトップ画面</figcaption></figure>



<h3 class="wp-block-heading">豊富なアプリケーション</h3>



<p>スタートメニューを開くと、通常版よりも多くのアプリが入っているのがわかります。Raspberry Pi OSには「通常版」と「Full版」があり、Full版には教育用ソフトやオフィスソフト、簡単なゲームなどが最初から揃っています。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="583" height="507" src="https://sozorablog.com/wp-content/uploads/2025/08/image-1.png" alt="" class="wp-image-15587" style="width:473px;height:auto"/></figure>



<p>Raspberry Pi 500にはこのFull版が入っており、「Thonny」や「Scratch」、「Chromium」、「LibreOffice」に加え、5種類のゲームも含まれていました。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="380" height="393" src="https://sozorablog.com/wp-content/uploads/2025/08/image-2.png" alt="" class="wp-image-15631" style="width:317px;height:auto"/></figure>



<p>「Thonny（ソニー）」は、初心者でも使いやすいPython専用のプログラミングアプリです。コードを書いてそのまま実行できるため、学習から実践までスムーズに進められます。電子工作でもThonnyとPythonを使えば、LEDの点灯やモーターの制御など、さまざまな電子パーツを動かすことができます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="508" src="https://sozorablog.com/wp-content/uploads/2025/08/pico-1-1-1.jpg" alt="" class="wp-image-15635" style="width:620px;height:auto"/></figure>



<p>Pythonがわからない方でもScratchというアプリを使えば、GPIOピンを制御できます。Scratchは命令が書かれたブロックを組み合わせてプログラムを作れるビジュアルプログラミング環境です。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="709" height="503" src="https://sozorablog.com/wp-content/uploads/2025/08/image-3.png" alt="" class="wp-image-15649"/><figcaption class="wp-element-caption">Scratch 3の画面</figcaption></figure>



<p>コードを書く必要がないため、小学生や初心者でも直感的に操作できます。GPIO制御用のブロックが用意されており、LEDを点滅させたり、スイッチの状態を読み取ったりといった電子工作が簡単に体験できます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="234" height="190" src="https://sozorablog.com/wp-content/uploads/2025/08/image-4.png" alt="" class="wp-image-15651" style="width:583px;height:auto"/><figcaption class="wp-element-caption">LEDを点滅させるプログラムの例</figcaption></figure>



<p>上記のプログラムでは、次の処理が組まれています。</p>



<div class="wp-block-sbd-list"><ul class="sbd-list sbd-list-border"><li>GPIO 21を出力モードにして「high（電圧を出す）」状態にする</li><li>1秒待つ</li><li>GPIO 21を「low（電圧を止める）」状態にする</li><li>1秒待つ</li><li>この動作を繰り返す</li></ul></div>



<p>このプログラムを実行すると、GPIO 21に接続したLEDが<strong>1秒ごとに点滅</strong>します。Scratchを使うことで、電子工作の制御をマウス操作だけで簡単に作れます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="891" src="https://sozorablog.com/wp-content/uploads/2025/08/IMG_9480.jpeg" alt="" class="wp-image-15652" style="width:470px;height:auto"/><figcaption class="wp-element-caption"><a href="https://akizukidenshi.com/catalog/g/g112519">抵抗内蔵LED</a>を点灯</figcaption></figure>



<p>今回は<a href="https://akizukidenshi.com/catalog/g/g112519">抵抗内蔵LED</a>を使用しているため、別途抵抗は不要です。接続はLEDの足の長い方（アノード）をGPIO 21に、短い方（カソード）をGNDピンに接続します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="762" src="https://sozorablog.com/wp-content/uploads/2025/08/image-2.jpg" alt="" class="wp-image-15588" style="width:480px;height:auto"/></figure>



<p>ブラウザも利用可能で、先代のRaspberry Pi 400ではやや動作が重く感じたYouTubeも、スムーズに再生できました。</p>



<h2 class="wp-block-heading">GPIO端子付きで電子工作もできる</h2>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="633" src="https://sozorablog.com/wp-content/uploads/2025/08/IMG_9362.jpeg" alt="" class="wp-image-15532"/></figure>



<p>Raspberry Pi 500はキーボード一体型ながら、他のRaspberry Piと同様にGPIO端子を備えています。これにより、センサーやLEDといった電子パーツを接続して、電子工作やハードウェア制御の学習にも活用できます。</p>



<h3 class="wp-block-heading">インフォメーションディスプレイの作成</h3>



<p>今回は、Raspberry Pi 500のGPIO端子に小型のLCDディスプレイ（ILI9341）を接続し、プログラミングによって画面の表示を制御してみます。</p>



<!-- START MoshimoAffiliateEasyLink -->
<script type="text/javascript">
(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;
b[a]=b[a]||function(){arguments.currentScript=c.currentScript
||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};
c.getElementById(a)||(d=c.createElement(f),d.src=g,
d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})
(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");
msmaflink({"n":"Hailege 2.2\u0022 ILI9341 SPI TFT LCDディスプレイ240x320 ILI9341 LCDスクリーン、Arduino Raspberry Pi用SDカードスロット","b":"Hailege","t":"H-A-0191","d":"https:\/\/m.media-amazon.com","c_p":"\/images\/I","p":["\/418wYf3koZL._SL500_.jpg","\/41t5jOFHmxL._SL500_.jpg","\/41J2n4cDVNL._SL500_.jpg","\/41J0D7SgIsL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B08D7D14X9","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":1,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B08D7D14X9","a_id":3038653,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"id":2,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/Hailege%202.2%22%20ILI9341%20SPI%20TFT%20LCD%E3%83%87%E3%82%A3%E3%82%B9%E3%83%97%E3%83%AC%E3%82%A4240x320%20ILI9341%20LCD%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%BC%E3%83%B3%E3%80%81Arduino%20Raspberry%20Pi%E7%94%A8SD%E3%82%AB%E3%83%BC%E3%83%89%E3%82%B9%E3%83%AD%E3%83%83%E3%83%88\/","a_id":3038654,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":2}],"eid":"JcjPt","s":"s"});
</script>
<div id="msmaflink-JcjPt">リンク</div>
<!-- MoshimoAffiliateEasyLink END -->



<p>ここでは、CPUの使用率と温度を1秒ごとに取得し、過去30秒分のグラフを表示する「インフォメーションディスプレイ」を作ってみましょう。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="802" src="https://sozorablog.com/wp-content/uploads/2025/08/IMG_9462.jpeg" alt="" class="wp-image-15576" style="width:431px;height:auto"/></figure>



<p>Raspberry Pi 500とLCDディスプレイは、ジャンパワイヤを使い、以下のように接続します。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="552" src="https://sozorablog.com/wp-content/uploads/2025/08/pico-2025-08-03T193258.572.jpg" alt="" class="wp-image-15564"/></figure>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="774" src="https://sozorablog.com/wp-content/uploads/2025/08/IMG_9385.jpeg" alt="" class="wp-image-15573" style="width:448px;height:auto"/></figure>



<div class="wp-block-sbd-background-block sbd-bg-color sbd-inner-block-init is-style-yellow">
<p>Raspberry PiでLCDを使用するための準備手順は、以下の記事で詳しく紹介しています。<br><strong><a href="https://sozorablog.com/himawari/">≫ラズパイで気象衛星ひまわりの画像を表示する装置を作ろう</a></strong></p>
</div>



<p>以下のコマンドで、日本語フォント「Takaoフォント」をインストールしました。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo apt install fonts-takao</code></pre></div>



<p>「Thonny」でプログラムを作成し、実行ボタンを押すと、内容がLCDに表示されます。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="450" src="https://sozorablog.com/wp-content/uploads/2025/08/pico-2025-08-07T105637.929.jpg" alt="" class="wp-image-15584" srcset="https://sozorablog.com/wp-content/uploads/2025/08/pico-2025-08-07T105637.929.jpg 800w, https://sozorablog.com/wp-content/uploads/2025/08/pico-2025-08-07T105637.929-320x180.jpg 320w, https://sozorablog.com/wp-content/uploads/2025/08/pico-2025-08-07T105637.929-224x126.jpg 224w" sizes="(max-width: 800px) 100vw, 800px" /></figure>



<p>以下のプログラムは、Raspberry PiのCPU使用率と温度をリアルタイムで取得し、グラフで小型ディスプレイ（ILI9341）に表示するものです。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>import time
import psutil
from collections import deque
from PIL import Image, ImageDraw, ImageFont
from board import SCK, MOSI, MISO, D5, D18, D23, D24
from busio import SPI
from digitalio import DigitalInOut, Direction
from adafruit_rgb_display.ili9341 import ILI9341

def get_cpu_temp():
    try:
        with open(&quot;/sys/class/thermal/thermal_zone0/temp&quot;, &quot;r&quot;) as f:
            return int(f.read()) / 1000.0
    except:
        return None
    
CS = DigitalInOut(D5)
DC = DigitalInOut(D24)
RST = DigitalInOut(D23)
BL = DigitalInOut(D18)
BL.direction = Direction.OUTPUT
BL.value = True

spi = SPI(clock=SCK, MOSI=MOSI, MISO=MISO)
display = ILI9341(spi, cs=CS, dc=DC, rst=RST, width=240, height=320)    

cpu_history = deque(maxlen=30)
temp_history = deque(maxlen=30)

font_path = &quot;/usr/share/fonts/truetype/takao-gothic/TakaoGothic.ttf&quot;
font_l = ImageFont.truetype(font_path, 30)
font = ImageFont.truetype(font_path, 24)

bar_width = 5.4
base_y_cpu = 115
base_y_temp = 260
cpu_graph_height = 100
temp_graph_height = 100

while True:
    cpu = psutil.cpu_percent()
    temp = get_cpu_temp() or 0
    cpu_history.append(cpu)
    temp_history.append(temp)

    cpu_min = max(0, min(cpu_history) - 1)
    cpu_max = min(100, max(cpu_history) + 5)
    cpu_range = max(cpu_max - cpu_min, 1)

    temp_min = max(0, min(temp_history) - 3)
    temp_max = max(temp_history) + 1
    temp_range = max(temp_max - temp_min, 1)

    image = Image.new(&quot;RGB&quot;, (240, 320), (0, 0, 0))
    draw = ImageDraw.Draw(image)

    draw.text((170, 10), &quot;CPU&quot;, font=font_l, fill=(255, 255, 255))
    draw.text((170, 85), f&quot;{cpu:.1f}%&quot;, font=font, fill=(255, 255, 255))

    for i in range(1, len(cpu_history)):
        x1 = int((i - 1) * bar_width) + 5
        y1 = base_y_cpu - int((cpu_history[i - 1] - cpu_min) / cpu_range * cpu_graph_height)
        x2 = int(i * bar_width) + 5
        y2 = base_y_cpu - int((cpu_history[i] - cpu_min) / cpu_range * cpu_graph_height)
        draw.line((x1, y1, x2, y2), fill=(255, 255, 255))

    draw.text((170, base_y_temp - 55), f&quot;{temp:.1f}℃&quot;, font=font, fill=(255, 255, 255))

    for i, t in enumerate(temp_history):
        h = int((t - temp_min) / temp_range * temp_graph_height)
        x = i * bar_width
        if x + bar_width &lt;= 240:
            draw.rectangle((x, base_y_temp - h, x + bar_width - 1, base_y_temp), fill=(255, 255, 255))

    rotated = image.rotate(90, expand=True)
    resized = rotated.resize((240, 320))
    display.image(resized)

    time.sleep(1)
</code></pre></div>



<p>取得したデータはそれぞれ<code>deque</code>という構造で最大30件まで保持されており、グラフには過去30秒間の変化がリアルタイムで描画されます。</p>



<p>CPU使用率は折れ線グラフで、温度は棒グラフで表示され、1秒ごとに更新されます。グラフはPillowライブラリを使って描画され、<code>draw.line()</code>でCPUの推移を、<code>draw.rectangle()</code>で温度の推移を視覚的に表現しています。画面上には現在のCPU使用率と温度の数値もあわせて表示され、データの変化する様子を確認できます。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="531" src="https://sozorablog.com/wp-content/uploads/2025/08/IMG_9454.jpeg" alt="" class="wp-image-15574"/></figure>



<p>ディスプレイをRaspberry Pi 500に固定するため、<a href="https://sozorablog.com/ankermake-m5c/">3Dプリンター</a>で専用のスタンドを作ってみました。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="530" src="https://sozorablog.com/wp-content/uploads/2025/08/IMG_9387.jpeg" alt="" class="wp-image-15575"/></figure>



<h2 class="wp-block-heading">Raspberry Pi 500が向いている人・向いていない人</h2>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="535" src="https://sozorablog.com/wp-content/uploads/2025/08/IMG_9465.jpeg" alt="" class="wp-image-15594"/></figure>



<p>Raspberry Pi 500はキーボード一体型で、microSDカードにはOSがあらかじめインストールされており、電源やモニター、マウスをつなげばすぐに使える手軽さが魅力です。初めての人でもパソコン感覚でラズパイの世界に入っていけます。Pythonの学習や電子工作にも対応しており、教育用途にもぴったりです。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="400" src="https://sozorablog.com/wp-content/uploads/2025/08/pico-100.jpg" alt="" class="wp-image-15634" style="width:840px;height:auto"/><figcaption class="wp-element-caption">ラズパイはリモート操作が可能</figcaption></figure>



<p>ただし、SSHや<a href="https://sozorablog.com/vnc/">VNC</a>を使ったリモート操作に慣れている人や、機器に組み込んで常時稼働させたいと考えている人には不向きです。Raspberry Pi 500は本体サイズが大きく、キーボード一体型の構造上、狭いスペースに収める用途には適していません。価格もやや高めなので、用途に対してスペックを持て余す可能性もあります。リモートで管理する運用が前提であれば、Raspberry Pi 4や5といったスタンダードな基板タイプの方が柔軟に使えます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="780" src="https://sozorablog.com/wp-content/uploads/2025/08/pico-2025-08-04T174339.888.jpg" alt="" class="wp-image-15569" style="width:502px;height:auto"/><figcaption class="wp-element-caption">Raspberry Piシリーズの分類</figcaption></figure>



<p>まとめると、Raspberry Pi 500は「これから始めたい」「ラズパイをパソコンのように使いたい」という方に向いています。一方、「小型化」「組み込み用途」「コスト重視」といった目的がある人には、他のモデルを選ぶのが賢明です。</p>



<h2 class="wp-block-heading">まとめ</h2>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="671" src="https://sozorablog.com/wp-content/uploads/2025/08/IMG_9463-1.jpeg" alt="" class="wp-image-15595"/><figcaption class="wp-element-caption"><a href="https://sozorablog.com/himawari/">気象衛星ひまわりの画像を表示</a></figcaption></figure>



<p>Raspberry Pi 500は、ラズパイに初めて触れる人でも扱いやすく、教育現場や家庭での学習用途にも適したモデルです。</p>



<p>ただし、初心者向けとしては価格がやや高く、そこまでの性能を必要としない場合には割高に感じるかもしれません。基本的な操作や学習が目的であれば、少し安価な<a href="https://sozorablog.com/raspberry-pi-400-explanation/">Raspberry Pi 400</a>でも十分に対応できます。</p>



<!-- START MoshimoAffiliateEasyLink -->
<script type="text/javascript">
(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;
b[a]=b[a]||function(){arguments.currentScript=c.currentScript
||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};
c.getElementById(a)||(d=c.createElement(f),d.src=g,
d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})
(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");
msmaflink({"n":"Raspberry Pi 400 日本語キーボードバージョン","b":"RaspberryPi","t":"","d":"https:\/\/m.media-amazon.com","c_p":"","p":["\/images\/I\/31iZj7C9TkL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B09R6H27JY","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":3,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B09R6H27JY","a_id":3038653,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"id":2,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/Raspberry%20Pi%20400%20%E6%97%A5%E6%9C%AC%E8%AA%9E%E3%82%AD%E3%83%BC%E3%83%9C%E3%83%BC%E3%83%89%E3%83%90%E3%83%BC%E3%82%B8%E3%83%A7%E3%83%B3\/","a_id":3038654,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":2}],"eid":"pKLpc","s":"s"});
</script>
<div id="msmaflink-pKLpc">リンク</div>
<!-- MoshimoAffiliateEasyLink END -->



<p>ラズパイシリーズには、使う人の目的やスキルに合わせて選べる多彩なモデルがそろっています。あなたにぴったりの1台で、素敵なラズパイライフをお楽しみください。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sozorablog.com/raspberry-pi-500/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>ラズパイで簡単ファイル共有！初心者向けファイルサーバー設定ガイド</title>
		<link>https://sozorablog.com/raspberry-pi-file-server/</link>
					<comments>https://sozorablog.com/raspberry-pi-file-server/#respond</comments>
		
		<dc:creator><![CDATA[そぞら]]></dc:creator>
		<pubDate>Sun, 13 Jul 2025 09:01:47 +0000</pubDate>
				<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[使い方]]></category>
		<guid isPermaLink="false">https://sozorablog.com/?p=15364</guid>

					<description><![CDATA[Raspberry Piを買ったけれど、何に使えばいいのかよくわからない……。そんな方に試して欲しいのが「ファイルサーバー」としての活用です。 この記事ではRaspberry Piを使って、パソコンやスマホとファイルをや [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p><a href="https://sozorablog.com/raspberry-pi/">Raspberry Pi</a>を買ったけれど、何に使えばいいのかよくわからない……。そんな方に試して欲しいのが「ファイルサーバー」としての活用です。</p>



<p>この記事ではRaspberry Piを使って、パソコンやスマホとファイルをやり取りできる仕組みを作ります。特別な機器は必要ありません。手元のラズパイ1台で、低コストかつ省スペースなファイル共有環境が実現します。</p>



<!-- START MoshimoAffiliateEasyLink -->
<script type="text/javascript">
(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;
b[a]=b[a]||function(){arguments.currentScript=c.currentScript
||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};
c.getElementById(a)||(d=c.createElement(f),d.src=g,
d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})
(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");
msmaflink({"n":"Raspberrypi5 8G ラズベリーパイ5 技適取得済マーク入り商品","b":"Raspberry Pi","t":"","d":"https:\/\/m.media-amazon.com","c_p":"\/images\/I","p":["\/31ulVhoF7LL._SL500_.jpg","\/31Paz5taW5L._SL500_.jpg","\/31wPYoxjgCL._SL500_.jpg","\/31ArwA0xXgL._SL500_.jpg","\/31wPYoxjgCL._SL500_.jpg","\/314jAZZTefL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0CQZHN2K4","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":1,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0CQZHN2K4","a_id":3038653,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1}],"eid":"6dQw8","s":"s"});
</script>
<div id="msmaflink-6dQw8">リンク</div>
<!-- MoshimoAffiliateEasyLink END -->



<h2 class="wp-block-heading">ファイル共有に便利なファイルサーバー</h2>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="549" src="https://sozorablog.com/wp-content/uploads/2025/07/pico-2025-07-13T174837.901.png" alt="" class="wp-image-15426"/></figure>



<p>複数のパソコンやスマホを使っていると、ファイルのやりとりが面倒なことがあります。メールで送ったり、USBメモリにコピーしたりと、操作の手間が気になるものです。</p>



<p>そんなときに便利なのが、ファイルを一か所にまとめて管理できる「ファイルサーバー」です。写真や書類などをこのサーバーに保存しておけば、ほかの端末からもすぐにアクセスできます。ファイルを端末ごとに保存しなくて済むので、スマホやタブレットの容量を節約できるのも大きなメリットです。</p>



<h3 class="wp-block-heading">Raspberry Piはファイルサーバーに最適</h3>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="554" src="https://sozorablog.com/wp-content/uploads/2025/07/IMG_9253.jpeg" alt="" class="wp-image-15424"/></figure>



<p>Raspberry Pi（ラズベリーパイ）は、手のひらサイズの小さなコンピューターです。消費電力が少なく、場所も取らないため、24時間ずっと動かしておくのに向いています。</p>



<p>ファイルサーバーは一度設定すれば、あとは電源を入れたままにしておくだけで、いつでもファイルを保存したり取り出したりできます。ラズパイなら電気代をほとんど気にせず、静かに動作させることができます。</p>



<h2 class="wp-block-heading">準備するもの</h2>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="413" src="https://sozorablog.com/wp-content/uploads/2025/07/ChatGPT-Image-2025年7月13日-20_04_39.jpg" alt="" class="wp-image-15436"/></figure>



<p>ファイル共有を始める前に、必要なものをそろえましょう。</p>



<h3 class="wp-block-heading">Raspberry Pi 本体</h3>



<p>Wi-Fiに対応したモデルであれば、どれでもファイルサーバーとして利用できます。ラズパイ3や4、Zero 2 Wなど、小型で省電力なモデルが扱いやすくおすすめです。常時稼働するので、ケースを用意しましょう。</p>



<h3 class="wp-block-heading">電源アダプター</h3>



<p>電源アダプターは専用品を用意しましょう。汎用品だと電流不足で正常に動作しない場合があります。</p>



<figure class="wp-block-table wp-block-sbd-table wp-block-sbd-table-vertical"><table class="has-fixed-layout"><thead><tr><th>モデル名</th><th>推奨電源</th><th>コネクタ</th><th>おすすめ</th></tr></thead><tbody><tr><td>Raspberry Pi 5</td><td>5.1V / 5A</td><td>USB-C</td><td><span class="sbd-table-btn"><a href="https://www.switch-science.com/products/9345">おすすめアダプター</a></span></td></tr><tr><td>Raspberry Pi 4</td><td>5.1V / 3A</td><td>USB-C</td><td><span class="sbd-table-btn"><a href="https://akizukidenshi.com/catalog/g/g114935/">おすすめアダプター</a></span></td></tr><tr><td>Raspberry Pi 3A+</td><td>5.1V / 2.5A</td><td>micro USB</td><td><span class="sbd-table-btn"><a href="https://akizukidenshi.com/catalog/g/g112001/">おすすめアダプター</a></span></td></tr><tr><td>Raspberry Pi Zero 2W</td><td>5.1V / 2.5A</td><td>micro USB</td><td><span class="sbd-table-btn"><a href="https://akizukidenshi.com/catalog/g/g112001/">おすすめアダプター</a></span></td></tr><tr><td>Raspberry Pi Zero W</td><td>5.1V / 2.0A</td><td>micro USB</td><td><span class="sbd-table-btn"><a href="https://akizukidenshi.com/catalog/g/g112001/">おすすめアダプター</a></span></td></tr></tbody></table></figure>



<h3 class="wp-block-heading">microSDカード</h3>



<p>Raspberry PiではmicroSDカードがOSのインストール先であり、同時にファイルを保存する場所にもなります。お試しで使うなら32GBでも十分ですが、本格的にファイルを保存・共有するなら64GB以上をおすすめします。</p>



<!-- START MoshimoAffiliateEasyLink -->
<script type="text/javascript">
(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;
b[a]=b[a]||function(){arguments.currentScript=c.currentScript
||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};
c.getElementById(a)||(d=c.createElement(f),d.src=g,
d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})
(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");
msmaflink({"n":"【 サンディスク 正規品 】 SanDisk microSD カード 32GB UHS-I U1 Class10 Nintendo Switch メーカー動作確認済 Ultra SDSQUA4-032G-GH3MA 簡易デザインパッケージ 10年間限定保証","b":"SanDisk","t":"SDSQUA4-032G-GH3MA","d":"https:\/\/m.media-amazon.com","c_p":"\/images\/I","p":["\/41SqvUEpuxL._SL500_.jpg","\/41BWt55RLVL._SL500_.jpg","\/41CzE-jpW5L._SL500_.jpg","\/51Ooj+2u5QL._SL500_.jpg","\/51Vt9UyQ7hL._SL500_.jpg","\/41HjeLVv6sL._SL500_.jpg","\/51En9zgEKCL._SL500_.jpg","\/519N3yR7t1L._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0CH2WM7QY","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":1,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0CH2WM7QY","a_id":3038653,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"id":3,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/%E3%80%90%20%E3%82%B5%E3%83%B3%E3%83%87%E3%82%A3%E3%82%B9%E3%82%AF%20%E6%AD%A3%E8%A6%8F%E5%93%81%20%E3%80%91%20SanDisk%20microSD%20%E3%82%AB%E3%83%BC%E3%83%89%2032GB%20UHS-I%20U1%20Class10%20Nintendo%20Switch%20%E3%83%A1%E3%83%BC%E3%82%AB%E3%83%BC%E5%8B%95%E4%BD%9C%E7%A2%BA%E8%AA%8D%E6%B8%88%20Ultra%20SDSQUA4-032G-GH3MA%20%E7%B0%A1%E6%98%93%E3%83%87%E3%82%B6%E3%82%A4%E3%83%B3%E3%83%91%E3%83%83%E3%82%B1%E3%83%BC%E3%82%B8%2010%E5%B9%B4%E9%96%93%E9%99%90%E5%AE%9A%E4%BF%9D%E8%A8%BC\/","a_id":3038654,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":2}],"eid":"0fAL9","s":"s"});
</script>
<div id="msmaflink-0fAL9">リンク</div>
<!-- MoshimoAffiliateEasyLink END -->



<p>また、外付けのHDDやSSDを使えば、OSとファイルの保存先を分けることができます。これにより、システムに不具合があっても、保存したファイルに影響が出にくくなります。外付けストレージは速度や耐久性にも優れているため、ファイルの読み書きをより安定して行えるのも利点です。</p>



<h2 class="wp-block-heading">OSのインストール</h2>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="450" src="https://sozorablog.com/wp-content/uploads/2025/07/pico-2025-07-13T175941.822.jpg" alt="" class="wp-image-15429" style="width:519px;height:auto" srcset="https://sozorablog.com/wp-content/uploads/2025/07/pico-2025-07-13T175941.822.jpg 800w, https://sozorablog.com/wp-content/uploads/2025/07/pico-2025-07-13T175941.822-320x180.jpg 320w, https://sozorablog.com/wp-content/uploads/2025/07/pico-2025-07-13T175941.822-224x126.jpg 224w" sizes="(max-width: 800px) 100vw, 800px" /><figcaption class="wp-element-caption">使用したOS</figcaption></figure>



<p>ファイルサーバー専用で使うなら「Raspberry Pi OS Lite」が軽くておすすめですが、今回は初心者でも扱いやすいように、デスクトップ画面付きの「Raspberry Pi OS Desktop（GUI付き）」を使います。Zero WやZero WHを使用する場合は、32-bit版を選択します。</p>



<div class="wp-block-sbd-background-block sbd-bg-color sbd-inner-block-init is-style-yellow">
<p>Raspberry Pi OSをインストールする方法は、以下の記事で詳しく解説しています。<br><strong><a href="https://sozorablog.com/raspberrypi_initial_setting/">≫【2025年最新版】OSインストールから初期設定まで｜セットアップ手順のすべて</a></strong></p>
</div>



<h2 class="wp-block-heading">Sambaでファイルサーバーを構築</h2>



<p>Raspberry Piを使ってファイルサーバーを作るには、「<strong>Samba（サンバ）</strong>」というソフトを使うのが一般的です。Sambaは、WindowsやMacからもアクセスできる共有フォルダを作ることができるソフトで、無料で使えます。</p>



<p>ここでは、Sambaを使って、ラズパイ上に共有フォルダを作成し、ネットワーク上のパソコンやスマホからファイルを読み書きできるように設定していきます。</p>



<h3 class="wp-block-heading">Sambaのインストール</h3>



<p>まずは、Raspberry Piでコマンド操作をするために「<strong>ターミナル</strong>」を開きます。画面の左上にある黒いアイコン（ウィンドウに &gt; があるマーク）をクリックしてください。</p>



<p>ターミナルが開いたら、以下のコマンドを入力して、Enterキーを押してください。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo apt update</code></pre></div>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/07/pi-terminal.jpg" alt="" class="wp-image-4"/></figure>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p><code>sudo apt update</code> は、ソフトの最新情報を取得するコマンドです。ラズパイにインストールできるソフトの一覧を新しくして、次のインストール作業を正しく行えるようにします。</p>
</div></div>



<p>以下のコマンドでSambaをインストールします。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo apt install samba -y</code></pre></div>



<h3 class="wp-block-heading">共有フォルダを作成する</h3>



<p>ファイルを保存する場所となるフォルダをつくります。ここでは「share」という名前にします。以下は「<code>/home/pi</code> フォルダの中に <code>share</code> という名前の新しいフォルダを作るコマンド」です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>mkdir /home/pi/share</code></pre></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="433" src="https://sozorablog.com/wp-content/uploads/2025/07/pico-2025-07-14T114702.682.png" alt="" class="wp-image-15440" style="width:436px;height:auto"/></figure>



<p>作ったフォルダにファイルを保存できるように、誰でも中のファイルを読み書きできる設定にします。家庭内で使うだけなら、この設定で問題ありません。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>chmod 777 /home/pi/share</code></pre></div>



<h3 class="wp-block-heading">Sambaの設定ファイルを編集する</h3>



<p>先ほど作成したフォルダを、ネットワーク上で共有するための設定を行います。Sambaの設定ファイルに、そのフォルダの場所やアクセス条件を追加します。以下を実行すると、Sambaの設定ファイル <code>smb.conf</code> をテキストエディタ（nano）で開いて編集できるようになります。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo nano /etc/samba/smb.conf</code></pre></div>



<p>nanoが開いたら、キーボードの矢印キーで一番下までスクロールし、以下のような内容を追加してください。追加したら、<code>Ctrl + O</code> で保存し、<code>Enter</code> を押してから <code>Ctrl + X</code> で終了します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>[Share]
   path = /home/pi/share
   browseable = yes
   writable = yes
   guest ok = no
   valid users = pi</code></pre></div>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/07/pico-2025-07-12T045927.693.jpg" alt=""/></figure>



<p>この設定では、<code>/home/pi/share</code> フォルダをネットワーク上に共有します。<code>browseable = yes</code> は、他の機器からこのフォルダを見えるようにする設定です。<code>writable = yes</code> によって、共有先からファイルの書き込みもできるようになります。<code>guest ok = no</code> は、誰でも自由にアクセスできる状態を防ぎ、ユーザー認証を求める設定です。最後の <code>valid users = pi</code> は、「pi」というユーザーだけがこのフォルダにアクセスできるよう制限しています。</p>



<div class="wp-block-sbd-checkpoint-block"><p class="sbd-checkpoint-title">チェックポイント</p><div class="sbd-checkpoint-content sbd-inner-block-init"><p>OSのインストール時に「pi」ではなく、別のユーザー名を設定した場合は、<code>valid users = pi</code> の部分を<strong>自分が設定したユーザー名に書き換える必要があります</strong>。たとえば「user1」という名前で設定していた場合は、<code>valid users = user1</code> と記載してください。設定と実際のユーザー名が一致していないと、共有フォルダにアクセスできません</p></div></div>



<h4 class="wp-block-heading">iPhoneからのアクセスに必要な追加設定</h4>



<p>iPhoneの「ファイル」アプリから接続したときにファイルの保存ができないことがあるため、smb.confファイルの「[global]」という項目に、次の設定を追加してください。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code> vfs objects = fruit streams_xattr</code></pre></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="298" src="https://sozorablog.com/wp-content/uploads/2025/07/pico-2025-07-14T174917.187.png" alt="" class="wp-image-15446" style="width:628px;height:auto"/></figure>



<p>iPhoneの「ファイル」アプリからSambaに接続すると、ログインしたユーザー名（たとえば「pi」）に対応するホームフォルダ（/home/pi）に自動でアクセスしてしまうことがあります。「share」フォルダだけを表示させたい場合は、以下のように<code>smb.conf</code> の <code>[homes]</code> セクションをすべてコメントアウトしてください。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/07/image-6.png" alt=""/></figure>



<h3 class="wp-block-heading">Sambaユーザーを登録する</h3>



<p>Sambaにアクセスするためのパスワードを設定します。<br>以下のコマンドを入力してください。「pi」の部分は、自身が設定したユーザー名に適宜変更してください。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo smbpasswd -a pi</code></pre></div>



<p>コマンドを実行すると、「New SMB password:」ようにパスワードを聞かれます。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/07/image.png" alt="" class="wp-image-4"/></figure>



<p>ここで、自分が使いたいパスワードを入力します。<br>例：<code>raspi2025</code> など、自分で自由に決めてOKです。このパスワードは、Windowsやスマホからファイルサーバーにアクセスするときに使うことになります。</p>



<p>確認のため2回パスワードを入力すると、以下のように表示され、設定が完了します。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/07/image-1.png" alt="" class="wp-image-4"/></figure>



<h3 class="wp-block-heading">Sambaを再起動する</h3>



<p>設定を反映させるために、Sambaを再起動します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo systemctl restart smbd</code></pre></div>



<p>これで、Raspberry Piの中にファイルを共有できるサーバーができました。</p>



<h3 class="wp-block-heading">IPアドレスの確認</h3>



<p>他のデバイスからRaspberry Piに接続するために、IPアドレスを確認しておきます。画面の右上にある電波アイコンにカーソルを合わせると、IPアドレスが表示されます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/05/pico-2025-01-25T074301.726.jpg" alt="" class="wp-image-4" style="width:840px;height:auto"/></figure>



<h2 class="wp-block-heading">パソコンからアクセスする</h2>



<p>Raspberry Piに共有フォルダの設定ができたら、次はパソコンからアクセスしてみましょう。ここでは、<strong>Windows</strong>と<strong>Mac</strong>の両方から接続する方法を紹介します。</p>



<h3 class="wp-block-heading">Windowsからアクセスする方法</h3>



<p>キーボードの <code>Windowsキー + R</code> を押して、「ファイル名を指定して実行」ウィンドウを開きます。</p>



<p>「<code>\\ラズパイのIPアドレス\share</code>」と入力してOKをクリックします。<br>　（例： <code>\\</code>192.168.1.159<code>\</code>share）</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/07/image-2.png" alt="" class="wp-image-4"/></figure>



<p>ユーザー名とパスワードを求められたら、ラズパイ側で設定したものを入力します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/07/image-4.png" alt="" class="wp-image-4" style="width:473px;height:auto"/></figure>



<p><br>　ユーザー名は <code>pi</code>（または自分で設定した名前）、パスワードは <code>smbpasswd</code> で設定したものです。</p>



<p>接続に成功すると、共有フォルダが表示されます。ファイルの読み書きが可能です。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/07/image-5.png" alt="" class="wp-image-4"/></figure>



<h3 class="wp-block-heading">Macからアクセスする方法</h3>



<p>Finder を開き、メニューの「移動」→「サーバへ接続&#8230;」を選びます。<br>「サーバアドレス」に <code>smb://ラズパイのIPアドレス/share</code> を入力します。<br>　（例： <code>smb://192.168.1.159/share</code>）</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/07/スクリーンショット-2025-07-13-5.10.28.png" alt="" class="wp-image-4"/></figure>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/07/スクリーンショット-2025-07-13-5.11.54.png" alt="" class="wp-image-4"/></figure>



<p>接続をクリックすると、ユーザー名とパスワードを聞かれます。<br>　ここも同様に、ユーザー名は <code>pi</code>（または自分で設定した名前）、パスワードはSamba用に設定したものです。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/07/スクリーンショット-2025-07-13-5.12.46.png" alt="" class="wp-image-4"/></figure>



<p>正しく入力すると、Finder上に共有フォルダが表示されます。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/07/スクリーンショット-2025-07-13-5.14.08.png" alt="" class="wp-image-4"/></figure>



<h2 class="wp-block-heading">iPhoneからアクセスする</h2>



<p>iPhoneからも、Raspberry Piに作った共有フォルダにアクセスできます。iPhoneに最初から入っている「<strong>ファイル</strong>」アプリを使えば簡単です。</p>



<p>iPhoneで「ファイル」アプリを開きます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="640" src="https://sozorablog.com/wp-content/uploads/2025/07/pico-2025-07-13T170216.294.jpg" alt="" class="wp-image-15417" style="width:323px;height:auto"/></figure>



<p>画面右上の「…（三点メニュー）」をタップし、「サーバへ接続」を選びます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="587" src="https://sozorablog.com/wp-content/uploads/2025/07/pico-2025-07-13T170502.467.png" alt="" class="wp-image-15418" style="width:324px;height:auto"/></figure>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="523" height="1080" src="https://sozorablog.com/wp-content/uploads/2025/07/pico-2025-07-13T170120.864.png" alt="" class="wp-image-15416" style="width:185px;height:auto"/></figure>



<p>「smb://ラズパイのIPアドレス」を入力します（例： <code>smb://192.168.1.159<code>/</code></code>）。フォルダ名（例：<code>/share</code>）を付けても反映されないため、IPアドレスのみを入力してください。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="750" height="405" src="https://sozorablog.com/wp-content/uploads/2025/07/IMG_9252.png" alt="" class="wp-image-15419" style="width:419px;height:auto"/></figure>



<p>接続方法を聞かれたら「登録ユーザー」を選び、ユーザー名（例：pi）とSambaで設定したパスワードを入力します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="750" height="750" src="https://sozorablog.com/wp-content/uploads/2025/07/IMG_9249.jpeg" alt="" class="wp-image-15422" style="width:416px;height:auto"/></figure>



<p>接続が完了すると、共有フォルダが表示され、ファイルの表示・保存ができるようになります。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="750" height="501" src="https://sozorablog.com/wp-content/uploads/2025/07/IMG_9251.jpeg" alt="" class="wp-image-15421" style="width:416px;height:auto"/></figure>



<h2 class="wp-block-heading">Sambaが不要になった場合の削除方法</h2>



<p>ファイル共有が不要になった場合に、Sambaを削除する方法を紹介します。使っていない共有機能を放置しておくと、思わぬセキュリティリスクになることもあるため、必要がなくなったら整理しておきましょう。</p>



<p>Samba本体を削除します。ターミナルを開いて、以下のコマンドを実行してください。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo apt remove samba samba-common -y</code></pre></div>



<p>これでファイル共有機能が無効になります。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sozorablog.com/raspberry-pi-file-server/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【2025年最新版】モニターなしでRaspberry Piを初期設定する方法</title>
		<link>https://sozorablog.com/raspberrypi-headless-setup/</link>
					<comments>https://sozorablog.com/raspberrypi-headless-setup/#respond</comments>
		
		<dc:creator><![CDATA[そぞら]]></dc:creator>
		<pubDate>Sat, 21 Jun 2025 01:28:12 +0000</pubDate>
				<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[初期設定]]></category>
		<guid isPermaLink="false">https://sozorablog.com/?p=15172</guid>

					<description><![CDATA[Raspberry Piを使い始めたいけれど、「モニターやキーボードがないからセットアップできない」と悩んでいませんか？ 実はモニター・キーボード・マウスを使わずに、パソコンだけでRaspberry Piを初期設定する方 [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p><a href="https://sozorablog.com/raspberry-pi/">Raspberry Pi</a>を使い始めたいけれど、「モニターやキーボードがないからセットアップできない」と悩んでいませんか？</p>



<p>実はモニター・キーボード・マウスを使わずに、パソコンだけでRaspberry Piを初期設定する方法があります。設定が完了すれば、<a href="https://sozorablog.com/vnc/">VNC</a>というリモート操作の仕組みを使い、<span class="sbd-text-red">パソコンの画面上でRaspberry Piを操作</span>できるようになります。<br></p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="350" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-7-3.jpg" alt="" class="wp-image-15311"/></figure>



<p>この記事では、モニターやキーボードを使わずにRaspberry Piをセットアップする方法を、わかりやすく解説します。</p>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>本記事で紹介する方法では、設定中の状況がイメージしにくい場合があります。<span class="sbd-text-red">完全に初めての方</span>でモニターやキーボード・マウスをお持ちの場合は、それらを使って<a href="https://sozorablog.com/raspberrypi_initial_setting/">通常の方法</a>で設定することをおすすめします。</p>
</div></div>



<h2 class="wp-block-heading">用意するもの</h2>



<p>ヘッドレスセットアップを行う前に、以下の機器を準備しておきましょう。また、ネットワークに接続する必要があるため、Wi-Fiを使う場合はSSIDとパスワードを確認しておいてください。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-9.png" alt=""/></figure>



<div class="wp-block-sbd-list"><ul class="sbd-list sbd-list-border"><li>パソコン（SDカードリーダーが必要）</li><li>microSDカード</li><li>電源アダプター</li></ul></div>



<p>以下のmicroSDカードは、僕が何度もリピート購入しているものです。ブログ記事の動作検証でOSを繰り返しインストールしても、安定して使えています。容量は32GBですが、不足を感じたことはありません。</p>



<!-- START MoshimoAffiliateEasyLink -->
<script type="text/javascript">
(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;
b[a]=b[a]||function(){arguments.currentScript=c.currentScript
||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};
c.getElementById(a)||(d=c.createElement(f),d.src=g,
d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})
(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");
msmaflink({"n":"【 サンディスク 正規品 】 SanDisk microSD カード 32GB UHS-I U1 Class10 Nintendo Switch メーカー動作確認済 Ultra SDSQUA4-032G-GH3MA 簡易デザインパッケージ 10年間限定保証","b":"SanDisk","t":"SDSQUA4-032G-GH3MA","d":"https:\/\/m.media-amazon.com","c_p":"\/images\/I","p":["\/41SqvUEpuxL._SL500_.jpg","\/41BWt55RLVL._SL500_.jpg","\/41CzE-jpW5L._SL500_.jpg","\/51Ooj+2u5QL._SL500_.jpg","\/51Vt9UyQ7hL._SL500_.jpg","\/41HjeLVv6sL._SL500_.jpg","\/51En9zgEKCL._SL500_.jpg","\/519N3yR7t1L._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0CH2WM7QY","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":1,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0CH2WM7QY","a_id":3038653,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"id":3,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/%E3%80%90%20%E3%82%B5%E3%83%B3%E3%83%87%E3%82%A3%E3%82%B9%E3%82%AF%20%E6%AD%A3%E8%A6%8F%E5%93%81%20%E3%80%91%20SanDisk%20microSD%20%E3%82%AB%E3%83%BC%E3%83%89%2032GB%20UHS-I%20U1%20Class10%20Nintendo%20Switch%20%E3%83%A1%E3%83%BC%E3%82%AB%E3%83%BC%E5%8B%95%E4%BD%9C%E7%A2%BA%E8%AA%8D%E6%B8%88%20Ultra%20SDSQUA4-032G-GH3MA%20%E7%B0%A1%E6%98%93%E3%83%87%E3%82%B6%E3%82%A4%E3%83%B3%E3%83%91%E3%83%83%E3%82%B1%E3%83%BC%E3%82%B8%2010%E5%B9%B4%E9%96%93%E9%99%90%E5%AE%9A%E4%BF%9D%E8%A8%BC\/","a_id":3038654,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":2}],"eid":"0fAL9","s":"s"});
</script>
<div id="msmaflink-0fAL9">リンク</div>
<!-- MoshimoAffiliateEasyLink END -->



<p>電源アダプターは専用品を用意しましょう。汎用品だと電流不足で正常に動作しない場合があります。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="743" src="https://sozorablog.com/wp-content/uploads/2025/08/IMG_9472.jpeg" alt="" class="wp-image-15606" style="aspect-ratio:1.0767193706674976;width:334px;height:auto"/><figcaption class="wp-element-caption"><a href="https://akizukidenshi.com/catalog/g/g130329/">Raspberry Pi公式電源アダプター</a></figcaption></figure>



<figure class="wp-block-table wp-block-sbd-table wp-block-sbd-table-vertical"><table class="has-fixed-layout"><thead><tr><th>モデル名</th><th>推奨電源</th><th>コネクタ</th><th>おすすめ</th></tr></thead><tbody><tr><td>Raspberry Pi 5</td><td>5.1V / 5A</td><td>USB-C</td><td><span class="sbd-table-btn"><a href="https://akizukidenshi.com/catalog/g/g130329/">おすすめアダプター</a></span></td></tr><tr><td>Raspberry Pi 4</td><td>5.1V / 3A</td><td>USB-C</td><td><span class="sbd-table-btn"><a href="https://akizukidenshi.com/catalog/g/g114935/">おすすめアダプター</a></span></td></tr><tr><td>Raspberry Pi 3A+</td><td>5.1V / 2.5A</td><td>micro USB</td><td><span class="sbd-table-btn"><a href="https://akizukidenshi.com/catalog/g/g112001/">おすすめアダプター</a></span></td></tr><tr><td>Raspberry Pi Zero 2W</td><td>5.1V / 2.5A</td><td>micro USB</td><td><span class="sbd-table-btn"><a href="https://akizukidenshi.com/catalog/g/g112001/">おすすめアダプター</a></span></td></tr><tr><td>Raspberry Pi Zero W</td><td>5.1V / 2.0A</td><td>micro USB</td><td><span class="sbd-table-btn"><a href="https://akizukidenshi.com/catalog/g/g112001/">おすすめアダプター</a></span></td></tr></tbody></table></figure>



<h2 class="wp-block-heading">PCで「Raspberry Pi Imager」を使うための準備</h2>



<p>まずRaspberry Piで使用するOSをmicroSDカードにインストールします。OSのインストールには「<strong><a href="https://www.raspberrypi.org/downloads/">Raspberry Pi Imager</a></strong>」を使います。「Raspberry Pi Imager」はmicroSDカードの初期化から、OSインストールまでを自動で行う便利なソフトです。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/11/pico-1.png" alt=""/></figure>



<p>「Raspberry Pi&nbsp;Imager」を<a href="https://www.raspberrypi.org/downloads/" target="_blank" rel="noreferrer noopener">Raspberry Pi公式サイト</a>からパソコンにダウンロードします。</p>



<div class="wp-block-sbd-btn is-style-sbd-btn-orange"><p class="sbd-btn-copy"></p><div class="sbd-btn sbd-btn-75 sbd-btn-circle"><a href="https://www.raspberrypi.org/downloads/" target="_blank" rel="noopener">「Raspberry Pi Imager」のダウンロードはこちらから</a></div></div>



<p>「Raspberry Pi Imager」には、Windows版・macOS版・Ubuntu版の3種類があります。本記事ではWindows版をダウンロードします。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/11/raspberry-pi-OS-install3.png" alt="Raspberry Pi 公式ページの画面" style="aspect-ratio:1.275735294117647;width:510px;height:auto"/></figure>



<p>Windowsの場合は「Download for Windows」をクリックします。ダウンロードしたexeファイルをダブルクリックすると、インストーラーが起動します。</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/04/無題4.png" alt="" class="wp-image-4" style="aspect-ratio:1.2773722627737227;width:492px;height:auto"/></figure>



<p>「Install」をクリックする。</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/04/5.png" alt="" class="wp-image-4" style="aspect-ratio:1.2950819672131149;width:485px;height:auto"/></figure>



<p>「Finish」をクリックすると、インストールが完了します。</p>



<h2 class="wp-block-heading">microSDカードにOSをインストールする</h2>



<p>まずパソコンにmicroSDカードをセットします。エクスプローラーが自動で開いたり、ポップアップが表示された場合は、無視して閉じて構いません。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/11/IMG_8691.jpeg" alt="" style="width:507px;height:auto"/></figure>



<h3 class="wp-block-heading">「Raspberry Pi Imager」を起動</h3>



<p>インストールした「Raspberry Pi Imager」を起動します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/11/raspberry-pi-imager-How-to-start.png" alt="" style="width:504px;height:412px"/></figure>



<p>「Raspberry Pi Imager」の画面が開いたら、「デバイスを選択」をクリックします。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-8.png" alt="" style="width:503px;height:auto"/></figure>



<p>使用するRaspberry Piのモデルを選択します。この選択により、使用できるOSの選択肢が絞り込まれます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/スクリーンショット-2025-06-18-8.30.41.png" alt="" style="width:499px;height:auto"/></figure>



<h3 class="wp-block-heading">インストールするOSを選択する</h3>



<p>「OSを選択」をクリックします。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-1-2.png" alt="" style="width:496px;height:auto"/></figure>



<p>Raspberry Pi 5を選択した場合は、以下の選択肢が表示されます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/スクリーンショット-2025-06-18-8.33.06.png" alt="" style="width:502px;height:auto"/></figure>



<p>さまざまなOSを選択できますが、今回は公式のOSである<a href="https://sozorablog.com/raspberry-pi-os/">Raspberry Pi OS</a>をインストールします。Windows OSに近い操作性で、アプリケーションの起動やファイル管理などがマウス操作で直感的にできます。</p>



<p>2025年12月時点で選択できるRaspberry Pi OSの種類は以下のとおりです。</p>



<figure class="wp-block-table wp-block-sbd-table wp-block-sbd-table-vertical sbd-table--scroll sbd-table--fixed sbd-table--scroll-none"><table><thead><tr><th>OS名</th><th>ベースとなるDebian<br>のバージョン</th><th>Raspberry Pi 5<br>Raspberry Pi 500</th><th>Raspberry Pi 4<br>Raspberry Pi 3<br>Raspberry Pi Zero 2 W<br>Raspberry Pi 400</th><th>Raspberry Pi Zero</th><th>特徴</th></tr></thead><tbody><tr><td>Raspberry Pi&nbsp;OS（64-bit）(推奨)</td><td><span class="sbd-text-red">Trixie</span></td><td>〇</td><td>〇</td><td>－</td><td>最新OSの64ビット版</td></tr><tr><td>Raspberry Pi&nbsp;OS<br>（32-bit）</td><td><span class="sbd-text-red">Trixie</span></td><td>〇</td><td>〇</td><td>〇</td><td>上記の32ビット版</td></tr><tr><td>Raspberry Pi&nbsp;OS Full<br>（64-bit）</td><td><span class="sbd-text-red">Trixie</span></td><td>〇</td><td>〇</td><td>－</td><td>アプリが充実している<br>容量は大きい</td></tr><tr><td>Raspberry Pi&nbsp;OS Full<br>（32-bit）</td><td><span class="sbd-text-red">Trixie</span></td><td>〇</td><td>〇</td><td>〇</td><td>アプリが充実している<br>容量は大きい</td></tr><tr><td>Raspberry Pi&nbsp;OS Lite<br>（64-bit）</td><td><span class="sbd-text-red">Trixie</span></td><td>〇</td><td>〇</td><td>－</td><td>GUIなし<br>上級者用</td></tr><tr><td>Raspberry Pi&nbsp;OS Lite<br>（32-bit）</td><td><span class="sbd-text-red">Trixie</span></td><td>〇</td><td>〇</td><td>〇</td><td>GUIなし<br>上級者用</td></tr><tr><td>Raspberry Pi&nbsp;OS<br>（Legacy,64-bit）</td><td>Bookworm</td><td>－</td><td>〇</td><td>－</td><td>1世代前のOSを使いたい人用</td></tr><tr><td>Raspberry Pi&nbsp;OS<br>（Legacy,32-bit）</td><td>Bookworm</td><td>－</td><td>－</td><td>〇</td><td>1世代前のOSを使いたい人用</td></tr><tr><td>Raspberry Pi&nbsp;OS Full<br>（Legacy,64-bit）</td><td>Bookworm</td><td>－</td><td>〇</td><td>－</td><td>1世代前のOSを使いたい人用<br>アプリが充実</td></tr><tr><td>Raspberry Pi&nbsp;OS Full<br>（Legacy,32-bit）</td><td>Bookworm</td><td>－</td><td>〇</td><td>〇</td><td>1世代前のOSを使いたい人用<br>アプリが充実</td></tr><tr><td>Raspberry Pi&nbsp;OS Lite<br>（Legacy,64-bit）</td><td>Bookworm</td><td>－</td><td>〇</td><td>－</td><td>1世代前のOSを使いたい人用<br>上級者向き</td></tr><tr><td>Raspberry Pi&nbsp;OS Lite<br>（Legacy,32-bit）</td><td>Bookworm</td><td>－</td><td>〇</td><td>〇</td><td>1世代前のOSを使いたい人用<br>上級者向き</td></tr></tbody></table><figcaption class="wp-element-caption">Raspberry Pi OSの種類</figcaption></figure>



<p>Raspberry Pi OSには主に「Trixie（最新版）」と「Bookworm（旧版）」があります。特別な理由がなければ、最新版を選びましょう。</p>



<p>OSは「64ビット」と「32ビット」がありますが、特に理由がなければ「64ビット」を選んでおけば問題ありません。エディションは「Full版」「Lite版」「通常版」の3つです。</p>



<p>迷った場合は、「<span class="sbd-text-bold">with the Raspberry Pi Desktop(Recommended)</span>」と表示されているOSを選ぶのが安心です。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="428" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-8-2.jpg" alt="" class="wp-image-15313"/></figure>



<h3 class="wp-block-heading">ストレージを選択</h3>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-2-1.png" alt="" style="width:510px;height:auto"/></figure>



<p>書き込み先のストレージであるmicroSDカードを選択します。名前と容量を確認し、対象をクリックします。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-3-2.png" alt="" style="width:504px;height:auto"/></figure>



<p>右下のチェックボックス「Exclude System Drives（システムドライブを除外）」は、誤ってパソコン本体のドライブなどにOSを書き込まないように保護する設定です。基本的に<span class="sbd-text-red">チェックのまま</span>でOKです。</p>



<div class="wp-block-sbd-checkpoint-block"><p class="sbd-checkpoint-title">チェックポイント</p><div class="sbd-checkpoint-content sbd-inner-block-init"><p>microSDカードの名称が正しいか不安な場合は、カードを一度抜いて画面から消えるか確認し、再度挿して表示されるかをチェックすると安心です。</p></div></div>



<p>「次へ」をクリックします。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-4-3.png" alt="" style="width:520px;height:auto"/></figure>



<h3 class="wp-block-heading">カスタマイズ設定をする</h3>



<p>「Would you like to apply OS customization settings?（OSのカスタマイズ設定を適用しますか？）」という画面が出るので、「設定を編集する」をクリックします。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-5-2.png" alt="" style="width:526px;height:auto"/></figure>



<p>この画面では、Raspberry Piの設定情報をOSのインストールと同時にSDカードに書き込むことができます。ここで設定しておくと、ラズパイを起動後すぐにWi-Fi接続などができるようになります。</p>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>モニターやキーボードを使わない「ヘッドレスセットアップ」を行う場合には、この設定が必須です。</p>
</div></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/Raspberry-Pi進化の歴史.png" alt="" style="width:553px;height:auto"/></figure>



<h4 class="wp-block-heading">①ホスト名</h4>



<p>ホスト名は、ネットワーク上でRaspberry Piを識別するための名前です。デフォルトで「raspberrypi」に設定されており、基本的にはそのままで問題ありません。</p>



<div class="wp-block-sbd-checkpoint-block"><p class="sbd-checkpoint-title">チェックポイント</p><div class="sbd-checkpoint-content sbd-inner-block-init"><p>すでにネットワークに接続されたRaspberry Piを使っている環境で、<span class="sbd-text-red">2台目のラズパイをセットアップする場合</span>は名前の変更が必要です<strong>。</strong>複数台が同じホスト名だと、初回のSSHで正しく接続できなくなることがあります。</p></div></div>



<h4 class="wp-block-heading">②ユーザー名とパスワードを設定する</h4>



<p>ユーザー名とパスワードは、Raspberry Piの起動時に入力するので、どちらも忘れないように控えておいてください。</p>



<h4 class="wp-block-heading">③Wi-Fiを設定する</h4>



<p>Wi-Fiの設定では、自宅のSSID（ネットワーク名）とWi-Fiパスワードを入力します。</p>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>Raspberry Pi Zeroシリーズは、<strong>2.4GHz帯のWi-Fi</strong>のみに対応しています。</p>
</div></div>



<p>SSID（Wi-Fiのネットワーク名）が非公開（ブロードキャストされていない）場合には、「ステルスID」チェックを入れます。通常はチェック不要です。</p>



<p>「Wifiを使う国」は「JP」を選択します。</p>



<h4 class="wp-block-heading">④ロケールを設定する</h4>



<p>タイムゾーンは「Asia/Tokyo」を選択（日本時間を使用）、キーボードレイアウトは「jp」を選択（日本語キーボードを使用）します。</p>



<h4 class="wp-block-heading">SSHの設定</h4>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-6-1.png" alt="" style="width:482px;height:auto"/></figure>



<p>上部の「サービス」タブをクリックし、「SSHを有効化する」にチェックを入れたあと、「パスワード認証を使う」を選択します。</p>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>SSHとは、ネットワーク経由でラズベリーパイなどの機器を安全に操作するためのリモート接続方法です。</p>
</div></div>



<p>「保存」をクリックすると、以下の画面が出るので、「はい」 をクリックします。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-8-1.png" alt="" style="width:525px;height:auto"/></figure>



<h3 class="wp-block-heading">OSの書き込み</h3>



<p>「はい」をクリックすると書き込みを開始します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-7-2.png" alt="" style="width:537px;height:auto"/></figure>



<p>イメージファイルの書き込みが完了するまで、しばらく待ちます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/スクリーンショット-2025-06-18-11.29.57.png" alt="" style="width:509px;height:auto"/></figure>



<p>OSの種類やパソコンの性能によって時間は変わりますが、通常は10〜20分で書き込みが終わることが多いです。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/11/raspberry-pi-imager11.png" alt="" style="width:512px;height:337px"/></figure>



<p>書き込みが完了したら、作業用PCからmicroSDカードを取り出します。</p>



<h2 class="wp-block-heading">Raspberry Piの起動</h2>



<p>Raspberry Pi本体にmicroSDカードをセットします。ラベルのある面を上にして、スロットにまっすぐ差し込みます。奥まで入ればセット完了です。クリック音やロックはありません。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-9.jpg" alt=""/><figcaption class="wp-element-caption">microSDカードをセット</figcaption></figure>



<p>Raspberry Piに電源ケーブルを接続すると、自動的に起動し、microSDカード内のOSの読み込みが始まります。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-10.jpg" alt=""/><figcaption class="wp-element-caption">電源コネクターの位置</figcaption></figure>



<h2 class="wp-block-heading">パソコンからラズパイの設定をする</h2>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="329" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-6-2.jpg" alt="" class="wp-image-15310"/></figure>



<p>ここからは、パソコンからネットワーク経由でRaspberry Piにアクセスし、デスクトップ画面を操作するための設定をしていきます。</p>



<h3 class="wp-block-heading">SSH接続する</h3>



<p>Windowsの場合はコマンドプロンプトを開きます。デスクトップ画面左下の検索ボックスに「cmd」と入力し、表示された「コマンドプロンプト」をクリックすると開けます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/image-2.jpg" alt="" style="width:491px;height:auto"/></figure>



<p>macOSの場合は、Launchpad → 「その他」フォルダ → 「ターミナル」の順にクリックします。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-9-1.jpg" alt=""/></figure>



<p>以下のようなコマンドを入力します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>ssh ユーザー名@ホスト名.local</code></pre></div>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>同じネットワーク内のRaspberry Piに、ユーザー名とホスト名を使ってSSH接続するためのコマンドです。</p>
</div></div>



<p>たとえば、ユーザー名が <code>pi</code>、ホスト名が <code>raspberrypi</code> の場合は「ssh pi@raspberrypi.local」と入力して、Enterキーを押します。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/image-2.png" alt=""/></figure>



<p>初回接続では「この接続を信頼していいですか？」と確認するメッセージが出るので、「yes」と入力してEnterキーを押します。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="737" height="84" src="https://sozorablog.com/wp-content/uploads/2025/06/スクリーンショット-2025-06-19-4.08.04-1.png" alt="" class="wp-image-15319"/></figure>



<p>パスワードを聞かれるので、事前に設定したパスワードを入力します。<span class="sbd-text-red">画面には表示されません</span>が、そのまま入力して Enter キーを押してください。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/image-4.png" alt=""/></figure>



<p>認証に成功すると「pi@raspberrypi:~ $」のような表示が出ます。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/image-5.png" alt=""/></figure>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>これは、Raspberry Piがコマンドの入力を受け付ける準備ができたことを示しています。</p>
</div></div>



<p>ここからコマンドを入力して、Raspberry Piの設定をしていきます。</p>



<h3 class="wp-block-heading">VNCを使用するための設定</h3>



<p>VNC（Virtual Network Computing）を有効にします。これにより、同じネットワーク内のパソコンからRaspberry Piの画面を遠隔操作できるようになります。</p>



<p>以下のコマンドを入力して、Enterキーを押します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo raspi-config nonint do_vnc 0</code></pre></div>



<p>Raspberry PiのIPアドレスを確認します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>hostname -I</code></pre></div>



<p>最初に表示されている「192.168.1.159」は、IPアドレスの一例です。実際の値は環境によって異なります。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-1-3.png" alt=""/></figure>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>あとでVNC接続する際に必要なので、表示されたIPアドレスを控えておきましょう。</p>
</div></div>



<h3 class="wp-block-heading">その他の設定</h3>



<p>以下の設定を済ませておくことで、Raspberry Piをより快適に使えるようになります。コマンドを順に実行していきます。</p>



<p>OSやソフトウェアを最新の状態に更新します。まずインストール可能なソフトウェアの最新情報を取得して、パッケージ一覧を最新の状態に更新します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo apt update</code></pre></div>



<p>取得した最新情報をもとに、すでにインストールされているソフトウェアをすべて更新します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo apt upgrade -y</code></pre></div>



<p>Raspberry Piのシステム言語（ロケール）を日本語に設定します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo raspi-config nonint do_change_locale ja_JP.UTF-8</code></pre></div>



<p>デスクトップ環境で日本語入力をできるようにするため、fcitx5とMozcをインストールします。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo apt install -y fcitx5-mozc</code></pre></div>



<p>設定を反映させるために、Raspberry Piを再起動します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo reboot</code></pre></div>



<h2 class="wp-block-heading">パソコンからVNC接続をする</h2>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-2-3-1.jpg" alt=""/></figure>



<p>パソコンに「RealVNC Viewer」をインストールし、ラズパイのIPアドレスを入力して接続すれば、Raspberry Piの画面を操作できます。</p>



<div class="wp-block-sbd-background-block sbd-bg-color sbd-inner-block-init is-style-yellow">
<p>VNCのインストール方法は、以下の記事で詳しく解説しています。<br><span class="sbd-text-bold"><a href="https://sozorablog.com/vnc/">≫【ラズベリーパイを遠隔操作】VNCでＰＣからリモート接続する方法</a></span></p>
</div>



<p>上記の記事を参考にして、VNCをインストールします。</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/05/82.png" alt="" style="width:463px;height:333px"/></figure>



<p>RealVNC Viewerを起動し、Raspberry PiのIPアドレス・ユーザー名・パスワードを入力して「OK」をクリックします。</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/05/83.png" alt="" class="wp-image-4" style="aspect-ratio:1.154109589041096;width:468px;height:auto"/></figure>



<p>初回の接続時には警告が出ますが、「Continue」をクリックして接続します。以降、同じサーバーではこの警告は表示されません。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/05/pico-2025-01-25T065327.988.jpg" alt="" class="wp-image-4" style="width:469px;height:auto"/></figure>



<p>接続が完了すると、パソコンの画面にラズベリーパイのデスクトップが表示されます。そのまま操作可能です。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/05/vnc.jpg" alt="" class="wp-image-4" style="width:840px;height:auto"/></figure>



<div class="wp-block-sbd-background-block sbd-bg-color sbd-inner-block-init is-style-yellow">
<p>Raspberry Piの基本操作については、以下の記事の後半部分を参考にしてください。<br><span class="sbd-text-bold"><a href="https://sozorablog.com/raspberrypi_initial_setting/">≫【2025年最新版】OSインストールから初期設定まで｜ラズベリーパイ(Raspberry Pi)セットアップ手順のすべて</a></span></p>
</div>



<h2 class="wp-block-heading">VNC画面の解像度を調整する</h2>



<p>VNCで表示される画面が大きすぎる場合は、解像度を変更して調整できます。画面左上のラズベリーマークをクリックし、「設定」→「Screen Configuration」を選択します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-4-4.jpg" alt="" class="wp-image-4" style="width:422px;height:auto"/></figure>



<p>設定画面が開いたら、「Screens」をクリックします。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-1-4.png" alt="" class="wp-image-4" style="width:428px;height:auto"/></figure>



<p>「NOOP-1」などの名称を選択し、解像度を選択。表示された中から希望の解像度を選択します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-3-3-1.jpg" alt="" class="wp-image-4" style="width:431px;height:auto"/></figure>



<p>「Apply」をクリックして変更を適用します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-4-5.png" alt="" style="width:441px;height:auto"/></figure>



<p>画面サイズに問題がなければ「OK」をクリックします。もし見づらい場合は「Cancel」を押して、解像度を再度調整します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="450" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-5-3.png" alt="" class="wp-image-15308" style="width:439px;height:auto" srcset="https://sozorablog.com/wp-content/uploads/2025/06/pico-5-3.png 800w, https://sozorablog.com/wp-content/uploads/2025/06/pico-5-3-320x180.png 320w, https://sozorablog.com/wp-content/uploads/2025/06/pico-5-3-224x126.png 224w" sizes="(max-width: 800px) 100vw, 800px" /></figure>



<h2 class="wp-block-heading">まとめ</h2>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="809" src="https://sozorablog.com/wp-content/uploads/2025/06/IMG_9128.jpeg" alt="" class="wp-image-15304" style="width:492px;height:auto"/></figure>



<p>モニターやキーボードを使わずにラズベリーパイをセットアップする「ヘッドレスセットアップ」は、手順を覚えれば通常の方法より手早く準備できます。</p>



<p>Raspberry Pi Imagerでは一度設定した内容が保存されるため、次回以降は同じ設定を使えて、複数台のセットアップもスムーズに行えます。作業時間の短縮にもつながるため、慣れてくると非常に便利な方法です。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sozorablog.com/raspberrypi-headless-setup/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>ラズパイで気象衛星ひまわりの画像を表示する装置を作ろう</title>
		<link>https://sozorablog.com/himawari/</link>
					<comments>https://sozorablog.com/himawari/#comments</comments>
		
		<dc:creator><![CDATA[そぞら]]></dc:creator>
		<pubDate>Tue, 17 Jun 2025 08:03:57 +0000</pubDate>
				<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[使い方]]></category>
		<guid isPermaLink="false">https://sozorablog.com/?p=14947</guid>

					<description><![CDATA[はるか3万6千kmの上空から、静かに地球を見つめる「気象衛星ひまわり」。 その目に映る宇宙の静けさと地球のうつろいを、自宅の小さなディスプレイに映し出せたら…そんな夢のような装置をRaspberry Piで作ってみました [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>はるか3万6千kmの上空から、静かに地球を見つめる「気象衛星ひまわり」。</p>



<p>その目に映る宇宙の静けさと地球のうつろいを、自宅の小さなディスプレイに映し出せたら…そんな夢のような装置を<a href="https://sozorablog.com/raspberry-pi/">Raspberry Pi</a>で作ってみました。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="777" src="https://sozorablog.com/wp-content/uploads/2025/06/IMG_9116.jpg" alt="" class="wp-image-15147"/></figure>



<p><br>この記事では、ひまわりの最新画像を自動で取得して、ディスプレイ表示するシステムの作り方を紹介します。比較的安価な小型ディスプレイを使っているので、ぜひお試しください。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="536" src="https://sozorablog.com/wp-content/uploads/2025/06/IMG_9021.jpg" alt="" class="wp-image-15132"/></figure>



<p>記事の後半では、ダイソーのミラーデジタル時計に装置一式を収納する応用方法も紹介しています。</p>



<h2 class="wp-block-heading">用意するもの</h2>



<p>使用したラズパイは、<a href="https://sozorablog.com/raspberry-pi-zero-2-w/">Raspberry Pi Zero 2 W</a>にピンヘッダーを取り付けたものです。サイズ的にもスペック的にも今回のプロジェクトに適任です。まだ持っていない場合は、あらかじめピンヘッダーが実装されている「WH」モデルを選ぶと、配線作業がスムーズに進みます。</p>



<!-- START MoshimoAffiliateEasyLink -->
<script type="text/javascript">
(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;
b[a]=b[a]||function(){arguments.currentScript=c.currentScript
||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};
c.getElementById(a)||(d=c.createElement(f),d.src=g,
d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})
(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");
msmaflink({"n":"Raspberry Pi Zero 2 WH - はんだ付け済みヘッダー付き","b":"Raspberry Pi","t":"SC0721","d":"https:\/\/m.media-amazon.com","c_p":"\/images\/I","p":["\/3163qDOAfcL._SL500_.jpg","\/31+bar+PxKL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0DB2JBD9C","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":1,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0DB2JBD9C","a_id":3038653,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"id":2,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/Raspberry%20Pi%20Zero%202%20WH%20-%20%E3%81%AF%E3%82%93%E3%81%A0%E4%BB%98%E3%81%91%E6%B8%88%E3%81%BF%E3%83%98%E3%83%83%E3%83%80%E3%83%BC%E4%BB%98%E3%81%8D\/","a_id":3038654,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":2}],"eid":"OtHms","s":"s"});
</script>
<div id="msmaflink-OtHms">リンク</div>
<!-- MoshimoAffiliateEasyLink END -->



<p>Zero 2 Wの<a href="https://www.sengoku.co.jp/mod/sgk_cart/detail.php?code=EEHD-6JMG">電源アダプター</a>は、2.5A以上が推奨されています。コネクタはmicroUSBです。</p>



<p>本記事のコードは、以下のモデルでも動作確認しています。</p>



<div class="wp-block-sbd-list"><ul class="sbd-list sbd-list-border"><li><a href="https://sozorablog.com/pi5/">Raspberry Pi 5</a></li><li><a href="https://sozorablog.com/raspberry-pi-4-revue/">Raspberry Pi 4</a></li><li><a href="https://sozorablog.com/raspberry-pi-3-model-a/">Raspberry Pi 3 A+</a></li><li><a href="https://sozorablog.com/raspberry-pi-500/">Raspberry Pi 500</a></li></ul></div>



<p>表示に使用したのは、SPI接続のILI9341ドライバーを搭載した2.2インチのディスプレイです。解像度は240×320ピクセルで、気象衛星ひまわりの画像も鮮明に表示できます。</p>



<!-- START MoshimoAffiliateEasyLink -->
<script type="text/javascript">
(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;
b[a]=b[a]||function(){arguments.currentScript=c.currentScript
||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};
c.getElementById(a)||(d=c.createElement(f),d.src=g,
d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})
(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");
msmaflink({"n":"Hailege 2.2\u0022 ILI9341 SPI TFT LCDディスプレイ240x320 ILI9341 LCDスクリーン、Arduino Raspberry Pi用SDカードスロット","b":"Hailege","t":"H-A-0191","d":"https:\/\/m.media-amazon.com","c_p":"\/images\/I","p":["\/418wYf3koZL._SL500_.jpg","\/41t5jOFHmxL._SL500_.jpg","\/41J2n4cDVNL._SL500_.jpg","\/41J0D7SgIsL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B08D7D14X9","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":1,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B08D7D14X9","a_id":3038653,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"id":2,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/Hailege%202.2%22%20ILI9341%20SPI%20TFT%20LCD%E3%83%87%E3%82%A3%E3%82%B9%E3%83%97%E3%83%AC%E3%82%A4240x320%20ILI9341%20LCD%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%BC%E3%83%B3%E3%80%81Arduino%20Raspberry%20Pi%E7%94%A8SD%E3%82%AB%E3%83%BC%E3%83%89%E3%82%B9%E3%83%AD%E3%83%83%E3%83%88\/","a_id":3038654,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":2}],"eid":"JcjPt","s":"s"});
</script>
<div id="msmaflink-JcjPt">リンク</div>
<!-- MoshimoAffiliateEasyLink END -->



<p>Raspberry PiとLCDを接続するためのジャンパーワイヤーが必要です。ジャンパーワイヤーはGPIOピンとディスプレイの端子に差し込んで接続するための細い電線です。今回はメス－メスのジャンパーワイヤーを9本使用します。</p>



<!-- START MoshimoAffiliateEasyLink -->
<script type="text/javascript">
(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;
b[a]=b[a]||function(){arguments.currentScript=c.currentScript
||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};
c.getElementById(a)||(d=c.createElement(f),d.src=g,
d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})
(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");
msmaflink({"n":"ELEGOO 120pcs多色デュポンワイヤー、arduino用ワイヤ—ゲ—ジ28AWG オス-メス オス-オス メス –メス ブレッドボードジャンパーワイヤー","b":"ELEGOO","t":"JP-EL-CP-004","d":"https:\/\/m.media-amazon.com","c_p":"\/images\/I","p":["\/61TQP733AwL._SL500_.jpg","\/51HXtm4ZIlL._SL500_.jpg","\/51X0hlpDgxL._SL500_.jpg","\/51xNzsKVu0L._SL500_.jpg","\/51kRXsE11KL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B06Y48V9DL","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":1,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B06Y48V9DL","a_id":3038653,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"id":2,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/ELEGOO%20120pcs%E5%A4%9A%E8%89%B2%E3%83%87%E3%83%A5%E3%83%9D%E3%83%B3%E3%83%AF%E3%82%A4%E3%83%A4%E3%83%BC%E3%80%81arduino%E7%94%A8%E3%83%AF%E3%82%A4%E3%83%A4%E2%80%94%E3%82%B2%E2%80%94%E3%82%B828AWG%20%E3%82%AA%E3%82%B9-%E3%83%A1%E3%82%B9%20%E3%82%AA%E3%82%B9-%E3%82%AA%E3%82%B9%20%E3%83%A1%E3%82%B9%20%E2%80%93%E3%83%A1%E3%82%B9%20%E3%83%96%E3%83%AC%E3%83%83%E3%83%89%E3%83%9C%E3%83%BC%E3%83%89%E3%82%B8%E3%83%A3%E3%83%B3%E3%83%91%E3%83%BC%E3%83%AF%E3%82%A4%E3%83%A4%E3%83%BC\/","a_id":3038654,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":2}],"eid":"Njd8v","s":"s"});
</script>
<div id="msmaflink-Njd8v">リンク</div>
<!-- MoshimoAffiliateEasyLink END -->



<h2 class="wp-block-heading">ラズパイとディスプレイの接続</h2>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="807" src="https://sozorablog.com/wp-content/uploads/2025/06/IMG_9089.jpg" alt="" class="wp-image-15152" style="width:477px;height:auto"/></figure>



<p>ディスプレイは、SPI通信を使ってRaspberry Piと接続します。配線には、データ転送に必要なSCKやMOSIのほか、制御用のCS（チップセレクト）、DC（データ/コマンド切り替え）、RST（リセット）ピン、さらにバックライト用のBLピンを使用します。</p>



<p>以下の図のように、ジャンパーワイヤーを使ってRaspberry PiのGPIOピンとディスプレイの各ピンを接続します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="450" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-1.jpg" alt="" class="wp-image-15139" style="width:840px;height:auto" srcset="https://sozorablog.com/wp-content/uploads/2025/06/pico-1.jpg 800w, https://sozorablog.com/wp-content/uploads/2025/06/pico-1-320x180.jpg 320w, https://sozorablog.com/wp-content/uploads/2025/06/pico-1-224x126.jpg 224w" sizes="(max-width: 800px) 100vw, 800px" /></figure>



<h2 class="wp-block-heading">ソフトウェアの準備</h2>



<p>Raspberry Pi OSはBookworm 64-bitのデスクトップ版を使用しました。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="461" height="128" src="https://sozorablog.com/wp-content/uploads/2025/06/image-1.png" alt="" class="wp-image-15146" style="width:840px;height:auto"/></figure>



<div class="wp-block-sbd-background-block sbd-bg-color sbd-inner-block-init is-style-yellow">
<p>Raspberry PiのOSをインストールする方法は、以下の記事で詳しく解説しています。<br><strong><a href="https://sozorablog.com/raspberrypi_initial_setting/">≫【2025年最新版】OSインストールから初期設定まで｜セットアップ手順のすべて</a></strong></p>
</div>



<h3 class="wp-block-heading">ラズパイのSPIを有効にする</h3>



<p>LCDを使うには、SPIインターフェースを有効にする必要があります。</p>



<p>デスクトップ左上の「ラズベリーマーク（メニュー）」をクリックし、設定」→「Raspberry Piの設定」を選びます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/11/pico-2-3.jpg" alt="" style="width:533px;height:auto"/></figure>



<p>「インターフェイス」タブを開き、「SPI」の項目を「有効」に切り替えます。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-1.png" alt=""/><figcaption class="wp-element-caption">SPIが有効になっている状態</figcaption></figure>



<p>再起動を求められた場合は「はい」を選んで再起動します。</p>



<h3 class="wp-block-heading">ライブラリのインストール</h3>



<p>Pythonで使う「ライブラリ」とは、便利な機能が詰まった道具箱のようなものです。ライブラリ使うと、本来は長くなってしまうプログラムを短いコードで書けるようになります。</p>



<p>以下の手順に沿って、必要なライブラリをインストールします。インストール作業はターミナルを使って行います。</p>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>ターミナルとは、コマンドを入力してRaspberry Piを操作するための画面です。</p>
</div></div>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="485" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-99.jpg" alt="" class="wp-image-15138"/></figure>



<p>Pythonライブラリをインストールするため仮想環境myenvを作成します。myenvは仮想環境の名前です。好きな名前に変更できます。</p>



<div class="wp-block-sbd-checkpoint-block"><p class="sbd-checkpoint-title">チェックポイント</p><div class="sbd-checkpoint-content sbd-inner-block-init"><p>仮想環境とは、Pythonの実行環境をプロジェクトごとに独立して管理できる仕組みです。これにより、ライブラリ同士のバージョンによる競合を防ぎ、予期せぬエラーを回避できます。</p></div></div>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>Bookwormでは仮想環境を使用せずにpipを実行するとエラーが発生し、ライブラリをインストールできない仕様になっています。</p>
</div></div>



<p>下記のコマンドをターミナルに入力してEnterキーを押してください。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>python3 -m venv ~/myenv --system-site-packages</code></pre></div>



<p>作成した仮想環境myenvを有効にします。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>source myenv/bin/activate</code></pre></div>



<p>pipを最新バージョンにアップグレードします。pipはPython専用のインストールツールです。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>pip install --upgrade pip</code></pre></div>



<p><a href="https://www.adafruit.com/?srsltid=AfmBOoqUEpXUkQP7sp5Gpo9RHC3zaQFOsHqDF4iv92B5WlyezkfNyHgW">Adafruit</a>が公開しているRGBディスプレイを制御するための<a href="https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display">adafruit-circuitpython-rgb-display</a>ライブラリをインストールします。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>pip install adafruit-circuitpython-rgb-display</code></pre></div>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>adafruit-circuitpython-rgb-displayは、ILI9341などの汎用的なディスプレイコントローラーにも対応しており、Adafruit製以外のディスプレイでも利用できます。</p>
</div></div>



<div class="wp-block-sbd-checkpoint-block"><p class="sbd-checkpoint-title">チェックポイント</p><div class="sbd-checkpoint-content sbd-inner-block-init"><p>Raspberry Pi OSの最新版「Bookworm」を使っていると、<code>adafruit-circuitpython-rgb-display</code>をインストールした際に、<strong>Jetson.GPIOという不要なライブラリ</strong>が一緒に入ることがあります。この状態でプログラムを実行すると、「Exception: Could not determine Jetson model」のようなエラーが出ることがあります。</p><p>解決策として、次のコマンドで不要なライブラリを削除します：</p><p>pip uninstall -y Jetson.GPIO</p></div></div>



<h2 class="wp-block-heading">ディスプレイの動作確認をする</h2>



<p>Raspberry PiでPythonのプログラムを動かして、ディスプレイが正常に動作するかを確認します。</p>



<h3 class="wp-block-heading">Thonnyを使ってPythonプログラムを実行する</h3>



<p>Raspberry Piでは「Thonny（ソニー）」という初心者向けのPython開発環境が標準でインストールされています。以下の手順でプログラムを実行できます。</p>



<p>デスクトップ画面左上の「ラズベリーメニュー」から「プログラミング」→「Thonny」を開く。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="580" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-2-2.jpg" alt="" class="wp-image-15145" style="width:516px;height:auto"/></figure>



<p>Thonnyでは画面上部の大きな白いスペースにプログラムを入力し、画面上の「▶（再生マーク）」をクリックします。すると、下の部分（シェル）に実行結果が表示されます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="508" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-1-1-1.jpg" alt="" class="wp-image-15148" style="width:620px;height:auto"/></figure>



<p>ディスプレイのプログラムを実行する前に、<span class="sbd-text-bg-yellow">仮想環境に切り替える</span>操作をします。</p>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>仮想環境に切り替えることにより、先ほどインストールしたライブラリが使用可能になります。</p>
</div></div>



<h3 class="wp-block-heading">仮想環境への切り替え</h3>



<p>Thonnyでそのままプログラムを実行すると、先ほどインストールしたライブラリが見つからずにエラーが出ます。これを避けるため、以下の手順で仮想環境に切り替えます。</p>



<p>Thonnyの画面右下部分をクリックします。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-7.png" alt="" style="width:514px;height:auto"/></figure>



<p>「Configure interpreter&#8230;」をクリック。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="328" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-1-1-1.png" alt="" class="wp-image-15133" style="width:512px;height:auto"/></figure>



<p>「&#8230;」のボタンをクリック。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="615" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-3-1.png" alt="" class="wp-image-15150" style="width:513px;height:auto"/></figure>



<p>「ホーム」をクリックする。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="386" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-4-2.png" alt="" class="wp-image-15135"/></figure>



<p>先ほど作成した仮想環境のmyenvフォルダを開き、binフォルダ内のpythonを選択します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="450" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-5-1.png" alt="" class="wp-image-15136" style="width:764px;height:auto" srcset="https://sozorablog.com/wp-content/uploads/2025/06/pico-5-1.png 800w, https://sozorablog.com/wp-content/uploads/2025/06/pico-5-1-320x180.png 320w, https://sozorablog.com/wp-content/uploads/2025/06/pico-5-1-224x126.png 224w" sizes="(max-width: 800px) 100vw, 800px" /></figure>



<p>「OK」をクリックします。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-6.png" alt="" style="width:466px;height:auto"/></figure>



<p>プログラムの実行環境が仮想環境に切り替わりました。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="529" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-0b6acb87-d27b-482d-8ad9-f073d7925d1f.png" alt="" class="wp-image-15137" style="width:472px;height:auto"/></figure>



<h3 class="wp-block-heading">テスト用コードの実行</h3>



<p>以下は、ディスプレイに赤い背景と「Hello, ILI9341!」という文字を表示する<strong>シンプルな動作確認用コード</strong>です。Thonny画面上部のスペースにコピーペーストし、画面上の「▶（再生マーク）」をクリックします。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>from board import SCK, MOSI, MISO, D5, D18, D23, D24
from busio import SPI
from digitalio import DigitalInOut, Direction
from adafruit_rgb_display.ili9341 import ILI9341
from PIL import Image, ImageDraw, ImageFont

# Setup GPIO pins for display
CS = DigitalInOut(D5)
DC = DigitalInOut(D24)
RST = DigitalInOut(D23)
BL = DigitalInOut(D18)
BL.direction = Direction.OUTPUT
BL.value = True  # Turn on backlight

# Initialize SPI and display
spi = SPI(clock=SCK, MOSI=MOSI, MISO=MISO)
display = ILI9341(spi, cs=CS, dc=DC, rst=RST, width=240, height=320)

# Create a red image
image = Image.new(&quot;RGB&quot;, (240, 320), (255, 0, 0))
draw = ImageDraw.Draw(image)

# Load default font
font = ImageFont.load_default()

# Draw text
draw.text((20, 150), &quot;Hello, ILI9341!&quot;, font=font, fill=(255, 255, 255))

# Display the image
display.image(image)
</code></pre></div>



<p>このコードでは、最初にGPIOピンを設定します。ディスプレイのCS（チップセレクト）、DC（データ/コマンド）、RST（リセット）には、それぞれD5、D24、D23のピンを割り当てています。また、D18のピンを使ってバックライト（BL）を制御し、出力として設定した上で点灯させます。</p>



<p>次に、SPI通信を初期化します。Raspberry PiのSCK（クロック）、MOSI（マスターアウトスレーブイン）、MISO（マスターインスレーブアウト）のピンを使い、ILI9341ディスプレイと通信する準備を整えます。</p>



<p>ディスプレイを使うために、画面の幅を240ピクセル、高さを320ピクセルとして初期設定を行います。次に、Pillowライブラリを使って赤い背景の画像を作り、その上に白い文字で「Hello, ILI9341!」というメッセージを描きます。</p>



<p>最後にその画像を <code>.image()</code> メソッドを使ってディスプレイに表示します。これにより、ディスプレイの接続やSPI通信が正常に行われているかを確認できます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/IMG_9091.jpeg" alt="" style="width:456px;height:auto"/></figure>



<h2 class="wp-block-heading">ひまわり画像の取得先と画像タイプの違い</h2>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/himawari89.jpg" alt=""/></figure>



<p>「ひまわり」は日本の気象庁が運用する静止気象衛星で、赤道上空約3万6千kmの宇宙空間に位置し、<span class="sbd-text-red">地球の同じ場所を常に観測</span>し続けています。現在は「ひまわり8号」と「9号」が運用されており、アジア太平洋地域全体をリアルタイムに監視しています。</p>



<p>本プロジェクトでは、国立情報学研究所（NII）が提供する<a href="https://agora.ex.nii.ac.jp/digital-typhoon/">デジタル台風（Digital Typhoon）</a>という公開データベースからひまわりの画像を取得します。</p>



<p>気象衛星画像には「赤外画像」と「可視画像」の2種類があります。</p>



<figure class="wp-block-table wp-block-sbd-table wp-block-sbd-table-vertical"><table class="has-fixed-layout"><thead><tr><th>種類</th><th>特徴</th><th>メリット</th><th>デメリット</th></tr></thead><tbody><tr><td>赤外画像<br><img decoding="async" width="150" height="150" class="wp-image-14991" style="width: 150px;" src="https://sozorablog.com/wp-content/uploads/2025/06/ir.jpg" alt=""></td><td>赤外線（熱）をとらえて表示</td><td>昼夜問わず常に全体を表示可能</td><td>色味がやや不自然</td></tr><tr><td>可視画像<br><img decoding="async" width="150" height="150" class="wp-image-14992" style="width: 150px;" src="https://sozorablog.com/wp-content/uploads/2025/06/20250611070000.jpg" alt=""></td><td>太陽光を反射した様子を表示</td><td>昼間は自然な見た目で美しい</td><td>夜間はほとんど見えない</td></tr></tbody></table></figure>



<p>赤外画像は、地球や雲が放つ赤外線（熱）をもとに作られており、昼夜を問わず常に地球全体が表示されます。夜でも雲の動きが見えるのが大きな利点です。ただし、<span class="sbd-text-red">色味</span><span class="sbd-text-red">が</span><span class="sbd-text-red">人工的で、可視画像のような自然な見た目ではありません</span>。</p>



<p>可視画像は太陽の光を反射した様子をとらえたもので、雲や地表を<span class="sbd-text-bg-yellow">自然な美しい色合い</span>で表示します。昼間は鮮明に表示されますが、夜間は太陽光が当たらないため地球の一部が暗くなり、月の満ち欠けのように少しずつ見える範囲が変化します。そのため、<span class="sbd-text-red">夜間はほとんど何も見えず</span>、表示としては物足りない場合があります。</p>



<p>本記事ではこれらの特徴を活かした<span class="sbd-text-bold">2つの表示方法</span>を紹介します。ひとつは最新の赤外画像をシンプルに表示する方法。もうひとつは直近24時間分の可視画像を集めて、連続再生するアニメーション表示です。</p>



<h2 class="wp-block-heading">ひまわりの赤外画像を表示</h2>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/IMG_9090.jpeg" alt=""/></figure>



<p>以下のコードはRaspberry Piで気象衛星ひまわりの赤外画像を10分ごとに取得し、ILI9341ディスプレイに表示するものです。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>import time
import requests
from PIL import Image, ImageDraw
from io import BytesIO

from board import SCK, MOSI, MISO, D5, D18, D23, D24
from busio import SPI
from digitalio import DigitalInOut, Direction
from adafruit_rgb_display.ili9341 import ILI9341

# --- Display setup ---
CS = DigitalInOut(D5)
DC = DigitalInOut(D24)
RST = DigitalInOut(D23)
BL = DigitalInOut(D18)
BL.direction = Direction.OUTPUT
BL.value = True

spi = SPI(clock=SCK, MOSI=MOSI, MISO=MISO)
display = ILI9341(spi, cs=CS, dc=DC, rst=RST, width=240, height=320)

# ひまわりの最新画像を取得する関数
def fetch_image():
    url = &quot;http://agora.ex.nii.ac.jp/digital-typhoon/latest/globe/512x512/ir.jpg&quot;
    try:
        response = requests.get(url, timeout=10)
        response.raise_for_status()
        img = Image.open(BytesIO(response.content)).convert(&quot;RGB&quot;)
        return img
    except Exception as e:
        print(&quot;Fetch failed:&quot;, e)
        return None

# 表示用に画像を整形する関数
def prepare_image(img):
    img = img.rotate(90, expand=True) # 表示向きに90度回転 
    img = img.resize((240, 240))      # ディスプレイ用にサイズ変更

    # 円形マスクを作成して地球部分だけを切り抜き
    mask = Image.new(&quot;L&quot;, (240, 240), 0)
    draw = ImageDraw.Draw(mask)
    draw.ellipse((0, 0, 240, 240), fill=255)

    black_bg = Image.new(&quot;RGB&quot;, (240, 240), (0, 0, 0))       # 黒背景画像
    earth_only = Image.composite(img, black_bg, mask)        # 円形で切り抜いた画像と合成

    canvas = Image.new(&quot;RGB&quot;, (240, 320), (0, 0, 0))
    canvas.paste(earth_only, (0, 40))
    return canvas

# --- メインループ ---
last_canvas = None

while True:
    img = fetch_image()
    if img:
        last_canvas = prepare_image(img)
        print(&quot;New image fetched and prepared.&quot;)
    else:
        print(&quot;Using previous image.&quot;)

    if last_canvas:
        display.image(last_canvas)

    time.sleep(600)  # 10 minutes

</code></pre></div>



<p>まず、<code>fetch_image()</code>関数では、「デジタル台風」のサイトから最新の<span class="sbd-text-red">赤外画像</span>をダウンロードし、PILライブラリを使って画像として読み込みます。使用している画像のURLは <code>http://agora.ex.nii.ac.jp/digital-typhoon/latest/globe/512x512/ir.jpg</code> で、このURLは<span class="sbd-text-bg-yellow">1時間ごと</span>に新しい画像が公開されます。</p>



<p>画像を表示する前に、<code>prepare_image()</code>関数でディスプレイに合わせた加工を行います。画像は90度回転させ、ディスプレイの横向き表示に対応させています。続いて画像サイズを240×240に縮小し、円形のマスクをかけることで、日付や時刻などの文字を隠し、地球だけが目立つように調整。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="305" src="https://sozorablog.com/wp-content/uploads/2025/06/himawari_save1png-1.jpg" alt="" class="wp-image-15141" style="width:824px;height:auto"/></figure>



<p>最後に、ディスプレイと同じサイズである240×320ピクセルのキャンバスの中央に、地球の画像を配置します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="313" src="https://sozorablog.com/wp-content/uploads/2025/06/himawari_save2-1.jpg" alt="" class="wp-image-15142" style="width:840px;height:auto"/></figure>



<p>メイン処理では、まず画像を取得して加工し、ディスプレイに表示します。取得に失敗した場合でも、最後に表示した画像をそのまま再表示することで、画面が真っ黒になってしまうのを防ぎます。この処理は10分ごとに繰り返されるため、新しい画像があれば自動的に更新されます。</p>



<p>赤外画像は昼夜を問わず観測できるため、常に地球全体を表示できます。</p>



<h2 class="wp-block-heading">ひまわりの可視画像をアニメーション表示する</h2>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-6-1.jpg" alt=""/></figure>



<p>赤外画像は色合いが人工的で、可視画像のような自然な見た目にはなりません。一方、可視画像は昼間は美しく表示されますが、夜は真っ暗になります。そこで、直近24時間分の可視画像を集めて連続再生することで、常に表示があり、動きのある地球を楽しめるようにしました。</p>



<h3 class="wp-block-heading">ひまわりの可視画像を保存するプログラム</h3>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-7-1.jpg" alt="" style="width:840px;height:auto"/><figcaption class="wp-element-caption">2つのプログラムを別々に実行する</figcaption></figure>



<p>本プロジェクトではプログラムが複雑になりすぎないように、画像の取得用プログラムと、保存された画像をアニメーションのように表示するプログラムを<span class="sbd-text-bg-yellow">分けて作成</span>し、それぞれを同時に実行する構成としました。</p>



<p>ここでは、まず画像を保存する側のプログラムを紹介します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>import os
import requests
from datetime import datetime, timedelta, timezone
from PIL import Image
from io import BytesIO
import time

# Constants
IMAGE_DIR = &quot;/home/pi/image&quot;
MAX_IMAGES = 144
INTERVAL = 8 * 60  # 8 minutes

# JST timezone
JST = timezone(timedelta(hours=9))

# Ensure image directory exists
os.makedirs(IMAGE_DIR, exist_ok=True)

# 最新の保存済み画像の時刻を取得する
def get_latest_saved_time():
    files = sorted(f for f in os.listdir(IMAGE_DIR) if f.endswith(&quot;.bmp&quot;))
    if not files:
        return None
    latest_file = files[-1]
    try:
        dt = datetime.strptime(latest_file[:13], &quot;%Y%m%d_%H%M&quot;)  # ?: &quot;20250612_1530&quot;
        return dt
    except Exception:
        return None

# 指定時刻から取得候補となる「分」のリストを返す（10分刻み）
def generate_valid_minute_slots(base_time_utc, full=False):
    if full:
        return [&quot;50&quot;, &quot;40&quot;, &quot;30&quot;, &quot;20&quot;, &quot;10&quot;, &quot;00&quot;]
    current_minute = int(base_time_utc.strftime(&#39;%M&#39;))
    return [f&quot;{m:02d}&quot; for m in [50, 40, 30, 20, 10, 0] if m &lt;= current_minute]

# 指定された画像を保存する（JSTのタイムスタンプをファイル名に付ける）
def save_image(canvas, jst_dt):
    filename = jst_dt.strftime(&quot;%Y%m%d_%H%M&quot;) + &quot;.bmp&quot;
    filepath = os.path.join(IMAGE_DIR, filename)
    canvas.save(filepath, format=&quot;BMP&quot;)
    print(f&quot;Saved: {filepath}\n&quot;)

# 古い画像を削除して、最大枚数を超えないようにする
def cleanup_old_images():
    files = sorted(f for f in os.listdir(IMAGE_DIR) if f.endswith(&quot;.bmp&quot;))
    print(len(files))
    while len(files) &gt; MAX_IMAGES:
        os.remove(os.path.join(IMAGE_DIR, files[0]))
        print(&quot;Deleted:&quot;, files[0])
        files.pop(0)

# 指定したUTC時刻をもとに画像を取得し、保存・整理を行う
def try_fetch_and_save(base_time_utc, full_range=False):
    date_str = base_time_utc.strftime(&#39;%Y/%m/%d&#39;)
    base_date_str = base_time_utc.strftime(&#39;%Y%m%d&#39;)
    hour_str = base_time_utc.strftime(&#39;%H&#39;)
    minute_slots = generate_valid_minute_slots(base_time_utc, full=full_range)

    for mnt in minute_slots:
        time_str = f&quot;{base_date_str}{hour_str}{mnt}&quot;
        url = f&quot;http://agora.ex.nii.ac.jp/digital-typhoon/iiif/{date_str}/{time_str}00.tif/0,0,11000,11000/688,/0/default.jpg&quot;

        try:
            response = requests.get(url, timeout=10)
            response.raise_for_status()
            img = Image.open(BytesIO(response.content)).rotate(90, expand=True)
            img = img.resize((240, 240))
            canvas = Image.new(&quot;RGB&quot;, (240, 320), (0, 0, 0))
            canvas.paste(img, (0, 40))
            jst_dt = datetime.strptime(time_str + &quot;00&quot;, &quot;%Y%m%d%H%M%S&quot;).replace(tzinfo=timezone.utc).astimezone(JST)
            save_image(canvas, jst_dt)
            cleanup_old_images()
            return True
        except Exception:
            jst_dt = datetime.strptime(time_str + &quot;00&quot;, &quot;%Y%m%d%H%M%S&quot;).replace(tzinfo=timezone.utc).astimezone(JST)
            print(&quot;No data time (JST):&quot;, jst_dt.strftime(&quot;%Y/%m/%d %H:%M:%S&quot;))
            time.sleep(2)
    return False

# Main loop
while True:
    wait_after_backfill = False

    latest_jst = get_latest_saved_time()
    if latest_jst:
        target_jst = latest_jst - timedelta(minutes=10)
        filename = target_jst.strftime(&quot;%Y%m%d_%H%M&quot;) + &quot;.bmp&quot;
        filepath = os.path.join(IMAGE_DIR, filename)
        if not os.path.exists(filepath):
            print(&quot;Trying backfill for:&quot;, filename)
            target_utc = target_jst.astimezone(timezone.utc)
            if try_fetch_and_save(target_utc):
                wait_after_backfill = True

    if wait_after_backfill:
        time.sleep(5)

    now_utc = datetime.now(timezone.utc)
    if not try_fetch_and_save(now_utc):
        print(&quot;Retrying with 1 hour earlier...&quot;)
        try_fetch_and_save(now_utc - timedelta(hours=1), full_range=True)

    time.sleep(INTERVAL)

</code></pre></div>



<p>上記は「デジタル台風」から最新の気象衛星画像を定期的にダウンロードし、BMP形式で保存するプログラムです。保存された画像は指定フォルダに最大144枚まで保管され、古いものから自動で削除されます。ひまわりの可視画像は10分おきに提供されるため、144枚で24時間分のデータに相当します。</p>



<p>画像の取得には以下のようなURLが使われます：</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>url = f&quot;http://agora.ex.nii.ac.jp/digital-typhoon/iiif/{date_str}/{time_str}00.tif/0,0,11000,11000/688,/0/default.jpg&quot;</code></pre></div>



<p>このURLは指定した日時（<code>date_str</code>と<code>time_str</code>）に対応する可視画像を取得するためのもので、必要な時間の画像を個別にダウンロードできます。</p>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>URLで指定する時刻は、<span class="sbd-text-red">UTC（協定世界時）</span>であり、日本時間（JST）より9時間遅れています。</p>
</div></div>



<p>プログラムは8分ごとに最新のひまわり画像を取得して保存します。まず、現在の「分」情報から取得できそうな時刻の候補（たとえば35分なら、30・20・10・00）を新しい順に試していきます。最初に見つかった画像を保存し、取得できない場合は1時間前のデータまでさかのぼって取得を試みます。取得した画像は240×320に加工され、「20250612_1530.bmp」のように日本時間（JST）のタイムスタンプをファイル名として保存します。</p>



<p>/home/pi/に「image」という名称のフォルダが作成され、そこに画像が自動で保存されていきます。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="800" height="369" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-4-1-1.png" alt="" class="wp-image-15144"/></figure>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>保存する画像の枚数が多くなるので、専用のフォルダを作ることにしました。</p>
</div></div>



<p>画像の取りこぼしを防ぐための工夫として、保存済み画像の中で最新の時刻を確認し、その10分前の画像が存在しない場合には、そちらを優先して取得するようにしました。これは、ひまわり画像の提供時刻が必ずしも一定間隔とは限らず、8分ごとに取得しても一部の時刻が抜け落ちてしまうことがあるためです。</p>



<p>プログラムを<span class="sbd-text-bold">himawari_image_save.py</span>という名称で/home/piフォルダに保存します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-5-1.jpg" alt="" style="width:482px;height:auto"/></figure>



<p>Saveボタンをクリックして、名前に「himawari_image_save.py」を入力し、OKを押します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="450" src="https://sozorablog.com/wp-content/uploads/2025/06/pico-3-1-1.jpg" alt="" class="wp-image-15143" style="width:484px;height:auto" srcset="https://sozorablog.com/wp-content/uploads/2025/06/pico-3-1-1.jpg 800w, https://sozorablog.com/wp-content/uploads/2025/06/pico-3-1-1-320x180.jpg 320w, https://sozorablog.com/wp-content/uploads/2025/06/pico-3-1-1-224x126.jpg 224w" sizes="(max-width: 800px) 100vw, 800px" /></figure>



<h4 class="wp-block-heading">ターミナルから保存用プログラムを実行</h4>



<p>画像保存用のプログラム <code>himawari_image_save.py</code> は、<span class="sbd-text-bg-yellow">Thonnyではなくターミナルから実行</span>します。Thonnyで起動すると、次に紹介するアニメーション表示用のプログラムが同時に動かせなくなるためです。</p>



<p>ターミナルで以下のコマンドを入力して実行します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>python3 himawari_image_save.py</code></pre></div>



<figure class="wp-block-image size-full"><img decoding="async" width="410" height="203" src="https://sozorablog.com/wp-content/uploads/2025/06/E382B9E382AFE383AAE383BCE383B3E382B7E383A7E38383E38388-2025-06-14-18.00.06.png" alt="" class="wp-image-15134"/></figure>



<p>/home/pi/imageに画像が保存されていきます。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="496" height="327" src="https://sozorablog.com/wp-content/uploads/2025/06/E382B9E382AFE383AAE383BCE383B3E382B7E383A7E38383E38388-2025-06-14-19.41.00.png" alt="" class="wp-image-15140"/></figure>



<p>ダブルクリックしてみると、保存された画像を確認できます。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="429" height="425" src="https://sozorablog.com/wp-content/uploads/2025/06/スクリーンショット-2025-06-17-17.12.52.png" alt="" class="wp-image-15158"/></figure>



<h3 class="wp-block-heading">保存された画像をアニメーション表示するプログラム</h3>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="750" height="699" src="https://sozorablog.com/wp-content/uploads/2025/06/IMG_9111.jpg" alt="" class="wp-image-15151" style="width:485px;height:auto"/></figure>



<p>himawari_image_save.pyが画像の保存をしている間に、アニメーション表示するプログラムを用意します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>import glob
import time
from PIL import Image

from board import SCK, MOSI, MISO, D5, D18, D23, D24
from busio import SPI
from digitalio import DigitalInOut, Direction
from adafruit_rgb_display.ili9341 import ILI9341

# Setup GPIO pins for display
CS = DigitalInOut(D5)
DC = DigitalInOut(D24)
RST = DigitalInOut(D23)
BL = DigitalInOut(D18)
BL.direction = Direction.OUTPUT
BL.value = True  # Turn on backlight

# Initialize SPI and display
spi = SPI(clock=SCK, MOSI=MOSI, MISO=MISO)
display = ILI9341(spi, cs=CS, dc=DC, rst=RST, width=240, height=320)

while True:
    # 画像フォルダからBMPファイルをすべて取得し、名前順に並べる
    image_files = sorted(glob.glob(&quot;/home/pi/image/*.bmp&quot;))

    # 画像を1枚ずつ表示
    for filepath in image_files:
        img = Image.open(filepath)
        display.image(img)
        time.sleep(0.01)

    time.sleep(5)  # 5秒待ってから画像リストを再取得（新しい画像が増えている可能性があるため）

</code></pre></div>



<p>このコードは、Raspberry PiとILI9341ディスプレイを使って、「/home/pi/image」フォルダ内にあるBMP画像を順番に1枚ずつ表示するものです。画像を高速で切り替えて表示することで、アニメーションのような視覚効果を得ることができます。</p>



<p>フォルダ内の画像ファイルは、「20250612_1530.bmp」のように日時が名前に含まれた形式で保存されています。そのため、ファイル名を文字列順に並べると<strong>古い順（撮影された順）</strong>になります。この順番で画像を1枚ずつ読み込み、180度回転させてディスプレイに表示します。すべての画像を表示し終わると、5秒待機してから同じ処理を繰り返します。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/Videotogif.gif" alt=""/></figure>



<p>この処理を実行している間も、画像取得用のプログラム（<code>himawari_image_save.py</code>）が最新の画像を継続的に保存しているため、アニメーションで表示される画像も自動で更新されていきます。</p>



<h2 class="wp-block-heading">ダイソーのミラーデジタル時計に収納する</h2>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/IMG_9032.jpeg" alt=""/></figure>



<p>表示の仕組みが完成したら、ケースに入れたくなるものです。ダイソーの<a href="https://jp.daisonet.com/products/4550480194400?srsltid=AfmBOorXrGfeIBw4te9Kv3adCBuy-j-lwUaUy7KUHFopH-qgUHVTc0QM">ミラーデジタル時計</a>を加工して、ラズパイ本体とディスプレイを収納することにしました。むき出しのディスプレイや配線のごちゃごちゃした印象をすっきり隠せるので、スマートな見た目に仕上がります。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/IMG_9046.jpeg" alt=""/></figure>



<p>前面は鏡のような仕上がりで、周囲の風景が映り込みます。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/IMG_5041.jpeg" alt=""/></figure>



<p>さっそく容赦なく分解していきます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/IMG_5042.jpeg" alt="" style="width:421px;height:auto"/></figure>



<p>鏡の部分は薄いシート状になっており、時計の数字が表示される箇所だけが光を通すようになっています。それ以外の部分も、裏側のコーティングを削れば光を通すようにできます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/IMG_9016.jpeg" alt="" style="width:410px;height:auto"/></figure>



<p>ディスプレイを取り付ける部分のコーティングを、マイナスドライバーで少しずつ削っていきます。逆に透けさせたくない部分は、油性マジックで塗りつぶして光が漏れないようにしました。</p>



<p>ケース本体側も大幅に加工が必要です。ラズパイ本体やディスプレイ、配線が干渉する部分をニッパーで切り取り、必要なスペースを確保します。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/IMG_9118.jpeg" alt=""/></figure>



<p>ディスプレイの土台部分は3Dプリンターで作成しました。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/スクリーンショット-2025-06-17-12.27.22.jpg" alt=""/><figcaption class="wp-element-caption">3D CADで設計したディスプレイのベース部品</figcaption></figure>



<p>電源ケーブルの取り回しを考慮し、ラズパイは以下の位置に配置することにしました。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/IMG_5070.jpeg" alt=""/></figure>



<p>ケースに収納したラズパイを外部から操作できるようにするため、あらかじめ<a href="https://sozorablog.com/vnc/">VNC</a>の設定をしておきます。VNCとは「Virtual Network Computing（バーチャル・ネットワーク・コンピューティング）」の略で、離れた場所からラズパイの画面を操作できる仕組みです。</p>



<div class="wp-block-sbd-background-block sbd-bg-color sbd-inner-block-init is-style-yellow">
<p>VNCの設定方法は、以下の記事で詳しく解説しています。<br><strong><a href="https://sozorablog.com/vnc/">≫【ラズベリーパイを遠隔操作】VNCでＰＣからリモート接続する方法</a></strong></p>
</div>



<p>ディスプレイは水色の土台部分に両面テープで固定しています。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/IMG_9119.jpeg" alt=""/></figure>



<p>ケースの背面には、ラズパイの電源コネクタに直接差し込めるように穴を追加しました。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/IMG_9120.jpeg" alt="" style="width:446px;height:auto"/></figure>



<p>雑な加工ですが、ケーブルを差し込めばほとんど目立たなくなります。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/06/IMG_5069.jpeg" alt="" style="width:508px;height:auto"/></figure>



<p>完成。ミラーの奥に、ぼんやりと地球が浮かび上がります。ミラー越しだと少しぼやけて見えるため、赤外画像のほうが輪郭がはっきりして見やすく感じます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="771" src="https://sozorablog.com/wp-content/uploads/2025/06/IMG_9122.jpeg" alt="" class="wp-image-15101" style="width:840px;height:auto"/></figure>



<h2 class="wp-block-heading">円形ディスプレイに表示する</h2>



<figure class="wp-block-image size-full"><img decoding="async" width="750" height="671" src="https://sozorablog.com/wp-content/uploads/2025/06/IMG_9145.jpeg" alt="" class="wp-image-15352"/></figure>



<p>地球のアニメーションを、より魅力的に見せる方法として円形ディスプレイを使うと効果的です。円形ディスプレイの<a href="https://shop.pimoroni.com/products/hyperpixel-round?variant=39381081882707">HyperPixel 2.1 Round</a>を使って、画像をアニメーション表示してみました。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/スクリーンショット-2025-05-18-5.29.14.jpg" alt=""/><figcaption class="wp-element-caption">出典：<a href="https://shop.pimoroni.com/products/hyperpixel-round?variant=39381081882707">Pimoroni</a></figcaption></figure>



<p>ひまわりの可視画像を保存するプログラムは、先ほど紹介した「<strong>himawari_image_save.py</strong>」をそのまま使用します。</p>



<p>次のコードは、指定したフォルダ内のBMP画像を順番に読み込み、Raspberry PiのGUI画面上に全画面で表示するプログラムです。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>import glob
import time
from PIL import Image
import cv2
import numpy as np

# ウィンドウサイズ
WIDTH = 480
HEIGHT = 480
WINDOW_NAME = &quot;Earth Viewer&quot;

# OpenCVウィンドウを全画面で作成
cv2.namedWindow(WINDOW_NAME, cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty(WINDOW_NAME, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)

while True:
    # 画像ファイルを時刻順に取得
    image_files = sorted(glob.glob(&quot;/home/pi/image/*.bmp&quot;))

    for filepath in image_files:
        # BMP画像を開いてNumPy配列に変換
        pil_img = Image.open(filepath).convert(&quot;RGB&quot;)

        # 背景キャンバスを作成（黒背景）
        canvas = Image.new(&quot;RGB&quot;, (WIDTH, HEIGHT), (0, 0, 0))
        
        # PILで中心に貼り付ける位置を計算
        img_w, img_h = pil_img.size
        pos_x = (WIDTH - img_w) // 2
        pos_y = (HEIGHT - img_h) // 2
        canvas.paste(pil_img, (pos_x, pos_y))

        # NumPy配列に変換 → BGRに変換（OpenCV用）
        img_np = np.array(canvas)
        img_bgr = cv2.cvtColor(img_np, cv2.COLOR_RGB2BGR)

        # 表示
        cv2.imshow(WINDOW_NAME, img_bgr)

        # ESCキーが押されたら終了（27はESCのキーコード）
        if cv2.waitKey(10) == 27:
            cv2.destroyAllWindows()
            exit()

    time.sleep(5)

</code></pre></div>



<p>先ほど紹介した「保存された画像をアニメーション表示するプログラム」との違いは、SPI接続のディスプレイではなくRaspberry PiのGUI画面（デスクトップ画面）に表示している点です。どちらも「画像フォルダの中にあるBMP画像を順番に表示する」という目的は同じです。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="481" height="491" src="https://sozorablog.com/wp-content/uploads/2025/06/スクリーンショット-2025-06-23-12.28.42.jpg" alt="" class="wp-image-15353"/><figcaption class="wp-element-caption">円形ディスプレイに表示する画面</figcaption></figure>



<p>OpenCVは以下のコマンドでインストールします。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo apt install python3-opencv</code></pre></div>



<figure class="wp-block-embed is-type-rich is-provider-twitter wp-block-embed-twitter"><div class="wp-block-embed__wrapper">
<blockquote class="twitter-tweet" data-width="500" data-dnt="true"><p lang="ja" dir="ltr">Raspberry Piと円形ディスプレイがあったら、絶対作りたくなるやつ。 <a href="https://t.co/cov9A3QEHx">pic.twitter.com/cov9A3QEHx</a></p>&mdash; そぞら@Raspberry Pi 電子工作 (@sozoraemon) <a href="https://twitter.com/sozoraemon/status/1937090870672834744?ref_src=twsrc%5Etfw">June 23, 2025</a></blockquote><script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
</div></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://sozorablog.com/himawari/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
		<item>
		<title>ラズパイとADS-B受信機でミニ飛行機レーダーを作ろう</title>
		<link>https://sozorablog.com/flightradar/</link>
					<comments>https://sozorablog.com/flightradar/#comments</comments>
		
		<dc:creator><![CDATA[そぞら]]></dc:creator>
		<pubDate>Tue, 27 May 2025 06:43:35 +0000</pubDate>
				<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[使い方]]></category>
		<guid isPermaLink="false">https://sozorablog.com/?p=14648</guid>

					<description><![CDATA[飛行機の音が聞こえたとき、「この機体はどこへ行くのだろう」と気になったことはありませんか？ この記事では、Raspberry Piで航空機信号用の受信機を使う方法と「レーダー風表示装置」の作り方を紹介します。リアルタイム [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>飛行機の音が聞こえたとき、「この機体はどこへ行くのだろう」と気になったことはありませんか？</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/IMG_8969.jpeg" alt="" class="wp-image-4" style="width:444px;height:auto"/></figure>



<p>この記事では、<a href="https://sozorablog.com/raspberry-pi/">Raspberry Pi</a>で航空機信号用の受信機を使う方法と「レーダー風表示装置」の作り方を紹介します。リアルタイムで頭上を飛ぶ航空機の位置情報を画面に表示し、自宅で<strong>小さな管制塔気分</strong>が楽しめます。</p>



<h2 class="wp-block-heading">ラズパイで飛行機の信号を受信</h2>



<p>多くの飛行機は、現在位置・高度・速度・機体番号などの情報を送信しています。そうした通信手段の中でも、旅客機をはじめとする多くの航空機で使われているのが、<strong>ADS-B（Automatic Dependent Surveillance–Broadcast）</strong> という仕組みです。</p>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>ADS-Bの信号は、受信機を使えばRaspberry Piでも受信できます。</p>
</div></div>



<h3 class="wp-block-heading">ADS-B受信機を使用</h3>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/IMG_8943.jpeg" alt="" class="wp-image-4" style="width:459px;height:auto"/><figcaption class="wp-element-caption">NESDR Mini</figcaption></figure>



<p>今回は<a href="https://www.nooelec.com/store/?srsltid=AfmBOoobYNyhKjJ7p_SQU13t7o1VFn1MbSNxhsaL8hmbh96Oa6V6am4a">Nooelec社</a>のNESDR MiniというUSBスティック型のADS-B受信機を使用します。Raspberry Piに接続し、専用のソフトウェアをインストールすることで、航空機が発信する1090MHz帯の信号を受信できます。</p>



<!-- START MoshimoAffiliateEasyLink -->
<script type="text/javascript">
(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;
b[a]=b[a]||function(){arguments.currentScript=c.currentScript
||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};
c.getElementById(a)||(d=c.createElement(f),d.src=g,
d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})
(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");
msmaflink({"n":"Nooelec NESDR Mini ミニUSB RTL-SDRおよびADS-B受信機セット、RTL2832UおよびR820Tチューナー、MCX入力。 多くのSDRソフトウェアパッケージと互換性のある低コストソフトウェア無線機。 R820Tチューナ","b":"NooElec","t":"100556","d":"https:\/\/m.media-amazon.com","c_p":"\/images\/I","p":["\/31Vb71v4fTL._SL500_.jpg","\/314CXt2ANJL._SL500_.jpg","\/31QS842oE2L._SL500_.jpg","\/41fYlg-Nw3L._SL500_.jpg","\/31bzg-noaGL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B009U7WZCA","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":1,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B009U7WZCA","a_id":3038653,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"id":2,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/Nooelec%20NESDR%20Mini%20%E3%83%9F%E3%83%8BUSB%20RTL-SDR%E3%81%8A%E3%82%88%E3%81%B3ADS-B%E5%8F%97%E4%BF%A1%E6%A9%9F%E3%82%BB%E3%83%83%E3%83%88%E3%80%81RTL2832U%E3%81%8A%E3%82%88%E3%81%B3R820T%E3%83%81%E3%83%A5%E3%83%BC%E3%83%8A%E3%83%BC%E3%80%81MCX%E5%85%A5%E5%8A%9B%E3%80%82%20%E5%A4%9A%E3%81%8F%E3%81%AESDR%E3%82%BD%E3%83%95%E3%83%88%E3%82%A6%E3%82%A7%E3%82%A2%E3%83%91%E3%83%83%E3%82%B1%E3%83%BC%E3%82%B8%E3%81%A8%E4%BA%92%E6%8F%9B%E6%80%A7%E3%81%AE%E3%81%82%E3%82%8B%E4%BD%8E%E3%82%B3%E3%82%B9%E3%83%88%E3%82%BD%E3%83%95%E3%83%88%E3%82%A6%E3%82%A7%E3%82%A2%E7%84%A1%E7%B7%9A%E6%A9%9F%E3%80%82%20R820T%E3%83%81%E3%83%A5%E3%83%BC%E3%83%8A\/","a_id":3038654,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":2}],"eid":"8T0PA","s":"s"});
</script>
<div id="msmaflink-8T0PA">リンク</div>
<!-- MoshimoAffiliateEasyLink END -->



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>アンテナを室内に置いた状態で、<strong>約50km</strong>離れた航空機の信号を受信できました。</p>
</div></div>



<p>専用アンテナも付属しているため、すぐに使い始められます。ただし、Raspberry Pi Zeroシリーズを使う場合は、別売りの<a href="https://akizukidenshi.com/catalog/g/g113430/">USB microBコネクタ用のOTGケーブル</a>が必要です。</p>



<h3 class="wp-block-heading">Flightradar24にデータ提供も可能</h3>



<p>世界中の航空機をリアルタイムで表示するサービス<a href="https://www.flightradar24.com/">Flightradar24</a>も、ADS-B信号をもとにしています。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/スクリーンショット-2025-05-18-5.15.30.jpg" alt="" class="wp-image-4"/><figcaption class="wp-element-caption"><a href="https://www.flightradar24.com/">Flightradar24</a></figcaption></figure>



<p>Flightradar24は基本機能を無料で使えますが、30分で自動的にセッションが終了する制限があります。一方、ADS-B受信機を設置すれば、設置場所の周辺に限定されますが、航空機の情報を制限なく受信・表示できます。</p>



<div class="wp-block-sbd-checkpoint-block"><p class="sbd-checkpoint-title">チェックポイント</p><div class="sbd-checkpoint-content sbd-inner-block-init"><p>Raspberry PiとADS-B受信機を使って<span class="sbd-text-red">Flightradar24にデータを提供</span>することで、プレミアム機能を無償で利用できます。Flightradar24へのデータ提供方法については、記事の後半で紹介しています。</p></div></div>



<h2 class="wp-block-heading">ADS-B受信機の使用準備</h2>



<p>今回使用したADS-B受信機は、以下のモデルで動作を確認しました。</p>



<div class="wp-block-sbd-list"><ul class="sbd-list sbd-list-border"><li><a href="https://sozorablog.com/raspberry-pi-zero-2-w/">Raspberry Pi Zero 2 W</a></li><li><a href="https://sozorablog.com/raspberry-pi-4-revue/">Raspberry Pi 4</a></li><li><a href="https://sozorablog.com/pi5/">Raspberry Pi 5</a>　※<a href="https://shop.pimoroni.com/products/hyperpixel-round?variant=39381081882707">HyperPixel 2.1 Round</a>（円形ディスプレイ）は非対応</li></ul></div>



<p>Raspberry Pi OSについては、ADS-B受信機だけを使う場合はBookwormで動作します。僕は<a href="https://shop.pimoroni.com/products/hyperpixel-round?variant=39381081882707">HyperPixel 2.1 Round</a>（円形ディスプレイ）を使いたかったので、Bullseyeを使用しました。</p>



<div class="wp-block-sbd-background-block sbd-bg-color sbd-inner-block-init is-style-yellow">
<p>Raspberry PiのOSをインストールする方法は、以下の記事で詳しく解説しています。<br><strong><a href="https://sozorablog.com/raspberrypi_initial_setting/">≫【2025年最新版】OSインストールから初期設定まで｜セットアップ手順のすべて</a></strong></p>
</div>



<h3 class="wp-block-heading">ラズパイとADS-B受信機の接続</h3>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/IMG_8987.jpeg" alt="" class="wp-image-4" style="width:439px;height:auto"/></figure>



<p>ADS-B受信機をRaspberry PiのUSBポートに挿すだけで接続できます。Raspberry Pi Zeroシリーズを使う場合は、別売りの<a href="https://akizukidenshi.com/catalog/g/g113430/">USB microBコネクタ用のOTGケーブル</a>が必要です。</p>



<h3 class="wp-block-heading">ソフトウェアの設定</h3>



<p>ここからはRaspberry Piを起動して、ADS-B受信機を使える状態にします。</p>



<p>航空機の発信するADS-B信号を受信・表示するために、<a href="https://ja.flightaware.com/">FlightAware</a>が提供する<span class="sbd-text-bg-yellow">dump1090-fa</span>というソフトを使います。</p>



<p>dump1090-faを使うために、FlightAwareのパッケージリポジトリをRaspberry Piに追加します。</p>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>リポジトリは、データを管理する「インターネット上の倉庫」のようなイメージです。その倉庫の場所をRaspberry Piに教える作業をします。</p>
</div></div>



<p>ターミナルを開いて、次のコマンドを実行します。これによりFlightAwareが提供するリポジトリ登録用の.debパッケージ（設定ファイル）をインターネットからダウンロードします。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>wget https://www.flightaware.com/adsb/piaware/files/packages/pool/piaware/f/flightaware-apt-repository/flightaware-apt-repository_1.2_all.deb</code></pre></div>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/pico-2.jpg" alt="" class="wp-image-4"/></figure>



<p>次のコマンドで、先ほどダウンロードした .debパッケージをインストールします。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo dpkg -i flightaware-apt-repository_1.2_all.deb</code></pre></div>



<p>Raspberry Piのパッケージリストを更新します。これにより、dump1090-faがインストール候補として認識されるようになります。</p>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>パッケージリストとは、利用可能なソフトウェアの一覧情報のことです。</p>
</div></div>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo apt update</code></pre></div>



<p>dump1090-faをインストールします。<code>-y</code> オプションは「続行しますか？ [Y/n]」の確認をスキップして、自動的に「yes」と答えるためのものです。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo apt install -y dump1090-fa</code></pre></div>



<p>以下はRaspberry Piの起動時に <code>dump1090-fa</code> を自動で起動するよう設定するコマンドです。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo systemctl enable dump1090-fa</code></pre></div>



<p>レーダー表示を自作するために、Pythonで画像や映像を扱えるOpenCVライブラリをインストールします。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo apt install -y python3-opencv</code></pre></div>



<p>Raspberry Piを再起動します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo reboot</code></pre></div>



<p>再起動後にdump1090-faが自動で起動します。</p>



<h2 class="wp-block-heading">ADS-B信号の受信を確認</h2>



<p>dump1090-faが正常に動作しているかを確認します。Raspberry Piの<span class="sbd-text-red">ブラウザを開いて</span>、「http://localhost:8080/」をアドレスバーに入力します。すると、dump1090の<strong>リアルタイム航空機マップ</strong>が表示されます。自宅周辺のマップを確認すると、航空機の情報がキャッチされていることがわかります。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/スクリーンショット-2025-05-17-15.10.34.jpg" alt="" class="wp-image-4" style="width:840px;height:auto"/></figure>



<h3 class="wp-block-heading">ページが表示されない場合</h3>



<p>以下のようにページが表示されない場合があります。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/スクリーンショット-2026-04-04-6.37.07.jpg" alt="" class="wp-image-4" style="width:387px;height:auto"/></figure>



<p>まずは、以下のコマンドで状態を確認します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo systemctl status dump1090-fa</code></pre></div>



<p>「active (running)」と表示されていれば正常です。それ以外の場合は、起動に失敗しています。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/pico-6.jpg" alt="" class="wp-image-4" style="width:654px;height:auto"/></figure>



<p>今回のようなケースで多い原因が、DVBドライバとの競合です。使用しているRTL-SDRドングルは、もともとテレビ受信用の機器です。そのため、Raspberry Piは自動でテレビ用のドライバ（DVBドライバ）を割り当てます。しかし、ADS-B受信ではこのドライバは不要で、逆にdump1090-faの動作を妨げてしまいます。</p>



<p>この問題は、DVBドライバを無効化することで解決できます。以下のコマンドを1行ずつ順に実行して<span class="sbd-text-red">再起動</span>します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>echo &quot;blacklist dvb_usb_rtl28xxu&quot; | sudo tee /etc/modprobe.d/blacklist-rtl.conf
echo &quot;blacklist rtl2832&quot; | sudo tee -a /etc/modprobe.d/blacklist-rtl.conf
echo &quot;blacklist rtl2830&quot; | sudo tee -a /etc/modprobe.d/blacklist-rtl.conf</code></pre></div>



<p>再起動後、以下を実行して状態を確認します。「active (running)」になっていれば成功です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo systemctl status dump1090-fa</code></pre></div>



<h3 class="wp-block-heading">取得できる航空機データ</h3>



<p>画面の右側には、受信した航空機のリアルタイムデータが表形式で表示されます。各列の意味は以下のとおりです。</p>



<figure class="wp-block-table wp-block-sbd-table wp-block-sbd-table-vertical"><table><tbody><tr><td>ICAO</td><td class="has-text-align-left" data-align="left">航空機ごとに割り当てられた識別コード（16進数形式）</td></tr><tr><td>Ident</td><td class="has-text-align-left" data-align="left">航空会社名と便名（例：ANA536）</td></tr><tr><td>Squawk</td><td class="has-text-align-left" data-align="left">航空機が送信している4桁の識別コード（航空交通管制で使用）</td></tr><tr><td>Altitude (ft)</td><td class="has-text-align-left" data-align="left">高度（フィート単位）</td></tr><tr><td>Speed (kt)</td><td class="has-text-align-left" data-align="left">速度（ノット単位＝海里/時）</td></tr><tr><td>Heading</td><td class="has-text-align-left" data-align="left">進行方向（度）</td></tr><tr><td>Msgs</td><td class="has-text-align-left" data-align="left">受信したメッセージの回数</td></tr><tr><td>Age</td><td class="has-text-align-left" data-align="left">最新データを受信してからの経過時間（秒）</td></tr></tbody></table></figure>



<p>この画面は同じネットワークに接続されたPCやスマホからも閲覧可能です。もしRaspberry PiのIPアドレスが <strong>192.168.1.100</strong> であれば、「http://192.168.1.100:8080/」にアクセスすることで確認できます。</p>



<p>航空機の動きをリアルタイムで見るだけでもワクワクします。ですが、せっかくRaspberry Piを使っているので、受信したデータを活用して、さらに面白いことに挑戦したくなるものです。</p>



<h2 class="wp-block-heading">Pythonで受信データを処理する</h2>



<p>ADS-B信号を活用して何かを作りたいとき、Pythonでデータを取得できると便利です。dump1090-faは受信した航空機の情報を <code>http://localhost:8080/data/aircraft.json</code> というURLでJSON形式として公開しています。このJSONには航空機ごとの緯度・経度・高度・速度・方位などのデータが含まれており、Pythonからアクセスできます。</p>



<h3 class="wp-block-heading">Thonnyを使ってPythonプログラムを実行する</h3>



<p>Raspberry Piでは「Thonny（ソニー）」という初心者向けのPython開発環境が標準でインストールされています。以下の手順でプログラムを実行できます。</p>



<p>デスクトップ画面左上の「ラズベリーメニュー」から「プログラミング」→「Thonny」を開く。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2024/03/blynk2.jpg" alt="" class="wp-image-4" style="width:570px;height:auto"/></figure>



<p>画面中央のエリアに、プログラムをコピー＆ペーストして、「実行」ボタンを押す。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/pico-3.jpg" alt="" class="wp-image-4" style="width:568px;height:auto"/></figure>



<p>下部の「シェル」エリアに、実行結果（航空機の情報）が表示されます。</p>



<h3 class="wp-block-heading">航空機データの取得テスト</h3>



<p>以下のプログラムを実行して、航空機のデータが表示されるかを確認します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>import time
import requests

# 航空機データを取得する関数
def get_aircraft_positions():
    try:
        res = requests.get(&quot;http://localhost:8080/data/aircraft.json&quot;, timeout=1)
        return [a for a in res.json().get(&quot;aircraft&quot;, []) if &#39;lat&#39; in a and &#39;lon&#39; in a]
    except:
        return []

# 10秒ごとに航空機データを表示
while True:
    aircraft_list = get_aircraft_positions()

    print(f&quot;現在受信中の航空機数: {len(aircraft_list)} 機&quot;)
    for a in aircraft_list:
        hex_id = a.get(&#39;hex&#39;, &#39;不明&#39;)
        flight = a.get(&#39;flight&#39;, hex_id).strip()
        lat = a.get(&#39;lat&#39;)
        lon = a.get(&#39;lon&#39;)
        alt = a.get(&#39;alt_baro&#39;, &#39;不明&#39;)
        speed = a.get(&#39;gs&#39;, &#39;不明&#39;)
        track = a.get(&#39;track&#39;, &#39;不明&#39;)

        print(f&quot;便名: {flight} | 緯度: {lat} | 経度: {lon} | 高度: {alt} ft | 速度: {speed} kt | 方位: {track}°&quot;)

    # 10秒待機
    time.sleep(10)

</code></pre></div>



<p>このプログラムでは、まずURLにアクセスして航空機データを取得し、位置情報（緯度・経度）を持つものだけを抽出しています。そして、10秒ごとにその情報をシェルに表示します。表示される内容には、便名、緯度・経度、高度（フィート）、速度（ノット）、進行方向（度）が含まれており、上空を飛ぶ航空機の状況がリアルタイムに確認できます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/スクリーンショット-2025-05-18-8.03.11.png" alt="" class="wp-image-4" style="width:840px;height:auto"/><figcaption class="wp-element-caption">「シェル」エリアに表示された航空機の情報</figcaption></figure>



<p>これでPythonでデータを取得できることが確認できました。ここからは、このデータを処理するプログラムを作成していきます。</p>



<h3 class="wp-block-heading">航空機と測定地点の距離を計算</h3>



<p>緯度や経度の数値だけを見ても、近いのか遠いのかを判断できません。航空機と測定地点との距離を計算すると、接近しているのか遠ざかっているのかがわかります。</p>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>緯度・経度から距離を計算する方法については、ChatGPTに相談しながらアルゴリズムを作成しました。</p>
</div></div>



<p>以下のプログラムは自宅と航空機の緯度・経度をもとに直線距離を計算し、最も近い航空機の便名とその距離を表示します。この距離は測定地点と航空機の水平距離であり、高度は考慮していません。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>import time
import requests
import math

# 自宅の緯度・経度に変更してください（例：東京駅付近）
HOME_LAT = 35.681236
HOME_LON = 139.767125

# 航空機データを取得する関数
def get_aircraft_positions():
    try:
        res = requests.get(&quot;http://localhost:8080/data/aircraft.json&quot;, timeout=1)
        return [a for a in res.json().get(&quot;aircraft&quot;, []) if &#39;lat&#39; in a and &#39;lon&#39; in a]
    except:
        return []

# ハーサイン距離計算（地球上の2点間の距離をkmで返す）
def haversine(lat1, lon1, lat2, lon2):
    R = 6371.0  # 地球の半径 (km)
    lat1_rad = math.radians(lat1)
    lon1_rad = math.radians(lon1)
    lat2_rad = math.radians(lat2)
    lon2_rad = math.radians(lon2)
    dlat = lat2_rad - lat1_rad
    dlon = lon2_rad - lon1_rad
    a = math.sin(dlat/2)**2 + math.cos(lat1_rad) * math.cos(lat2_rad) * math.sin(dlon/2)**2
    c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
    return R * c

# 10秒ごとに一番近い航空機を表示
while True:
    aircraft_list = get_aircraft_positions()
    closest = None
    min_distance = float(&#39;inf&#39;)

    for a in aircraft_list:
        lat = a.get(&#39;lat&#39;)
        lon = a.get(&#39;lon&#39;)
        if lat is not None and lon is not None:
            distance = haversine(HOME_LAT, HOME_LON, lat, lon)
            if distance &lt; min_distance:
                min_distance = distance
                closest = a

    if closest:
        flight = closest.get(&#39;flight&#39;, closest.get(&#39;hex&#39;, &#39;不明&#39;)).strip()
        print(f&quot;最も近い便名: {flight} | 自宅からの距離: {min_distance:.2f} km&quot;)
    else:
        print(&quot;航空機データが取得できませんでした。&quot;)

    time.sleep(10)
</code></pre></div>



<p>測定地点の座標は、プログラム内6行目の <code>HOME_LAT</code>（緯度）と <code>HOME_LON</code>（経度）という変数に設定されています。東京駅の座標が入力されていますが、この値は自由に変更できます。</p>



<div class="wp-block-sbd-checkpoint-block"><p class="sbd-checkpoint-title">チェックポイント</p><div class="sbd-checkpoint-content sbd-inner-block-init"><p>緯度と経度は<a href="https://www.google.co.jp/maps/">Googleマップ</a>で調べることができます。地図上で自宅などの位置を右クリックすると、小さなメニューが表示されます。その一番上に、「35.○○○○○○, 139.○○○○○○」のような緯度と経度の数値が出てきます。</p></div></div>



<p>このプログラムは10秒ごとに航空機のデータを取得し、各機体との距離を順に計算。その中で<span class="sbd-text-red">もっとも距離が近い機体</span>を特定し、便名と距離を表示します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/スクリーンショット-2025-05-18-8.25.31.png" alt="" class="wp-image-4" style="width:572px;height:auto"/></figure>



<h4 class="wp-block-heading">LCD 1602表示する</h4>



<p>コードを応用すれば、以下のようなLCD表示も可能です。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/IMG_8994.jpeg" alt="" class="wp-image-4" style="width:443px;height:auto"/></figure>



<p>このLCDは「I2C接続の16文字2行キャラクタLCD（LCD1602）」と呼ばれています。もともとは並列通信で制御するタイプですが、背面にI2Cインターフェースモジュールが取り付けられており、4本の配線で使用できます。</p>



<!-- START MoshimoAffiliateEasyLink -->
<script type="text/javascript">
(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;
b[a]=b[a]||function(){arguments.currentScript=c.currentScript
||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};
c.getElementById(a)||(d=c.createElement(f),d.src=g,
d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})
(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");
msmaflink({"n":"Freenove I2C IIC LCD 1602モジュール、新タイプTWIシリアル16x2ディスプレイ、Arduino Raspberry Pi Pico ESP_Seriesと互換性あり","b":"Freenove","t":"FNK0079","d":"https:\/\/m.media-amazon.com","c_p":"\/images\/I","p":["\/51zdrKMSb-L._SL500_.jpg","\/51yV6Y1dg6L._SL500_.jpg","\/51wMFvA9hWL._SL500_.jpg","\/512HUqf8sPL._SL500_.jpg","\/41PAy3h0WBL._SL500_.jpg","\/41wzhotJskL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0B76YGDV4","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":1,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0B76YGDV4","a_id":3038653,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"id":4,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/Freenove%20I2C%20IIC%20LCD%201602%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB%E3%80%81%E6%96%B0%E3%82%BF%E3%82%A4%E3%83%97TWI%E3%82%B7%E3%83%AA%E3%82%A2%E3%83%AB16x2%E3%83%87%E3%82%A3%E3%82%B9%E3%83%97%E3%83%AC%E3%82%A4%E3%80%81Arduino%20Raspberry%20Pi%20Pico%20ESP_Series%E3%81%A8%E4%BA%92%E6%8F%9B%E6%80%A7%E3%81%82%E3%82%8A\/","a_id":3038654,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":2}],"eid":"QU2k0","s":"s"});
</script>
<div id="msmaflink-QU2k0">リンク</div>
<!-- MoshimoAffiliateEasyLink END -->



<p>ラズパイとLCD1602は以下のように接続します。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/image-1.png" alt="" class="wp-image-4"/><figcaption class="wp-element-caption">ラズパイとLCD1602の接続</figcaption></figure>



<p>LCD1602を使うためには、Raspberry PiでI2C通信を有効にする必要があります。以下のコマンドを実行後に再起動すると、I2Cを有効にできます。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo raspi-config nonint do_i2c 0</code></pre></div>



<p>次のコードは自宅の位置を基準にして、近くを飛んでいる航空機の情報を取得し、LCDに表示するものです。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>import smbus
import time
import requests
import math

ADDR = 0x27 # LCDのI2Cアドレス（例: 0x27や0x3F、使用前にi2cdetectで確認）
bus = smbus.SMBus(1)

# 自宅の緯度・経度に変更してください（例：東京駅付近）
HOME_LAT = 35.681236
HOME_LON = 139.767125

def write(data, mode=0):
    for val in [(data & 0xF0), ((data &lt;&lt; 4) & 0xF0)]:
        b = val | mode | 0x08
        bus.write_byte(ADDR, b | 0x04)
        time.sleep(0.0005)
        bus.write_byte(ADDR, b)

def init():
    for cmd in [0x33, 0x32, 0x06, 0x0C, 0x28, 0x01]:
        write(cmd)
    time.sleep(0.001)

def message(text, row=0, col=0):
    addr = 0x80 + col if row == 0 else 0xC0 + col
    write(addr)
    for c in text.ljust(16 - col):
        write(ord(c), 1)

# 航空機データを取得する関数
def get_aircraft_positions():
    try:
        res = requests.get(&quot;http://localhost:8080/data/aircraft.json&quot;, timeout=1)
        return [a for a in res.json().get(&quot;aircraft&quot;, []) if &#39;lat&#39; in a and &#39;lon&#39; in a]
    except:
        return []

# ハーサイン距離計算（地球上の2点間の距離をkmで返す）
def haversine(lat1, lon1, lat2, lon2):
    R = 6371.0  # 地球の半径 (km)
    lat1_rad = math.radians(lat1)
    lon1_rad = math.radians(lon1)
    lat2_rad = math.radians(lat2)
    lon2_rad = math.radians(lon2)
    dlat = lat2_rad - lat1_rad
    dlon = lon2_rad - lon1_rad
    a = math.sin(dlat/2)**2 + math.cos(lat1_rad) * math.cos(lat2_rad) * math.sin(dlon/2)**2
    c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
    return R * c

prev_line1 = &quot;&quot;
prev_line2 = &quot;&quot;

while True:
    aircraft_list = get_aircraft_positions()
    closest = None
    min_distance = float(&#39;inf&#39;)

    for a in aircraft_list:
        lat = a.get(&#39;lat&#39;)
        lon = a.get(&#39;lon&#39;)
        if lat is not None and lon is not None:
            distance = haversine(HOME_LAT, HOME_LON, lat, lon)
            if distance &lt; min_distance:
                min_distance = distance
                closest = a

    if closest:
        flight = closest.get(&#39;flight&#39;, closest.get(&#39;hex&#39;, &#39;UNKNOWN&#39;)).strip()
        line1 = flight
        line2 = &quot;Dist: {:.2f} km&quot;.format(min_distance)
    else:
        line1 = &quot;No aircraft&quot;
        line2 = &quot;in range&quot;

    # 表示内容に変化があるときだけ更新
    if line1 != prev_line1 or line2 != prev_line2:
        print(f&quot;Updating display:\n{line1}\n{line2}&quot;)
        init()
        message(line1, row=0, col=0)
        message(line2, row=1, col=2)
        prev_line1 = line1
        prev_line2 = line2

    time.sleep(2)</code></pre></div>



<p>表示内容が前回と同じであればLCDを更新せず、画面のちらつき防止を図ります。航空機がいない場合は「No aircraft」「in range」と表示します。</p>



<p>距離の数値が少しずつ縮まっていくのを見ると、ワクワクして思わず窓を開け、飛行機の音に耳を澄ませてしまいます。</p>



<h3 class="wp-block-heading">簡易的なレーダー風表示の作成</h3>



<p>航空機の緯度経度情報をもとに、他の機体や測定地点との位置関係をプロットする方法を模索します。以下のコードは取得した航空機の位置データをリアルタイムで画面に可視化するものです。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>import cv2
import requests
import numpy as np
import math
import time

# 自宅の緯度経度（例：東京駅周辺）
HOME_LAT = 35.6812
HOME_LON = 139.7671

# ウィンドウサイズと中心座標
WIDTH = 480
HEIGHT = 480
CENTER_X = WIDTH // 2
CENTER_Y = HEIGHT // 2

# 縮尺（緯度経度 → ピクセル）
SCALE = 400

# 航空機データ取得関数
def get_aircraft_positions():
    try:
        res = requests.get(&quot;http://localhost:8080/data/aircraft.json&quot;, timeout=1)
        return [a for a in res.json().get(&quot;aircraft&quot;, []) if &#39;lat&#39; in a and &#39;lon&#39; in a]
    except:
        return []

# 点線円を描く関数    
def draw_dotted_circle(img, center, radius, color=(0, 255, 0), spacing=2, dot_length=1):
    cx, cy = center
    circumference = 2 * math.pi * radius
    steps = int(circumference / (spacing + dot_length))

    for i in range(steps):
        angle_start = 2 * math.pi * (i * (spacing + dot_length)) / circumference
        angle_end = angle_start + (dot_length / radius)

        x1 = int(cx + radius * math.cos(angle_start))
        y1 = int(cy + radius * math.sin(angle_start))
        x2 = int(cx + radius * math.cos(angle_end))
        y2 = int(cy + radius * math.sin(angle_end))

        cv2.line(img, (x1, y1), (x2, y2), color, 1)

# 三角形で航空機を描画する関数
def draw_triangle(img, center, angle_deg, color=(0, 255, 0)):
    x, y = center
    length = 15
    width = 5
    angle_rad = math.radians(angle_deg)

    tip = (int(x + length * math.sin(angle_rad)), int(y - length * math.cos(angle_rad)))
    left = (int(x - width * math.cos(angle_rad)), int(y - width * math.sin(angle_rad)))
    right = (int(x + width * math.cos(angle_rad)), int(y + width * math.sin(angle_rad)))

    points = np.array([tip, left, right], dtype=np.int32)
    cv2.fillPoly(img, [points], color)

cv2.namedWindow(&quot;Radar Display&quot;)
cv2.resizeWindow(&quot;Radar Display&quot;, WIDTH, HEIGHT)

last_update = 0
aircraft_list = []

while True:
    frame = np.zeros((HEIGHT, WIDTH, 3), dtype=np.uint8)

    # 中心（自宅）のマーカー
    cv2.circle(frame, (CENTER_X, CENTER_Y), 2, (0, 255, 0), -1)
    
    # 緑の点線の中央縦線
    for y in range(0, HEIGHT, 10):
        if (y // 10) % 2 == 0:
            cv2.line(frame, (CENTER_X, y), (CENTER_X, y + 5), (0, 255, 0), 1)

    # 緑の点線の中央横線
    for x in range(0, WIDTH, 10):
        if (x // 10) % 2 == 0:
            cv2.line(frame, (x, CENTER_Y), (x + 5, CENTER_Y), (0, 255, 0), 1)

    # 点線円を3本描く
    for r in [60, 140, 220]:
        draw_dotted_circle(frame, (CENTER_X, CENTER_Y), r)


    # 1秒ごとにデータ更新
    if time.time() - last_update &gt; 1.0:
        aircraft_list = get_aircraft_positions()
        last_update = time.time()

    # 各航空機を描画
    for a in aircraft_list:
        dx = (a[&#39;lon&#39;] - HOME_LON) * SCALE
        dy = (a[&#39;lat&#39;] - HOME_LAT) * SCALE
        x = int(CENTER_X + dx)
        y = int(CENTER_Y - dy)

        if 0 &lt;= x &lt; WIDTH and 0 &lt;= y &lt; HEIGHT:
            if &#39;track&#39; in a and isinstance(a[&#39;track&#39;], (int, float)):
                draw_triangle(frame, (x, y), a[&#39;track&#39;])
            else:
                cv2.circle(frame, (x, y), 5, (0, 255, 0), -1)

    cv2.imshow(&quot;Radar Display&quot;, frame)

    if cv2.waitKey(30) & 0xFF == 27:  # ESCキーで終了
        break

cv2.destroyAllWindows()
</code></pre></div>



<p>まず、自宅の緯度経度を基準としてウィンドウの中心に固定し、各航空機の緯度・経度の差をピクセル換算（<code>SCALE</code>）して、画面上に位置を描画します。</p>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>この部分も、自分の環境に応じた緯度経度に変更してください。</p>
</div></div>



<p>18行目の<code>SCALE = 400</code> は、緯度・経度の差を画面上のピクセルに変換するための倍率です。この値を大きくすると表示範囲が狭くなり、航空機が大きく動くように見えます。逆に小さくすると広範囲を表示できます。表示範囲や航空機の密度に応じて、<code>SCALE</code> の数値は適宜調整してください。</p>



<p>進行中の機体には「track」と呼ばれる方位情報が含まれており、これは航空機がどの方角へ向かっているか（真北を0度として時計回り）を示します。</p>



<p>この方位情報をもとに、航空機のアイコンを進行方向に向かって回転させて表示します。アイコンは三角形を使って機体の向きを表現しており、先端が進行方向を指すように描画します。trackの値が取得できない場合には、代わりに緑色の円で機体の位置を示します。</p>



<p>1秒ごとにデータ取得・描画を繰り返すことで、リアルタイムな位置関係を描き出しています。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/IMG_9002.jpeg" alt="" class="wp-image-4" style="width:491px;height:auto"/></figure>



<p>飛行機がどの方向へ向かっているか、測定地点から見てどこに位置しているかを、視覚的に把握することが可能になりました。</p>



<h2 class="wp-block-heading">ミニレーダー風表示装置の作り方</h2>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/IMG_8983.jpeg" alt="" class="wp-image-4"/></figure>



<p>いよいよミニレーダーの作成に着手します。ここからの内容は、以下の構成で作成しています。</p>



<figure class="wp-block-table wp-block-sbd-table wp-block-sbd-table-vertical"><table><tbody><tr><td>モデル</td><td class="has-text-align-left" data-align="left"><a href="https://sozorablog.com/raspberry-pi-zero-2-w/">Raspberry Pi Zero 2 W</a></td></tr><tr><td>OS</td><td class="has-text-align-left" data-align="left">Raspberry Pi OS Bullseye (Legacy, 32-bit)</td></tr><tr><td>ディスプレイ</td><td class="has-text-align-left" data-align="left"><a href="https://shop.pimoroni.com/products/hyperpixel-round?variant=39381081882707">HyperPixel 2.1 Round</a></td></tr></tbody></table></figure>



<h3 class="wp-block-heading">HyperPixel 2.1 Roundの設定</h3>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/スクリーンショット-2025-05-18-5.29.14.jpg" alt="" class="wp-image-4"/><figcaption class="wp-element-caption">出典：<a href="https://shop.pimoroni.com/products/hyperpixel-round?variant=39381081882707">Pimoroni</a></figcaption></figure>



<p>ディスプレイは<a href="https://shop.pimoroni.com/products/hyperpixel-round?variant=39381081882707">HyperPixel 2.1 Round</a>を使用しました。小型の円形ディスプレイで、ミニレーダーにはぴったりなアイテムです。GPIOに接続し、設定を行うことで、Raspberry Piのデスクトップ画面をそのまま表示できます。</p>



<p>ラズパイはディスプレイの裏側にすっきり収まるサイズのRaspberry Pi Zero 2 Wを使用しました。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/IMG_8984.jpeg" alt="" class="wp-image-4"/><figcaption class="wp-element-caption">HyperPixel 2.1 RoundとZero 2 W</figcaption></figure>



<p>Raspberry Piとディスプレイを接続します。40本のピンヘッダーをまるごと差し込みます。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/IMG_8985.jpeg" alt="" class="wp-image-4"/></figure>



<p>HyperPixel 2.1 RoundでRaspberry Piの画面を表示するには、カーネルドライバを有効にする必要があります。</p>



<p>ターミナルを開いて以下のコマンドを1行ずつ順に実行します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>git clone https://github.com/pimoroni/hyperpixel2r
cd hyperpixel2r
sudo ./install.sh</code></pre></div>



<p>ディスプレイを正しく動作させるために、<code>/boot/config.txt</code>の中にある「dtoverlay=vc4-kms-v3d」の行を無効化します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo nano /boot/config.txt</code></pre></div>



<p>開いたファイルの中で、「dtoverlay=vc4-kms-v3d」の行を探して、先頭に <code>#</code> を追加します。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/pico-1.jpg" alt="" class="wp-image-4"/></figure>



<p>編集が終わったら、<strong>Ctrl + O</strong>&nbsp;で保存し、<strong>Ctrl + X</strong>&nbsp;でエディタを終了します。</p>



<p>以下のコマンドでI2Cを無効化します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo raspi-config nonint do_i2c 1</code></pre></div>



<p>再起動すると、画面が表示されます。ディスプレイは円形のため、画面の四隅にあるスタートメニューなどは表示されません。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/IMG_8976.jpeg" alt="" class="wp-image-4"/></figure>



<p>タッチ操作にも対応していますが、このサイズではGUI操作が難しいため、基本的には<a href="https://sozorablog.com/vnc/">VNC</a>での操作をおすすめします。</p>



<h3 class="wp-block-heading">画面の自動暗転機能を無効化する</h3>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2024/02/pico-43.jpg" alt="" class="wp-image-4"/></figure>



<p>「Raspberry Piの設定」を開いて「画面のブランク」という項目をオフにします。これは、一定時間何も操作しないと画面が暗くなる機能です。<span class="sbd-text-bg-yellow">この機能が有効になっていると、レーダーを長時間表示し続けることができません。</span></p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2024/02/mm7-2.png" alt="" class="wp-image-4" style="width:840px;height:auto"/></figure>



<h3 class="wp-block-heading">スタンドの作成</h3>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/IMG_8996.jpeg" alt="" class="wp-image-4" style="width:445px;height:auto"/></figure>



<p>機器を設置するためのスタンドを、Tinkercadで設計して<a href="https://sozorablog.com/ankermake-m5c/">3Dプリンター</a>で作りました。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/スクリーンショット-2025-05-18-5.25.54.png" alt="" class="wp-image-4" style="width:444px;height:auto"/></figure>



<p>デザインは、戦闘機のコックピットにある計器をイメージしています。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/IMG_8950.jpeg" alt="" class="wp-image-4" style="width:434px;height:auto"/></figure>



<p>設計が完成したらプリント開始。およそ2時間で印刷が終わりました。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/IMG_8953.jpeg" alt="" class="wp-image-4" style="width:434px;height:auto"/></figure>



<p>スタンドに機器を取り付けた様子。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/IMG_8973.jpeg" alt="" class="wp-image-4" style="width:433px;height:auto"/></figure>



<p>デザインやサイズを調整しながら、5回ほど試作を重ねました。以下のボタンからSTLファイルをダウンロードできます。</p>


<div class='w3eden'><!-- WPDM Link Template: Default Template -->

<div class="link-template-default card mb-2">
    <div class="card-body">
        <div class="media">
            <div class="mr-3 img-48"><img decoding="async" class="wpdm_icon" alt="アイコン" src="https://sozorablog.com/wp-content/plugins/download-manager/assets/file-type-icons/zip.svg" /></div>
            <div class="media-body">
                <h3 class="package-title"><a href='https://sozorablog.com/download/hyperpixel-round-stand/'>HyperPixel-Round-stand</a></h3>
                <div class="text-muted text-small"><i class="fas fa-copy"></i> 1 ファイル <i class="fas fa-hdd ml-3"></i> 130.01 KB</div>
            </div>
            <div class="ml-3">
                <a class='wpdm-download-link download-on-click btn btn-primary ' rel='nofollow' href='#' data-downloadurl="https://sozorablog.com/download/hyperpixel-round-stand/?wpdmdl=16709&refresh=69e5655bd8f901776641371">ダウンロード</a>
            </div>
        </div>
    </div>
</div>

</div>



<h3 class="wp-block-heading">レーダー画像と飛行機アイコンの準備</h3>



<p>回転するレーダーの動画は、<a href="https://pixabay.com/ja/videos/%E3%83%AC%E3%83%BC%E3%83%80%E3%83%BC-%E3%82%BD%E3%83%8A%E3%83%BC-ping-2420/">Pixabay</a>で公開されているものをダウンロードして使用します。Pixabayは著作権フリーの画像、動画、音声などを共有するサイトです。サイズは<span class="sbd-text-red">640×360</span>のものをダウンロードしました。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2024/03/radar2.jpg" alt="" class="wp-image-4"/><figcaption class="wp-element-caption"><a href="https://pixabay.com/ja/videos/%E3%83%AC%E3%83%BC%E3%83%80%E3%83%BC-%E3%82%BD%E3%83%8A%E3%83%BC-ping-2420/">Pixabay</a></figcaption></figure>



<p>飛行機の位置を示すためのアイコン画像を作成しました。透過PNG形式の飛行機アイコン画像は、ChatGPTに作ってもらい、サイズはパソコンで48ピクセルに調整しました。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/plane_icon-1.png" alt="" class="wp-image-4"/><figcaption class="wp-element-caption">plane_icon.png</figcaption></figure>


<div class='w3eden'><!-- WPDM Link Template: Default Template -->

<div class="link-template-default card mb-2">
    <div class="card-body">
        <div class="media">
            <div class="mr-3 img-48"><img decoding="async" class="wpdm_icon" alt="アイコン" src="https://sozorablog.com/wp-content/plugins/download-manager/assets/file-type-icons/png.svg" /></div>
            <div class="media-body">
                <h3 class="package-title"><a href='https://sozorablog.com/download/%e9%a3%9b%e8%a1%8c%e6%a9%9f%e3%82%a2%e3%82%a4%e3%82%b3%e3%83%b3plane_icon-png/'>飛行機アイコン(plane_icon.png)</a></h3>
                <div class="text-muted text-small"><i class="fas fa-copy"></i> 1 ファイル <i class="fas fa-hdd ml-3"></i> 1.09 KB</div>
            </div>
            <div class="ml-3">
                <a class='wpdm-download-link download-on-click btn btn-primary ' rel='nofollow' href='#' data-downloadurl="https://sozorablog.com/download/%e9%a3%9b%e8%a1%8c%e6%a9%9f%e3%82%a2%e3%82%a4%e3%82%b3%e3%83%b3plane_icon-png/?wpdmdl=14757&refresh=69e5655bdb0901776641371">ダウンロード</a>
            </div>
        </div>
    </div>
</div>

</div>



<p>動画とアイコンはファイル名をradar.mp4とplane_icon.pngに変更して、Raspberry Piの「/home/pi」ディレクトリ、または実行するプログラムを保存するディレクトリに保存します。WindowsパソコンからRaspberry Piにファイルを移動する場合は、<a href="https://sozorablog.com/winscp/">WinSCP</a>を利用すると便利です。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/pico-1-1.jpg" alt="" class="wp-image-4"/></figure>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>ファイル名や保存場所が正しくないと、プログラムから呼び出せなくなります。</p>
</div></div>



<h3 class="wp-block-heading">ミニレーダー風ディスプレイのプログラム</h3>



<p>以下のプログラムでは、先ほど保存した <code>radar.mp4</code> を背景動画として表示し、<code>plane_icon.png</code> の飛行機アイコンを航空機の位置に合わせて画面上に描画します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>import cv2
import requests
import numpy as np
import math
import time

# 自宅の緯度経度に変更してください（以下は東京駅周辺）
HOME_LAT = 35.6812
HOME_LON = 139.7671

# 画面サイズと中心座標
WIDTH = 480
HEIGHT = 480
CENTER_X = WIDTH // 2
CENTER_Y = HEIGHT // 2

# 緯度経度→ピクセル変換倍率
SCALE = 300

# 飛行機アイコンの読み込み（アルファチャンネル付き）
icon = cv2.imread(&quot;plane_icon.png&quot;, cv2.IMREAD_UNCHANGED)
icon_h, icon_w = icon.shape[:2]

# 背景レーダー動画の読み込み
cap = cv2.VideoCapture(&quot;radar.mp4&quot;)
fps = cap.get(cv2.CAP_PROP_FPS)
delay = int(1000 / fps) if fps &gt; 0 else 33  # フレーム遅延時間(ms)

# 航空機データ取得関数
def get_aircraft_positions():
    try:
        res = requests.get(&quot;http://localhost:8080/data/aircraft.json&quot;, timeout=1)
        return [a for a in res.json().get(&quot;aircraft&quot;, []) if &#39;lat&#39; in a and &#39;lon&#39; in a]
    except:
        return []

# 飛行機アイコンを回転描画する関数
def draw_icon_rotated(img, icon, center, angle_deg):
    x, y = center
    M = cv2.getRotationMatrix2D((icon_w // 2, icon_h // 2), -angle_deg, 1.0)
    rotated = cv2.warpAffine(
        icon, M, (icon_w, icon_h),
        flags=cv2.INTER_NEAREST,
        borderMode=cv2.BORDER_CONSTANT,
        borderValue=(0, 0, 0, 0)
    )

    # アイコン貼り付け位置の計算
    x1 = x - icon_w // 2
    y1 = y - icon_h // 2
    x2 = x1 + icon_w
    y2 = y1 + icon_h

    # 画面外ならスキップ
    if x1 &lt; 0 or y1 &lt; 0 or x2 &gt; img.shape[1] or y2 &gt; img.shape[0]:
        return

    # ROI合成（アルファブレンド）
    roi = img[y1:y2, x1:x2]
    if rotated.shape[2] == 4:
        alpha = rotated[:, :, 3] / 255.0
        for c in range(3):
            roi[:, :, c] = (1 - alpha) * roi[:, :, c] + alpha * rotated[:, :, c]

# ウィンドウを全画面表示
cv2.namedWindow(&quot;Radar Display&quot;, cv2.WINDOW_NORMAL)
cv2.setWindowProperty(&quot;Radar Display&quot;, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)

# 初期化
aircraft_list = []
last_update = 0

while True:
    now = time.time()
    if now - last_update &gt;= 1.0:
        aircraft_list = get_aircraft_positions()
        last_update = now    
    
    # 動画フレームの読み込み
    ret, video_frame = cap.read()
    if not ret:
        cap.set(cv2.CAP_PROP_POS_FRAMES, 0)  # 動画を最初に戻す
        continue

    # 動画のリサイズ（1.8倍ズーム＋アスペクト比維持）
    video_h, video_w = video_frame.shape[:2]
    scale = min(WIDTH / video_w, HEIGHT / video_h) * 1.8
    new_w = int(video_w * scale)
    new_h = int(video_h * scale)
    resized = cv2.resize(video_frame, (new_w, new_h), interpolation=cv2.INTER_NEAREST)
    resized = cv2.convertScaleAbs(resized, alpha=0.6, beta=0)  # 薄く表示

    # 最終描画フレーム（黒背景）
    frame = np.zeros((HEIGHT, WIDTH, 3), dtype=np.uint8)

    # 動画の貼り付け位置計算（中央寄せ）
    x_offset = (WIDTH - new_w) // 2
    y_offset = (HEIGHT - new_h) // 2
    x1_dst = max(x_offset, 0)
    y1_dst = max(y_offset, 0)
    x1_src = max(-x_offset, 0)
    y1_src = max(-y_offset, 0)
    x2_dst = min(x_offset + new_w, WIDTH)
    y2_dst = min(y_offset + new_h, HEIGHT)
    x2_src = x1_src + (x2_dst - x1_dst)
    y2_src = y1_src + (y2_dst - y1_dst)

    # 動画フレームを合成
    frame[y1_dst:y2_dst, x1_dst:x2_dst] = resized[y1_src:y2_src, x1_src:x2_src]

    # 航空機データ取得
    aircraft_list = get_aircraft_positions()

    # 航空機ごとにアイコンを描画
    for a in aircraft_list:
        dx = (a[&#39;lon&#39;] - HOME_LON) * SCALE
        dy = (a[&#39;lat&#39;] - HOME_LAT) * SCALE
        x = int(CENTER_X + dx)
        y = int(CENTER_Y - dy)

        # 画面内に収まっているか判定
        if 0 &lt;= x &lt; WIDTH and 0 &lt;= y &lt; HEIGHT:
            if &#39;track&#39; in a and isinstance(a[&#39;track&#39;], (int, float)):
                draw_icon_rotated(frame, icon, (x, y), a[&#39;track&#39;])
            else:
                cv2.circle(frame, (x, y), 5, (0, 255, 0), -1)

    # フレーム表示
    cv2.imshow(&quot;Radar Display&quot;, frame)

    # ESCキーで終了
    key = cv2.waitKey(delay) & 0xFF
    if key == 27:
        break

# 終了処理
cap.release()
cv2.destroyAllWindows()
</code></pre></div>



<p><code>HOME_LAT</code> と <code>HOME_LON</code> は、レーダー画面の中心となる自宅の位置を表す緯度・経度です（この例では東京駅付近を指定しています）。航空機の位置は、この基準点からの相対的な距離をもとに計算され、画面上に配置されます。</p>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>自分の環境に応じた緯度と経度に変更してください。</p>
</div></div>



<p><code>SCALE = 300</code> は、緯度・経度の差を画面上のピクセルに変換するための倍率です。この値を大きくすると表示範囲が狭くなり、航空機が大きく動くように見えます。逆に小さくすると広範囲を表示できます。表示範囲や航空機の密度に応じて、<code>SCALE</code> の数値は適宜調整してください。</p>



<p>プログラムの終了は、<span class="sbd-text-bg-yellow"><code>ESC</code>キーを押す</span>ことでウィンドウが閉じられ、処理が終了します。画面はフルスクリーンで表示されるため、実際のレーダー装置のような見た目に仕上がります。</p>



<p>ESCキーでプログラムを終了できます。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/スクリーンショット-2025-05-17-16.55.47.png" alt="" class="wp-image-4"/><figcaption class="wp-element-caption">レーダー画面の表示例</figcaption></figure>



<p>無事にミニレーダーが完成しました。飛行機の動きを眺めているだけでも飽きません。</p>



<figure class="wp-block-embed is-type-rich is-provider-twitter wp-block-embed-twitter"><div class="wp-block-embed__wrapper">
<blockquote class="twitter-tweet" data-width="500" data-dnt="true"><p lang="ja" dir="ltr">Raspberry Piで作ったレーダー風ガジェット。<br><br>飛行機から送信されるADS-B信号を受信し、リアルタイムな位置を表示します。 <a href="https://t.co/cRcj0Q6rCZ">pic.twitter.com/cRcj0Q6rCZ</a></p>&mdash; そぞら@Raspberry Pi 電子工作 (@sozoraemon) <a href="https://twitter.com/sozoraemon/status/1927312233266082016?ref_src=twsrc%5Etfw">May 27, 2025</a></blockquote><script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
</div></figure>



<h3 class="wp-block-heading">【改良版】便名を表示する</h3>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/image.png" alt="" class="wp-image-4"/></figure>



<p>以下は飛行機アイコンの<strong>すぐ下に便名（flight）を表示</strong>するコードを追加したものです。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>import cv2
import requests
import numpy as np
import math
import time

# 自宅の緯度経度に変更してください（以下は東京駅周辺）
HOME_LAT = 35.6812
HOME_LON = 139.7671

# 画面サイズと中心座標
WIDTH = 480
HEIGHT = 480
CENTER_X = WIDTH // 2
CENTER_Y = HEIGHT // 2

# 緯度経度→ピクセル変換倍率
SCALE = 600

# 飛行機アイコンの読み込み（アルファチャンネル付き）
icon = cv2.imread(&quot;plane_icon.png&quot;, cv2.IMREAD_UNCHANGED)
icon_h, icon_w = icon.shape[:2]

# 背景レーダー動画の読み込み
cap = cv2.VideoCapture(&quot;radar.mp4&quot;)
fps = cap.get(cv2.CAP_PROP_FPS)
delay = int(1000 / fps) if fps &gt; 0 else 33  # フレーム遅延時間(ms)

# 航空機データ取得関数
def get_aircraft_positions():
    try:
        res = requests.get(&quot;http://localhost:8080/data/aircraft.json&quot;, timeout=1)
        return [a for a in res.json().get(&quot;aircraft&quot;, []) if &#39;lat&#39; in a and &#39;lon&#39; in a]
    except:
        return []

# 飛行機アイコンを回転描画する関数
def draw_icon_rotated(img, icon, center, angle_deg):
    x, y = center
    M = cv2.getRotationMatrix2D((icon_w // 2, icon_h // 2), -angle_deg, 1.0)
    rotated = cv2.warpAffine(
        icon, M, (icon_w, icon_h),
        flags=cv2.INTER_NEAREST,
        borderMode=cv2.BORDER_CONSTANT,
        borderValue=(0, 0, 0, 0)
    )

    # アイコン貼り付け位置の計算
    x1 = x - icon_w // 2
    y1 = y - icon_h // 2
    x2 = x1 + icon_w
    y2 = y1 + icon_h

    # 画面外ならスキップ
    if x1 &lt; 0 or y1 &lt; 0 or x2 &gt; img.shape[1] or y2 &gt; img.shape[0]:
        return

    # ROI合成（アルファブレンド）
    roi = img[y1:y2, x1:x2]
    if rotated.shape[2] == 4:
        alpha = rotated[:, :, 3] / 255.0
        for c in range(3):
            roi[:, :, c] = (1 - alpha) * roi[:, :, c] + alpha * rotated[:, :, c]

# ウィンドウを全画面表示
cv2.namedWindow(&quot;Radar Display&quot;, cv2.WINDOW_NORMAL)
cv2.setWindowProperty(&quot;Radar Display&quot;, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)

# 初期化
aircraft_list = []
last_update = 0

while True:
    now = time.time()
    if now - last_update &gt;= 1.0:
        aircraft_list = get_aircraft_positions()
        last_update = now    
    
    # 動画フレームの読み込み
    ret, video_frame = cap.read()
    if not ret:
        cap.set(cv2.CAP_PROP_POS_FRAMES, 0)  # 動画を最初に戻す
        continue

    # 動画のリサイズ（1.8倍ズーム＋アスペクト比維持）
    video_h, video_w = video_frame.shape[:2]
    scale = min(WIDTH / video_w, HEIGHT / video_h) * 1.8
    new_w = int(video_w * scale)
    new_h = int(video_h * scale)
    resized = cv2.resize(video_frame, (new_w, new_h), interpolation=cv2.INTER_NEAREST)
    resized = cv2.convertScaleAbs(resized, alpha=0.6, beta=0)  # 薄く表示

    # 最終描画フレーム（黒背景）
    frame = np.zeros((HEIGHT, WIDTH, 3), dtype=np.uint8)

    # 動画の貼り付け位置計算（中央寄せ）
    x_offset = (WIDTH - new_w) // 2
    y_offset = (HEIGHT - new_h) // 2
    x1_dst = max(x_offset, 0)
    y1_dst = max(y_offset, 0)
    x1_src = max(-x_offset, 0)
    y1_src = max(-y_offset, 0)
    x2_dst = min(x_offset + new_w, WIDTH)
    y2_dst = min(y_offset + new_h, HEIGHT)
    x2_src = x1_src + (x2_dst - x1_dst)
    y2_src = y1_src + (y2_dst - y1_dst)

    # 動画フレームを合成
    frame[y1_dst:y2_dst, x1_dst:x2_dst] = resized[y1_src:y2_src, x1_src:x2_src]

    # 航空機ごとにアイコンを描画
    for a in aircraft_list:
        dx = (a[&#39;lon&#39;] - HOME_LON) * SCALE
        dy = (a[&#39;lat&#39;] - HOME_LAT) * SCALE
        x = int(CENTER_X + dx)
        y = int(CENTER_Y - dy)

        # 画面内に収まっているか判定
        if 0 &lt;= x &lt; WIDTH and 0 &lt;= y &lt; HEIGHT:
            if &#39;track&#39; in a and isinstance(a[&#39;track&#39;], (int, float)):
                draw_icon_rotated(frame, icon, (x, y), a[&#39;track&#39;])
            else:
                cv2.circle(frame, (x, y), 5, (0, 255, 0), -1)
                
            # --- 便名を描画 ---
            if &#39;flight&#39; in a and a[&#39;flight&#39;]:
                flight_text = a[&#39;flight&#39;]
                font = cv2.FONT_HERSHEY_SIMPLEX
                font_scale = 0.5
                thickness = 1
                text_size, _ = cv2.getTextSize(flight_text, font, font_scale, thickness)
                text_x = x - text_size[0] // 2 + 6
                text_y = y + icon_h // 2 + text_size[1] - 2 # アイコン下
                cv2.putText(frame, flight_text, (text_x, text_y), font, font_scale, (0, 255, 0), thickness, cv2.LINE_AA)                

    # フレーム表示
    cv2.imshow(&quot;Radar Display&quot;, frame)

    # ESCキーで終了
    key = cv2.waitKey(delay) & 0xFF
    if key == 27:
        break

# 終了処理
cap.release()
cv2.destroyAllWindows()
</code></pre></div>



<h2 class="wp-block-heading">Flightradar24へデータ提供する</h2>



<p>自宅で受信した航空機のADS-B信号をFlightradar24に提供することで、航空ネットワークに貢献できます。その見返りとして、通常は有料のプレミアム機能が無料で使えるようになります。<br>ここでは、データ提供するメリットとデメリットを整理します。</p>



<p>メリット</p>



<div class="wp-block-sbd-list"><ul class="sbd-list sbd-list-border"><li>Flightradar24のContributorプランが利用可能</li><li>いつでもやめられる（データ送信を停止しても金銭的・法的な不利益なし）</li></ul></div>



<p>デメリット</p>



<div class="wp-block-sbd-list"><ul class="sbd-list sbd-list-border"><li>Raspberry Piのリソースを使用（低スペック機では他の作業に影響）</li><li>ラズパイの位置情報をFlightradar24に提供する必要あり</li></ul></div>



<h3 class="wp-block-heading">Flightradar24のアカウントを作成する</h3>



<p>データを提供するには、Flightradar24のアカウントが必要です。</p>



<p><a href="https://www.flightradar24.com/">Flightradar24のウェブサイト</a>にアクセスし、画面右上の「Login」をクリックします。</p>



<p>表示されたウィンドウの下部にある　<strong>“Learn more | Create account”</strong> をクリックします。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/pico-1.png" alt="" class="wp-image-4" style="width:451px;height:auto"/></figure>



<p>表示されたこのプラン比較画面で、左端の「Free」プランの下にある「Create account」ボタンをクリックします。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/pico-4.jpg" alt="" class="wp-image-4"/></figure>



<p>メールアドレス・パスワードを入力し、アカウントを作成します。</p>



<p>登録したメールアドレスに確認メールが届くので、リンクをクリックして認証します。</p>



<h3 class="wp-block-heading">fr24feed（フィーダーソフト）をインストールする</h3>



<p>次に、Flightradar24にデータを送るためのソフト「fr24feed」をRaspberry Piにインストールします。</p>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>このソフトを使うには、<strong>dump1090-fa</strong>がインストールされていて、起動している必要があります。</p>
</div></div>



<p>dump1090-faのインストールや起動がまだの場合は、この記事の前半にある<span class="sbd-text-bg-yellow">「ソフトウェアの設定」パートの手順を先に行ってください。</span></p>



<p>ターミナルで以下のコマンドを実行</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo bash -c &quot;$(wget -O - https://repo-feed.flightradar24.com/install_fr24_rpi.sh)&quot;</code></pre></div>



<p>このコマンドは、Flightradar24のデータ送信ソフト「fr24feed」をRaspberry Piにダウンロードしてインストールするためのものです。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/スクリーンショット-2025-05-23-4.07.37.png" alt="" class="wp-image-4" style="width:840px;height:auto"/></figure>



<p>インストール後、自動的に設定ウィザードが始まります。ターミナルにいくつかの質問が表示されるので、それぞれに答えてエンターキーを押してください。以下のように回答します。</p>



<figure class="wp-block-table wp-block-sbd-table wp-block-sbd-table-vertical"><table><thead><tr><th>Step</th><th class="has-text-align-left" data-align="left">質問内容</th><th>回答の例</th></tr></thead><tbody><tr><td>1.1</td><td class="has-text-align-left" data-align="left">Flightradar24アカウントのメールアドレス</td><td>登録したメールアドレスを入力</td></tr><tr><td>1.2</td><td class="has-text-align-left" data-align="left">Sharing keyの入力</td><td>以前使用したキーがあれば入力<br>なければそのままEnter</td></tr><tr><td>1.3</td><td class="has-text-align-left" data-align="left">MLAT(Multilateration)に参加するか？<br>※複数の受信機が同時に受け取った信号の到達時間差からADS-B信号のない航空機の位置を推定する技術</td><td><br>yes または no を入力してEnter<br>（基本は yes でOK）</td></tr><tr><td>3.A</td><td class="has-text-align-left" data-align="left">アンテナ設置位置の緯度</td><td>例：35.6812<br><a href="https://www.google.com/maps/?hl=ja">Googleマップ</a>等で調査可</td></tr><tr><td>3.B</td><td class="has-text-align-left" data-align="left">アンテナ設置位置の経度</td><td>例：139.7671</td></tr><tr><td>3.C</td><td class="has-text-align-left" data-align="left">アンテナ設置位置の高度（フィート）</td><td>例: <code>108</code><br>地面の標高＋アンテナ設置位置までの高さ（m）× 3.28084（フィート換算）<br>標高は<a href="https://maps.gsi.go.jp/">国土地理院地図</a>で調査可</td></tr><tr><td></td><td class="has-text-align-left" data-align="left">入力内容の確認</td><td>yes または no を入力してEnter</td></tr><tr><td></td><td class="has-text-align-left" data-align="left">「autoconfig 機能」を使うかどうかの確認</td><td>基本は yes でOK</td></tr></tbody></table></figure>



<p>すべて正常に完了すると、「Installation and configuration completed!」と表示されます。</p>



<h3 class="wp-block-heading">データ提供の確認</h3>



<p>以下のコマンドでfr24feedの動作状況を確認します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>fr24feed-status</code></pre></div>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/pico-2-1.jpg" alt="" class="wp-image-4"/></figure>



<p>最下行の「FR24 MLAT: not running &#8230; failed!」は、MLAT（複数の受信機で航空機の位置を推定する機能）が正常に動作していないことを示しています。</p>



<div class="wp-block-sbd-checkpoint-block"><p class="sbd-checkpoint-title">申し訳ありません</p><div class="sbd-checkpoint-content sbd-inner-block-init"><p>「FR24 MLAT: not running &#8230; failed!」について、以下の記事を参考に設定を見直しましたが、解決には至っていません。<a href="https://intaa.net/archives/21762">https://intaa.net/archives/21762</a>　</p></div></div>



<p><a href="https://forum.flightradar24.com/forum/radar-forums/flightradar24-feeding-data-to-flightradar24/9479-fr24feed-uploader-additional-info">Flightradar24（FR24）の公式フォーラム</a>によると、MLATが動作するには、同じ航空機の信号を<strong>複数の受信局</strong>が同時に受信している必要があります。今回はMLATだけが停止しているため、この受信条件が満たされていない可能性があると推測されますが、現時点で断定はできません。</p>



<p>なお、ADS-B信号の受信とFlightradar24へのデータ提供は正常に行われており、<span class="sbd-text-red">Businessプランの適用に影響はありません。</span></p>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>今後、MLATが正常に動作する方法が分かり次第、この記事に追記します。</p>
</div></div>



<p>Raspberry Piのブラウザで <code>http://localhost:8754</code> にアクセスすると、fr24feedの動作状況（受信状態、送信状態、MLATの状態など）をリアルタイムで確認できます。</p>



<p>Flightradar24のウェブサイトにアクセスし、画面右上のユーザーアイコンに「CONTRIBUTOR」と表示されていれば、CONTRIBUTORプランが適用済みです。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/pico-1-1-1.jpg" alt="" class="wp-image-4"/></figure>



<h3 class="wp-block-heading">Flightradar24へのデータ提供を中止する</h3>



<p>データ提供はいつでも停止することができます。中止しても料金が発生することはありません。</p>



<p>データ提供を中止するには、以下を1行ずつ実行します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo systemctl stop fr24feed
sudo systemctl disable fr24feed</code></pre></div>



<p>これにより、fr24feedが停止し、次回以降の起動時にも自動実行されなくなります。</p>



<h2 class="wp-block-heading">まとめ</h2>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/Videotogif.gif" alt="" class="wp-image-4"/></figure>



<p>ADS-B受信機は買って大正解のアイテムでした。Raspberry Piとの相性も抜群で、ラズパイユーザーには特におすすめです。</p>



<!-- START MoshimoAffiliateEasyLink -->
<script type="text/javascript">
(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;
b[a]=b[a]||function(){arguments.currentScript=c.currentScript
||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};
c.getElementById(a)||(d=c.createElement(f),d.src=g,
d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})
(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");
msmaflink({"n":"Nooelec NESDR Mini ミニUSB RTL-SDRおよびADS-B受信機セット、RTL2832UおよびR820Tチューナー、MCX入力。 多くのSDRソフトウェアパッケージと互換性のある低コストソフトウェア無線機。 R820Tチューナ","b":"NooElec","t":"100556","d":"https:\/\/m.media-amazon.com","c_p":"\/images\/I","p":["\/31Vb71v4fTL._SL500_.jpg","\/314CXt2ANJL._SL500_.jpg","\/31QS842oE2L._SL500_.jpg","\/41fYlg-Nw3L._SL500_.jpg","\/31bzg-noaGL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B009U7WZCA","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":1,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B009U7WZCA","a_id":3038653,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"id":2,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/Nooelec%20NESDR%20Mini%20%E3%83%9F%E3%83%8BUSB%20RTL-SDR%E3%81%8A%E3%82%88%E3%81%B3ADS-B%E5%8F%97%E4%BF%A1%E6%A9%9F%E3%82%BB%E3%83%83%E3%83%88%E3%80%81RTL2832U%E3%81%8A%E3%82%88%E3%81%B3R820T%E3%83%81%E3%83%A5%E3%83%BC%E3%83%8A%E3%83%BC%E3%80%81MCX%E5%85%A5%E5%8A%9B%E3%80%82%20%E5%A4%9A%E3%81%8F%E3%81%AESDR%E3%82%BD%E3%83%95%E3%83%88%E3%82%A6%E3%82%A7%E3%82%A2%E3%83%91%E3%83%83%E3%82%B1%E3%83%BC%E3%82%B8%E3%81%A8%E4%BA%92%E6%8F%9B%E6%80%A7%E3%81%AE%E3%81%82%E3%82%8B%E4%BD%8E%E3%82%B3%E3%82%B9%E3%83%88%E3%82%BD%E3%83%95%E3%83%88%E3%82%A6%E3%82%A7%E3%82%A2%E7%84%A1%E7%B7%9A%E6%A9%9F%E3%80%82%20R820T%E3%83%81%E3%83%A5%E3%83%BC%E3%83%8A\/","a_id":3038654,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":2}],"eid":"8T0PA","s":"s"});
</script>
<div id="msmaflink-8T0PA">リンク</div>
<!-- MoshimoAffiliateEasyLink END -->



<p>受信したデータを自動で処理したり、リアルタイムに表示したりといった処理を、小型で省電力なRaspberry Piだけで完結できるからです。</p>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>本記事で紹介したプログラムは、ChatGPTの力を借りながら作成しました。</p>
</div></div>



<p>初心者の方でも、AIを活用すれば比較的ハードルを感じずに取り組めると思います。</p>



<p>ADS-B受信機はほかにもいろいろな活用ができそうなので、試行錯誤を楽しんでいるところです。新しいものを作ったらまた紹介します。</p>



<h2 class="wp-block-heading">ドラゴンレーダー風ミニレーダーの作成</h2>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/IMG_9077.jpeg" alt="" class="wp-image-4" style="width:496px;height:auto"/></figure>



<p>飛行機レーダーのノウハウと手頃な円形ディスプレイがあれば、「あのドラゴンレーダー」を作ってみたくなるものです。</p>



<p>円形ディスプレイは<a href="https://www.switch-science.com/products/9027?srsltid=AfmBOoo1W1ysVXjDQQNc0XH-GR_97YopXnXRjNjTt5BqhrL31AldC4ko">1.28inch Touch LCD</a>を使用しました。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/pico-2-2.jpg" alt="" class="wp-image-4"/></figure>



<p>円形ディスプレイを収納するケースは3Dプリンターで作成。Thingiverseで公開されている<a href="https://www.thingiverse.com/thing:6637362">Radar Dragon Ball</a>をベースに、サイズやデザインを調整しています。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/スクリーンショット-2025-06-13-9.49.30.jpg" alt="" class="wp-image-4"/></figure>



<p>レーダーの背景となる画像はCanvaで作成しました。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/スクリーンショット-2025-06-13-9.41.07.png" alt="" class="wp-image-4"/></figure>



<p>レーダーを表示するだけではおもしろくないので、方位がわかる地磁気センサーを使ってみました。レーダー本体が向いている方向にあわせて画面が回るようにして、飛行機の位置が感覚的にわかるようにしました。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/IMG_9078.jpeg" alt="" class="wp-image-4"/><figcaption class="wp-element-caption">ケース内に搭載した地磁気センサー</figcaption></figure>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
import sys
import time
import math
import smbus2
import requests
import numpy as np
import cv2
from PIL import Image
sys.path.append(&quot;..&quot;)
from lib import LCD_1inch28

# ── QMC5883L 設定 ──
QMC5883L_ADDRESS = 0x0D
X_OFFSET    = -110.0
Y_OFFSET    = -587.5
X_SCALE     = 1.0234375
Y_SCALE     = 0.95
DECLINATION = -8.0
HEADING_OFFSET = 76.4

# ── 自宅座標とスケール ──
HOME_LAT = 35.6812
HOME_LON = 139.7671
SCALE = 250 #350
WIDTH = 240
HEIGHT = 240
CENTER_X = WIDTH // 2
CENTER_Y = HEIGHT // 2

# ── LCD 初期化 ──
disp = LCD_1inch28.LCD_1inch28()
disp.Init()
disp.clear()

# ── I2C 初期化 ──
bus = smbus2.SMBus(1)
bus.write_byte_data(QMC5883L_ADDRESS, 0x0B, 0x01)
time.sleep(0.1)
bus.write_byte_data(QMC5883L_ADDRESS, 0x09, 0x1D)
time.sleep(0.1)

# ── 方位取得 ──
def read_axis(reg_lsb):
    lsb = bus.read_byte_data(QMC5883L_ADDRESS, reg_lsb)
    msb = bus.read_byte_data(QMC5883L_ADDRESS, reg_lsb + 1)
    value = (msb &lt;&lt; 8) | lsb
    if value &gt;= 0x8000:
        value -= 0x10000
    return value

def get_heading():
    raw_x = read_axis(0x00)
    raw_y = read_axis(0x02)
    adj_x = (raw_x - X_OFFSET) * X_SCALE
    adj_y = (raw_y - Y_OFFSET) * Y_SCALE
    raw_heading = math.degrees(math.atan2(adj_y, adj_x))
    if raw_heading &lt; 0:
        raw_heading += 360.0
    heading = (raw_heading - HEADING_OFFSET + DECLINATION) % 360.0
    return heading

# ── 航空機データ取得 ──
def get_aircraft_positions():
    try:
        res = requests.get(&quot;http://192.168.1.46:8080/data/aircraft.json&quot;, timeout=1)
        return [a for a in res.json().get(&quot;aircraft&quot;, []) if &#39;lat&#39; in a and &#39;lon&#39; in a]
    except:
        return []

# ── 背景画像の読み込み ──
original = Image.open(&quot;dragon2.png&quot;).convert(&quot;RGB&quot;)
original = original.resize((240, 240))
original_cv = cv2.cvtColor(np.array(original), cv2.COLOR_RGB2BGR)

# ── メインループ ──
last_update = 0
aircraft_list = []

while True:
    # 背景画像をコピー（毎回初期化）
    frame = original_cv.copy()

    # 1秒ごとに航空機情報を更新
    if time.time() - last_update &gt; 2.0:
        aircraft_list = get_aircraft_positions()
        last_update = time.time()
    print(&quot;航空機数: {}&quot;.format(len(aircraft_list)))
    for a in aircraft_list:
        print(&quot;  LAT: {:.4f}, LON: {:.4f}&quot;.format(a[&#39;lat&#39;], a[&#39;lon&#39;]))        

    # 航空機を黄色い円で描画
    for a in aircraft_list:
        dx = (a[&#39;lon&#39;] - HOME_LON) * SCALE
        dy = (a[&#39;lat&#39;] - HOME_LAT) * SCALE
        x = int(CENTER_X + dx)
        y = int(CENTER_Y - dy)
        if 0 &lt;= x &lt; WIDTH and 0 &lt;= y &lt; HEIGHT:
            cv2.circle(frame, (x, y), 6, (0, 255, 255), -1)  # BGRで黄色

    # OpenCV → PIL に変換して回転
    image_pil = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
    # ── センサー読み取り ──
    raw_x = read_axis(0x00)
    raw_y = read_axis(0x02)
    raw_z = read_axis(0x04)

    adj_x = (raw_x - X_OFFSET) * X_SCALE
    adj_y = (raw_y - Y_OFFSET) * Y_SCALE

    raw_heading = math.degrees(math.atan2(adj_y, adj_x))
    if raw_heading &lt; 0:
        raw_heading += 360.0

    heading = raw_heading - HEADING_OFFSET + DECLINATION
    heading %= 360.0

    # ── デバッグ表示 ──
    #print(&quot;raw_x = {:6d}, raw_y = {:6d}, heading = {:.2f}°&quot;.format(raw_x, raw_y, heading))
    rotated = image_pil.rotate(heading, expand=True)

    # 黒背景に中央配置
    background = Image.new(&quot;RGB&quot;, (240, 240), (0, 0, 0))
    x_offset = (240 - rotated.width) // 2
    y_offset = (240 - rotated.height) // 2
    background.paste(rotated, (x_offset, y_offset))

    # LCDに表示
    disp.ShowImage(background)

    time.sleep(0.3)
</code></pre></div>



<p>今回は本記事の前半で紹介したRaspberry Pi Zero 2 Wから、ネットワーク経由で航空機データを取得しています。「http://192.168.1.46:8080/data/aircraft.json」のようにZero 2 WのIPアドレスを指定することで、周囲を飛行中の航空機の情報（緯度・経度など）を含むデータを取得できます。</p>



<p>取得した情報をもとに、ディスプレイ上に航空機の位置をプロットします。さらに、内蔵の地磁気センサー（QMC5883L）で取得した方位に応じて画面を回転させることで、レーダーの向いている方向に合わせた直感的な表示を実現します。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/IMG_9093.jpeg" alt="" class="wp-image-4"/></figure>



<h2 class="wp-block-heading">くるくる進行方向表示装置</h2>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/IMG_9332.jpeg" alt="" class="wp-image-4"/></figure>



<p>これまではディスプレイを使い航空機の情報を可視化してきましたが、今回はその手法を変え、動きで示す装置を作りました。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/IMG_9326.jpeg" alt="" class="wp-image-4" style="width:840px;height:auto"/><figcaption class="wp-element-caption">受信待ちしている状態</figcaption></figure>



<p>この装置は最も近くを飛んでいる航空機の進行方向をリアルタイムで取得し、模型の飛行機をその方向に回転させます。便名や距離はLCDに表示され、動く模型とテキスト情報が重なることで、空で起きていることをよりリアルに感じ取ることが可能です。画面を見るだけでは味わえなかった臨場感が、そこに生まれます。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/IMG_9337.jpeg" alt="" class="wp-image-4"/></figure>



<p>今回の装置はRaspberry Pi Pico 2 Wを使用しました。ADS-B受信機を接続したRaspberry PiからWi-Fi経由で航空機のデータを取得する仕組みです。LCDは、本記事の前半でも紹介したI2C接続の16文字2行キャラクタLCD（LCD1602）を使用しています。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/image-2.png" alt="" class="wp-image-4"/><figcaption class="wp-element-caption">各パーツの接続</figcaption></figure>



<p>回転の制御には<a href="https://akizukidenshi.com/catalog/g/g108761/">SG90</a>というサーボモーターを使用しています。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/IMG_9338.jpeg" alt="" class="wp-image-4"/></figure>



<p>本来であれば180°しか回転できないこのモーターにギヤを組み合わせることで、模型が360度回転できるように工夫しました。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/IMG_9322.jpeg" alt="" class="wp-image-4"/></figure>



<p>各パーツを収納する筐体やギヤの部分は、3Dプリンターで作成しています。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/IMG_9303.jpeg" alt="" class="wp-image-4"/><figcaption class="wp-element-caption">装置の内部</figcaption></figure>



<p>起動後、Raspberry Pi Pico 2 WはWi-Fiに接続し、ローカルネットワーク内のRaspberry PiからADS-Bデータを定期的に取得します。その中から最も近い航空機を特定し、自宅からの相対位置と進行方向を計算します。取得した便名と距離はLCDに表示され、進行方向に応じてサーボモーターが駆動します。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/Videotogif-2.gif" alt="" class="wp-image-4"/></figure>



<p><br>進行方向のデータ（0〜360度）は、南を基準に±90度の範囲へ変換します。これはサーボモーターの可動範囲に収めるためです。そのうえで、サーボの出力をギヤで拡大し、模型が1回転できるようにしました。</p>



<h2 class="wp-block-heading">空港の案内表示風画面を作成</h2>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/IMG_9858-1.jpeg" alt="" class="wp-image-4" style="width:447px;height:auto"/></figure>



<p>自宅の上空を飛ぶ航空機の情報を、空港の案内板のように表示してみました。使用したディスプレイは、Raspberry Pi公式 <a href="https://sozorablog.com/touch-display-2/">Touch Display 2</a>（5インチ）です。このプロジェクトでは、航空会社のロゴとともに3便分の「便名」「到着地」「到着時刻」を表示します。</p>



<p>記事の前半部分で紹介しているADS-B受信機のデータには、到着地や到着予定時刻は含まれていません。そこで、それらを補うために <strong>「AeroDataBox API」</strong> を使います。</p>



<p>実現したいことは次の通りです。</p>



<div class="wp-block-sbd-list"><ul class="sbd-list sbd-list-border"><li>ADS-B受信機からリアルタイムの航空機位置情報を取得</li><li><strong>AeroDataBox API</strong> で便名から到着地と到着予定時刻を取得</li><li>航空会社のロゴとともに3便分表示</li></ul></div>



<div class="wp-block-sbd-checkpoint-block"><p class="sbd-checkpoint-title">チェックポイント</p><div class="sbd-checkpoint-content sbd-inner-block-init"><p>AeroDataBoxの無料プランでは、月あたり最大 1,000回までリクエスト可能という制限があります。そのため、短い間隔で何度もデータを取得するような「常時更新」には向いていません。</p></div></div>



<h3 class="wp-block-heading">AeroDataBox APIを使用</h3>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/IMG_9859.jpeg" alt="" class="wp-image-4"/></figure>



<p>AeroDataBox API は、便名を指定するだけでフライト情報を取得できる便利なAPIです。このAPIは、RapidAPIというAPIマーケットプレイスで提供されています。利用するには次の手順でAPIキーを取得します。</p>



<p><a href="https://rapidapi.com/">RapidAPI公式サイト</a> にアクセスして無料アカウントを作成します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/pico-31.jpg" alt="" class="wp-image-4" style="width:691px;height:auto"/></figure>



<p>「AeroDataBox」で検索し、APIページを開きます。</p>



<p>「Subscribe to Test」を選択します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/pico-30.png" alt="" class="wp-image-4" style="width:679px;height:auto"/></figure>



<p>Basic（無料）プランを選択します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/pico-30-1.png" alt="" class="wp-image-4" style="width:358px;height:auto"/></figure>



<p>表示された <strong>X-RapidAPI-Key</strong> が、コードで使用するAPIキーです。</p>



<h3 class="wp-block-heading">完成したコード</h3>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/IMG_9856.jpeg" alt="" class="wp-image-4"/></figure>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>import requests
import math
from datetime import datetime
from PIL import Image, ImageDraw, ImageFont
from io import BytesIO
import cv2
import numpy as np
import re

# ===============================
# 設定
# ===============================

# 自宅の緯度経度に変更してください（以下は東京駅周辺）
HOME_LAT = 35.6812
HOME_LON = 139.7671

# RapidAPI（AeroDataBox）キー
RAPIDAPI_KEY = &quot;RapidAPIキーを入力してください&quot;

# dump1090-fa のローカルURL
DUMP1090_URL = &quot;http://localhost:8080/data/aircraft.json&quot;

# ===============================
# 航空機データ取得関数
# ===============================
def get_aircraft_positions_dump1090():
    &quot;&quot;&quot;dump1090-fa から航空機位置データを取得&quot;&quot;&quot;
    try:
        res = requests.get(DUMP1090_URL, timeout=1)
        data = res.json()
        return [a for a in data.get(&quot;aircraft&quot;, []) if &#39;lat&#39; in a and &#39;lon&#39; in a]
    except:
        return []

# ===============================
# 距離計算
# ===============================

def haversine(lat1, lon1, lat2, lon2):
    &quot;&quot;&quot;2点間の距離（km）をハーサイン式で計算&quot;&quot;&quot;
    R = 6371.0
    dlat = math.radians(lat2 - lat1)
    dlon = math.radians(lon2 - lon1)
    a = math.sin(dlat / 2)**2 + math.cos(math.radians(lat1)) * math.cos(math.radians(lat2)) * math.sin(dlon / 2)**2
    return R * 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))

# ===============================
# AeroDataBox から便情報取得
# ===============================

def get_flight_info(flight_number):
    &quot;&quot;&quot;便名から到着地と到着時刻を取得&quot;&quot;&quot;
    date = datetime.today().strftime(&#39;%Y-%m-%d&#39;)
    url = f&quot;https://aerodatabox.p.rapidapi.com/flights/number/{flight_number}/{date}&quot;
    headers = {
        &quot;X-RapidAPI-Key&quot;: RAPIDAPI_KEY,
        &quot;X-RapidAPI-Host&quot;: &quot;aerodatabox.p.rapidapi.com&quot;
    }
    try:
        res = requests.get(url, headers=headers, timeout=3)
        data = res.json()
        if isinstance(data, list) and data:
            f = data[0]
            flight = f[&#39;number&#39;]
            airport = f[&#39;arrival&#39;][&#39;airport&#39;][&#39;name&#39;]
            time_str = f[&#39;arrival&#39;][&#39;scheduledTime&#39;][&#39;local&#39;]
            arrival_time = datetime.fromisoformat(time_str).strftime(&#39;%H:%M&#39;)
            return flight, airport, arrival_time
    except:
        pass
    return None, None, None

# ===============================
# メイン処理
# ===============================

# 航空機データを取得
aircraft_list = get_aircraft_positions_dump1090()

if not aircraft_list:
    print(&quot;航空機が見つかりませんでした。&quot;)
    exit()

# ===============================
# 距離順にソートして3機選択
# ===============================

for a in aircraft_list:
     # 各航空機について、自宅（HOME_LAT, HOME_LON）からの距離を計算して追加
    a[&quot;distance&quot;] = haversine(HOME_LAT, HOME_LON, a[&quot;lat&quot;], a[&quot;lon&quot;])
    
# 距離（&quot;distance&quot;）の値を基準に昇順ソート（最も近い機体が先頭に来る）
aircraft_list.sort(key=lambda x: x[&quot;distance&quot;])
# 最も近い3機だけを抽出
closest_aircrafts = aircraft_list[:3]

# ===============================
# 表示処理（3機を縦に並べて描画）
# ===============================

icao_to_iata = {
    &quot;ANA&quot;: &quot;NH&quot;, &quot;JAL&quot;: &quot;JL&quot;, &quot;ADO&quot;: &quot;HD&quot;, &quot;SNA&quot;: &quot;7G&quot;, &quot;SKY&quot;: &quot;BC&quot;,
    &quot;APJ&quot;: &quot;MM&quot;, &quot;FDA&quot;: &quot;JH&quot;, &quot;CPA&quot;: &quot;CX&quot;, &quot;UAE&quot;: &quot;EK&quot;, &quot;THA&quot;: &quot;TG&quot;,
    &quot;MAS&quot;: &quot;MH&quot;, &quot;CES&quot;: &quot;MU&quot;, &quot;CSN&quot;: &quot;CZ&quot;, &quot;CCA&quot;: &quot;CA&quot;, &quot;PAL&quot;: &quot;PR&quot;,
    &quot;TGW&quot;: &quot;TR&quot;, &quot;SIA&quot;: &quot;SQ&quot;, &quot;JST&quot;: &quot;JQ&quot;, &quot;JJP&quot;: &quot;GK&quot;, &quot;TNA&quot;: &quot;9C&quot;,
    &quot;BAW&quot;: &quot;BA&quot;, &quot;AAL&quot;: &quot;AA&quot;, &quot;UAL&quot;: &quot;UA&quot;, &quot;DAL&quot;: &quot;DL&quot;, &quot;KLM&quot;: &quot;KL&quot;,
    &quot;AFR&quot;: &quot;AF&quot;, &quot;DLH&quot;: &quot;LH&quot;, &quot;QFA&quot;: &quot;QF&quot;,
}

base = Image.new(&quot;RGB&quot;, (1280, 720), (0, 0, 80))
draw = ImageDraw.Draw(base)
font_path = &quot;/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf&quot;
font = ImageFont.truetype(font_path, 60)

y_base = 60          # 1段目（最初の航空機情報）の描画開始位置（上から60pxの位置）
block_height = 220   # 各段の高さ（1つの航空機情報を描く縦スペース）

# ==== 近い3機を順に処理して、便情報を取得 ====
for idx, ac in enumerate(closest_aircrafts):
    # 航空機の便名（flight）を取得。空白やNoneの場合は空文字に置き換え
    ident = ac.get(&quot;flight&quot;, &quot;&quot;).strip()
    
    # 便名が空、または先頭が英字でない（例: 数字のみや不正データ）の場合はスキップ
    if not ident or not ident[0].isalpha():
        continue
    
    # AeroDataBox APIを使って、便名から到着地と到着時刻を取得
    flight, airport, arrival_time = get_flight_info(ident)
    if not all([flight, airport, arrival_time]):
        continue
    
    print(f&quot;[{idx}] 便名: {flight}&quot;)
    print(f&quot;    距離: {ac[&#39;distance&#39;]:.1f} km&quot;)
    print(f&quot;    到着地: {airport}&quot;)
    print(f&quot;    到着時刻: {arrival_time}&quot;)
    print()
    
    # 便名の先頭3文字を抽出（例: &quot;JAL124&quot; → &quot;JAL&quot;）
    airline_code = flight.strip()[:3].upper()
    
    # ICAOコード（3文字）をIATAコード（2文字）に変換
    # 変換できない場合は、先頭2文字をそのまま使う    
    iata = icao_to_iata.get(airline_code, airline_code[:2])
    
     # 便名から数字部分だけを抽出（例: &quot;JAL124&quot; → &quot;124&quot;）
    flight_number = &#39;&#39;.join(re.findall(r&#39;\d+&#39;, flight))
    
    # 到着地の文字列を最大9文字までに制限（長すぎる地名対策）
    destination = airport[:9]

    # ==== 航空会社ロゴの取得 ====
    # Daisycon APIを利用して、航空会社のロゴ画像を取得
    # IATAコードを使ってURLを生成（白色ロゴ・横幅300px）
    if iata == &quot;BC&quot;:
        # スカイマーク（IATA: BC）は正しいロゴが取得できないため、例外的に Airhex（https://content.airhex.com/）のロゴを使用
        url = &quot;https://content.airhex.com/content/logos/airlines_BC_300_100_s.png&quot;
    else:
        # それ以外の航空会社は Daisycon から白色ロゴを取得
        url = f&quot;https://images.daisycon.io/airline/?width=300&height=95&color=ffffff&iata={iata}&quot;
        
    img_data = requests.get(url, timeout=5).content# 画像データをダウンロード（バイナリとして取得）
    logo = Image.open(BytesIO(img_data)).convert(&quot;RGBA&quot;)# 取得したロゴをRGBA形式（透過対応）で読み込み
    white_bg = Image.new(&quot;RGBA&quot;, logo.size, (255,255,255,255))# 白背景を作成（透過部分を白に塗りつぶすため）
    logo_with_white = Image.alpha_composite(white_bg, logo)# 白背景とロゴを合成（透過部分が白になる）
    logo_w, logo_h = logo_with_white.size# ロゴ画像の幅と高さを取得（後で配置位置を計算するため）

    # 配置位置
    y_offset = y_base + idx * block_height
    base.paste(logo_with_white.convert(&quot;RGB&quot;), (40, y_offset), mask=logo_with_white.split()[3])

    # テキスト描画
    text_start_x = 360  # テキストの描画開始位置（左からのオフセット）
    # 便名（数字部分）を描画
    draw.text((text_start_x, y_offset+10), flight_number, fill=(255,255,255), font=font)
    # 到着地（空港名）を描画
    draw.text((text_start_x+190, y_offset+10), destination, fill=(255,255,255), font=font)
    # 到着予定時刻を描画
    draw.text((text_start_x+630, y_offset+10), arrival_time, fill=(255,255,255), font=font)

# ===============================
# OpenCVで全画面表示
# ===============================

cv2.namedWindow(&quot;Flight Info&quot;, cv2.WINDOW_NORMAL)
cv2.setWindowProperty(&quot;Flight Info&quot;, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
img_cv = cv2.cvtColor(np.array(base), cv2.COLOR_RGB2BGR)
cv2.imshow(&quot;Flight Info&quot;, img_cv)

while True:
    if cv2.waitKey(10) == 27:
        break
cv2.destroyAllWindows()


</code></pre></div>



<p><code>dump1090-fa</code> のJSONデータを取得し、自宅位置（<code>HOME_LAT</code>, <code>HOME_LON</code>）からの距離を計算し、<span class="sbd-text-bg-yellow">距離が近い3機</span>を選んで表示対象にします。取得した便名を使って <strong>AeroDataBox API</strong> に問い合わせ、「到着地」と「到着予定時刻」を取得します。</p>



<p>航空会社名はシステムによって呼び方が異なります。dump1090-fa では「ANA」「JAL」などの <strong>ICAOコード（3文字）</strong>を返しますが、航空会社ロゴを提供するAPIは「NH」「JL」などの <strong>IATAコード（2文字）</strong>で指定する必要があります。そのため、<code>icao_to_iata</code> という対応表を用意して、コードを変換しています。</p>



<p>ロゴ画像は主に<a href="https://www.daisycon.com/en/developers/productfeeds/product-images/airline-logos/">Daisycon</a><strong>（</strong>航空会社ロゴを無料で提供するAPI<strong>）</strong>から取得しますが、スカイマーク（BC）など<span class="sbd-text-red">一部の航空会社は正しいロゴが取得できない</span>ため、代わりに航空会社ロゴデータベース の<a href="https://www.airhex.com/">Airhex</a>から取得したロゴを使用しています。</p>



<p>最後に<code>cv2.namedWindow</code> と <code>setWindowProperty</code> でウィンドウを全画面モードにし、<code>imshow</code> で描いた画像を表示します。空港の案内板のように見せるために全画面にしていますが、操作できなくなると困るので、<span class="sbd-text-bg-yellow">Escキーを押すと終了できる</span>ようにしています。</p>



<h2 class="wp-block-heading">戦闘機のHUD風に表示</h2>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/IMG_9943.jpeg" alt="" class="wp-image-4" style="width:507px;height:auto"/></figure>



<p>戦闘機のHUD（ヘッドアップディスプレイ）のように、空の映像上に航空機情報を重ねてリアルな飛行感覚を再現しました。今回使用したのは、<a href="https://www.switch-science.com/products/9032">4インチ円形タッチスクリーンディスプレイ</a>です。ディスプレイ裏側に<a href="https://sozorablog.com/raspberry-pi-4-revue/">Raspberry Pi ４</a>を取り付けています。</p>



<p>実際に戦闘機を操縦しているような臨場感を演出するために、コックピットから撮影された空の動画を背景に使用します。動画は<a href="https://pixabay.com/ja/videos/%e7%a9%8d%e9%9b%b2-%e3%82%b3%e3%83%83%e3%82%af%e3%83%94%e3%83%83%e3%83%88-%e8%88%aa%e7%a9%ba-47338/">Pixabay</a>からダウンロードしました。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/スクリーンショット-2025-11-01-16.03.41.jpg" alt="" class="wp-image-4"/><figcaption class="wp-element-caption">出典：<a href="https://pixabay.com/ja/videos/%e7%a9%8d%e9%9b%b2-%e3%82%b3%e3%83%83%e3%82%af%e3%83%94%e3%83%83%e3%83%88-%e8%88%aa%e7%a9%ba-47338/">Pixabay</a></figcaption></figure>



<p>動画のサイズは1280×720を選択しています。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/スクリーンショット-2025-11-01-5.00.43.png" alt="" class="wp-image-4"/></figure>



<p>動画ファイルは、/home/piに「cockpit_view.mp4」という名称で保存します。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/スクリーンショット-2025-11-01-5.03.29.png" alt="" class="wp-image-4"/></figure>



<p>以下のプログラムは空の映像に、実際の航空機データを重ね合わせて戦闘機風に表示するものです。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>import cv2
import numpy as np
from datetime import datetime
import requests
import math
import time

# 自宅の緯度・経度（東京駅周辺など）
HOME_LAT = 35.681236
HOME_LON = 139.767125

# データ取得関数
def get_aircraft_positions():
    try:
        res = requests.get(&quot;http://192.168.1.46:8080/data/aircraft.json&quot;, timeout=1)
        return res.json().get(&quot;aircraft&quot;, [])
    except Exception as e:
        print(&quot;データ取得エラー:&quot;, e)
        return []
    
# 緯度経度から距離(km)を求める関数（簡易版・近距離用）
def calc_distance(lat1, lon1, lat2, lon2):
    R = 6371  # 地球の半径(km)
    dlat = math.radians(lat2 - lat1)
    dlon = math.radians(lon2 - lon1)
    a = math.sin(dlat / 2)**2 + math.cos(math.radians(lat1)) * math.cos(math.radians(lat2)) * math.sin(dlon / 2)**2
    c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
    return R * c

# HUD風オーバーレイ描画
def draw_target_overlay(img, offset_x=0, offset_y=0):
    &quot;&quot;&quot;中央ターゲットや計器枠などのHUD風描画（元の形状そのまま＋オフセット対応）&quot;&quot;&quot;
    scale = img.shape[0] / 128
    def s(x): return int(x * scale)

    ox = int(offset_x)
    oy = int(offset_y)

    # 中央座標
    center_x = img.shape[1] // 2 + ox
    center_y = img.shape[0] // 2 + oy

    # 中央円
    cv2.circle(img, (center_x, center_y), s(18), (0, 255, 0), 2)
    cv2.circle(img, (center_x, center_y), s(1), (0, 255, 0), -1)

    # 十字補助線
    cv2.line(img, (s(42) + ox, center_y), (s(50) + ox, center_y), (0, 255, 0), 2)
    cv2.line(img, (s(78) + ox, center_y), (s(86) + ox, center_y), (0, 255, 0), 2)
    cv2.line(img, (center_x, s(42) + oy), (center_x, s(50) + oy), (0, 255, 0), 2)
    cv2.line(img, (center_x, s(78) + oy), (center_x, s(86) + oy), (0, 255, 0), 2)

    cv2.line(img, (s(56) + ox, center_y), (s(60) + ox, center_y), (0, 255, 0), 2)
    cv2.line(img, (s(68) + ox, center_y), (s(72) + ox, center_y), (0, 255, 0), 2)
    cv2.line(img, (center_x, s(56) + oy), (center_x, s(60) + oy), (0, 255, 0), 2)
    cv2.line(img, (center_x, s(68) + oy), (center_x, s(72) + oy), (0, 255, 0), 2)

    # 左側グラフ
    cv2.line(img, (83 + ox, s(60) + oy), (83 + ox, s(92) + oy), (0, 255, 0), 2)
    cv2.line(img, (83 + ox, s(60) + oy), (99 + ox, s(60) + oy), (0, 255, 0), 2)
    cv2.line(img, (83 + ox, s(68) + oy), (93 + ox, s(68) + oy), (0, 255, 0), 2)
    cv2.line(img, (83 + ox, s(76) + oy), (99 + ox, s(76) + oy), (0, 255, 0), 2)
    cv2.line(img, (83 + ox, s(84) + oy), (93 + ox, s(84) + oy), (0, 255, 0), 2)
    cv2.line(img, (83 + ox, s(92) + oy), (99 + ox, s(92) + oy), (0, 255, 0), 2)

    # 右側グラフ
    cv2.line(img, (613 + ox, s(30) + oy), (613 + ox, s(92) + oy), (0, 255, 0), 2)
    cv2.line(img, (595 + ox, s(30) + oy), (628 + ox, s(30) + oy), (0, 255, 0), 2)
    cv2.line(img, (613 + ox, s(36) + oy), (623 + ox, s(36) + oy), (0, 255, 0), 2)
    cv2.line(img, (613 + ox, s(43) + oy), (623 + ox, s(43) + oy), (0, 255, 0), 2)
    cv2.line(img, (613 + ox, s(50) + oy), (628 + ox, s(50) + oy), (0, 255, 0), 2)
    cv2.line(img, (613 + ox, s(56) + oy), (623 + ox, s(56) + oy), (0, 255, 0), 2)
    cv2.line(img, (613 + ox, s(63) + oy), (623 + ox, s(63) + oy), (0, 255, 0), 2)
    cv2.line(img, (613 + ox, s(71) + oy), (628 + ox, s(71) + oy), (0, 255, 0), 2)
    cv2.line(img, (613 + ox, s(77) + oy), (623 + ox, s(77) + oy), (0, 255, 0), 2)
    cv2.line(img, (613 + ox, s(84) + oy), (623 + ox, s(84) + oy), (0, 255, 0), 2)
    cv2.line(img, (595 + ox, s(92) + oy), (628 + ox, s(92) + oy), (0, 255, 0), 2)

    # 半円ゲージ
    cv2.ellipse(
        img,
        (center_x, s(122) + oy),
        (s(20), s(20)),
        0, 180, 360,
        (0, 255, 0),
        2
    )
    cv2.line(img, (center_x, s(102) + oy), (center_x, s(105) + oy), (0, 255, 0), 2)
    cv2.line(img, (s(44) + ox, s(122) + oy), (s(46) + ox, s(122) + oy), (0, 255, 0), 2)
    cv2.line(img, (s(82) + ox, s(122) + oy), (s(84) + ox, s(122) + oy), (0, 255, 0), 2)

    # 半円ゲージの目盛り
    cv2.line(img, (300 + ox, 592 + oy), (305 + ox, 600 + oy), (0, 255, 0), 2)
    cv2.line(img, (259 + ox, 640 + oy), (268 + ox, 645 + oy), (0, 255, 0), 2)
    cv2.line(img, (417 + ox, 600 + oy), (422 + ox, 592 + oy), (0, 255, 0), 2)
    cv2.line(img, (453 + ox, 645 + oy), (462 + ox, 640 + oy), (0, 255, 0), 2)

    return img

# =============================
# メイン処理ループ
# =============================
cap = cv2.VideoCapture(&quot;cockpit_view.mp4&quot;)
if not cap.isOpened():
    print(&quot;動画ファイルを開けませんでした。&quot;)
    exit()

cv2.namedWindow(&quot;Square View&quot;, cv2.WINDOW_NORMAL)
cv2.resizeWindow(&quot;Square View&quot;, 720, 720)
cv2.setWindowProperty(&quot;Square View&quot;, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)

# 総フレーム数を取得
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
skip_point = int(total_frames * 0.85)  # 後半1/4の開始フレーム

# 前回のデータ取得時刻を記録
last_fetch = 0

while True:
    ret, frame = cap.read()
    if not ret:
        cap.set(cv2.CAP_PROP_POS_FRAMES, 0)
        continue
    
    # 8枚スキップして再生を速くする
    for _ in range(8):
        cap.grab()    
    
    # --- 2秒に1回だけAPIを呼ぶ ---
    now = time.time()
    if now - last_fetch &gt;= 2.0:
        aircraft_data = get_aircraft_positions()
        last_fetch = now  # 時刻を更新
        
        # 有効な座標を持つ航空機だけを抽出
        valid = [a for a in aircraft_data if &#39;lat&#39; in a and &#39;lon&#39; in a]

        if not valid:
            print(&quot;有効なデータがありません。&quot;)
            ident = &quot;No aircraft&quot;
            alt_m = 0
            hdg = 0
            dist = 0
            spd_kmh = 0
        else:
            # それぞれの機体との距離を計算
            for a in valid:
                a[&quot;distance_km&quot;] = calc_distance(HOME_LAT, HOME_LON, a[&quot;lat&quot;], a[&quot;lon&quot;])

            # 最も近い機体を選択
            nearest = min(valid, key=lambda a: a[&quot;distance_km&quot;])

            ident = nearest.get(&quot;flight&quot;, &quot;Unknown&quot;)
            alt_ft = nearest.get(&quot;alt_baro&quot;, &quot;N/A&quot;)
            spd_kt = nearest.get(&quot;gs&quot;, &quot;N/A&quot;)
            hdg = nearest.get(&quot;track&quot;, &quot;0&quot;)
            dist = nearest.get(&quot;distance_km&quot;, 0)
            
            # フィート→メートル換算
            if isinstance(alt_ft, (int, float)):
                alt_m = alt_ft * 0.3048
            else:
                alt_m = 0
                
            # ノット→km/h換算
            spd_kmh = spd_kt * 1.852 if isinstance(spd_kt, (int, float)) else 0            

            print(f&quot;最も近い航空機:&quot;)
            print(f&quot;Ident: {ident}&quot;)
            print(f&quot;Altitude: {alt_ft} ft ({alt_m:.0f} m)&quot;)
            print(f&quot;Speed: {spd_kt} kt ({spd_kmh:.0f} km/h)&quot;)
            print(f&quot;Heading: {hdg}&quot;)
            print(f&quot;Distance: {dist:.1f} km&quot;)        
    
    # 現在のフレーム番号を取得
    current_frame = int(cap.get(cv2.CAP_PROP_POS_FRAMES))  

    # --- 後半1/4に到達したら最初に戻す ---
    if current_frame &gt;= skip_point:
        cap.set(cv2.CAP_PROP_POS_FRAMES, 0)
        continue    

    height, width, _ = frame.shape
    frame = frame[:int(height * 0.6), int(width * 0.35):]
    square_size = frame.shape[0]
    frame = frame[:, :square_size]
    frame_resized = cv2.resize(frame, (720, 720), interpolation=cv2.INTER_AREA)
    
    # --- 少し黒っぽく（明るさを下げる）処理 ---
    dark_factor = 0.5  # 0.7で少し暗め（0.5ならもっと黒っぽい）
    frame_resized = (frame_resized * dark_factor).astype(np.uint8)        

    # --- 図形を描画（オフセット指定可能）---
    frame_resized = draw_target_overlay(frame_resized)
    
    # --- HUDテキスト描画 ---
    font = cv2.FONT_HERSHEY_SIMPLEX
    color = (0, 255, 0)
    aa = cv2.LINE_AA

    cv2.putText(frame_resized, ident, (80, 170), font, 1.5, color, 2, aa)
    cv2.putText(frame_resized, &#39;ALTITUDE&#39;, (80, 250), font, 0.7, color, 2, aa)
    cv2.putText(frame_resized, f&quot;{alt_m:.0f}&quot;, (80, 290), font, 1.2, color, 2, aa)

    cv2.putText(frame_resized, &#39;RANGE&#39;, (499, 195), font, 0.7, color, 2, aa)
    cv2.putText(frame_resized, f&quot;{dist:.1f}&quot;, (499, 230), font, 1.2, color, 2, aa)

    cv2.putText(frame_resized, &#39;HEADING&#39;, (469, 495), font, 0.7, color, 2, aa)
    cv2.putText(frame_resized, str(int(hdg)), (470, 540), font, 1.5, color, 2, aa)

    cv2.putText(frame_resized, &#39;SPEED&#39;, (325, 645), font, 0.7, color, 2, aa)
    cv2.putText(frame_resized, str(int(spd_kmh)), (315, 690), font, 1.5, color, 2, aa)

    cv2.putText(frame_resized, &#39;-0&#39;, (40, 433), font, 0.8, color, 2, aa)
    cv2.putText(frame_resized, &#39;3800&#39;, (635, 290), font, 0.6, color, 1, aa)
    cv2.putText(frame_resized, &#39;4000&#39;, (635, 407), font, 0.6, color, 1, aa)
    cv2.putText(frame_resized, &#39;46&#39;, (348, 605), font, 0.6, color, 1, aa)
    cv2.putText(frame_resized, &#39;10&#39;, (258, 690), font, 0.6, color, 1, aa)

    cv2.imshow(&quot;Square View&quot;, frame_resized)
    if cv2.waitKey(1) == 27:
        break

cap.release()
cv2.destroyAllWindows()

</code></pre></div>



<p>今回は本記事の前半で紹介したRaspberry Pi Zero 2 Wから、ネットワーク経由で航空機データを取得しています。「http://192.168.1.46:8080/data/aircraft.json」のようにZero 2 WのIPアドレスを指定することで、周囲を飛行中の航空機の情報（緯度・経度など）を含むデータを取得できます。</p>



<p>プログラムは、ADS-B受信機などから航空機データを定期的に取得し、最も近い機体の便名、高度、速度、方位、距離を算出して画面に表示します。映像上には中央ターゲットや半円ゲージなどが緑色で描かれ、戦闘機のHUDのような雰囲気を再現しています。</p>



<p>動画再生時に8枚のフレームをスキップし、より戦闘機らしいスピード感を演出しています。映像は少し暗く調整し、重ねた緑色のデータが際立って見えるよう工夫しました。</p>



<h2 class="wp-block-heading">GPSモジュールで緯度・経度を取得</h2>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/05/IMG_0721.jpeg" alt="" style="width:450px;height:auto"/><figcaption class="wp-element-caption">車載も可能</figcaption></figure>



<p>GPSモジュールを使えば、緯度・経度を自動で取得できます。あらかじめ設定した座標を使う方法と違い、設置場所が変わっても現在位置をそのまま反映できるため、より実用的な表示が可能です。</p>



<p>今回使用する<strong><a href="https://electronicwork.shop/items/69bb8f24ea2af023b7c4dcaf?srsltid=AfmBOopbuqSxRQoW4GcFqsHuqpRh8SVM-W_oIYcuM1_EbPAt2TTO_r08">ATGM336H</a></strong>は、電子工作で定番の安価なGPSモジュールです。上空にある複数のGPS衛星からの電波を受信し、現在地の「緯度・経度・高度」および「正確な時刻」を計算します。データは「UART（シリアル通信）」という形式で出力されるため、Raspberry Piで簡単に受け取ることができます。</p>



<h3 class="wp-block-heading">配線</h3>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="790" src="https://sozorablog.com/wp-content/uploads/2025/05/pico-7.jpg" alt="" class="wp-image-16661" style="aspect-ratio:1.0126754572522332;width:311px;height:auto"/></figure>



<p>Raspberry PiとATGM336Hは、以下のように接続します。</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>ATGM336H</th><th>Raspberry Pi</th></tr></thead><tbody><tr><td>VCC</td><td>5V</td></tr><tr><td>GND</td><td>GND</td></tr><tr><td>TX</td><td>RX（GPIO15 / ピン10）</td></tr><tr><td>RX</td><td>TX（GPIO14 / ピン8）</td></tr></tbody></table></figure>



<p>電源はVCCを5V、GNDをGNDに接続します。通信はシリアル通信を使うため、GPSのTXをRaspberry PiのRX（GPIO15 / ピン10）、GPSのRXをRaspberry PiのTX（GPIO14 / ピン8）に交差して接続します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="627" src="https://sozorablog.com/wp-content/uploads/2025/05/IMG_0677.jpeg" alt="" class="wp-image-16673" style="width:537px;height:auto"/></figure>



<h3 class="wp-block-heading">UARTを有効にする</h3>



<p>ターミナルで以下のコマンドを入力します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sudo raspi-config</code></pre></div>



<p>矢印キーで <strong><code>3 Interface Options</code></strong>を選択して <code>Enter</code> を押します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="353" src="https://sozorablog.com/wp-content/uploads/2025/05/スクリーンショット-2026-04-03-11.15.39.jpg" alt="" class="wp-image-16613" style="aspect-ratio:2.266340177057826;width:510px;height:auto"/></figure>



<p>矢印キーで <strong><code>3 Interface Options</code></strong>を選択して <code>Enter</code> を押します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="361" src="https://sozorablog.com/wp-content/uploads/2025/05/スクリーンショット-2026-04-03-11.16.33.jpg" alt="" class="wp-image-16614" style="width:474px;height:auto"/></figure>



<p>&#8220;Would you like a login shell to be accessible over serial?&#8221;で<strong>いいえ (No)</strong> を選択します。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="475" height="315" src="https://sozorablog.com/wp-content/uploads/2025/05/スクリーンショット-2026-04-10-19.54.12.png" alt="" class="wp-image-16666"/></figure>



<p>&#8220;Would you like the serial port hardware to be enabled?&#8221;で<strong>はい (Yes)</strong> を選択します。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="464" height="306" src="https://sozorablog.com/wp-content/uploads/2025/05/スクリーンショット-2026-04-10-19.55.01.png" alt="" class="wp-image-16667"/></figure>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="357" src="https://sozorablog.com/wp-content/uploads/2025/05/スクリーンショット-2026-04-03-11.20.31.jpg" alt="" class="wp-image-16617" style="width:509px;height:auto"/></figure>



<p><strong><code>&lt;Finish&gt;</code></strong> を選択します。<code>Would you like to reboot now?</code> と聞かれたら <strong><code>&lt;Yes&gt;</code></strong> を選択して再起動してください。</p>



<h3 class="wp-block-heading">テストコード</h3>



<p>以下のコードは、<strong>GPSモジュールから送られてくる位置情報を読み取って、読みやすい形式に変換するプログラム</strong>です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>import serial
import time

ser = serial.Serial(&quot;/dev/serial0&quot;, 9600, timeout=1)

def convert_to_decimal(raw, direction):
    if raw == &quot;&quot;:
        return None

    if direction in [&quot;N&quot;, &quot;S&quot;]:
        deg = int(raw[:2])
        minutes = float(raw[2:])
    else:
        deg = int(raw[:3])
        minutes = float(raw[3:])

    value = deg + minutes / 60

    if direction in [&quot;S&quot;, &quot;W&quot;]:
        value *= -1

    return value

def convert_time(utc_str):
    if utc_str == &quot;&quot;:
        return None

    hh = int(utc_str[0:2])
    mm = int(utc_str[2:4])
    ss = int(utc_str[4:6])

    hh = (hh + 9) % 24
    return f&quot;{hh:02}:{mm:02}:{ss:02}&quot;

while True:
    try:
        line = ser.readline()
    except:
        print(&quot;serial error&quot;)
        time.sleep(1)
        continue

    if not line:
        continue

    try:
        line = line.decode(&quot;utf-8&quot;).strip()
    except:
        continue

    # ★ 生データ確認（必要なら）
    # print(line)

    if line.startswith(&quot;$GNGGA&quot;) or line.startswith(&quot;$GPGGA&quot;):
        parts = line.split(&quot;,&quot;)

        if len(parts) &gt; 6:
            fix = parts[6]
            lat = convert_to_decimal(parts[2], parts[3])
            lon = convert_to_decimal(parts[4], parts[5])
            jst = convert_time(parts[1])

            if lat is not None and lon is not None:
                print(f&quot;{lat},{lon}&quot;)
            else:
                print(&quot;位置未取得&quot;)

            print(&quot;fix:&quot;, fix, &quot;日本時間:&quot;, jst)
</code></pre></div>



<p>GPSの電波は微弱なため、厚いコンクリートの壁や金属の板、屋根などに遮断されやすいという特性があります。そのため、テストを行う際は窓際や屋外といった、上空が開けていて空が見える場所を選んでください。</p>



<p>GPSモジュールの動作状況は、基板裏側のLEDで確認できます。電源を入れた直後は赤色のLEDが点灯したままの状態が続きますが、これが1秒おきに点滅し始めたら、複数の衛星を捕捉して測位に成功したことを示しています。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="617" src="https://sozorablog.com/wp-content/uploads/2025/05/IMG_0722.jpeg" alt="" class="wp-image-16679" style="width:364px;height:auto"/><figcaption class="wp-element-caption">受信状況を示すLED</figcaption></figure>



<p>初めて電源を入れた場合は、衛星を見つけて位置を特定するまでに5〜10分ほどの時間が必要です。衛星の軌道情報を取得するために必要な待ち時間ですので、LEDの点滅が始まるまで待ちましょう。</p>



<h3 class="wp-block-heading">完成したコード</h3>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="842" src="https://sozorablog.com/wp-content/uploads/2025/05/IMG_0723.jpeg" alt="" class="wp-image-16687" style="width:474px;height:auto"/></figure>



<p>以下はGPSで取得した現在位置を中心として航空機との位置関係を計算し、周辺の航空機をレーダー風にリアルタイム表示するコードです。今回は720×720の<a href="https://www.switch-science.com/products/9032">4インチ円形タッチスクリーンディスプレイ</a>を使用しました。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>import cv2
import numpy as np
import math
import time
import serial
import requests

# ===== GPS設定 =====
ser = serial.Serial(&quot;/dev/serial0&quot;, 9600, timeout=1)

last_lat = None
last_lon = None
has_fix_once = False
gps_status = &quot;WAITING GPS&quot;

def convert_to_decimal(raw, direction):
    if raw == &quot;&quot;:
        return None

    if direction in [&quot;N&quot;, &quot;S&quot;]:
        deg = int(raw[:2])
        minutes = float(raw[2:])
    else:
        deg = int(raw[:3])
        minutes = float(raw[3:])

    value = deg + minutes / 60

    if direction in [&quot;S&quot;, &quot;W&quot;]:
        value *= -1

    return value

def get_gps():
    global last_lat, last_lon, has_fix_once, gps_status

    try:
        line = ser.readline()
    except:
        gps_status = &quot;GPS ERROR&quot;
        return last_lat, last_lon

    if not line:
        return last_lat, last_lon

    try:
        line = line.decode(&quot;utf-8&quot;).strip()
    except:
        return last_lat, last_lon

    if line.startswith(&quot;$GNGGA&quot;) or line.startswith(&quot;$GPGGA&quot;):
        parts = line.split(&quot;,&quot;)

        if len(parts) &gt; 6:
            fix = parts[6]
            lat = convert_to_decimal(parts[2], parts[3])
            lon = convert_to_decimal(parts[4], parts[5])

            current_valid = (lat is not None and lon is not None and fix != &quot;0&quot;)

            if current_valid:
                last_lat = lat
                last_lon = lon
                has_fix_once = True
                gps_status = &quot;GPS OK&quot;
            else:
                if has_fix_once:
                    gps_status = &quot;GPS LOST (using last)&quot;
                else:
                    gps_status = &quot;WAITING GPS&quot;

    return last_lat, last_lon


# ===== 表示設定 =====
WIDTH = 720
HEIGHT = 720
CENTER_X = WIDTH // 2
CENTER_Y = HEIGHT // 2
SCALE = 450

icon = cv2.imread(&quot;plane_icon.png&quot;, cv2.IMREAD_UNCHANGED)
icon_h, icon_w = icon.shape[:2]

cap = cv2.VideoCapture(&quot;radar.mp4&quot;)
fps = cap.get(cv2.CAP_PROP_FPS)
delay = int(1000 / fps) if fps &gt; 0 else 33


# ===== 航空機データ取得関数 =====
def get_aircraft_positions():
    try:
        res = requests.get(&quot;http://localhost:8080/data/aircraft.json&quot;, timeout=1)
        return [a for a in res.json().get(&quot;aircraft&quot;, []) if &#39;lat&#39; in a and &#39;lon&#39; in a]
    except:
        return []

# ===== アイコン描画 =====
def draw_icon_rotated(img, icon, center, angle_deg):
    x, y = center

    M = cv2.getRotationMatrix2D((icon_w // 2, icon_h // 2), -angle_deg, 1.0)
    rotated = cv2.warpAffine(
        icon, M, (icon_w, icon_h),
        flags=cv2.INTER_NEAREST,
        borderMode=cv2.BORDER_CONSTANT,
        borderValue=(0, 0, 0, 0)
    )

    x1 = x - icon_w // 2
    y1 = y - icon_h // 2
    x2 = x1 + icon_w
    y2 = y1 + icon_h

    if x1 &lt; 0 or y1 &lt; 0 or x2 &gt; img.shape[1] or y2 &gt; img.shape[0]:
        return

    roi = img[y1:y2, x1:x2]

    if rotated.shape[2] == 4:
        alpha = rotated[:, :, 3] / 255.0
        for c in range(3):
            roi[:, :, c] = (1 - alpha) * roi[:, :, c] + alpha * rotated[:, :, c]


# ===== 画面 =====
cv2.namedWindow(&quot;Radar Display&quot;, cv2.WINDOW_NORMAL)
cv2.setWindowProperty(&quot;Radar Display&quot;, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)

aircraft_list = []
last_update = 0


# ===== メインループ =====
while True:

    # GPS取得
    HOME_LAT, HOME_LON = get_gps()

    # 初回待ち
    if not has_fix_once:
        frame = np.zeros((HEIGHT, WIDTH, 3), dtype=np.uint8)

        cv2.putText(frame, &quot;WAITING GPS&quot;, (330, 20),
                    cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 255), 2)

        cv2.imshow(&quot;Radar Display&quot;, frame)

        if cv2.waitKey(delay) & 0xFF == 27:
            break
        continue

    # 航空機更新
    now = time.time()
    if now - last_update &gt;= 1.0:
        aircraft_list = get_aircraft_positions()
        last_update = now

    # 背景動画
    ret, video_frame = cap.read()
    if not ret:
        cap.set(cv2.CAP_PROP_POS_FRAMES, 0)
        continue

    video_h, video_w = video_frame.shape[:2]
    scale = min(WIDTH / video_w, HEIGHT / video_h) * 1.8
    new_w = int(video_w * scale)
    new_h = int(video_h * scale)

    resized = cv2.resize(video_frame, (new_w, new_h), interpolation=cv2.INTER_NEAREST)
    resized = cv2.convertScaleAbs(resized, alpha=0.6, beta=0)

    frame = np.zeros((HEIGHT, WIDTH, 3), dtype=np.uint8)

    x_offset = (WIDTH - new_w) // 2
    y_offset = (HEIGHT - new_h) // 2

    x1_dst = max(x_offset, 0)
    y1_dst = max(y_offset, 0)
    x1_src = max(-x_offset, 0)
    y1_src = max(-y_offset, 0)
    x2_dst = min(x_offset + new_w, WIDTH)
    y2_dst = min(y_offset + new_h, HEIGHT)
    x2_src = x1_src + (x2_dst - x1_dst)
    y2_src = y1_src + (y2_dst - y1_dst)

    frame[y1_dst:y2_dst, x1_dst:x2_dst] = resized[y1_src:y2_src, x1_src:x2_src]

    # 飛行機描画
    for a in aircraft_list:
        dx = (a[&#39;lon&#39;] - HOME_LON) * SCALE
        dy = (a[&#39;lat&#39;] - HOME_LAT) * SCALE

        x = int(CENTER_X + dx)
        y = int(CENTER_Y - dy)

        if 0 &lt;= x &lt; WIDTH and 0 &lt;= y &lt; HEIGHT:
            if &#39;track&#39; in a and isinstance(a[&#39;track&#39;], (int, float)):
                draw_icon_rotated(frame, icon, (x, y), a[&#39;track&#39;])
            else:
                cv2.circle(frame, (x, y), 5, (0, 255, 0), -1)

            # ===== 便名表示 =====
            flight = a.get(&#39;flight&#39;, &#39;&#39;).strip()

            if flight != &quot;&quot;:
                font = cv2.FONT_HERSHEY_SIMPLEX
                font_scale = 0.4
                thickness = 1

                text_size, _ = cv2.getTextSize(flight, font, font_scale, thickness)

                text_x = x - text_size[0] // 2
                text_y = y + 25  # アイコンの下

                cv2.putText(frame, flight,
                            (text_x, text_y),
                            font, font_scale,
                            (0, 255, 0),
                            thickness,
                            cv2.LINE_AA)

    # GPS状態表示
    color = (0, 255, 0) if gps_status == &quot;GPS OK&quot; else (0, 0, 255)

    cv2.putText(frame, gps_status, (330, 20),
                cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)

    # 表示
    cv2.imshow(&quot;Radar Display&quot;, frame)

    if cv2.waitKey(delay) & 0xFF == 27:
        break


cap.release()
cv2.destroyAllWindows()
</code></pre></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="591" height="427" src="https://sozorablog.com/wp-content/uploads/2025/05/スクリーンショット-2026-04-11-4.35.51-1.png" alt="" class="wp-image-16683" style="width:431px;height:auto"/><figcaption class="wp-element-caption">GPS取得待機画面</figcaption></figure>



<p>まず、画面の中央点となる「基準座標」を決定します。GPSモジュールから送られてくる文字列を解析し、緯度と経度を数値として抽出します。この位置が確定するまでは、計算の基準が作れないため、画面上には「WAITING GPS」というステータスのみが表示されます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="726" height="717" src="https://sozorablog.com/wp-content/uploads/2025/05/スクリーンショット-2026-04-11-5.11.33.jpg" alt="" class="wp-image-16684" style="width:409px;height:auto"/><figcaption class="wp-element-caption">GPSの測位が開始するとアニメーションが表示される</figcaption></figure>



<p>現在位置が確定すると、画面中央（360, 360）が自分の現在地として固定されます。次に、背景として読み込んだアニメーション動画が描画されます。この背景の上に、ネットワークから取得した航空機の位置を重ねていきます。</p>



<p>動作中にGPS信号が途絶えた場合、最後に正常に受信できた座標を保持し続けます。これにより、航空機との相対位置を維持したまま表示を継続します。このとき、画面上部のステータス表示は「GPS OK」から「GPS LOST (using last)」へと変化し、ユーザーにGPSデータの更新が止まっていることを通知します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="711" height="559" src="https://sozorablog.com/wp-content/uploads/2025/05/スクリーンショット-2026-04-11-16.39.06.jpg" alt="" class="wp-image-16698" style="width:387px;height:auto"/><figcaption class="wp-element-caption">円形ディスプレイのスタンド</figcaption></figure>



<p>円形ディスプレイのスタンドは3Dプリンターで作成しました。以下のボタンからSTLファイルをダウンロードできます。</p>


<div class='w3eden'><!-- WPDM Link Template: Default Template -->

<div class="link-template-default card mb-2">
    <div class="card-body">
        <div class="media">
            <div class="mr-3 img-48"><img decoding="async" class="wpdm_icon" alt="アイコン" src="https://sozorablog.com/wp-content/plugins/download-manager/assets/file-type-icons/zip.svg" /></div>
            <div class="media-body">
                <h3 class="package-title"><a href='https://sozorablog.com/download/round-touch-display-stand/'>Round Touch Display Stand</a></h3>
                <div class="text-muted text-small"><i class="fas fa-copy"></i> 1 ファイル <i class="fas fa-hdd ml-3"></i> 21 KB</div>
            </div>
            <div class="ml-3">
                <a class='wpdm-download-link download-on-click btn btn-primary ' rel='nofollow' href='#' data-downloadurl="https://sozorablog.com/download/round-touch-display-stand/?wpdmdl=16705&refresh=69e5655bdcf391776641371">ダウンロード</a>
            </div>
        </div>
    </div>
</div>

</div>
]]></content:encoded>
					
					<wfw:commentRss>https://sozorablog.com/flightradar/feed/</wfw:commentRss>
			<slash:comments>34</slash:comments>
		
		
			</item>
		<item>
		<title>外からラズパイを操作！Raspberry Pi Connectの設定方法</title>
		<link>https://sozorablog.com/raspberry-pi-connect/</link>
					<comments>https://sozorablog.com/raspberry-pi-connect/#comments</comments>
		
		<dc:creator><![CDATA[そぞら]]></dc:creator>
		<pubDate>Sat, 01 Feb 2025 19:09:58 +0000</pubDate>
				<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[使い方]]></category>
		<guid isPermaLink="false">https://sozorablog.com/?p=13849</guid>

					<description><![CDATA[自宅のラズパイに接続したカメラ映像の確認や、センサーのデータをリアルタイムでチェックしたいと思ったことはありませんか？　Raspberry Pi Connectを使えば、世界中どこからでも安全にラズパイへアクセスできます [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>自宅の<a href="https://sozorablog.com/raspberry-pi/">ラズパイ</a>に接続したカメラ映像の確認や、センサーのデータをリアルタイムでチェックしたいと思ったことはありませんか？　<a href="https://www.raspberrypi.com/software/connect/">Raspberry Pi Connect</a>を使えば、世界中どこからでも安全にラズパイへアクセスできます。しかも<strong>無料</strong>で利用可能です。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/01/IMG_6818-1.jpeg" alt="" class="wp-image-4"/><figcaption class="wp-element-caption">スマホやPCから接続できる</figcaption></figure>



<p>従来の<a href="https://sozorablog.com/vnc/">VNC</a>は基本的にLAN内での接続が前提でしたが、Raspberry Pi Connectは外部からアクセス可能。IoTシステムの遠隔監視や離れた場所からラズパイを操作することができます。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/02/pico-2025-02-04T062648.623.jpg" alt="" class="wp-image-4"/><figcaption class="wp-element-caption">VNCとRaspberry Pi Connectの違い</figcaption></figure>



<p>本記事ではRaspberry Pi Connectの導入手順や設定方法を詳しく解説します。</p>



<h2 class="wp-block-heading"><strong>待望のRaspberry Pi Connect</strong></h2>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/02/connect1.jpg" alt="" class="wp-image-4"/><figcaption class="wp-element-caption">出典：<a href="https://www.raspberrypi.com/software/connect/">Raspberry Pi公式サイト</a></figcaption></figure>



<p>Raspberry Pi Connectは<span class="sbd-text-red">公式から発表された</span>リモートアクセスツールです。これにより、インターネット経由でRaspberry Piを遠隔操作・管理することが可能になりました。特別なネットワーク設定やファイアウォールのポート開放なしで使用できるよう設計されています。外出先から自宅のRaspberry Piに簡単に接続し、デスクトップやシェルを使ってリモート操作できます。</p>



<p>2025年5月にはバージョン2.5のリリースとともにベータ版が終了し、正式なサービスとなりました。</p>



<div class="wp-block-sbd-balloon sbd-balloon sbd-balloon--id-4 sbd-balloon--flat sbd-balloon--l sbd-balloon--green block-box"><div class="sbd-balloon__profile"><figure class="sbd-balloon__icon"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2021/09/アイコン.jpg" alt="そぞら" class="sbd-balloon__img"/></figure><div class="sbd-balloon__name">そぞら</div></div><div class="sbd-balloon__text-box sbd-inner-block-init">
<p>通信方式が改善され、接続時の待機方法やデータ送信がより効率化されています。</p>
</div></div>



<h3 class="wp-block-heading">Raspberry Pi Connectの対応デバイスと必要な環境</h3>



<p>Raspberry Pi Connectには、<strong>リモートデスクトップ機能</strong> と <strong>リモートシェル機能</strong> の2種類があります。リモートデスクトップ機能は、Raspberry Pi OS <span class="sbd-text-bg-yellow">Bookworm</span>が動作するモデルに限定されています。一方、リモートシェル機能は、<a href="https://sozorablog.com/raspberry-pi-pico/">Raspberry Pi Pico</a>を除くすべてのRaspberry Piで動作します。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/02/pico-3.jpg" alt="" class="wp-image-4"/></figure>



<p>Raspberry Pi Connectを利用するためには、Raspberry Pi本体と操作する端末の両方がインターネットに接続されている必要があります。</p>



<h3 class="wp-block-heading">Raspberry Pi Connectの仕組み</h3>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/02/pico-2.jpg" alt="" class="wp-image-4" style="width:840px;height:auto"/></figure>



<p>Raspberry Pi ConnectはWebRTCを利用してピアツーピア（P2P）接続を確立し、<span class="sbd-text-bg-yellow">ブラウザとRaspberry Piの間で直接データをやり取り</span>します。これはZoomやSlackなどのリアルタイム通信ツールと同様で、安全かつ低遅延な接続を実現します。（参考：<a href="https://www.raspberrypi.com/news/raspberry-pi-connect/">Raspberry Pi公式ブログ</a>）</p>



<p>基本的にP2P接続が優先される設計ですが、ネットワーク環境によっては確立できない場合があります。その際は、<span class="sbd-text-red">Raspberry Pi ConnectのTURNサーバーを経由したリレー接続</span>が行われます。この通信はDTLSで暗号化されますが、現在TURNサーバーはイギリスに1つしかないため、遅延が発生する可能性があります。</p>



<h2 class="wp-block-heading">Raspberry Pi Connectの設定</h2>



<p>Raspberry Pi Connectを利用するには、まずRaspberry Piのデスクトップ画面で設定を行います。ここでは、有効化の手順やデバイスの登録方法を説明します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/02/image-1.png" alt="" style="width:840px;height:auto"/><figcaption class="wp-element-caption">使用したOS</figcaption></figure>



<p>今回は<span class="sbd-text-bg-yellow">Raspberry Pi OS Bookworm(64-bit)</span>を使用しました。</p>



<h3 class="wp-block-heading">Raspberry Pi Connectを有効にする</h3>



<p>デフォルトでは、Raspberry Pi Connectはインストール済みですが無効化されています。有効にするには、以下の手順を実行します。</p>



<p>メニューバーからRaspberry Pi Connectのアイコンをクリックします。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/01/pico-2025-01-31T092432.769.jpg" alt="" class="wp-image-4"/></figure>



<p>「Turn On Raspberry Pi Connect」をクリックすると、Raspberry Pi Connectの機能が有効になります。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/01/pico-2025-01-31T092137.537.jpg" alt="" class="wp-image-4" style="width:840px;height:auto"/></figure>



<p>初めて利用する場合は、ブラウザが開いて<a href="https://connect.raspberrypi.com/sign-in">Raspberry Pi Connectのウェブページ</a>が表示されます。</p>



<h3 class="wp-block-heading">Raspberry Pi IDを作成する</h3>



<p>Raspberry Pi Connectを利用するには、Raspberry Pi IDが必要です。「create one for free」（無料でアカウントを作成）をクリックし、新規アカウントを作成します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/01/pico-2025-01-31T093251.595.png" alt="" class="wp-image-4" style="width:840px;height:auto"/></figure>



<p>必要な情報を入力します。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/01/pico-2025-01-31T100004.918.png" alt="" class="wp-image-4" style="width:431px;height:auto"/></figure>



<p>Continueボタンをクリックすると、登録したメールアドレスに確認メールが届きます。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/01/pico-2025-01-31T050423.588.png" alt="" class="wp-image-4"/></figure>



<h4 class="wp-block-heading">メールアドレスを認証する</h4>



<p>PCまたはスマートフォンで、「id@raspberrypi.com」から届いた確認メールを開き、「Verify email」をクリックします。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/01/picone3.png" alt="" class="wp-image-4" style="width:800px;height:auto"/></figure>



<p>「Sign in」をクリックします。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/01/picone4.png" alt="" class="wp-image-4"/></figure>



<p>先ほど設定したメールアドレスとパスワードを入力します。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/01/piconect1.png" alt="" class="wp-image-4"/></figure>



<p>以下の画面が出れば、サインイン完了です。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/01/pico-2025-01-31T050728.948.png" alt="" class="wp-image-4"/></figure>



<h3 class="wp-block-heading">デバイスを登録する</h3>



<p>Raspberry Pi Connectに自分のRaspberry Piを紐づけて、リモートアクセスできるようにします。</p>



<p>Raspberry Piの「Raspberry Pi Connect」アイコンをクリック後、「Sign In」をクリックします。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/01/pico-2025-01-31T113735.666.jpg" alt="" class="wp-image-4" style="width:444px;height:auto"/></figure>



<p>「Sign in as 〇〇」をクリックします。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/01/pico-2025-01-31T114922.727.png" alt="" class="wp-image-4" style="width:798px;height:auto"/></figure>



<p>デバイス登録画面が表示されたら、デバイス名を入力し（例：「MyPi」など）、「Create device and sign in」ボタンをクリックします。複数のラズパイを使用している場合は、「Pi5-8GB」などの名前を付けると識別しやすくなります。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/01/pico-2025-01-31T115218.881.png" alt="" class="wp-image-4" style="width:840px;height:auto"/></figure>



<p>「Device sign in successful」の画面が出たら設定は完了です。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/01/picone11.png" alt="" class="wp-image-4"/></figure>



<p>「view your dashboard」 をクリックして、登録されたデバイスが正しく表示されているか確認してみます。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/01/picone12.png" alt="" class="wp-image-4"/></figure>



<div class="wp-block-sbd-checkpoint-block"><p class="sbd-checkpoint-title">チェックポイント</p><div class="sbd-checkpoint-content sbd-inner-block-init"><p>デバイス名は、各デバイスごとに割り当てる必要があります。試しに同じmicroSDを別のラズパイに挿してRaspberry Pi Connectを使おうとしましたが、新たにデバイス名を設定しなければなりませんでした。</p></div></div>



<h2 class="wp-block-heading">PCからリモート操作する</h2>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/02/IMG_8392.jpeg" alt="" class="wp-image-4"/></figure>



<p>PCのブラウザで <a href="https://connect.raspberrypi.com/">Raspberry Pi Connect</a> にアクセスします。サインインすると、以下の画面が出ます。「Connect via」 ボタンをクリックします。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/01/pico-2025-01-31T123408.740.png" alt="" class="wp-image-4"/></figure>



<p>「Screen sharing」または「Remote shell」 を選択します。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/01/pico-2025-01-31T131250.188.png" alt="" class="wp-image-4"/><figcaption class="wp-element-caption">どちらかを選択</figcaption></figure>



<p>「Screen sharing」はRaspberry Pi の<span class="sbd-text-red">デスクトップ画面</span>をブラウザ上で操作できます。マウスやキーボードを使ってGUIアプリを操作したり、デスクトップ環境の設定を変更したりするときに便利です。</p>



<p>「Remote shell」Raspberry Pi の<span class="sbd-text-bg-yellow">ターミナル</span>（CLI）に接続されます。コマンドを直接入力してシステムの設定変更や再起動を行ったり、PythonやBashのスクリプトを実行したりする際に役立ちます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/01/pico-2025-01-31T130848.863.jpg" alt="" class="wp-image-4" style="width:840px;height:auto"/></figure>



<h3 class="wp-block-heading">Screen sharingを使った操作感</h3>



<p>「Screen sharing」を選択すると、以下のようにデスクトップ画面が表示されます。接続までにかかった時間は15秒でした。VNC接続と比べると、やや時間がかかる印象です。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/01/picone13.jpg" alt="" class="wp-image-4"/></figure>



<p>VNC接続をしている場合は画面が表示されませんでした。<span class="sbd-text-bg-yellow">「Raspberry Pi Connect」とVNCは同時に使用できない</span>ようです。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/02/IMG_8394.jpeg" alt="" class="wp-image-4"/></figure>



<p>キーボードやマウスを使って快適に操作できます。遠隔地からでも自在に扱えるのは、とても便利です。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/02/pico-4.jpg" alt="" class="wp-image-4"/><figcaption class="wp-element-caption">上部のボタンで操作可能</figcaption></figure>



<h2 class="wp-block-heading">スマートフォンからリモート操作する</h2>



<p>PCの場合と同様に、ブラウザで <a href="https://connect.raspberrypi.com/">Raspberry Pi Connect</a> にアクセスします。以下はiPhoneからアクセスした際の画面です。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/01/IMG_8377.jpeg" alt="" class="wp-image-4" style="width:349px;height:auto"/></figure>



<p>サインインすると、デバイス管理画面が表示されます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/01/IMG_8379.jpeg" alt="" class="wp-image-4" style="width:340px;height:auto"/></figure>



<p>「Screen sharing」（画面共有）を押すと、以下のようにデスクトップ画面が表示されます。画面の拡大縮小はできないようです。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/02/IMG_8390.jpeg" alt="" class="wp-image-4" style="width:335px;height:auto"/></figure>



<p>PCから接続しているかどうかで、<span class="sbd-text-red">スマホに表示される画面サイズが変わります</span>。PCで先に接続すると、その解像度が適用され、後からスマホで接続すると表示が変わるようです。これは、Raspberry Pi Connectが最初に接続したデバイスの解像度を基準にセッションを設定し、後から接続するデバイスはその解像度を引き継ぐためと思われます。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/01/pico-2025-01-31T175653.200.jpg" alt="" class="wp-image-4" style="width:840px;height:auto"/><figcaption class="wp-element-caption">スマホ縦向き表示の比較</figcaption></figure>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/01/pico-2025-01-31T181735.433.jpg" alt="" class="wp-image-4" style="width:840px;height:auto"/><figcaption class="wp-element-caption">スマホ横向き表示の比較</figcaption></figure>



<p>スマートフォン仕様の画面だと一部の領域しか表示できませんが、ボタンの操作は可能です。</p>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/01/Videotogif.gif" alt="" class="wp-image-4"/></figure>



<p>逆にPCを先に接続した場合の画面では、全画面表示されますが、ボタンが小さくて操作は困難です。</p>



<h3 class="wp-block-heading">スマホからコマンドを実行</h3>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/01/IMG_8385.png" alt="" class="wp-image-4" style="width:319px;height:auto"/><figcaption class="wp-element-caption">「Remote shell」モードでは文字入力可能</figcaption></figure>



<p>Raspberry PiのCPU温度を取得するコマンドを実行してみました。以下のコマンドを使用します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>vcgencmd measure_temp</code></pre></div>



<p>スマートフォンからの操作で、CPU温度を取得できました。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/01/image.png" alt="画像に alt 属性が指定されていません。ファイル名: IMG_8386.png" class="wp-image-4" style="width:320px;height:auto"/></figure>



<h2 class="wp-block-heading">カメラの映像をリモートで確認する</h2>



<figure class="wp-block-image size-full"><img decoding="async" src="https://sozorablog.com/wp-content/uploads/2025/02/IMG_8396.jpeg" alt="" class="wp-image-4"/><figcaption class="wp-element-caption">Raspberry Pi 5とカメラモジュールV3</figcaption></figure>



<p><a href="https://sozorablog.com/camera-module-v3/">カメラモジュールV3</a>で撮影した映像をスマートフォンに表示してみます。</p>



<p>以下のコマンドはカメラのプレビュー画面を表示するためのものです。あらかじめRaspberry Pi側でこのコマンドを実行し、その映像をスマートフォンから確認できるか試してみます。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>libcamera-hello --timeout 0</code></pre></div>



<h3 class="wp-block-heading">スマホからの操作性は今後の改善に期待</h3>



<p>スマートフォンからRaspberry Pi Connectに接続すると、以下のように表示されます。遅延はほぼ気にならないレベルです。</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="800" height="1040" src="https://sozorablog.com/wp-content/uploads/2025/02/IMG_8397.jpeg" alt="" class="wp-image-14010" style="width:449px;height:auto"/></figure>



<p>スマートフォンでは<span class="sbd-text-red">全画面表示ができない</span>ようです。スマートフォンを横向きにしても、画像のサイズはあまり大きくなりませんでした。そのため、デスクトップ画面のGUI操作はほとんどできない状態です。スマホで本格的なプログラミングをするわけではないにせよ、エディターを開いてプログラムを起動するなど、最低限の操作ができるようになってほしいところです。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sozorablog.com/raspberry-pi-connect/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
	</channel>
</rss>
