This is Gentoo's testing wiki. It is a non-operational environment and its textual content is outdated.
Please visit our production wiki at https://wiki.gentoo.org
Arduino
Arduino is an open source development platform. This document describes how to use the platform on Gentoo. Note that in addition to official and clone Arduino products based on Atmel AVR microprocessors, the environment can also support other Atmel AVR microprocessors (such as ATtiny13), nRF52, STM32 microprocessors, etc.
Prepare the kernel for USB connection
The arduino boards will be connected via USB to the computer. With this connection it is possible to write binaries to the atmega microprocessor and get debug messages from the board during run mode. Different boards have different USB interface chips. In case you prefer to use ICSP programming with an external adapter you don't need this for programming any more, but you may still need it for debugging.
Arduino NG (FTDI)
'"`UNIQ--pre-00000000-QINU`"'
Arduino MEGA, 8U2, 16U2, 32U4 (CDC ACM)
'"`UNIQ--pre-00000003-QINU`"'
Arduino NANO (CH340)
These have used a range of serial converter chips, but mostly they use CH340.
'"`UNIQ--pre-00000006-QINU`"'
Validate connectivity
After booting with the new kernel this can be tested after connecting the board to the computers USB port:
root #
dmesg
'"`UNIQ--pre-00000009-QINU`"'
'"`UNIQ--pre-0000000C-QINU`"'
Grant access
Every user who are privileged to connect to the board should be added to the uucp group.
root #
usermod -a -G uucp user
Prepare the toolchain
Because we need to compile code into binaries for another target platform (Atmel AVR microprocessors) we have to install a cross development toolchain.
Recommended: Install the toolchain using crossdev
If you haven't already, check out the section on Creating a cross-compiler from the Embedded Handbook. This will give you a good introduction to crossdev and how it works.
Installing crossdev
Install crossdev if you don't have it.
root #
emerge --ask crossdev
Should you have any issues running crossdev, try upgrading to a more recent masked or unstable version.
Creating the local overlay
Before building the toolchain, you need to create a local overlay called crossdev.
The crossdev overlay will be auto-selected by the crossdev tool to build packages for all crossdev-targeted platforms — so creating only this one overlay is enough to ensure that all of the crossdev built packages remain completely separate from the native packages for your system.
These commands are a quick installation method. For more details please refer to the custom repository page, Crossdev section.
root #
mkdir -p /usr/local/portage-crossdev/{profiles,metadata}
root #
echo 'crossdev' > /usr/local/portage-crossdev/profiles/repo_name
root #
echo 'masters = gentoo' > /usr/local/portage-crossdev/metadata/layout.conf
root #
chown -R portage:portage /usr/local/portage-crossdev
Then instruct portage and crossdev to use this overlay:
/etc/portage/repos.conf/crossdev.conf
[crossdev] location = /usr/local/portage-crossdev priority = 10 masters = gentoo auto-sync = no
Build and install the toolchain
OK, now you're all set. The toolchain to build is specific to the architecture you are targeting with your development. Most arduino users want the AVR toolchain only.
AVR (Arduino/Genuino/ATmicro/ATmega/etc.)
Build and install the AVR toolchain with this command:
root #
crossdev -s4 --stable --portage --verbose --target avr
This works as of January 2018.
An older alternative recommendation from the arduino overlay is this command:
root #
USE="-nls -openmp -pch -sanitize -vtv" crossdev -t avr -s4 --without-headers
ARM (STM32/GD32/etc.)
root #
crossdev -s4 --stable --portage --verbose --target arm
Troubleshooting
Should you have any issues running crossdev, try upgrading to a more recent masked or unstable version.
In the event you have problems with the gcc stages, try:
root #
USE="-openmp -hardened -sanitize -vtv" crossdev -s4 --stable --portage --verbose --target avr
You may also need a workaround so that the linking works as expected (see bug 147155).
For amd64:
root #
ln -s /usr/x86_64-pc-linux-gnu/avr/lib/ldscripts /usr/avr/lib/ldscripts
Or x86:
root #
ln -s /usr/i686-pc-linux-gnu/avr/lib/ldscripts /usr/avr/lib/ldscripts
Discouraged: Install non-Gentoo toolchain
Using the original Atmel AVR toolchain seems to be possible but not tested.
Using the Debian precompiled toolchain is described over here.
Installing the arduino IDE
Portage tree
There is currently up to date of arduino IDE in official gentoo tree:
root #
emerge =dev-embedded/arduino-1.8.5
Many thanks to Virgil Dupras (hsoft).
Arduino overlay
- Benefit: Currently up to date. Packaged. Updates through portage possible. Pure command line (no IDE) possible.
- Drawback: Unofficial distribution with unofficial packages.
In order to make use of the arduino-overlay...
/etc/portage/repos.conf/arduino-overlay.conf
Add the arduino overlay[arduino-overlay] priority = 50 location = /var/lib/arduino-overlay sync-type = git sync-uri = https://github.com/mapmot/arduino-overlay.git auto-sync = Yes
Then you can check out the overlay...
root #
emerge --sync
Then install the command line sketch build tool.
root #
emerge -av =dev-embedded/arduino-builder-1.3.25
Then install the IDE.
root #
emerge -av =dev-embedded/arduino-1.8.5
Official download
- Benefit: Always up to date.
- Drawback: Not packaged for Gentoo. All or nothing. Not built from source. Requires manual updates.
Official tarball downloads (including beta and hourly versions).
Configuring the Arduino IDE
After first start of Arduino IDE (a link should be found in the application/development section of your start menu) it will create default sketch directory ~/Arduino. This location can be changed in preferences (File/Preferences/Sketchbook location:).
If you are targeting any platforms that aren't included in the default distribution (such as ATtiny processors or ARM processors such as the STM32 or GD32) then you will need to install new Arduino platform implementations, which are known as 'cores'. Cores can then be associated with board definitions. Some example cores...
- ARM
- STM32/GD32: stm32duino
- Nordic Semiconductor
- Atmel AVR
- ATtiny Series
- ATtiny13: MCUdude/MicroCore
- ATtiny24/25/44/45/85: damellis/attiny
- ATmega Series
- ATmega64/128/640/1280/1281/2560/2561: MCUdude/MegaCore
- ATmega16/32/164/324/644/1284/8535: MCUdude/MightyCore
- ATtiny Series
- XTensa (see also esp-open-sdk)
- Espressif
- ESP8266: esp8266/Arduino (see also esp8266.com)
- ESP31B/32: espressif/arduino-esp32 (older ESP31B support)
- Espressif
Using eclipse IDE
After installing eclipse IDE you can choose between two eclipse plugins. Plugins can be installed via provided update sites. Simply add the given site via eclipse menu/help/software-updates/add-site.
Installation of eclipse IDE is out of the scope of this article. Please read Eclipse wiki for that topic.
There are major changes since arduino installation version 1 (formerly versions were "022" etc.). Also major changes since arduino installation version 1.5.x where done. Last but not least the plugin "Arduino Eclipse Extension" has reworked between version 1.2.4 and version 2.x to support the new arduino way (more details there) so the version 2.x is only compatible with eclipse juno (not helios and not indigo). Please choose the right version of eclipse for your needs!
Arduino Eclipse Extension
Arduino Eclipse Extension is a free eclipse plugin for arduino projects developed by Jantje. It depends on the installation of arduino IDE.
Use the update site "http://www.baeyens.it/eclipse/update" for the installation of a plugin version which is compatible with arduino 1.0.4 and eclipse helios and indigo.
Use the update site "http://www.baeyens.it/eclipse/V2" for installation of a plugin version which is compatible with arduino 1.5.x and eclipse juno.
AVR Eclipse Plugin
AVR Eclipse Plugin is a free eclipse plugin for developing boards with avr atmel microprocessors. It is not especially make for the arduino boards, but it can used for that. It is not necessary to install arduino IDE for using that plugin. More informations can be found on the wiki site.
Use the update site "http://avr-eclipse.sourceforge.net/updatesite/" for installation of the plugin which is known to work with eclipse helios.
V1 of the Arduino Eclipse Extension contains the AVR Eclipse Plugin as such you can not have both on your eclipse without confusion. V2 no longer includes the AVR Eclipse Plugin so you can easily install AVR Eclipse Plugin next to the Arduino Eclipse Extension.
Tips and Tricks
udev rule for Arduino NG
This rule can be used to make an symlink /dev/arduino, especially usefull in case of more than one arduino boards. For example create an file 12-mikrocontroller.rules and add the line below:
/etc/udev/rules.d/12-mikrocontroller.rules
SUBSYSTEMS=="usb", ATTRS{product}=="FT232R USB UART", ATTRS{manufacturer}=="FTDI", NAME="ttyUSB%n", SYMLINK+="arduino"
udev rule for Arduino MEGA
This rule can be used to make an symlink /dev/arduino, especially usefull in case of more than one arduino boards.
For example create an file 12-mikrocontroller.rules and add the line below:
/etc/udev/rules.d/12-mikrocontroller.rules
SUBSYSTEMS=="usb", ATTRS{product}=="Arduino Mega 2560", ATTRS{manufacturer}=="Arduino (www.arduino.cc)", NAME="ttyACM%n", SYMLINK+="arduino"
Troubleshooting
Problem with deprecated items in avr-libc v1.8.0 and above (and Mega 2560)
If you can see the messages below you have found this compatibility issue (arduino forum).
'"`UNIQ--pre-00000016-QINU`"'
To fix this manipulate your Arduino.h at the third line:
/usr/share/arduino/hardware/arduino/cores/arduino/Arduino.h
#ifndef Arduino_h #define Arduino_h //start: fix the compatibility issue #define __AVR_LIBC_DEPRECATED_ENABLE__ 1 //end: fix the compatibility issue #include <stdlib.h> ...
See also
For MSP430 support, take a look at Energia.
External resources
- Embedded Handbook - More information about embedded systems, cross compiling, and other related topics.
- Outdated guide for arduino on Gentoo (arduino official hosted site).
- Arduino eclipse extension main site.
- AVR section on old crossdev wiki page