LoginSignup
5
4

More than 3 years have passed since last update.

初めてのRaspberry Pi Pico ① C言語でLチカ ver.2

Last updated at Posted at 2021-01-28

 https://pico.raspberrypi.org/files/getting_started.pdf
に従って、ラズパイ4に開発、デバッグ環境をインストールします。この作業で必要なのは、次の三つです。

  • ラズパイ
  • USBケーブル
  • Pico

IMGP0132b.png

準備はたったの4ステップで完了

 ラズパイ4の2GBモデルを使っています。SDメモリは32GBです。現時点で、January 11th 2021が最新のOSですが、このマシンはその前のダウンロード版を、更新しながら使っています。

sudo apt-get update
sudo apt-get upgrade -y

 リブート後、まずwgetをインストールします。

sudo apt install wget

 インストールに必要なことが記述されたスクリプトを取得します。

 wget https://raw.githubusercontent.com/raspberrypi/pico-setup/master/pico_setup.sh

 実行権を付けます。

 chmod +x pico_setup.sh

 実行します。

 ./pico_setup.sh

 全部コピペでターミナルに貼り付けています。
 30分ほどで作業が完了します。df -hで見ると残りの容量は45%ぐらいになっていました。VScodeやOpenOCDも入ります。
 リブートします。

reboot

blinkをコンパイル

 ビルドされているので、何もしません。

 cmakeとGNU Embedded Toolchain for Armをインストールします。

sudo apt update
sudo apt install cmake gcc-arm-none-eabi libnewlib-arm-none-eabi build essential

 移動します。

cd pico
cd pico-examples

 pathを通します。

export PICO_SDK_PATH=../../pico-sdk

cmake ..

 makeを実行します。

cd blink
make -j4

ファイルをコピーして実行

 ボード上にあるBOOTSELを押したまま、USBケーブルでラズパイとPicoをつなぎます。ラズパイの画面上にドライブがマウントされます。BOOTSELから手を放します。
pico201.png

 File Managerを立ち上げます。/home/pi/pico/pico-examples/build/blinkまで下りていきます。ここにあるblink.uf2をRPI-RP2ドライブへドラッグします。
pico202.png

 RPI-RP2ドライブは画面から消え、Picoはリセットがかかって、USBコネクタの横にある黄色のLEDが点滅します。
 /home/pi/pico/pico-examples/blinkディレクトリのblink.cをテキスト・エディタで開き、sleep_ms()の時間を変更して保存します。
 /home/pi/pico/pico-examples/build/blinkのディレクトリで、

make -j4

を実行し、そのディレクトリに作られた新しいblink.uf2をRPI-RP2ドライブへドラッグします。点滅の時間が変われば、うまく動いています。

/**
 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include "pico/stdlib.h"

int main() {
    const uint LED_PIN = 25;
    gpio_init(LED_PIN);
    gpio_set_dir(LED_PIN, GPIO_OUT);
    while (true) {
        gpio_put(LED_PIN, 1);
        sleep_ms(1000);
        gpio_put(LED_PIN, 0);
        sleep_ms(2000);
    }
}
5
4
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
5
4