Arduino

提供: ArchWiki
2015年4月3日 (金) 18:55時点におけるKusakata (トーク | 投稿記録)による版 (ページの作成:「Category:開発 Category:計算と科学 en:Arduino Arduino は柔軟で手軽なハードウェアとソフトウェアによる、オープンソースの...」)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
ナビゲーションに移動 検索に移動

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

インストール

  • AUR から arduinoAUR をインストールしてください。
  • ユーザーを uucplock グループに追加してください (詳しくは次のセクションを参照: "シリアル通信")。
  • cdc_acm モジュールをロードする必要があります。
# modprobe cdc_acm
  • PKGBUILD の arch=('i686' 'x86_64') 行に 'armv6h' を追加して arch=('i686' 'x86_64' 'armv6h') とすることで Raspberry Pi 上でもビルドできます。

Arduino Due / Yun

Arduino DueArduino Yun は Arduino IDE バージョン 1.5 以上を必要とします。

Pinoccio Scout

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

Intel Galileo

Intel Galileo ボードをサポートする Arduino IDE は こちら からダウンロードできます。

Arm7 デバイス

こちら に対処方法が載っています。

設定

シリアル通信

arduino ボードはシリアル接続や USB シリアル接続によってコンピュータと通信します。そのためシリアルデバイスファイルへの読み書きアクセス権がユーザーに必要となります。Udevuucp グループによって所有されている /dev/tts/ にファイルを作成するためユーザーを uucp グループに追加することで必要な読み書き権限が与えられます。

gpasswd -a $USER uucp
gpasswd -a $USER lock
ノート: 変更を適用するには、一度ログアウトしてから再度ログインする必要があります。

arduino ボードは /dev/ttyACMx のように認識されます。上記の設定で上手くいかない場合、ユーザーを tty グループに追加してみてください:

gpasswd -a $USER tty

Arduino にアップロードを行う前に、Tools メニューからシリアルポート、ボード、プロセッサを適切に設定してください。

stty

Preparing:

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

Sending commands through Terminal without new line after command

# echo -n "Hello World" > /dev/ttyACM0
ノート: 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.

Reading what your Arduino has to tell you

$ cat /dev/ttyACM0

他の IDE

ArduIDE

ArduIDE は Arduino 用の Qt ベース IDE です。AURarduide-gitAUR からインストールできます。

ターミナルから作業したい場合、複数の選択肢が存在します。

Arduino-CMake

Using arduino-cmake and 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:

gnoduino

gnoduinoAUR 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

Ino is a command line toolkit for working with arduino hardware. inoAUR is available in the AUR.

Note that Ino looks for the file avrdude.conf in /etc/avrdude/avrdude.conf, while pacman appears to place this file (upon installation of avrdude) in /etc/avrdude.conf. In Ino gives you troubles create the directory /etc/avrdude and make the symlink:

ln -s /etc/avrdude.conf /etc/avrdude/avrdude.conf

Makefile

ノート: 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 on GitHub.

Instead of using the Arduino IDE it is possible to use another editor and a 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 /usr/share/arduino/hardware/cores/arduino/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
TARGET = your sketch's name
ARDUINO = /usr/share/arduino/lib/targets/arduino

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.

Now you should be able to make && make upload to your board to execute your sketch.

Arduino-mk

arduino-mkAUR is another alternative Makefile approach. It allows users to have a local Makefile that includes Arduino.mk. See project page for usage.

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
ARDMK_DIR = /usr/share/arduino
AVR_TOOLS_DIR = /usr
ARDUINO_CORE_PATH = /usr/share/arduino/hardware/arduino/avr/cores/arduino
BOARDS_TXT = /usr/share/arduino/hardware/arduino/avr/boards.txt
ARDUINO_VAR_PATH = /usr/share/arduino/hardware/arduino/avr/variants
BOOTLOADER_PARENT = /usr/share/arduino/hardware/arduino/avr/bootloaders


BOARD_TAG    = uno
ARDUINO_LIBS =

include /usr/share/arduino/Arduino.mk

In some cases you could need to install avr-libc and avrdude.

Scons

Using scons together with 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 python-pyserial and scons.

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 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 upload         # This will upload the project to your Arduino

PlatformIO

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.

インストール

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
#
# Atmel AVR based board + Arduino Wiring Framework
#
[env:ArduinoMega2560]
platform = atmelavr
framework = arduino
board = megaatmega2560   
upload_port = /dev/ttyACM0 
targets = upload
$ platformio run

Emacs

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

AUR から 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))

You can compile and upload the sketches using Arduino-mk (see above) with M-x compile make upload.

Main resource: here.

トラブルシューティング

Version 1.6

As of Oct 5, 2014, most of the 3rd party tools only work for Arduino 1.0 (arduino10AUR). Some of the tools may partially work for Arduino version 1.6 (arduinoAUR) 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:

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

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:

/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"

which will create a symlink in /dev/arduino/nano to the device with the specified serialnumber. You do need to unplug and replug your arduino for this to take effect or run

udevadm trigger

Error opening serial port

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.

Permissions to open serial port and create lockfile

Arduino uses java-rxtx to do the serial communications. It expects to create lock files in /var/lock/lockdev, so you need to be in the lock group. USB serial devices such as /dev/ttyUSB0 or /dev/ttyACM0 will often be assigned to the uucp group, so as long as you are adding yourself to groups, you should add that one too.

Missing twi.o

If the file /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.

Working with Uno/Mega2560

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.

The 8U2 firmware may need an update to ease serial communications. See [1] 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 [2].

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.

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

see this fix [3]

  • install package avr-gcc
  • Replace build-in avr-gcc compiler by same from package installed on previous step:
  1. cd /usr/share/arduino/hardware/tools/avr/bin
  2. mv ./avr-gcc ./avr-gcc-backup
  3. ln -s /usr/bin/avr-gcc ./

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 ./hardware/tools/avr in your arduino IDE installation"

An alternate approach to take is to download the corresponding Linux install from Arduino.cc and replace the /usr/share/arduino/hardware/tools/avr directory with the avr directory that comes in the stock installation archive.

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

Solve the dependency problem by creating a symbolic link

 $ cd /usr/lib
 $ sudo ln -s libncurses.so.5 libtinfo.so.5

For more info: https://bbs.archlinux.org/viewtopic.php?pid=1108717#p1108717

参照