Arduino

From Gentoo Wiki
Jump to: navigation, search
Resources

Arduino is an open source development platform using atmel microprocessors. This document describes how to use Arduino boards on Gentoo.

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 eventually for debugging.

  • Arduino NG -> FTDI
  • Arduino MEGA and most of the others (8U2, 16U2, 32U4) -> CDC ACM
KERNEL for FTDI chip (can also be a module)
Device Drivers  --->
    [*] USB support ---> 
      <*> USB Serial Converter support --->
        <*> USB FTDI Single Port Serial Driver
KERNEL for CDC ACM (can also be a module)
Device Drivers  --->
    [*] USB support ---> 
      <*> USB Modem (CDC ACM) support
  • Arduino NANO use CH341 serial converter chip
KERNEL for CH341 serial converter chip (can also be a module)
Device Drivers  --->
    [*] USB support ---> 
      <*> USB Serial Converter support --->
        <*> USB Winchiphead CH341 Single Port Serial Driver

After booting with the new kernel this can be tested after connecting the board to the computers USB port:

root #dmesg
after connect an Arduino NG

usb 5-4: FTDI USB Serial Device converter now attached to ttyUSB0
after connect an Arduino MEGA

cdc_acm 5-4:1.0: ttyACM0: USB ACM device

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 (avr atmel microprocessors) we have to install an cross development toolchain. We need three parts (Versions depend on your installation):

  • cross-avr/gcc-4.6.3
  • cross-avr/binutils-2.21.1-r1
  • cross-avr/avr-libc-1.8.0

this can be tested with:

root #emerge -pvv cross-avr/gcc cross-avr/binutils cross-avr/avr-libc

If gcc is already installed please pay attention of the use flag multilib. This have to be activated. These packages are not available until after you install crossdev.

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.

Take the opportunity to install crossdev if you don't have it:

root #emerge --ask crossdev


Build the avr toolchain with this command:

root #crossdev -s4 --stable --portage --verbose --target avr

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 also need 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

Install non Gentoo toolchain

Using the original Atmel AVR toolchain seems to be possible but not tested.

Using the Debian precompiled toolchain is described there.

Using arduino IDE

The arduino IDE can be installed with:

root #emerge --ask arduino
Note
At the moment avrdude is merged as a dependency of arduino although the arduino IDE seems to use its own avrdude package for downloading. Therefore don't take to much attention to gentoo's avrdude package.

After the start of arduino IDE (a link should be found in the application/development section of your start menu) the sketchbook location should be configured.
This is possible via the menu File/Preferences/Sketchbook location/.

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.

Note
Installation of eclipse IDE is out of the scope of this article. Please read Eclipse wiki for that topic.
Note
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.

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

FILE /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:

FILE /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).

Errors while compilation

/usr/share/arduino/hardware/arduino/cores/arduino/HardwareSerial.cpp:107:41: error: attempt to use poisoned "SIG_USART0_RECV"
/usr/share/arduino/hardware/arduino/cores/arduino/HardwareSerial.cpp:117:15: error: attempt to use poisoned "SIG_USART0_RECV"
/usr/share/arduino/hardware/arduino/cores/arduino/HardwareSerial.cpp:161:15: error: attempt to use poisoned "SIG_USART0_RECV"
/usr/share/arduino/hardware/arduino/cores/arduino/HardwareSerial.cpp:178:15: error: attempt to use poisoned "SIG_USART0_RECV"
/usr/share/arduino/hardware/arduino/cores/arduino/HardwareSerial.cpp:195:15: error: attempt to use poisoned "SIG_USART0_RECV"

To fix this manipulate your Arduino.h at the third line:

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

External resources