4
3

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 3 years have passed since last update.

Maker Pi RP2040をArduinoで使おう

Last updated at Posted at 2021-11-22

Maker Pi RP2040はCytronという会社の製品で1000円ちょっとで購入できるRP2040の多機能ボードになります。
https://www.cytron.io/p-maker-pi-rp2040-simplifying-robotics-with-raspberry-pi-rp2040
Github
https://github.com/CytronTechnologies/MAKER-PI-RP2040
2021年11月現在秋月電子で1,240円で販売されています。
今回は、このMakerPi RP2040を使ってみましょう。

仕様

モーター端子 2個
Grove端子 7個
LED
スイッチ 2個
などを搭載しており、Grove-ジャンパーケーブル4本も付属しています。
DSC_0847 (2).JPG

開発環境

RP2040ですから言語としてPythonやC、開発環境としてArduinoを使う事が出来ます。
今回は、Arduinoで使ってみます。

Arduinoのボードマネージャーに追加する

ツール⇒ボード⇒ボードマネージャー
をクリックします。
image.png
Arduino Mbed OS R2040 Boardsをインストールします。
スクリーンショット 2021-10-10 183217.png
USBのドライバーをインストールします。
スクリーンショット 2021-10-10 183620.png
これでRaspberry Pi Picoが使用できるようになりました。
image.png

Maker Pi RP2040用ボード設定

今回は、Raspberry Pi Picoのボードマネージャーのpins_arduino.hを少し加工してみましょう
回路図を参考に、I2Cやボタン、サーボの設定をしていきましょう。
https://drive.google.com/file/d/1Zp8GYO8x7ThObB1G8RIZx2YdqrXtdUc0/view
I2Cの設定がうまく出来なかったことがあったためボードマネージャーを修正しています。
C:\Users\user\AppData\Local\Arduino15\packages\arduino\hardware\mbed\2.5.2\variants\RASPBERRY_PI_PICO\pins_arduino.h
同じ苦労をされた方がいらっしゃいました。
Raspberry Pi Pico でAdafruitのArduinoスケッチ"bme680oled"が動かない! の対策
https://qiita.com/totuto/items/2a8db63abd1d3c82880f

修正したボードマネージャー(pins_arduino.h)の例

# pragma once
# include <macros.h>
# include <stdint.h>

# ifndef __PINS_ARDUINO__
# define __PINS_ARDUINO__

# ifdef __cplusplus
extern "C" unsigned int PINCOUNT_fn();
# endif

// Pin count
// ----
# define PINS_COUNT           (PINCOUNT_fn())
# define NUM_DIGITAL_PINS     (30u)
# define NUM_ANALOG_INPUTS    (4u)
# define NUM_ANALOG_OUTPUTS   (0u)

extern PinName digitalPinToPinName(pin_size_t P);

// LEDs
// ----
# define PIN_LED     (7u)
# define LED_BUILTIN PIN_LED
# define RGB     (18u)

// SwitchS
// ----
# define PIN_BTN1     (20u)
# define PIN_BTN2     (21u)

// BUZZER
// ----
# define BUZZER     (22u)

// Motor PWM
// ----
# define PWM1A     (8u)
# define PWM1B     (9u)
# define PWM2A     (10u)
# define PWM2B     (11u)

// SERVO
// ----
# define SRV1     (12u)
# define SRV2     (13u)
# define SRV3     (14u)
# define SRV4     (15u)

// Analog pins
// -----------
# define PIN_A0 (26u)
# define PIN_A1 (27u)
# define PIN_A2 (28u)
# define PIN_A3 (29u)

# define ADC3  (29u)

static const uint8_t A0  = PIN_A0;
static const uint8_t A1  = PIN_A1;
static const uint8_t A2  = PIN_A2;
static const uint8_t A3  = PIN_A3;

# define ADC_RESOLUTION 12

// Serial
# define PIN_SERIAL_TX (0ul)
# define PIN_SERIAL_RX (1ul)

// Wire
# define PIN_WIRE_SDA        (2u)
# define PIN_WIRE_SCL        (3u)

# define PIN_WIRE_SDA1       (4u)
# define PIN_WIRE_SCL1       (5u)

# define SERIAL_HOWMANY		1
# define SERIAL1_TX			(digitalPinToPinName(PIN_SERIAL_TX))
# define SERIAL1_RX			(digitalPinToPinName(PIN_SERIAL_RX))

# define SERIAL_CDC			1
# define HAS_UNIQUE_ISERIAL_DESCRIPTOR
# define BOARD_VENDORID		0x2e8a
# define BOARD_PRODUCTID		0x00c0
# define BOARD_NAME			"RaspberryPi Pico"

uint8_t getUniqueSerialNumber(uint8_t* name);
void _ontouch1200bps_();

# define WIRE_HOWMANY	(2)
# define I2C_SDA			(digitalPinToPinName(PIN_WIRE_SDA))
# define I2C_SCL			(digitalPinToPinName(PIN_WIRE_SCL))
# define I2C_SDA1			(digitalPinToPinName(PIN_WIRE_SDA1))
# define I2C_SCL1			(digitalPinToPinName(PIN_WIRE_SCL1))

# define digitalPinToPort(P)		(digitalPinToPinName(P)/32)

# define SERIAL_PORT_USBVIRTUAL      SerialUSB
# define SERIAL_PORT_MONITOR         SerialUSB
# define SERIAL_PORT_HARDWARE        Serial1
# define SERIAL_PORT_HARDWARE_OPEN   Serial1

# define USB_MAX_POWER	(500)

# endif //__PINS_ARDUINO__

なお、MakerPiRP2040としてこちらに用意してみました。
https://github.com/taisirou/ArduinoCore-mbed
これでI2Cやボタン、Servoが動くようになったと思います。

コンパイル

ArduinoUnoやESP32と同じくコンパイルをすると、自動書き込みされ、リセット起動します。

この後は、通常のArduinoと同じようにプログラミングしてみてください。

4
3
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
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?