Arduino on Gentoo Linux

Warning

Be aware that some of this guide requires the execution of commands with root privileges. If you do not know the risks involved please do not continue.

64-bit users

librxtx is reported to cause some problems on gentoo linux because of an overflow, causing the IDE to fail. This problem is noted at rxtx here. Please go here for fixed binaries.

Installing the Basics

First you need to log in as the superuser and install some necessary packages:

emerge -avq sun-jre-bin crossdev

As the Arduino IDE is written in Java sun-jre-bin is needed. crossdev allows the building of the AVR toolchain.

Building the Toolchain

Ensure that the file /etc/portage/make.conf has the following line:

source /var/lib/layman/make.conf

If it hasn't you probably need to install layman and follow the post-install instructions.

mkdir -pv /usr/local/portage

To build the toolchain:

USE="-openmp" crossdev -t avr -s4 -S --without-headers

"-S" ensures the use of stable package versions.

Obtain Toolchain from Atmel

If creating your own toolchain is not working, you can download a pre-built one from Atmel: http://www.atmel.com/tools/ATMELAVRTOOLCHAIN3_3_2FORLINUX.aspx

Configuring the Kernel for the Arduino's USB

This section is quite advanced and therefore a complete guide to kernel configuration is out of scope for this guide. The Gentoo documentation has a good guide on this topic.

The next step is to get the USB to serial adapter working. To save some time later I suggest that you first add your user to the tty and uucp groups. This is done by:

gpasswd -a YOUR_USERNAME tty uucp

Then you must check the permissions of /var/lock variable, and ensure that group uucp has write access to it. If not you cannot access your arduino board as normal user.

(at some point you'll need to logout and login again to apply this change). Then you need to enable support for the FTDI and/or for Uno and Mega the 8U2 (CDC ACM) in the kernel by setting:

Device Drivers -> USB support -> USB Serial Converter support -> USB FTDI Single Port Serial Driver

Device Drivers -> USB support -> USB Modem (CDC ACM) support

It should work either as a module or built into the kernel. Just for convenience its easiest to compile it as a module.

Once selected as [M] run the following command to compile, install and initialise the driver:

make && make modules && make modules_install && modprobe ftdi_sio

Next connect the Arduino board to the computer using a USB cable and then run dmesg. You should see something like:

usb 2-1: FTDI USB Serial Device converter now attached to ttyUSB0

Installing the packages (Emerging)

Run:

emerge arduino

If portage prints a message about keyword changes, you can use this command:

emerge --autounmask-write arduino || etc-update

and then finally run

emerge arduino

Now portage should compile and install all arduino packages.

Finishing Up

Hopefully at this stage you should be set to go; simply start "/opt/arduino/arduino" (or "/usr/bin/arduino" on newer systems) from your user shell or your desktop "run" command. (With older versions, you would need to be in the directory where it's installed, before you can start it. There is still a problem with symlinking it somewhere else... ideally you could make a symlink from /usr/local/bin/arduino to /opt/arduino/arduino, so that it's in your path, but as of version 0.21, you will then get an error about failing to find "processing/app/Base".)

With any luck the editor comes up without any error messages. Go to the tools menu and select /dev/ttyUSB0 as your serial port then try to upload one of the example sketches. If you get an error about the bootloader not responding then quit the editor and check in ~/.arduino/preferences.txt to make sure that serial.download_rate is set to the correct value for your board.

If uploading sketch fails with: avrdude: Yikes! Invalid device signature.

         Double check connections and try again, or use -F to override
         this check.

don't look for other version of avrdude, but edit file: /usr/share/arduino-0021/hardware/arduino/boards.txt

and change uploading protocol for your board e.g. change uno.upload.protocol=stk500 to uno.upload.protocol=arduino

And finally, to have arduino ide access the board as a normal user you must edit the ~/.arduino/preferences file and replace the: serial.port line with the following:

serial.port=/dev/ttyXXXX

where ttyXXXX is the device that is created when the board is connected.


NOTE: for AMD64 Gentoo users see this helpful link

If you want to use the Software Serial feature, you need to install version rxtx-2.2_pre2 or newer. This version is masked in the main portage tree, so you will need to unmask it by adding

  =dev-java/rxtx-2.2_pre2 ~x86 ~amd64

to /etc/portage/package.keywords, then emerge it

  emerge dev-java/rxtx

See also bug 340042 about some crossdev problems you might run into.

If you still have problems with uploading sketches (Arduino ide says: "Done Uploading" but nothing happen on the board) probably the problem is cross-avr/binutils that at version 2.21 seems to have problems uploading sketches, you can mask that package with

  echo "cross-avr/binutils-4.21" >> /etc/portage.mask

and emerge the package:

  emerge cross-avr/binutils

Now it emerge the 4.20 version of binutils. After that update probably you should have should face another problem, when arduino ide try to compile your sketch , it print the following error message:

  /usr/libexec/gcc/avr/ld: cannot open linker script file ldscripts/avr5.x: No such file or directory 

that will be solved with:

  ln -s /usr/lib/binutils/avr/2.20.1/ldscripts /usr/avr/lib/ldscripts 

If it print the following error message:

  /usr/libexec/gcc/avr/ld: cannot find crtm328p.o: No such file or directory

that will be solved with:

  ln -s /usr/avr/lib/avr5/crtm328p.o /usr/avr/lib/crtm328p.o

Originally by Jonny Stutters, Modified by Nick Stallman, Jon Noble, Shawn Rutledge, Soren Harward, Alexander BrĂ¼ning and Heiko Steindl, Ivan Gualandri.

Share