【Raspberry Pi Pico入門 – 23】各ボードのピン定義

Raspberry Pi Pico入門,応用編Arduino,Raspberry Pi Pico

概要

ここでは実際の使用方法から少し離れて、マイコンボードごとのデフォルトのピン定義を整理します。
Arduinoではよく使うピンを同じ名前で定義しているので、ここで整理している名前を使用するとコードを他のマイコンボードに移植する時にピン設定の手間が省けます。

Arduino-Picoのマイコンボードごとのピン定義は、以下の場所にマイコンボード名のフォルダで整理されています。
全ボード共通の定義はgeneric\common.h、ボードごとのピン定義はpins_arduino.hに記載されています。

C:\Users\{ユーザー名}\AppData\Local\Arduino15\packages\rp2040\hardware\rp2040\{バージョン}\variants

ここに記載しているヘッダファイルは全文ではなく、コーディングでよく使うものだけを抜粋しています。

/generic/common.h(ボード共通の定義)

#define PINS_COUNT          (30u)
#define NUM_DIGITAL_PINS    (30u)
#define NUM_ANALOG_INPUTS   (4u)
#define NUM_ANALOG_OUTPUTS  (0u)
#define ADC_RESOLUTION      (12u)
#define WIRE_INTERFACES_COUNT (WIRE_HOWMANY)

#ifdef PIN_LED
#define LED_BUILTIN PIN_LED
#endif

static const uint8_t SS = PIN_SPI0_SS;
static const uint8_t MOSI = PIN_SPI0_MOSI;
static const uint8_t MISO = PIN_SPI0_MISO;
static const uint8_t SCK = PIN_SPI0_SCK;

static const uint8_t SDA = PIN_WIRE0_SDA;
static const uint8_t SCL = PIN_WIRE0_SCL;

Raspberry Pi Pico

// LEDs
#define PIN_LED        (25u)

// Serial
#define PIN_SERIAL1_TX (0u)
#define PIN_SERIAL1_RX (1u)

#define PIN_SERIAL2_TX (8u)
#define PIN_SERIAL2_RX (9u)

// SPI
#define PIN_SPI0_MISO  (16u)
#define PIN_SPI0_MOSI  (19u)
#define PIN_SPI0_SCK   (18u)
#define PIN_SPI0_SS    (17u)

#define PIN_SPI1_MISO  (12u)
#define PIN_SPI1_MOSI  (15u)
#define PIN_SPI1_SCK   (14u)
#define PIN_SPI1_SS    (13u)

// Wire
#define PIN_WIRE0_SDA  (4u)
#define PIN_WIRE0_SCL  (5u)

#define PIN_WIRE1_SDA  (26u)
#define PIN_WIRE1_SCL  (27u)

#define SERIAL_HOWMANY (3u)
#define SPI_HOWMANY    (2u)
#define WIRE_HOWMANY   (2u)

#include "../generic/common.h"

Raspberry Pi Pico W

// LEDs
#define PIN_LED        (64u)

// 以下、Raspberry Pi Picoと同じ

Raspberry Pi Pico 2

#define PICO_RP2350A 1

// LEDs
#define PIN_LED        (25u)

// 以下、Raspberry Pi Picoと同じ

Raspberry Pi Pico W 2

#define PICO_RP2350A 1

// LEDs
#define PIN_LED        (64u)

// 以下、Raspberry Pi Picoと同じ