「Arduino」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(ページの作成:「Category:開発 Category:計算と科学 en:Arduino Arduino は柔軟で手軽なハードウェアとソフトウェアによる、オープンソースの...」)
 
(同期)
 
(4人の利用者による、間の12版が非表示)
1行目: 1行目:
 
[[Category:開発]]
 
[[Category:開発]]
[[Category:計算と科学]]
+
[[Category:科学]]
  +
[[de:Arduino]]
 
[[en:Arduino]]
 
[[en:Arduino]]
  +
[[zh-hans:Arduino]]
Arduino は柔軟で手軽なハードウェアとソフトウェアによる、オープンソースの電子工作プロトタイププラットフォームです。芸術家やデザイナー、ホビイスト、その他インタラクティブな機器や環境を作成したい全ての人を対象としています。詳細は [http://www.arduino.cc/ Arduino HomePage] を見て下さい。
 
  +
{{Related articles start}}
  +
{{Related|AVR}}
  +
{{Related articles end}}
  +
[[Wikipedia:ja:Arduino|Arduino]] は柔軟で手軽なハードウェアとソフトウェアによる、オープンソースの電子工作プロトタイププラットフォームです。芸術家やデザイナー、ホビイスト、その他インタラクティブな機器や環境を作成したい全ての人を対象としています。
  +
  +
デバイスを接続して設定すれば、シリアル接続で読み書きタスクを実行することができます。例としては、[[シリアルコンソール#接続|シリアル監視プログラム]]を使った、UART 経由のインターフェイスや、マイクロコントローラのプログラミングがあります。公式の Arduino IDE (公式リポジトリで利用可能) を使えば、プログラミング、コンパイル、及びコードのアップロードが容易になります。また、任意のコンパイラやプログラマを使って、マイクロコントローラのプログラミングを行うこともできます。
   
 
== インストール ==
 
== インストール ==
   
  +
* 次うちのどれかをインストールしてください: オリジナルの 1.x バージョン IDE の {{Pkg|arduino}}、公式 CLI の {{Pkg|arduino-cli}}、新しい 2.x IDE の {{AUR|arduino-ide-bin}}。1.x IDE のオフラインドキュメントは {{Pkg|arduino-docs}} でインストールできます。
* [[AUR]] から {{AUR|arduino}} をインストールしてください。
 
  +
* デバイスへの[[#シリアル通信|ユーザーによるアクセス]]を有効化してください。
* ユーザーを {{ic|uucp}} と {{ic|lock}} [[ユーザーとグループ|グループ]]に追加してください (詳しくは次のセクションを参照: "シリアル通信")。
 
* cdc_acm モジュールをロードする必要があ
+
* {{ic|cdc_acm}} モジュールを[[カーネルモジュール|ロード]]する必要があるかもしれせん
# modprobe cdc_acm
 
   
  +
=== Arduino IDE 1.x ===
* PKGBUILD の arch=('i686' 'x86_64') 行に 'armv6h' を追加して arch=('i686' 'x86_64' 'armv6h') とすることで Raspberry Pi 上でもビルドできます。
 
   
  +
以下のセクションは 1.x バージョンの IDE のみに適用されます。しかし、以下のいくつかは新しい方の IDE でも可能かもしれません。
=== Arduino Due / Yun ===
 
   
  +
==== AVR ボード ====
[http://arduino.cc/en/Main/arduinoBoardDue Arduino Due] と [http://arduino.cc/en/Main/ArduinoBoardYun Arduino Yun] は Arduino IDE バージョン 1.5 以上を必要とします。
 
   
  +
Arduino Uno などの AVR 基盤を使用する場合、任意で {{Pkg|arduino-avr-core}} をインストールすることで、バンドルされている古い avr-core の代わりに Arch Linux の上流の avr-gcc を使うことができます。古い arduino-core を使いたい場合 [https://docs.arduino.cc/learn/starting-guide/cores ボードマネージャでインストール] する必要があります。''Tools > Board'' メニューからコアをいつでも切り替えられます。
=== Pinoccio Scout ===
 
   
  +
==== Pinoccio Scout ====
[https://pinocc.io/ Pinoccio Scouts] も Arduino IDE を使ってプログラムすることが可能です。手順は [https://pinocc.io/solo こちら] に記載されています。もしくは、[[AUR]] から {{AUR|arduino-pinoccio}} をインストールすることもできます。
 
   
  +
[https://pinocc.io/ Pinoccio Scouts] も Arduino IDE を使ってプログラムすることが可能です。手順は [https://pinocc.io/solo こちら] に記載されています。
=== Intel Galileo ===
 
  +
もしくは、{{AUR|arduino-pinoccio}} をインストールすることもできます。
   
  +
==== Intel Galileo ====
[http://arduino.cc/en/ArduinoCertified/IntelGalileo Intel Galileo] ボードをサポートする Arduino IDE は [https://communities.intel.com/community/makers/software/drivers こちら] からダウンロードできます。
 
   
  +
Intel Galileo ボードを Arch Linux で使用したい場合、Arduino IDE をインストールし、''Tools > Board > Boards Manager'' から Galileo ツールのパッケージをダウンロードしてください。
=== Arm7 デバイス ===
 
  +
インストールを修正するには、[https://github.com/arduino/Arduino/issues/5523 こちらの github の投稿]に従ってください。
   
  +
=== Arduino IDE 1.x 及び 2.x ===
[http://blog.tklee.org/2014/10/arduino-ide-158-on-banana-pi.html こちら] に対処方法が載っています。
 
  +
  +
以下の手順は、両方のバージョンの IDE で有効であるはずです。
  +
  +
==== AVR ボード ====
  +
  +
AVR ボードは自動的に 2.x リリースの IDE によってインストールされますが、1.x と 2.x の両方のリリースで AVR ボードはボードマネージャから管理できます。1.x については[https://docs.arduino.cc/learn/starting-guide/cores こちら]を参照してください。
  +
  +
==== SparkFun ====
  +
  +
Pro Micro などの SparkFun ボードを使用するには、ボード定義をダウンロードしておく必要があります。詳細は、[https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide/installing-mac--linux こちら]と[https://github.com/sparkfun/Arduino_Boards こちら]を参照。
  +
  +
==== RedBear Duo ====
  +
  +
{{Pkg|perl-archive-zip}} をインストールしないと、crc32 が無いというエラーが発生するかもしれません。
   
 
== 設定 ==
 
== 設定 ==
   
  +
USB 経由での接続には、Arduino 上のインターフェイスチップが使用されます。純正のボードでは ATmegaxU2 が使用されていることが多いです (これは ACM デバイスとして認識されます)。Linux 上では、{{ic|cdc_acm}} [[カーネルモジュール|モジュール]]が使用されます。なので、Arduino が接続されると、Linux では {{ic|/dev/ttyACMx}} でアクセスできます。
=== シリアル通信 ===
 
   
  +
非純正の Arduino ボードでは安いインターフェイスチップが使用されていることが多く、たいてい中国製の CH34x ファミリが使用されます。CH34x は上述の標準規格を実装しておらず、デバイス自体を USB 経由でプロプライエタリな UART として公開します。この場合、{{ic|ch341}} [[カーネルモジュール|モジュール]]が使用され、Linux 上では {{ic|/dev/ttyUSBx}} でアクセスできます。デバイスファイルの命名規則は [[#Arduino デバイスの永続的な命名|udev ルールにより変更]]できます。
arduino ボードはシリアル接続や USB シリアル接続によってコンピュータと通信します。そのためシリアルデバイスファイルへの読み書きアクセス権がユーザーに必要となります。[[Udev]] は {{ic|uucp}} グループによって所有されている {{ic|/dev/tts/}} にファイルを作成するためユーザーを {{ic|uucp}} グループに追加することで必要な読み書き権限が与えられます。
 
   
  +
{{Note|コードのアップロード時には、プログラマ用にシリアルポートを開放するために、全てのシリアル監視プログラムを閉じてください。}}
gpasswd -a $USER uucp
 
gpasswd -a $USER lock
 
{{Note|変更を適用するには、一度ログアウトしてから再度ログインする必要があります。}}
 
   
  +
=== シリアル通信 ===
arduino ボードは {{ic|/dev/ttyACMx}} のように認識されます。上記の設定で上手くいかない場合、ユーザーを {{ic|tty}} グループに追加してみてください:
 
   
  +
USB 経由で UART を公開するボードの場合は、シリアルポートへの読み書きアクセス権をユーザに与える必要があります [https://arduino.stackexchange.com/a/21219]。[[Udev#通常ユーザーにデバイスの使用を許可する]] 章で説明されているように、以下のファイルを作成してください:
gpasswd -a $USER tty
 
   
  +
{{hc|/etc/udev/rules.d/01-ttyusb.rules|2=
Arduino にアップロードを行う前に、Tools メニューからシリアルポート、ボード、プロセッサを適切に設定してください。
 
  +
SUBSYSTEMS=="usb-serial", TAG+="uaccess"
  +
}}
  +
  +
[[Udev#新しいルールをロードする|Udev ルールを再読み込み]]し、Arduino デバイスを再度接続してください。Arduino 上にコードをアップロードする前に、Tools メニュー (バージョン 1.x) か IDE 上部の Select board オプション (バージョン 2.x) から適切なシリアルポート、ボード、プロセッサが設定されていることを確認してください。
   
 
== stty ==
 
== stty ==
   
  +
準備:
Preparing:
 
  +
 
# stty -F /dev/ttyACM0 cs8 9600 ignbrk -brkint -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts
 
# stty -F /dev/ttyACM0 cs8 9600 ignbrk -brkint -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts
   
  +
先のコマンドの後、Terminal から改行なしのコマンドを送信できます:
Sending commands through Terminal without new line after command
 
  +
 
# echo -n "Hello World" > /dev/ttyACM0
 
# echo -n "Hello World" > /dev/ttyACM0
{{Note| As autoreset on serial connection is activated by default on most boards, you need to disable this feature if you want to communicate directly with your board with the last command instead of a terminal emulator (arduino IDE, screen, picocom...). If you have a Leonardo board, you are not concerned by this, because it does not autoreset. If you have a Uno board, connect a 10 µF capacitor between the RESET and GND pins. If you have another board, connect a 120 ohms resistor between the RESET and 5V pins. See http://playground.arduino.cc/Main/DisablingAutoResetOnSerialConnection for more details.}}
 
   
  +
{{Note|ほとんどのボードでシリアル接続の自動リセットがデフォルトで有効化されているため、ターミナルエミュレータ (arduino IDE、screen、picocom...) を使わずにボードと直接通信する場合はこの機能を無効化しておく必要があります。Leonardo ボードは自動リセットしないため、このことを心配する必要はありません。Uno ボードの場合は、RESET ピンと GND ピンを 10 µF のコンデンサで繋げてください。その他のボードの場合は、RESET ピンと 5V ピンを 120 オームの抵抗で繋げてください。詳細は https://playground.arduino.cc/Main/DisablingAutoResetOnSerialConnection を参照してください。}}
Reading what your Arduino has to tell you
 
  +
  +
Arduino からデータを受信するには:
  +
 
$ cat /dev/ttyACM0
 
$ cat /dev/ttyACM0
   
== 他の IDE ==
+
== Arduino-Builder ==
   
  +
{{Out of date|このセクションは、2.x バージョンの IDE がリリースされる前に書かれたものであり、機能の説明が正確でないかもしれません。Arduino-Builder の GitHub のページには、Arduino-Builder は廃止予定で Arduino CLI に移行すると冒頭に書かれてあります。}}
=== ArduIDE ===
 
   
  +
{{Pkg|arduino-builder}} コマンドラインツールを使って Arduino のスケッチをビルドすることもできます。上流の {{Pkg|avr-gcc}} と {{Pkg|avrdude}} で {{Pkg|arduino-avr-core}} を使用するには設定ファイルの作成が必要です:
ArduIDE は Arduino 用の Qt ベース IDE です。[[AUR]] の {{AUR|arduide-git}} からインストールできます。
 
   
  +
{{hc|head=build.options.json |2=
ターミナルから作業したい場合、複数の選択肢が存在します。
 
  +
{
  +
"fqbn": "archlinux-arduino:avr:uno",
  +
"hardwareFolders": "/usr/share/arduino/hardware",
  +
"toolsFolders": "/usr/bin"
  +
}
  +
}}
   
  +
スケッチをコンパイルするには:
=== Arduino-CMake ===
 
   
  +
$ arduino-builder -build-options-file build.options.json blink.ino
Using [https://github.com/queezythegreat/arduino-cmake arduino-cmake] and [http://www.cmake.org/cmake/resources/software.html CMake] you can build Arduino firmware from the command line using multiple build systems. CMake lets you generate the build system that fits your needs, using the tools you like. It can generate any type of build system, from simple Makefiles, to complete projects for Eclipse, Visual Studio, XCode, etc.
 
   
  +
あるいはコマンドラインでオプションを渡す場合:
Requirements:
 
* [https://www.archlinux.org/packages/?sort=&q=cmake CMake]
 
* [https://aur.archlinux.org/packages/arduino/ Arduino SDK]
 
* [https://www.archlinux.org/packages/?sort=&q=gcc-avr gcc-avr]
 
* [https://www.archlinux.org/packages/?sort=&q=avr-binutils avr-binutils]
 
* [https://www.archlinux.org/packages/?sort=&q=avr-libc avr-libc]
 
* [https://www.archlinux.org/packages/?sort=&q=avrdude avrdude]
 
   
  +
$ arduino-builder -fqbn archlinux-arduino:avr:uno -hardware /usr/share/arduino/hardware -tools /usr/bin blink.ino
=== gnoduino ===
 
   
  +
== 他の IDE ==
{{AUR|gnoduino}} is an implementation of original Arduino IDE for GNOME available in the [[AUR]]. The original Arduino IDE software is written in Java. This is a Python implementation and it is targeted at GNOME but will work on xfce4 and other WM. Its purpose is to be light, while maintaining compatibility with the original Arduino IDE. The source editor is based on gtksourceview.
 
   
=== Ino ===
+
=== ArduIDE ===
   
  +
ArduIDE は Arduino 用の Qt ベースの IDE です。{{AUR|arduide-git}}{{Broken package link|package not found}} でインストールできます。
[https://github.com/amperka/ino Ino] is a command line toolkit for working with arduino hardware. {{AUR|ino}} is available in the [[AUR]].
 
   
  +
=== Arduino-CMake ===
Note that {{ic|Ino}} looks for the file {{ic|avrdude.conf}} in {{ic|/etc/avrdude/avrdude.conf}}, while [[pacman]] appears to place this file (upon installation of {{pkg|avrdude}}) in {{ic|/etc/avrdude.conf}}. In {{ic|Ino}} gives you troubles create the directory {{ic|/etc/avrdude}} and make the symlink:
 
ln -s /etc/avrdude.conf /etc/avrdude/avrdude.conf
 
   
  +
[https://github.com/a9183756-gh/Arduino-CMake-Toolchain Arduino-CMake-Toolchain] と [https://www.cmake.org/cmake/resources/software.html CMake] を使うことで、複数のビルド環境でコマンドラインから Arduino のファームウェアをビルドすることができます。CMake があなたのニーズに合わせたビルド環境を生成し、お好きなツールを使用できます。シンプルな Makefile から Eclipse、Visual Studio、XCode などのプロジェクトまであらゆるビルド環境を準備可能です。
=== Makefile ===
 
   
  +
必要なパッケージ: {{Pkg|cmake}}、{{Pkg|arduino}}、{{Pkg|avr-gcc}}、{{Pkg|avr-binutils}}、{{Pkg|avr-libc}}、{{Pkg|avrdude}}.
{{Note|Update 2015-03-23. Due to recent changes in Arduino ≥v1.5, many old Makefiles do not work without some modification. A simple Makefile for Arduino version 1.5+ can be found [https://github.com/tomswartz07/arduino-makefile on GitHub].}}
 
   
  +
=== Makefile ===
Instead of using the Arduino IDE it is possible to use another editor and a Makefile.
 
   
  +
Arduino IDE を使わずに、他のエディタと Makefile を使うこともできます。
Set up a directory to program your Arduino and copy the Makefile into this directory. A copy of the Makefile can be obtained from {{ic|/usr/share/arduino/hardware/cores/arduino/Makefile}}
 
   
  +
Arduino をプログラムするためのディレクトリをセットアップし、そのディレクトリへ Makefile をコピーしてください。Makefile のコピーは [https://github.com/tomswartz07/arduino-makefile GitHub にあるこのテンプレート]を使うことができます。設定にあわせて多少修正が必要です。Makefile には豊富に説明が付いています。以下は編集が必要な行の一例です:
You will have to modify this a little bit to reflect your settings. The makefile should be pretty self explanatory. Here are some lines you may have to edit.
 
   
PORT = usually /dev/ttyUSBx, where x is the usb serial port your arduino is plugged into
+
PORT = 通常は /dev/ttyUSBxx Arduino が接続されている USB シリアルポート
TARGET = your sketch's name
+
TARGET = スケッチの名前
 
ARDUINO = /usr/share/arduino/lib/targets/arduino
 
ARDUINO = /usr/share/arduino/lib/targets/arduino
   
  +
スケッチから呼び出されるライブラリ関数に合わせて、ライブラリをコンパイルする必要があります。そのために、SRC と CXXSRC を編集して必要なライブラリを include する必要があります。
Depending on which library functions you call in your sketch, you may need to compile parts of the library. To do that you need to edit your SRC and CXXSRC to include the required libraries.
 
   
  +
これで、{{ic|make && make upload}} を実行して、ボードにコードをアップロードして、スケッチを実行できるようになります。
Now you should be able to {{ic|make && make upload}} to your board to execute your sketch.
 
   
 
=== Arduino-mk ===
 
=== Arduino-mk ===
   
{{AUR|arduino-mk}} is another alternative Makefile approach. It allows users to have a local Makefile that includes Arduino.mk. See [https://github.com/sudar/Arduino-Makefile project page] for usage.
+
{{AUR|arduino-mk}} Makefile を使用するもうひとつのアプローチです。Arduino.mk include するローカルな Makefile を作成することができます。使い方は [https://github.com/sudar/Arduino-Makefile プロジェクトページ] を見てください。
   
  +
Arduino 1.5 の場合、以下のローカル Makefile を試してください (Arduino 1.5 のライブラリディレクトリの構造は少し変わっています):
For Arduino 1.5, try the following local Makefile (because Arduino 1.5's library directory structure is slightly different):
 
   
 
ARDUINO_DIR = /usr/share/arduino
 
ARDUINO_DIR = /usr/share/arduino
 
ARDMK_DIR = /usr/share/arduino
 
ARDMK_DIR = /usr/share/arduino
 
AVR_TOOLS_DIR = /usr
 
AVR_TOOLS_DIR = /usr
  +
AVRDUDE_CONF = /etc/avrdude.conf
ARDUINO_CORE_PATH = /usr/share/arduino/hardware/arduino/avr/cores/arduino
 
BOARDS_TXT = /usr/share/arduino/hardware/arduino/avr/boards.txt
+
ARDUINO_CORE_PATH = /usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino
ARDUINO_VAR_PATH = /usr/share/arduino/hardware/arduino/avr/variants
+
ARDUINO_PLATFORM_LIB_PATH = /usr/share/arduino/hardware/archlinux-arduino/avr/libraries
BOOTLOADER_PARENT = /usr/share/arduino/hardware/arduino/avr/bootloaders
+
BOARDS_TXT = /usr/share/arduino/hardware/archlinux-arduino/avr/boards.txt
  +
ARDUINO_VAR_PATH = /usr/share/arduino/hardware/archlinux-arduino/avr/variants
  +
BOOTLOADER_PARENT = /usr/share/arduino/hardware/archlinux-arduino/avr/bootloaders
 
 
 
 
126行目: 155行目:
 
include /usr/share/arduino/Arduino.mk
 
include /usr/share/arduino/Arduino.mk
   
In some cases you could need to install {{pkg|avr-libc}} and {{pkg|avrdude}}.
+
場合によっては {{pkg|avr-libc}} {{pkg|avrdude}} のインストールが必要です。
   
 
=== Scons ===
 
=== Scons ===
   
Using [http://www.scons.org/ scons] together with [https://github.com/suapapa/arscons arscons] it is very easy to use to compile and upload Arduino projects from the command line. Scons is based on python and you will need python-pyserial to use the serial interface. Install {{pkg|python-pyserial}} and {{pkg|scons}}.
+
[https://www.scons.org/ Scons] [https://github.com/suapapa/arscons arscons] を組み合わせて使うことでコマンドラインから簡単に Arduino プロジェクトをコンパイル・アップロードすることができます。Scons python で作成されており、シリアルインターフェイスを使うのに python-pyserial が必要です。{{pkg|python-pyserial}} {{pkg|scons}} をインストールしてください。
   
  +
パッケージをインストールすると必要な依存パッケージも一緒にインストールされます。上記のように Arduino 本体も必要なのでインストールしてください。プロジェクトディレクトリを作成したら (例: test)、新しいディレクトリに arduino のプロジェクトファイルを作成します。ディレクトリと同じ名前を付けて拡張子に .ino を追加してください (例: test.ino)。Arscons から [https://github.com/suapapa/arscons/blob/master/SConstruct SConstruct] スクリプトを取得してディレクトリに配置します。スクリプトの中身を確認して、必要であれば編集してください。中身は python スクリプトです。プロジェクトを編集したら、以下を実行してください:
That will get the dependencies you need too. You will also need Arduino itself so install it as described above. Create project directory (eg. test), then create a arduino project file in your new directory. Use the same name as the directory and add .ino (eg. test.ino). Get the [https://github.com/suapapa/arscons/blob/master/SConstruct SConstruct] script from arscons and put it in your directory. Have a peek in it and, if necessary, edit it. It is a python script. Edit your project as you please, then run
 
   
$ scons # This will build the project
+
$ scons # プロジェクトをビルドする
$ scons upload # This will upload the project to your Arduino
+
$ scons upload # プロジェクトを Arduino へアップロードする
   
 
=== PlatformIO ===
 
=== PlatformIO ===
   
  +
[https://docs.platformio.org/en/latest/core/quickstart.html PlatformIO] は複数のハードウェアプラットフォームのスケッチをビルド・アップロードすることができる [[python]] ツールです。現在、Arduino/AVR ベースの基盤、TI MSP430 や TI TM4C12x ボードに対応しています。近い将来、ライブラリ機能も追加して GitHub から直接ライブラリを検索できるようにすることを開発者は予定しています。
[http://docs.platformio.ikravets.com/en/latest/quickstart.html PlatformIO] is a python tool to build and upload sketches for multiple Hardware Platforms, at the moment of writing these are Arduino/AVR based boards, TI MSP430 and TI TM4C12x Boards. In the near future the author plans to add a library function that allows to search and include libraries directly from GitHub.
 
   
 
==== インストール ====
 
==== インストール ====
   
  +
{{pkg|platformio-core}} または {{AUR|platformio-git}} パッケージをインストールしてください。
Its recommended to use a virtual environment because platformio uses python2 because its based on SCons which does not support python3.
 
 
$ virtualenv --python=python2 venv
 
$ source ./venv/bin/activate
 
$ pip install platformio
 
   
 
==== 使用方法 ====
 
==== 使用方法 ====
 
$ platformio install atmelavr
 
$ platformio init
 
$ vim platformio.ini
 
   
  +
以下は、プロジェクトを作成しアップロードする方法を説明している公式の [https://docs.platformio.org/en/latest/core/quickstart.html PlatformIO クイックスタートガイド]を元にしています。
#
 
# Atmel AVR based board + Arduino Wiring Framework
 
#
 
[env:ArduinoMega2560]
 
platform = atmelavr
 
framework = arduino
 
board = megaatmega2560
 
upload_port = /dev/ttyACM0
 
targets = upload
 
   
  +
Platformio プロジェクト用の新しいディレクトリを作成し、そのディレクトリへ cd してください。
$ platformio run
 
  +
そして、以下のコマンドを実行し、プロジェクトを特定のボード用 (ここでは megaatmega2560) に初期化してください:
   
  +
$ pio project init --board megaatmega2560
===Emacs===
 
  +
  +
これで、ツールチェインと依存パッケージがダウンロードされます。次に、{{ic|platformio.ini}} を作成してください:
  +
  +
{{hc|platformio.ini|2=
  +
; PlatformIO Project Configuration File
  +
[env:megaatmega2560]
  +
platform = atmelavr
  +
board = megaatmega2560
  +
framework = arduino
  +
}}
  +
  +
src/ フォルダ内に main.cpp を作成し、コードを追加してください。コード例は[https://docs.platformio.org/en/latest/core/quickstart.html クイックスタートガイド]にあります。
  +
  +
そして、コードをコンパイルし、platformio.ini で指定したデバイスへアップロードしてください:
  +
  +
$ pio run
  +
$ pio run --target upload
  +
  +
=== Emacs ===
   
 
[[Emacs]] を IDE として設定することができます。
 
[[Emacs]] を IDE として設定することができます。
   
[[AUR]] から {{aur|emacs-arduino-mode-git}} パッケージをインストールして emacs で {{ic|arduino-mode}} を有効にしてください。
+
{{aur|emacs-arduino-mode-git}} パッケージをインストールして emacs で {{ic|arduino-mode}} を有効にしてください。
  +
  +
以下の init スクリプトを追加してください:
   
init スクリプトに追加:
 
 
{{hc|~/.emacs|
 
{{hc|~/.emacs|
 
;; arduino-mode
 
;; arduino-mode
180行目: 214行目:
 
(add-to-list 'auto-mode-alist '("\.ino$" . arduino-mode))}}
 
(add-to-list 'auto-mode-alist '("\.ino$" . arduino-mode))}}
   
You can compile and upload the sketches using {{ic|Arduino-mk}} (see above) with {{ic|M-x compile}} {{ic|make upload}}.
+
{{ic|Arduino-mk}} (上を参照) {{ic|M-x compile}} {{ic|make upload}} を使うことでスケッチをコンパイル・アップロードできます。
   
Main resource: [http://www.emacswiki.org/emacs/ArduinoSupport here].
+
[https://www.emacswiki.org/emacs/ArduinoSupport このページ]を参照。
   
 
== トラブルシューティング ==
 
== トラブルシューティング ==
   
  +
=== Arduino デバイスの永続的な命名 ===
=== Version 1.6 ===
 
   
  +
複数の Arduino を使っている場合、接続した順番で {{ic|/dev/ttyUSB[0-9]}} という名前がつけられているのに気づくかもしれません。IDE では大した問題ではありませんが、バックグラウンドで arduino プロジェクトと通信するようなソフトウェアをプログラムする場合、この仕様は問題となります。以下の ''udev'' ルールを使うことで、Arduino デバイスへ固定のシンボリックリンクを割り当てることができます:
As of Oct 5, 2014, most of the 3rd party tools only work for Arduino 1.0 ({{AUR|arduino10}}). Some of the tools may partially work for Arduino version 1.6 ({{AUR|arduino}}) and after. Check the version if the tools don't work.
 
   
=== Consistent naming of Arduino devices ===
 
 
If you have more than one arduino you may have noticed that they names /dev/ttyUSB[0-9] are assigned in the order of connection. In the IDE this is not so much of a problem, but when you have programmed your own software to communicate with an arduino project in the background this can be annoying. Use the following udev rules to assign static symlinks to your arduino's:
 
 
{{hc|/etc/udev/rules.d/52-arduino.rules|<nowiki>
 
{{hc|/etc/udev/rules.d/52-arduino.rules|<nowiki>
 
SUBSYSTEMS=="usb", KERNEL=="ttyUSB[0-9]*", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", SYMLINK+="sensors/ftdi_%s{serial}"
 
SUBSYSTEMS=="usb", KERNEL=="ttyUSB[0-9]*", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", SYMLINK+="sensors/ftdi_%s{serial}"
 
</nowiki>}}
 
</nowiki>}}
  +
Your arduino's will be available under names like "/dev/sensors/ftdi_A700dzaF". If you want you can also assign more meaningfull names to several devices like this:
 
  +
これで、Arduino に {{ic|/dev/sensors/ftdi_A700dzaF}} のような名前でアクセスできるようになります。もっと意味のある名前をデバイスにつけたい場合は:
  +
 
{{hc|/etc/udev/rules.d/52-arduino.rules|<nowiki>
 
{{hc|/etc/udev/rules.d/52-arduino.rules|<nowiki>
 
SUBSYSTEMS=="usb", KERNEL=="ttyUSB[0-9]*", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="A700dzaF", SYMLINK+="arduino/nano"
 
SUBSYSTEMS=="usb", KERNEL=="ttyUSB[0-9]*", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="A700dzaF", SYMLINK+="arduino/nano"
 
</nowiki>}}
 
</nowiki>}}
  +
which will create a symlink in /dev/arduino/nano to the device with the specified serialnumber.
 
  +
上記で指定したシリアル番号のデバイスのシンボリックリンクが {{ic|/dev/arduino/nano}} に作成されます。
You do need to unplug and replug your arduino for this to take effect or run
 
  +
Udev ルールの変更を適用するには、Arduino を接続しなおすか、以下のコマンドを実行する必要があります:
udevadm trigger
 
  +
  +
# udevadm trigger
  +
  +
一般的な {{ic|idVendor}}/{{ic|idProduct}} ペアは、ディストリビューションパッケージの {{ic|/usr/share/arduino/hardware/archlinux-arduino/avr/boards.txt}} で調べることができます。ただし、一部のペアは Arduino プラットフォームに固有のものではないことに注意してください (特に [[wikipedia:FTDI|FTDI]])。デバイスを識別する良い方法は {{ic|serial}} 属性を使うことです。
   
 
=== Error opening serial port ===
 
=== Error opening serial port ===
   
  +
IDE を起動したときシリアルポートが確認できても、アップロード時に TX/RX の LED が点灯しないことがあります。シリアルモニターで変更したボーレートが間違っている可能性があります。{{ic|~/.arduino/preferences.txt}} を編集して {{ic|serial.debug_rate}} を 115200 などの別の値にしてください。
You may see the serial port initially when the IDE starts, but the TX/RX leds do nothing when uploading. You may have previously changed the baudrate in the serial monitor to something it does not like. Edit ~/.arduino/preferences.txt so that serial.debug_rate is a different speed, like 115200.
 
   
  +
=== Uno/Mega2560 を使用する ===
=== Permissions to open serial port and create lockfile ===
 
   
  +
Arduino Uno と Mega2560 にはオンボード USB インターフェイス (Atmel 8U2) が存在しシリアルデータを受け取ります。そのため、デバイスを接続したときに cdc-acm カーネルモジュールによって作成される {{ic|/dev/ttyACM0}} からアクセスすることが可能です。
Arduino uses java-rxtx to do the serial communications. It expects to create lock files in {{ic|/var/lock/lockdev}}, so you need to be in the <tt>lock</tt> group. USB serial devices such as /dev/ttyUSB0 or /dev/ttyACM0 will often be assigned to the <tt>uucp</tt> group, so as long as you are adding yourself to groups, you should add that one too.
 
   
  +
シリアル接続をするには 8U2 ファームウェアのアップデートが必要な場合があります。詳しくは [https://forum.arduino.cc/t/easy-to-brick-arduino-uno-on-linux/47039] の #11 を確認してください。現在書き込むことができない Arduino の掲示板では、Uno を DFU にする方法が書かれている画像を見つけることができます。アカウントがなくて画像を閲覧できない場合、[https://www.scribd.com/doc/45913857/Arduino-UNO] を見てください。
=== Missing twi.o ===
 
   
  +
Uno をループバックモードにして 115200 ボーで Arduino のシリアルモニターに文字列を打ち込むことで機能のテストができます。文字列が返ってくるはずです。ループバックにするには、デジタル側でピン 0 -> 1 をショートさせてリセットボタンを押すか、入力する際に GND -> RESET ピンをショートさせてください。
If the file {{ic|/usr/share/arduino/lib/targets/libraries/Wire/utility/twi.o}} does not exist arduino may try to create it. Normal users do not have permission to write there so this will fail. Run arduino as root so it can create the file, after the file has been created arduino can be run under a normal user.
 
   
  +
=== 安い中国製クローンの Mega2560 で USB ポートが認識されない ===
=== Working with Uno/Mega2560 ===
 
   
  +
{{aur|i2c-ch341-dkms}} ドライバをインストールしてみてください。
The Arduino Uno and Mega2560 have an onboard USB interface (an Atmel 8U2) that accepts serial data, so they are accessed through /dev/ttyACM0 created by the cdc-acm kernel module when it is plugged in.
 
   
  +
=== ウィンドウマネージャで 1.x アプリケーションがリサイズできない、メニューがすぐに閉じてしまう ===
The 8U2 firmware may need an update to ease serial communications. See [http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1286350399] for more details and reply #11 for a fix. The original arduino bbs, where you can find an image explaining how to get your Uno into DFU, is now in a read-only state. If you do not have an account to view the image, see [http://www.scribd.com/doc/45913857/Arduino-UNO].
 
   
  +
[[Java#灰色のウィンドウ、ウィンドウマネージャでアプリがリサイズされない、メニューがすぐに閉じる]] を見てください。
You can perform a general function test of the Uno by putting it in loopback mode and typing characters into the arduino serial monitor at 115200 baud. It should echo the characters back to you. To put it in loopback, short pins 0 -> 1 on the digital side and either hold the reset button or short the GND -> RESET pins while you type.
 
   
  +
=== Fails to upload: programmer is not responding ===
=== error compiling ===
 
if you get following message (in verbose mode)
 
/usr/share/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../avr/bin/ld: cannot find -lm
 
   
  +
プロセッサの設定 (Arduino IDE の Tools->Processor) を {{ic|ATmega328P}} から {{ic|ATmega328P (Old Bootloader)}} に変更すると、アップロードの問題が解決することがあります。
see this fix [https://bbs.archlinux.org/viewtopic.php?pid=1343402#p1343402]
 
* install package avr-gcc
 
* Replace build-in avr-gcc compiler by same from package installed on previous step:
 
# cd /usr/share/arduino/hardware/tools/avr/bin
 
# mv ./avr-gcc ./avr-gcc-backup
 
# ln -s /usr/bin/avr-gcc ./
 
   
  +
=== インストール直後の状態で 1.x が java.lang.NullPointerException でクラッシュする ===
To use the avr tools that are system installed, remove the avr directory as per the Arduino Linux install page:
 
"If you want to use your system's compiler, delete the folder {{ic|./hardware/tools/avr}} in your arduino IDE installation"
 
   
  +
{{Pkg|arduino-avr-core}} をインストールする必要があります。
An alternate approach to take is to download the corresponding Linux install from Arduino.cc and replace the {{ic|/usr/share/arduino/hardware/tools/avr}} directory with the avr directory that comes in the stock installation archive.
 
   
  +
=== シリアルポートが brltty と衝突する ===
=== avrdude missing libtinfo.so.5 ===
 
When uploading a sketch to the Arduino, the following message is thrown in the Arduino UI concole:
 
/usr/share/arduino/hardware/tools/avr/bin/avrdude: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
 
   
  +
Arduino 用のシリアルポートが {{ic|/dev/ttyUSB*}} に無く、デバイス接続時に [[journal]] に以下のようなログが出力される場合:
Solve the dependency problem by creating a symbolic link
 
$ cd /usr/lib
 
$ sudo ln -s libncurses.so.5 libtinfo.so.5
 
   
  +
usb 3-1: usbfs: interface 0 claimed by ch341 while 'brltty' sets config #1
For more info:
 
  +
ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0
https://bbs.archlinux.org/viewtopic.php?pid=1108717#p1108717
 
  +
  +
{{Pkg|brltty}} をアンインストールする必要があるかもしれません。詳細は [https://forum.manjaro.org/t/cant-connect-serial-port-error-ch341-uart-disconnected-from-ttyusb0/87208] を見てください。
  +
  +
=== Nano RP2040 Connect でアップロードに失敗する ===
  +
  +
アップロードが以下のエラーで失敗する場合:
  +
  +
Failed uploading: uploading error: exit status 1
  +
  +
以下のスクリプトを実行して、Raspberry Pi RP2040 ブートローダーモードの udev ルールをセットアップしてみてください:
  +
  +
# ~/.arduino15/packages/arduino/hardware/mbed_nano/3.5.1/post_install.sh
   
 
== 参照 ==
 
== 参照 ==
   
* https://bbs.archlinux.org/viewtopic.php?pid=295312
+
* [https://www.arduino.cc/ 公式ウェブサイト]
  +
* [https://docs.arduino.cc/software/ide-v2/tutorials/getting-started-ide-v2 IDE v2 チュートリアルガイド]
* https://bbs.archlinux.org/viewtopic.php?pid=981348
 
* http://answers.ros.org/question/9097/how-can-i-get-a-unique-device-path-for-my-arduinoftdi-device/
+
* https://answers.ros.org/question/9097/how-can-i-get-a-unique-device-path-for-my-arduinoftdi-device/
  +
  +
{{TranslationStatus|Arduino|2023-12-13|794408}}

2023年12月13日 (水) 15:55時点における最新版

関連記事

Arduino は柔軟で手軽なハードウェアとソフトウェアによる、オープンソースの電子工作プロトタイププラットフォームです。芸術家やデザイナー、ホビイスト、その他インタラクティブな機器や環境を作成したい全ての人を対象としています。

デバイスを接続して設定すれば、シリアル接続で読み書きタスクを実行することができます。例としては、シリアル監視プログラムを使った、UART 経由のインターフェイスや、マイクロコントローラのプログラミングがあります。公式の Arduino IDE (公式リポジトリで利用可能) を使えば、プログラミング、コンパイル、及びコードのアップロードが容易になります。また、任意のコンパイラやプログラマを使って、マイクロコントローラのプログラミングを行うこともできます。

インストール

  • 次うちのどれかをインストールしてください: オリジナルの 1.x バージョン IDE の arduino、公式 CLI の arduino-cli、新しい 2.x IDE の arduino-ide-binAUR。1.x IDE のオフラインドキュメントは arduino-docs でインストールできます。
  • デバイスへのユーザーによるアクセスを有効化してください。
  • cdc_acm モジュールをロードする必要があるかもしれません。

Arduino IDE 1.x

以下のセクションは 1.x バージョンの IDE のみに適用されます。しかし、以下のいくつかは新しい方の IDE でも可能かもしれません。

AVR ボード

Arduino Uno などの AVR 基盤を使用する場合、任意で arduino-avr-core をインストールすることで、バンドルされている古い avr-core の代わりに Arch Linux の上流の avr-gcc を使うことができます。古い arduino-core を使いたい場合 ボードマネージャでインストール する必要があります。Tools > Board メニューからコアをいつでも切り替えられます。

Pinoccio Scout

Pinoccio Scouts も Arduino IDE を使ってプログラムすることが可能です。手順は こちら に記載されています。 もしくは、arduino-pinoccioAUR をインストールすることもできます。

Intel Galileo

Intel Galileo ボードを Arch Linux で使用したい場合、Arduino IDE をインストールし、Tools > Board > Boards Manager から Galileo ツールのパッケージをダウンロードしてください。 インストールを修正するには、こちらの github の投稿に従ってください。

Arduino IDE 1.x 及び 2.x

以下の手順は、両方のバージョンの IDE で有効であるはずです。

AVR ボード

AVR ボードは自動的に 2.x リリースの IDE によってインストールされますが、1.x と 2.x の両方のリリースで AVR ボードはボードマネージャから管理できます。1.x についてはこちらを参照してください。

SparkFun

Pro Micro などの SparkFun ボードを使用するには、ボード定義をダウンロードしておく必要があります。詳細は、こちらこちらを参照。

RedBear Duo

perl-archive-zip をインストールしないと、crc32 が無いというエラーが発生するかもしれません。

設定

USB 経由での接続には、Arduino 上のインターフェイスチップが使用されます。純正のボードでは ATmegaxU2 が使用されていることが多いです (これは ACM デバイスとして認識されます)。Linux 上では、cdc_acm モジュールが使用されます。なので、Arduino が接続されると、Linux では /dev/ttyACMx でアクセスできます。

非純正の Arduino ボードでは安いインターフェイスチップが使用されていることが多く、たいてい中国製の CH34x ファミリが使用されます。CH34x は上述の標準規格を実装しておらず、デバイス自体を USB 経由でプロプライエタリな UART として公開します。この場合、ch341 モジュールが使用され、Linux 上では /dev/ttyUSBx でアクセスできます。デバイスファイルの命名規則は udev ルールにより変更できます。

ノート: コードのアップロード時には、プログラマ用にシリアルポートを開放するために、全てのシリアル監視プログラムを閉じてください。

シリアル通信

USB 経由で UART を公開するボードの場合は、シリアルポートへの読み書きアクセス権をユーザに与える必要があります [1]Udev#通常ユーザーにデバイスの使用を許可する 章で説明されているように、以下のファイルを作成してください:

/etc/udev/rules.d/01-ttyusb.rules
SUBSYSTEMS=="usb-serial", TAG+="uaccess"

Udev ルールを再読み込みし、Arduino デバイスを再度接続してください。Arduino 上にコードをアップロードする前に、Tools メニュー (バージョン 1.x) か IDE 上部の Select board オプション (バージョン 2.x) から適切なシリアルポート、ボード、プロセッサが設定されていることを確認してください。

stty

準備:

# stty -F /dev/ttyACM0 cs8 9600 ignbrk -brkint -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts

先のコマンドの後、Terminal から改行なしのコマンドを送信できます:

# echo -n "Hello World" > /dev/ttyACM0
ノート: ほとんどのボードでシリアル接続の自動リセットがデフォルトで有効化されているため、ターミナルエミュレータ (arduino IDE、screen、picocom...) を使わずにボードと直接通信する場合はこの機能を無効化しておく必要があります。Leonardo ボードは自動リセットしないため、このことを心配する必要はありません。Uno ボードの場合は、RESET ピンと GND ピンを 10 µF のコンデンサで繋げてください。その他のボードの場合は、RESET ピンと 5V ピンを 120 オームの抵抗で繋げてください。詳細は https://playground.arduino.cc/Main/DisablingAutoResetOnSerialConnection を参照してください。

Arduino からデータを受信するには:

$ cat /dev/ttyACM0

Arduino-Builder

この記事またはセクションは情報が古くなっています。
理由: このセクションは、2.x バージョンの IDE がリリースされる前に書かれたものであり、機能の説明が正確でないかもしれません。Arduino-Builder の GitHub のページには、Arduino-Builder は廃止予定で Arduino CLI に移行すると冒頭に書かれてあります。 (Discuss)

arduino-builder コマンドラインツールを使って Arduino のスケッチをビルドすることもできます。上流の avr-gccavrdudearduino-avr-core を使用するには設定ファイルの作成が必要です:

build.options.json
{
    "fqbn": "archlinux-arduino:avr:uno",
    "hardwareFolders": "/usr/share/arduino/hardware",
    "toolsFolders": "/usr/bin"
}

スケッチをコンパイルするには:

$ arduino-builder -build-options-file build.options.json blink.ino

あるいはコマンドラインでオプションを渡す場合:

$ arduino-builder -fqbn archlinux-arduino:avr:uno -hardware /usr/share/arduino/hardware -tools /usr/bin blink.ino

他の IDE

ArduIDE

ArduIDE は Arduino 用の Qt ベースの IDE です。arduide-gitAUR[リンク切れ: package not found] でインストールできます。

Arduino-CMake

Arduino-CMake-ToolchainCMake を使うことで、複数のビルド環境でコマンドラインから Arduino のファームウェアをビルドすることができます。CMake があなたのニーズに合わせたビルド環境を生成し、お好きなツールを使用できます。シンプルな Makefile から Eclipse、Visual Studio、XCode などのプロジェクトまであらゆるビルド環境を準備可能です。

必要なパッケージ: cmakearduinoavr-gccavr-binutilsavr-libcavrdude.

Makefile

Arduino IDE を使わずに、他のエディタと Makefile を使うこともできます。

Arduino をプログラムするためのディレクトリをセットアップし、そのディレクトリへ Makefile をコピーしてください。Makefile のコピーは GitHub にあるこのテンプレートを使うことができます。設定にあわせて多少修正が必要です。Makefile には豊富に説明が付いています。以下は編集が必要な行の一例です:

PORT = 通常は /dev/ttyUSBx、x は Arduino が接続されている USB シリアルポート
TARGET = スケッチの名前
ARDUINO = /usr/share/arduino/lib/targets/arduino

スケッチから呼び出されるライブラリ関数に合わせて、ライブラリをコンパイルする必要があります。そのために、SRC と CXXSRC を編集して必要なライブラリを include する必要があります。

これで、make && make upload を実行して、ボードにコードをアップロードして、スケッチを実行できるようになります。

Arduino-mk

arduino-mkAUR は Makefile を使用するもうひとつのアプローチです。Arduino.mk を include するローカルな Makefile を作成することができます。使い方は プロジェクトページ を見てください。

Arduino 1.5 の場合、以下のローカル Makefile を試してください (Arduino 1.5 のライブラリディレクトリの構造は少し変わっています):

ARDUINO_DIR = /usr/share/arduino
ARDMK_DIR = /usr/share/arduino
AVR_TOOLS_DIR = /usr
AVRDUDE_CONF = /etc/avrdude.conf
ARDUINO_CORE_PATH = /usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino
ARDUINO_PLATFORM_LIB_PATH = /usr/share/arduino/hardware/archlinux-arduino/avr/libraries
BOARDS_TXT = /usr/share/arduino/hardware/archlinux-arduino/avr/boards.txt
ARDUINO_VAR_PATH = /usr/share/arduino/hardware/archlinux-arduino/avr/variants
BOOTLOADER_PARENT = /usr/share/arduino/hardware/archlinux-arduino/avr/bootloaders


BOARD_TAG    = uno
ARDUINO_LIBS =

include /usr/share/arduino/Arduino.mk

場合によっては avr-libcavrdude のインストールが必要です。

Scons

Sconsarscons を組み合わせて使うことでコマンドラインから簡単に Arduino プロジェクトをコンパイル・アップロードすることができます。Scons は python で作成されており、シリアルインターフェイスを使うのに python-pyserial が必要です。python-pyserialscons をインストールしてください。

パッケージをインストールすると必要な依存パッケージも一緒にインストールされます。上記のように Arduino 本体も必要なのでインストールしてください。プロジェクトディレクトリを作成したら (例: test)、新しいディレクトリに arduino のプロジェクトファイルを作成します。ディレクトリと同じ名前を付けて拡張子に .ino を追加してください (例: test.ino)。Arscons から SConstruct スクリプトを取得してディレクトリに配置します。スクリプトの中身を確認して、必要であれば編集してください。中身は python スクリプトです。プロジェクトを編集したら、以下を実行してください:

$ scons                # プロジェクトをビルドする
$ scons upload         # プロジェクトを Arduino へアップロードする

PlatformIO

PlatformIO は複数のハードウェアプラットフォームのスケッチをビルド・アップロードすることができる python ツールです。現在、Arduino/AVR ベースの基盤、TI MSP430 や TI TM4C12x ボードに対応しています。近い将来、ライブラリ機能も追加して GitHub から直接ライブラリを検索できるようにすることを開発者は予定しています。

インストール

platformio-core または platformio-gitAUR パッケージをインストールしてください。

使用方法

以下は、プロジェクトを作成しアップロードする方法を説明している公式の PlatformIO クイックスタートガイドを元にしています。

Platformio プロジェクト用の新しいディレクトリを作成し、そのディレクトリへ cd してください。 そして、以下のコマンドを実行し、プロジェクトを特定のボード用 (ここでは megaatmega2560) に初期化してください:

$ pio project init --board megaatmega2560

これで、ツールチェインと依存パッケージがダウンロードされます。次に、platformio.ini を作成してください:

platformio.ini
; PlatformIO Project Configuration File
[env:megaatmega2560]
platform = atmelavr
board = megaatmega2560
framework = arduino

src/ フォルダ内に main.cpp を作成し、コードを追加してください。コード例はクイックスタートガイドにあります。

そして、コードをコンパイルし、platformio.ini で指定したデバイスへアップロードしてください:

$ pio run
$ pio run --target upload

Emacs

Emacs を IDE として設定することができます。

emacs-arduino-mode-gitAUR パッケージをインストールして emacs で arduino-mode を有効にしてください。

以下の init スクリプトを追加してください:

~/.emacs
;; arduino-mode
(require 'cl)
(autoload 'arduino-mode "arduino-mode" "Arduino editing mode." t)
(add-to-list 'auto-mode-alist '("\.ino$" . arduino-mode))

Arduino-mk (上を参照) と M-x compile make upload を使うことでスケッチをコンパイル・アップロードできます。

このページを参照。

トラブルシューティング

Arduino デバイスの永続的な命名

複数の Arduino を使っている場合、接続した順番で /dev/ttyUSB[0-9] という名前がつけられているのに気づくかもしれません。IDE では大した問題ではありませんが、バックグラウンドで arduino プロジェクトと通信するようなソフトウェアをプログラムする場合、この仕様は問題となります。以下の udev ルールを使うことで、Arduino デバイスへ固定のシンボリックリンクを割り当てることができます:

/etc/udev/rules.d/52-arduino.rules
SUBSYSTEMS=="usb", KERNEL=="ttyUSB[0-9]*", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", SYMLINK+="sensors/ftdi_%s{serial}"

これで、Arduino に /dev/sensors/ftdi_A700dzaF のような名前でアクセスできるようになります。もっと意味のある名前をデバイスにつけたい場合は:

/etc/udev/rules.d/52-arduino.rules
SUBSYSTEMS=="usb", KERNEL=="ttyUSB[0-9]*", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="A700dzaF", SYMLINK+="arduino/nano"

上記で指定したシリアル番号のデバイスのシンボリックリンクが /dev/arduino/nano に作成されます。 Udev ルールの変更を適用するには、Arduino を接続しなおすか、以下のコマンドを実行する必要があります:

# udevadm trigger

一般的な idVendor/idProduct ペアは、ディストリビューションパッケージの /usr/share/arduino/hardware/archlinux-arduino/avr/boards.txt で調べることができます。ただし、一部のペアは Arduino プラットフォームに固有のものではないことに注意してください (特に FTDI)。デバイスを識別する良い方法は serial 属性を使うことです。

Error opening serial port

IDE を起動したときシリアルポートが確認できても、アップロード時に TX/RX の LED が点灯しないことがあります。シリアルモニターで変更したボーレートが間違っている可能性があります。~/.arduino/preferences.txt を編集して serial.debug_rate を 115200 などの別の値にしてください。

Uno/Mega2560 を使用する

Arduino Uno と Mega2560 にはオンボード USB インターフェイス (Atmel 8U2) が存在しシリアルデータを受け取ります。そのため、デバイスを接続したときに cdc-acm カーネルモジュールによって作成される /dev/ttyACM0 からアクセスすることが可能です。

シリアル接続をするには 8U2 ファームウェアのアップデートが必要な場合があります。詳しくは [2] の #11 を確認してください。現在書き込むことができない Arduino の掲示板では、Uno を DFU にする方法が書かれている画像を見つけることができます。アカウントがなくて画像を閲覧できない場合、[3] を見てください。

Uno をループバックモードにして 115200 ボーで Arduino のシリアルモニターに文字列を打ち込むことで機能のテストができます。文字列が返ってくるはずです。ループバックにするには、デジタル側でピン 0 -> 1 をショートさせてリセットボタンを押すか、入力する際に GND -> RESET ピンをショートさせてください。

安い中国製クローンの Mega2560 で USB ポートが認識されない

i2c-ch341-dkmsAUR ドライバをインストールしてみてください。

ウィンドウマネージャで 1.x アプリケーションがリサイズできない、メニューがすぐに閉じてしまう

Java#灰色のウィンドウ、ウィンドウマネージャでアプリがリサイズされない、メニューがすぐに閉じる を見てください。

Fails to upload: programmer is not responding

プロセッサの設定 (Arduino IDE の Tools->Processor) を ATmega328P から ATmega328P (Old Bootloader) に変更すると、アップロードの問題が解決することがあります。

インストール直後の状態で 1.x が java.lang.NullPointerException でクラッシュする

arduino-avr-core をインストールする必要があります。

シリアルポートが brltty と衝突する

Arduino 用のシリアルポートが /dev/ttyUSB* に無く、デバイス接続時に journal に以下のようなログが出力される場合:

usb 3-1: usbfs: interface 0 claimed by ch341 while 'brltty' sets config #1
ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0

brltty をアンインストールする必要があるかもしれません。詳細は [4] を見てください。

Nano RP2040 Connect でアップロードに失敗する

アップロードが以下のエラーで失敗する場合:

Failed uploading: uploading error: exit status 1

以下のスクリプトを実行して、Raspberry Pi RP2040 ブートローダーモードの udev ルールをセットアップしてみてください:

# ~/.arduino15/packages/arduino/hardware/mbed_nano/3.5.1/post_install.sh

参照

翻訳ステータス: このページは en:Arduino の翻訳バージョンです。最後の翻訳日は 2023-12-13 です。もし英語版に 変更 があれば、翻訳の同期を手伝うことができます。