Arduino: Difference between revisions

From ArchWiki
m (Add zh-hans interlanguage link.)
m (The arduino-ide (2.x) package is now available in the extra repository.)
 
(69 intermediate revisions by 25 users not shown)
Line 1: Line 1:
[[Category:Development]]
[[Category:Development]]
[[Category:Science]]
[[Category:Science]]
[[de:Arduino]]
[[ja:Arduino]]
[[ja:Arduino]]
[[zh-hans:Arduino]]
[[zh-hans:Arduino]]
{{Related articles start}}
{{Related|AVR}}
{{Related articles end}}
[[Wikipedia:Arduino|Arduino]] is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It is intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments.
[[Wikipedia:Arduino|Arduino]] is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It is intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments.
Once hooked up and configured the user may perform read/write tasks over the established serial connection. Examples are interfacing over UART using a [[Working with the serial console#Making Connections|serial monitoring program]], or programming the microcontroller. Writing, compiling and uploading your code is facilitated by using the official Arduino IDE, which is available in the official repositories. Equally the user may use a compiler and programmer of choice to program the microcontroller.


== Installation ==
== Installation ==


* Install {{Pkg|arduino}} and {{Pkg|arduino-docs}} for its offline documentation.
* Install either {{Pkg|arduino}} for the original 1.x version of the IDE, {{Pkg|arduino-cli}} for the official CLI or {{Pkg|arduino-ide}} for the new 2.x release of the IDE. The offline documentation for the 1.x IDE can be installed via {{Pkg|arduino-docs}}.
* Add your user to the {{ic|uucp}} and {{ic|lock}} [[user group]]s (more information in the [[#Accessing serial]] section).
* Enable [[#Accessing serial|user access]] to the device.
* You may need to [[Kernel modules|load]] the {{ic|cdc_acm}} module.
* You may need to [[Kernel modules|load]] the {{ic|cdc_acm}} module.


=== AVR Boards ===
=== Arduino IDE 1.x ===
To use AVR boards such as the Arduino Uno you can install {{Pkg|arduino-avr-core}} optionally to use archlinux upstream avr-gcc instead of the bundled older avr-core. If you still want to use the older arduino-core you need to [https://www.arduino.cc/en/Guide/Cores install it in the board manager]. You can always switch between the different cores in the "Tools>Board" menu.
 
The following section only applies to the 1.x version of the IDE. However, it may be possible to adapt some of this for the new IDE.
 
==== AVR Boards ====
 
To use AVR boards such as the Arduino Uno you can install {{Pkg|arduino-avr-core}} optionally to use Arch Linux upstream avr-gcc instead of the bundled older avr-core. If you still want to use the older arduino-core you need to [https://docs.arduino.cc/learn/starting-guide/cores install it in the board manager]. You can always switch between the different cores in the ''Tools > Board'' menu.


=== Pinoccio Scout ===
==== Pinoccio Scout ====


[https://pinocc.io/ Pinoccio Scouts] can also be programmed using the Arduino IDE. Instructions can be found [https://pinocc.io/solo here].
[https://pinocc.io/ Pinoccio Scouts]{{Dead link|2024|01|13|status=domain name not resolved}} can also be programmed using the Arduino IDE. Instructions can be found [https://pinocc.io/solo here]{{Dead link|2024|01|13|status=domain name not resolved}}.
Alternative you can install {{AUR|arduino-pinoccio}} from the [[AUR]].
Alternative you can install {{AUR|arduino-pinoccio}}.


=== Intel Galileo ===
==== Intel Galileo ====


To use the Intel Galileo boards with Archlinux install the Arduino IDE and download the Galileo tools package via "Tools->Board->Boards Manager".
To use the Intel Galileo boards with Arch Linux install the Arduino IDE and download the Galileo tools package via ''Tools > Board > Boards Manager''.
To fix the installation you can follow [https://github.com/arduino/Arduino/issues/5523 this github post].
To fix the installation you can follow [https://github.com/arduino/Arduino/issues/5523 this github post].


=== On Arm7 devices ===
=== Arduino IDE 1.x or 2.x ===
 
These steps should be valid for both versions of the IDE.
 
==== AVR Boards ====


See [http://blog.tklee.org/2014/10/arduino-ide-158-on-banana-pi.html here] for a work around.
AVR boards are automatically installed by the 2.x release of the IDE however on both the 1.x and 2.x releases the AVR boards can be managed from the boards manager. For 1.x see [https://docs.arduino.cc/learn/starting-guide/cores here].


=== RedBear Duo ===
==== SparkFun ====


You might need to install {{Pkg|perl-archive-zip}} or you'll get an error about missing crc32.
To use SparkFun boards such as the Pro Micro you need to download their board definitions. More information [https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide/installing-mac--linux here] and [https://github.com/sparkfun/Arduino_Boards here].
 
==== RedBear Duo ====
 
You might need to install {{Pkg|perl-archive-zip}} or you will get an error about missing crc32.


== Configuration ==
== Configuration ==
To interface over USB an interfacing chip is used on the Arduino. Genuine boards will typically use an ATmegaxU2, which registers itself as an ACM device. On Linux the {{ic|cdc_acm}} [[Kernel modules|module]] is used. Hence, when connected, the Arduino will show up as {{ic|/dev/ttyACMx}}.
Non-genuine Arduino boards typically cheap out on the interfacing chip, typically using one from the Chinese CH34x family. The CH34x does not implement the aforementioned standard and exposes itself as a proprietary UART over USB device. Here the {{ic|ch341}} [[Kernel modules|module]] is used, making such Arduinos show up as {{ic|/dev/ttyUSBx}}. This naming pattern may be customized by [[#Consistent naming of Arduino devices|altering udev rules]].
{{Note|Remember to keep any serial monitoring programs closed during uploading code in order to free the serial port for the programmer.}}


=== Accessing serial ===
=== Accessing serial ===


The arduino board communicates with the computer via a serial connection or a serial-over-USB connection, so the user needs read/write access to the serial device file. [[Udev]] creates files such as {{ic|/dev/ttyUSB0}} owned by group {{ic|uucp}} so adding the user to the {{ic|uucp}} group gives the required read/write access. Also, if you are planning to use the default Java IDE, add your user to the {{ic|lock}} group for {{ic|/var/lock/lockdev}} access. See [[Users and groups#Group management]] for details.
For the boards that expose a UART over USB, it is  necessary to allow read/write access to the serial port to users[https://arduino.stackexchange.com/a/21219]. As explained in [[Udev#Allowing regular users to use devices]], create a file containing:


Before uploading to the Arduino, be sure to set the correct serial port, board, and processor from the Tools menu.
{{hc|/etc/udev/rules.d/01-ttyusb.rules|2=
SUBSYSTEMS=="usb-serial", TAG+="uaccess"
}}
 
[[Udev#Loading new rules|Reload the udev rules]] and replug the Arduino device. Before uploading to the Arduino, be sure to set the correct serial port, board, and processor from the Tools menu in 1.x and the Select board option (located at the top of the IDE) in 2.x.


== stty ==
== stty ==


Preparing:
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


Sending commands through Terminal without new line after command
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 an 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
{{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 an 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 https://playground.arduino.cc/Main/DisablingAutoResetOnSerialConnection for more details.}}
 
Reading what your Arduino has to tell you:
 
  $ cat /dev/ttyACM0
  $ cat /dev/ttyACM0


== Arduino-Builder ==
== Arduino-Builder ==
{{Out of date|This section was written before the release of the 2.x version of the IDE and the description of the functions might be inaccurate. On the GitHub page for the Arduino-Builder it has been stated that the Arduino-Builder is being phased out in favor of the Arduino CLI}}
You can also build Arduino sketches with the {{Pkg|arduino-builder}} command line tool. In order to use the provided {{Pkg|arduino-avr-core}} with upstream {{Pkg|avr-gcc}} and {{Pkg|avrdude}} you need to create a small settings file:
You can also build Arduino sketches with the {{Pkg|arduino-builder}} command line tool. In order to use the provided {{Pkg|arduino-avr-core}} with upstream {{Pkg|avr-gcc}} and {{Pkg|avrdude}} you need to create a small settings file:


{{hc|head=build.options.json |output=
{{hc|head=build.options.json |2=
{
{
     "fqbn": "archlinux-arduino:avr:uno",
     "fqbn": "archlinux-arduino:avr:uno",
Line 64: Line 101:


Compile a sketch with:
Compile a sketch with:
  $ arduino-builder -build-options-file build.options.json blink.ino
  $ arduino-builder -build-options-file build.options.json blink.ino


Or pass all options via command line:
Or pass all options via command line:
  $ arduino-builder -fqbn archlinux-arduino:avr:uno -hardware /usr/share/arduino/hardware -tools /usr/bin blink.ino
  $ arduino-builder -fqbn archlinux-arduino:avr:uno -hardware /usr/share/arduino/hardware -tools /usr/bin blink.ino


== Alternatives for IDE ==
== Alternatives to the IDE ==


=== ArduIDE ===
=== ArduIDE ===


ArduIDE is a Qt-based IDE for Arduino. {{AUR|arduide-git}} is available in the [[AUR]].
ArduIDE is a Qt-based IDE for Arduino, available with {{AUR|arduide-git}}{{Broken package link|package not found}}.
 
=== gnoduino ===
 
{{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.
 
 
If you prefer working from terminal, below there are some other options to choose from.


=== Arduino-CMake ===
=== Arduino-CMake ===


Using [https://github.com/arduino-cmake/Arduino-CMake-NG Arduino-CMake-NG] 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.
Using [https://github.com/a9183756-gh/Arduino-CMake-Toolchain Arduino-CMake-Toolchain] and [https://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: {{Pkg|cmake}}, {{Pkg|arduino}}, {{Pkg|avr-gcc}}, {{Pkg|avr-binutils}}, {{Pkg|avr-libc}}, {{Pkg|avrdude}}.
Requirements: {{Pkg|cmake}}, {{Pkg|arduino}}, {{Pkg|avr-gcc}}, {{Pkg|avr-binutils}}, {{Pkg|avr-libc}}, {{Pkg|avrdude}}.
=== Ino ===
[https://github.com/amperka/ino Ino] is a command line toolkit for working with arduino hardware. {{AUR|ino}} is available in the [[AUR]].


=== Makefile ===
=== Makefile ===
{{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].}}


Instead of using the Arduino IDE it is possible to use another editor and a Makefile.
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 {{ic|/usr/share/arduino/hardware/cores/arduino/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 [https://github.com/tomswartz07/arduino-makefile this GitHub template]
 
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.
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.


Line 112: Line 137:
=== 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}}{{Broken package link|package not found}} 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.


For Arduino 1.5, try the following local Makefile (because Arduino 1.5's library directory structure is slightly different):
For Arduino 1.5, try the following local Makefile (because Arduino 1.5's library directory structure is slightly different):
Line 121: Line 146:
  AVRDUDE_CONF = /etc/avrdude.conf
  AVRDUDE_CONF = /etc/avrdude.conf
  ARDUINO_CORE_PATH = /usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino
  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
  BOARDS_TXT = /usr/share/arduino/hardware/archlinux-arduino/avr/boards.txt
  ARDUINO_VAR_PATH = /usr/share/arduino/hardware/archlinux-arduino/avr/variants
  ARDUINO_VAR_PATH = /usr/share/arduino/hardware/archlinux-arduino/avr/variants
Line 135: Line 161:
=== 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}}.
Using [https://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}}.


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
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
Line 144: Line 170:
=== PlatformIO ===
=== PlatformIO ===


[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.
[https://docs.platformio.org/en/latest/core/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.


==== Installation ====
==== Installation ====


Install the {{AUR|platformio}} or {{AUR|platformio-git}} package.
Install the {{pkg|platformio-core}} or {{AUR|platformio-git}} package.


==== Usage ====
==== Usage ====
$ platformio platforms install atmelavr
$ platformio init
$ vim platformio.ini


#
The following is based on the official [https://docs.platformio.org/en/latest/core/quickstart.html PlatformIO quickstart guide], which shows how to create and upload an example project.
  # Atmel AVR based board + Arduino Wiring Framework
 
#
Create a new directory for the platformio project and enter the directory.
[env:ArduinoMega2560]
Then run the following command to initialize the project for a specific board (here the megaatmega2560):
platform = atmelavr
 
framework = arduino
  $ pio project init --board megaatmega2560
board = megaatmega2560 
 
upload_port = /dev/ttyACM0
This downloads the tool chain and dependencies, and creates {{ic|platformio.ini}}:
targets = upload
{{hc|platformio.ini|2=
; PlatformIO Project Configuration File
[env:megaatmega2560]
platform = atmelavr
board = megaatmega2560
framework = arduino
}}
 
Create and add code to main.cpp in the src/ folder such as the example code in the [https://docs.platformio.org/en/latest/core/quickstart.html quickstart guide].


  $ platformio run
Then compile the code and upload it to the devices specified in platformio.ini:
  $ pio run
$ pio run --target upload


===Emacs===
=== Emacs ===


It is possible to configure [[Emacs]] as IDE.
It is possible to configure [[Emacs]] as IDE.


Install the package {{aur|emacs-arduino-mode-git}} from the [[AUR]] in order to enable the {{ic|arduino-mode}} in emacs.
Install the package {{aur|emacs-arduino-mode-git}} in order to enable the {{ic|arduino-mode}} in emacs.


Add to the init script:
Add to the init script:
Line 183: Line 215:
You can compile and upload the sketches using {{ic|Arduino-mk}} (see above) with {{ic|M-x compile}} {{ic|make upload}}.
You can compile and upload the sketches using {{ic|Arduino-mk}} (see above) with {{ic|M-x compile}} {{ic|make upload}}.


Main resource: [http://www.emacswiki.org/emacs/ArduinoSupport here].
Main resource: [https://www.emacswiki.org/emacs/ArduinoSupport here].


== Troubleshooting ==
== Troubleshooting ==


=== Version 1.6 ===
=== Consistent naming of Arduino devices ===
 
Some older 3rd party tools may only work with Arduino 1.0 ({{AUR|arduino10}}). Some of the tools may partially work for Arduino version 1.6 ({{Pkg|arduino}}) and after. Check the version if the tools do not work. Note that some newer boards do not work with the old Arduino IDE.


=== Consistent naming of Arduino devices ===
If you have more than one Arduino you may have noticed that they names {{ic|/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:


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:
 
Your Arduino's will be available under names like {{ic|/dev/sensors/ftdi_A700dzaF}}. If you want you can also assign more meaningfull names to several devices like this:
 
{{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.
You do need to unplug and replug your arduino for this to take effect or run
udevadm trigger


Common {{ic|idVendor}}/{{ic|idProduct}} pairs can be found in {{ic|hardware/arduino/avr/boards.txt}} in the distribution package. Note that some of them (notably [[wikipedia:FTDI|FTDI]] ones) are not unique to the Arduino platform. Using {{ic|serial}} attribute is a good way to distinguish between various devices.
which will create a symlink in {{ic|/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
 
Common {{ic|idVendor}}/{{ic|idProduct}} pairs can be found in {{ic|/usr/share/arduino/hardware/archlinux-arduino/avr/boards.txt}} in the distribution package. Note that some of them (notably [[wikipedia:FTDI|FTDI]] ones) are not unique to the Arduino platform. Using {{ic|serial}} attribute is a good way to distinguish between various devices.


=== Error opening serial port ===
=== 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.
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 {{ic|~/.arduino/preferences.txt}} so that {{ic|serial.debug_rate}} is a different speed, like 115200.


=== Working with Uno/Mega2560 ===
=== 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 Arduino Uno and Mega2560 have an onboard USB interface (an Atmel 8U2) that accepts serial data, so they are accessed through {{ic|/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 [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].
The 8U2 firmware may need an update to ease serial communications. See [https://forum.arduino.cc/t/easy-to-brick-arduino-uno-on-linux/47039] 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 [https://www.scribd.com/doc/45913857/Arduino-UNO].


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.
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.
Line 223: Line 256:
Try installing its driver: {{aur|i2c-ch341-dkms}}.
Try installing its driver: {{aur|i2c-ch341-dkms}}.


=== Application not resizing with WM, menus immediately closing ===
=== 1.x Application not resizing with WM, menus immediately closing ===
 
see [[Java#Gray window, applications not resizing with WM, menus immediately closing]]
see [[Java#Gray window, applications not resizing with WM, menus immediately closing]]


=== Fails to upload: programmer is not responding ===
=== Fails to upload: programmer is not responding ===
Changing processor setting from {{ic|ATmega328P}} to {{ic|ATmega328P (Old Bootloader)}} (See Tools->Processor in Arduino IDE) may help with upload failures.
Changing processor setting from {{ic|ATmega328P}} to {{ic|ATmega328P (Old Bootloader)}} (See Tools->Processor in Arduino IDE) may help with upload failures.
=== 1.x Crashing with java.lang.NullPointerException after a fresh install ===
You need to install {{Pkg|arduino-avr-core}}.
=== Serial port conflict with brltty ===
If the serial port for the arduino is not visible at {{ic|/dev/ttyUSB*}}, and the [[journal]] contains the following when the device is connected:
usb 3-1: usbfs: interface 0 claimed by ch341 while 'brltty' sets config #1
ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0
Then you may need to uninstall the {{Pkg|brltty}} package. See [https://forum.manjaro.org/t/cant-connect-serial-port-error-ch341-uart-disconnected-from-ttyusb0/87208] for more details.
=== Failure to upload with Nano RP2040 Connect ===
If your upload fails with
Failed uploading: uploading error: exit status 1
{{Accuracy|Do not suggest to run arbitrary script, at least explain what it does.}}
Try running the following script to setup Raspberry Pi RP2040 bootloader mode udev rules.
# ~/.arduino15/packages/arduino/hardware/mbed_nano/3.5.1/post_install.sh


== See also ==
== See also ==


* [https://www.arduino.cc/ Official website]
* [https://www.arduino.cc/ Official website]
* https://bbs.archlinux.org/viewtopic.php?pid=295312
* [https://docs.arduino.cc/software/ide-v2/tutorials/getting-started-ide-v2 IDE v2 Getting Started Guide]
* https://bbs.archlinux.org/viewtopic.php?pid=981348
* https://answers.ros.org/question/9097/how-can-i-get-a-unique-device-path-for-my-arduinoftdi-device/
* http://answers.ros.org/question/9097/how-can-i-get-a-unique-device-path-for-my-arduinoftdi-device/
* https://www.reddit.com/r/archlinux/comments/8j53dq/how_do_i_install_ch340_chip_drivers_on_arch/

Latest revision as of 19:47, 9 April 2024

Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It is intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments.

Once hooked up and configured the user may perform read/write tasks over the established serial connection. Examples are interfacing over UART using a serial monitoring program, or programming the microcontroller. Writing, compiling and uploading your code is facilitated by using the official Arduino IDE, which is available in the official repositories. Equally the user may use a compiler and programmer of choice to program the microcontroller.

Installation

  • Install either arduino for the original 1.x version of the IDE, arduino-cli for the official CLI or arduino-ide for the new 2.x release of the IDE. The offline documentation for the 1.x IDE can be installed via arduino-docs.
  • Enable user access to the device.
  • You may need to load the cdc_acm module.

Arduino IDE 1.x

The following section only applies to the 1.x version of the IDE. However, it may be possible to adapt some of this for the new IDE.

AVR Boards

To use AVR boards such as the Arduino Uno you can install arduino-avr-core optionally to use Arch Linux upstream avr-gcc instead of the bundled older avr-core. If you still want to use the older arduino-core you need to install it in the board manager. You can always switch between the different cores in the Tools > Board menu.

Pinoccio Scout

Pinoccio Scouts[dead link 2024-01-13 ⓘ] can also be programmed using the Arduino IDE. Instructions can be found here[dead link 2024-01-13 ⓘ]. Alternative you can install arduino-pinoccioAUR.

Intel Galileo

To use the Intel Galileo boards with Arch Linux install the Arduino IDE and download the Galileo tools package via Tools > Board > Boards Manager. To fix the installation you can follow this github post.

Arduino IDE 1.x or 2.x

These steps should be valid for both versions of the IDE.

AVR Boards

AVR boards are automatically installed by the 2.x release of the IDE however on both the 1.x and 2.x releases the AVR boards can be managed from the boards manager. For 1.x see here.

SparkFun

To use SparkFun boards such as the Pro Micro you need to download their board definitions. More information here and here.

RedBear Duo

You might need to install perl-archive-zip or you will get an error about missing crc32.

Configuration

To interface over USB an interfacing chip is used on the Arduino. Genuine boards will typically use an ATmegaxU2, which registers itself as an ACM device. On Linux the cdc_acm module is used. Hence, when connected, the Arduino will show up as /dev/ttyACMx.

Non-genuine Arduino boards typically cheap out on the interfacing chip, typically using one from the Chinese CH34x family. The CH34x does not implement the aforementioned standard and exposes itself as a proprietary UART over USB device. Here the ch341 module is used, making such Arduinos show up as /dev/ttyUSBx. This naming pattern may be customized by altering udev rules.

Note: Remember to keep any serial monitoring programs closed during uploading code in order to free the serial port for the programmer.

Accessing serial

For the boards that expose a UART over USB, it is necessary to allow read/write access to the serial port to users[1]. As explained in Udev#Allowing regular users to use devices, create a file containing:

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

Reload the udev rules and replug the Arduino device. Before uploading to the Arduino, be sure to set the correct serial port, board, and processor from the Tools menu in 1.x and the Select board option (located at the top of the IDE) in 2.x.

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
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 an 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 https://playground.arduino.cc/Main/DisablingAutoResetOnSerialConnection for more details.

Reading what your Arduino has to tell you:

$ cat /dev/ttyACM0

Arduino-Builder

This article or section is out of date.

Reason: This section was written before the release of the 2.x version of the IDE and the description of the functions might be inaccurate. On the GitHub page for the Arduino-Builder it has been stated that the Arduino-Builder is being phased out in favor of the Arduino CLI (Discuss in Talk:Arduino)

You can also build Arduino sketches with the arduino-builder command line tool. In order to use the provided arduino-avr-core with upstream avr-gcc and avrdude you need to create a small settings file:

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

Compile a sketch with:

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

Or pass all options via command line:

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

Alternatives to the IDE

ArduIDE

ArduIDE is a Qt-based IDE for Arduino, available with arduide-gitAUR[broken link: package not found].

Arduino-CMake

Using Arduino-CMake-Toolchain 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: cmake, arduino, avr-gcc, avr-binutils, avr-libc, avrdude.

Makefile

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 this GitHub template 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[broken link: package not found] 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
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

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.

Installation

Install the platformio-core or platformio-gitAUR package.

Usage

The following is based on the official PlatformIO quickstart guide, which shows how to create and upload an example project.

Create a new directory for the platformio project and enter the directory. Then run the following command to initialize the project for a specific board (here the megaatmega2560):

$ pio project init --board megaatmega2560

This downloads the tool chain and dependencies, and creates platformio.ini:

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

Create and add code to main.cpp in the src/ folder such as the example code in the quickstart guide.

Then compile the code and upload it to the devices specified in platformio.ini:

$ pio run
$ pio run --target upload

Emacs

It is possible to configure Emacs as IDE.

Install the package emacs-arduino-mode-gitAUR in order to enable the arduino-mode in emacs.

Add to the init script:

~/.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.

Troubleshooting

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

Common idVendor/idProduct pairs can be found in /usr/share/arduino/hardware/archlinux-arduino/avr/boards.txt in the distribution package. Note that some of them (notably FTDI ones) are not unique to the Arduino platform. Using serial attribute is a good way to distinguish between various devices.

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.

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 [2] 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 [3].

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.

Not recognizing USB port with Mega2560 cheap Chinese clones

Try installing its driver: i2c-ch341-dkmsAUR.

1.x Application not resizing with WM, menus immediately closing

see Java#Gray window, applications not resizing with WM, menus immediately closing

Fails to upload: programmer is not responding

Changing processor setting from ATmega328P to ATmega328P (Old Bootloader) (See Tools->Processor in Arduino IDE) may help with upload failures.

1.x Crashing with java.lang.NullPointerException after a fresh install

You need to install arduino-avr-core.

Serial port conflict with brltty

If the serial port for the arduino is not visible at /dev/ttyUSB*, and the journal contains the following when the device is connected:

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

Then you may need to uninstall the brltty package. See [4] for more details.

Failure to upload with Nano RP2040 Connect

If your upload fails with

Failed uploading: uploading error: exit status 1

The factual accuracy of this article or section is disputed.

Reason: Do not suggest to run arbitrary script, at least explain what it does. (Discuss in Talk:Arduino)

Try running the following script to setup Raspberry Pi RP2040 bootloader mode udev rules.

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

See also