2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Raspberry Pi Pico VSCodeにMicrosoft謹製のSerial Monitorをインストールする

Last updated at Posted at 2024-03-08

 前回の投稿「RaspberryPi Pico W 開発環境を Ubuntuで構築する」で、Ubuntu PC で VSCodeを使った開発環境の構築を紹介しましたが、USB接続で RaspberryPi Pico に書き込みしたあとシリアル出力をどうモニターしようかと迷っていました。
RaspberryPi Pico W 開発環境を Ubuntuで構築する (Qiita@pipito-yukio)

これ以降 Raspberry Pi をラズパイとして説明します。

 ラズパイ4にラズパイPicoの開発環境を構築したときにはセットアップスクリプト内でシリアルモニター(minicom)がインストールされており、minicom によりシリアル出力をターミナルからモニタすることが出来ましたが、開発PC (Ubuntu) にはインストールしていません。

開発環境

  • OS: Ubuntu 22.04
  • ラズパイ Pico 用のクロスコンパイラーがインストール済み
  • ラズパイ Pico SDK とサンプルがセットアップ済み
  • VSCode for Linux
  • ラズパイPico用設定ファイルでUSBモニターを有効に設定
    ※ コメント(★)の2行分の設定
CmakeLists.txt
add_executable(spi_mcp3002_adc
        main.c
        )

# pull in common dependencies and additional spi hardware support
target_link_libraries(spi_mcp3002_adc pico_stdlib hardware_adc hardware_spi)

# From  ~/pico/pico-examples/hello_world/usb/CMakeLists.txt
# (★) enable usb output, disable uart output
pico_enable_stdio_usb(spi_mcp3002_adc 1)
pico_enable_stdio_uart(spi_mcp3002_adc 0)

# create map/bin/hex file etc.
pico_add_extra_outputs(spi_mcp3002_adc)

以下がセットアップスクリプトのminicomインストール処理の抜粋になります。

pico_setup.sh
#!/bin/bash

# Exit on error
set -e

if grep -q Raspberry /proc/cpuinfo; then
    echo "Running on a Raspberry Pi"
else
    echo "Not running on a Raspberry Pi. Use at your own risk!"
fi

#... 一部省略 ...
UART_DEPS="minicom"
#... 一部省略 ...
# 一番最後にシリアルモニターのインストールとUARTの有効化を実行
# Enable UART
if [[ "$SKIP_UART" == 1 ]]; then
    echo "Skipping uart configuration"
else
    sudo apt install -y $UART_DEPS
    echo "Disabling Linux serial console (UART) so we can use it for pico"
    sudo raspi-config nonint do_serial 2
    echo "You must run sudo reboot to finish UART setup"
fi

 Ubuntuでも minicom が提供されているのでひとまずこれをインストールして使ってみたのですが、あまり使い勝手が良くないんですね。特にモニターの終了の仕方が特殊で分かりづらい。

 ネットでUbuntu用シリアルモニターとして検索すると、tinyserial とか gtkterm とかがヒットしましたが、どれも五十歩百歩という感じです。

 ネットの検索で下記 Qiita投稿を見つけたのでどれを使うかの検討の参考にさせていただきました。

 結論から言うと、私もESP-WROOM-02の開発では VSCode+PlatformIO IDEで開発していたので、(2)のMicrosoft謹製のシリアルモニターを採用しました。

 検索窓に [Serial Monitor] と入力すると、私の環境ではトップに表示されました。

VSCode_0_install_MS_SerialMonitor.png

(2) では Windows10 のVSCodeにイントールしていたものでシリアルポートが文字化けすると記載がありましたが、私の環境(Ubuntu)のVSCodeではポート文字化けはありませんてした。

こちらはVSCodeのシリアルモニターから実行した画面になります。
シリアルモニターを開いたときのデフォルトのポートは /dev/ttyS0になっているので、ラズパイPicoのポート/dev/ttyACM0に切り替えします。

VSCode_1_SerialMon_Raspi_picoW_mcp3002.png

 ファイル出力できるので、通常は以下のように端末からモニターしながら、エディタは満開にして編集できます。

SerialMon_terminal_logFile.png

最後に

 参考にさせて頂いた投稿(2)でも書いてありましたが、私もMicrosoft謹製のSerial Monitorの使い勝手は格段に良いと感じています。Windowsと比べると Linux系PC では使えるツール類も限定されてくるので VSCodeの拡張機能とはいえ Microsoftさんには感謝です。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?