LoginSignup
5
3

More than 3 years have passed since last update.

Raspberry Pi に arduino-cli を導入し、Arduino Unoを認識させる

Last updated at Posted at 2018-09-02

概要

今回は、Raspberry Pi に arduino-cli を入れて、 Arduino Unoを認識させるまでを整理しています。

なお、arduino-cliってなんだろうって方は、arduino-cli について整理してみたをどうぞ。

今回使ったものたち

  • Raspberry Pi3 ModelB
  • arduino-cli 0.2.1 preview
  • Arduino Uno

arduino-cliのインストール

下記の手順でインストールしていきます。

  1. arduino-cliのダウンロード
  2. arduino-cliの解凍
  3. arduino-cliにリネーム
  4. /usr/local/binへ移動

コマンドは下記のとおりです。

$ cd Downloads
$ wget http://downloads.arduino.cc/arduino-cli/arduino-cli-0.2.1-alpha.preview-linuxarm.tar.bz2
$ tar xf arduino-cli*
$ mv arduino-cli-0.2.1-alpha.preview-linuxarm arduino-cli
$ sudo mv arduino-cli /usr/local/bin

これで、基本的にはコマンドの実行ができるはずです。
疎通チェックには、 version コマンドを使うとわかりやすいです。

$arduino-cli version
arduino-cli version 0.2.1-alpha.preview

Arduino Unoを認識させてみる

arduino-cliで Raspberry Pi に 接続したArduino Unoが認識できているかどうかは、 board list コマンドで確認できます。

例えば、下記のような感じで出力されあます。

$ arduino-cli board list
FQBN            Port            ID          Board Name
    /dev/ttyACM0    2341:0043   unknown

この場合は、USBポートは認識しているものの、FQBNが空なのと、Board Name が unknownになってます。
どうも、これはcore ファイルが入ってないことが原因のようなです。

Coreのインストール

Arduino Unoを認識させるためには、 core コマンドを使ってAruino board のcoreファイルをインストールする必要があります。

coreファイルを検索する

まずインストールする前に、ターゲットとなるボード Arduino のcoreを検索します。

$ arduino-cli core search arduino
Searching for platforms matching 'arduino'

ID                  Version Installed   Name
Intel:arc32         2.0.2   No          Intel Curie Boards
arduino:avr         1.6.21  No          Arduino AVR Boards
arduino:nrf52       1.0.2   No          Arduino nRF52 Boards
arduino:sam         1.6.11  No          Arduino SAM Boards (32-bits ARM Cortex-M3)
arduino:samd        1.6.19  No          Arduino SAMD Boards (32-bits ARM Cortex-M0+)
arduino:samd_beta   1.6.23  No          Arduino SAMD Beta Boards (32-bits ARM Cortex-M0+)
arduino:stm32f4     1.0.1   No          Arduino STM32F4 Boards
littleBits:avr      1.0.0   No          littleBits Arduino AVR Modules

今回は、arduino Unoなので、 arduino:avr をインストールしていきます。

core update-index でエラーとなる場合

なお、core コマンドを実行した場合にエラーとなるケースがあります。

$ arduino-cli core search arduino
Error: loading json index file /home/pi/.arduino15/package_index.json: open /home/pi/.arduino15/package_index.json: no such file or directory
Failed to load https://downloads.arduino.cc/packages/package_index.json package index.
Try updating all indexes with `arduino-cli core update-index`.

これはフォルダがないことが原因だったようで、下記のようにフォルダを作ってあげればOKです。

$ mkdir /home/pi/.arduino15/
$ arduino-cli core update-index

coreファイルのインストール

core install コマンドを使って、coreファイルをインストールしていきます。

$ arduino-cli core install arduino:avr
Downloading arduino:avr-gcc@4.9.2-atmel3.5.4-arduino2...
arduino:avr-gcc@4.9.2-atmel3.5.4-arduino2 downloaded
Downloading arduino:avrdude@6.3.0-arduino9...
arduino:avrdude@6.3.0-arduino9 downloaded
Downloading arduino:arduinoOTA@1.1.1...
arduino:arduinoOTA@1.1.1 downloaded
Downloading arduino:avr@1.6.21...
arduino:avr@1.6.21 downloaded
Installing arduino:avr-gcc@4.9.2-atmel3.5.4-arduino2
arduino:avr-gcc@4.9.2-atmel3.5.4-arduino2 installed
Installing arduino:avrdude@6.3.0-arduino9
arduino:avrdude@6.3.0-arduino9 installed
Installing arduino:arduinoOTA@1.1.1
arduino:arduinoOTA@1.1.1 installed
Installing arduino:avr@1.6.21...
arduino:avr@1.6.21 installed

最後に

core ファイルをインストールした上で、再度Arduino Unoが認識できているか、再度 board list コマンドを叩いて確認してみます。

$ arduino-cli board list
FQBN            Port            ID          Board Name
arduino:avr:uno /dev/ttyACM0    2341:0043   Arduino/Genuino Uno

無事 arduino-cliで、arduino Unoが認識できました。

今回はデバイスの認識まででしたが、同様にaduino-cliを使ってさらに下記のようなことができます。

  • Libraryのインストール
  • スケッチのコンパイル
  • スケッチのアップロード
5
3
1

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
3