Arduino programming from Linux, gentoo-way, quick start
Unfortunately, the information needed to connect Arduino to a computer turned out to be fragmented from various sources in different languages. As you know, gentoo is a linux distribution with continuous development, in fact, there can be no such thing as a “distribution” in it. Because of this, a solution to a problem found on the Internet may not be functional simply because the target system has a different set of packages and settings.
In addition, authors, as a rule, give commands and solutions specific to a particular system at a particular point in time. Some time passes, product versions change, some paths and files change. This article is an attempt not only to consolidate information, but also to present it in such a way that the information is as old as possible and it is easy to modify the commands for your system. Perhaps this will be useful in other distributions.
After connecting the converter to the USB port, we see the following:
For this converter, the ftdi_sio driver is needed, I prefer not to add to the kernel what is not needed when the system boots, but to compile it in the form of a module. I do not use Genkernel, and you can compile the kernel in a way convenient for you.
We compile the module and load:
We have an interface:
Pay attention to the rights. You must add your user to the uucp group
If you use another converter, then add support to the kernel, otherwise everything should be the same.
Onlyrelevant for 64-bit systems:
At the time of writing, the stable version of the package isdev-java / rxtx-2.1.7.2-r3 , but the Arduino firmware will not work with it, you must install dev-java / rxtx-2.2_pre2 . Probably when a new stable version appears, the problem will be fixed.
Installation:
You can use the SDK or JRE, if you do not know if you need an SDK, then you do not need it, and choose sun-jre-bin:
Due to licensing restrictions, you will have to manually download the appropriate source file and copy it to / usr / portage / distfiles. In addition, VM is distributed under a separate license, so you need to add it to the make.conf file:
Make sure the correct VM is selected:
Add a line to the /etc/make.conf file, if it is not already there, and create a directory:
We compile the toolchain, the default options correspond to stage4 and the use of stable packages:
Since there is not a single stable version, then most likely it will not appear soon. Therefore, just install the latest version. Unlock the following packages by adding the following lines to the /etc/portage/package.keywords file:
You can add flags to install examples and documentation:
Installation:
We select your Arduino option in the Tools -> Board menu and Tools -> Serial Port - the port that appeared after the converter was connected, usually it is / dev / ttyUSB0. The simplest Blink sketch was already loaded on my board by the manufacturer, so to check how everything works, I modified it: now the LED blinks alternately with a short and long flash:
Click the “Check” checkbox and the “Download” arrow and you will be happy. In fact, it may not be, because it is necessary to eliminate some more problems, and more on that below.
If everyone checked, try rebooting the system, in one case it helped me.
the reason is that the paths along which the toolchain is installed do not match the paths where the arduino is looking for it. First we find where the file is:
then create a symbolic link:
For your board, the file name may be different, but the solution is the same; you need to create the corresponding symbolic link. We are looking for a file:
create a link:
UPDATE: 03/28/2013
The problem is that all of the above works, everything is compiled, assembled and loaded into the board without the slightest error. But the firmware does not work. In my case, the board simply blinks an LED, the second is on, it goes off for a second, that is, the classic Blink.
The solution is described here , the bug is registered on Gentoo's Bugzilla .
To solve the problem, reinstall the toolchain as follows:
Everything written above regarding incorrect paths remains valid.
UPDATE: 04/13/2013
The board itself and how to use it interested me in the context of building the Smart Home system. Now I have a major overhaul of the apartment in full swing, and I can lay any cables, place any junction boxes, etc.
In addition, authors, as a rule, give commands and solutions specific to a particular system at a particular point in time. Some time passes, product versions change, some paths and files change. This article is an attempt not only to consolidate information, but also to present it in such a way that the information is as old as possible and it is easy to modify the commands for your system. Perhaps this will be useful in other distributions.
For reference, the target system
Amd64 architecture, x86_64 kernel 3.7.10-gentoo
Stable packages of the latest versions are installed.
At an ebay auction, an Arduino Pro Mini 328p 16MHz 5V board and a USB converter to it on an FTDI chip were bought.
Stable packages of the latest versions are installed.
At an ebay auction, an Arduino Pro Mini 328p 16MHz 5V board and a USB converter to it on an FTDI chip were bought.
Install kernel support for USB converter
After connecting the converter to the USB port, we see the following:
# tail / var / log / messages my-pc kernel: usb 6-1: new full-speed USB device number 2 using uhci_hcd my-pc kernel: usb 6-1: New USB device found, idVendor = 0403, idProduct = 6001 my-pc kernel: usb 6-1: New USB device strings: Mfr = 1, Product = 2, SerialNumber = 3 my-pc kernel: usb 6-1: Product: FT232R USB UART my-pc kernel: usb 6-1: Manufacturer: FTDI my-pc kernel: usb 6-1: SerialNumber: A900eYdz
For this converter, the ftdi_sio driver is needed, I prefer not to add to the kernel what is not needed when the system boots, but to compile it in the form of a module. I do not use Genkernel, and you can compile the kernel in a way convenient for you.
Device Drivers ---> [*] USB support --->USB Serial Converter support ---> USB FTDI Single Port Serial Driver
We compile the module and load:
# make && make modules_install # modprobe ftdi_sio
#tail -f / var / log / messages my-pc kernel: usbcore: registered new interface driver usbserial my-pc kernel: usbcore: registered new interface driver usbserial_generic my-pc kernel: usbserial: USB Serial support registered for generic my-pc kernel: usbcore: registered new interface driver ftdi_sio my-pc kernel: usbserial: USB Serial support registered for FTDI USB Serial Device my-pc kernel: ftdi_sio 6-1: 1.0: FTDI USB Serial Device converter detected my-pc kernel: usb 6-1: Detected FT232RL my-pc kernel: usb 6-1: Number of endpoints 2 my-pc kernel: usb 6-1: Endpoint 1 MaxPacketSize 64 my-pc kernel: usb 6-1: Endpoint 2 MaxPacketSize 64 my-pc kernel: usb 6-1: Setting MaxPacketSize 64 my-pc kernel: usb 6-1: FTDI USB Serial Device converter now attached to ttyUSB0
We have an interface:
# ls -l / dev / ttyUSB0 crw-rw ---- 1 root uucp, March 0 9 13:04 AM / dev / ttyUSB0
Pay attention to the rights. You must add your user to the uucp group
# usermod -aG uucp
If you use another converter, then add support to the kernel, otherwise everything should be the same.
Install or update rxtx package
emerge dev-java / rxtx
Only
At the time of writing, the stable version of the package is
# echo = dev-java / rxtx-2.2_pre2 ~ amd64 >> /etc/portage/package.keywords
Installation:
emerge = dev-java / rxtx-2.2_pre2
Installing java virtual machine sun
You can use the SDK or JRE, if you do not know if you need an SDK, then you do not need it, and choose sun-jre-bin:
# emerge dev-java / sun-jdk or # emerge dev-java / sun-jre-bin
Due to licensing restrictions, you will have to manually download the appropriate source file and copy it to / usr / portage / distfiles. In addition, VM is distributed under a separate license, so you need to add it to the make.conf file:
ACCEPT_LICENSE = "Oracle-BCLA-JavaSE"
Make sure the correct VM is selected:
# eselect java-vm list Available Java Virtual Machines: [1] sun-jre-bin-1.6 system-vm
Setting the compilation toolchain environment
# emerge sys-devel / crossdev app-portage / layman
Add a line to the /etc/make.conf file, if it is not already there, and create a directory:
# echo source /var/lib/layman/make.conf >> /etc/make.conf # mkdir -pv / usr / local / portage
We compile the toolchain, the default options correspond to stage4 and the use of stable packages:
# crossdev -t avr
Installing the IDE itself for programming
Since there is not a single stable version, then most likely it will not appear soon. Therefore, just install the latest version. Unlock the following packages by adding the following lines to the /etc/portage/package.keywords file:
dev-embedded / arduino ~ amd64 dev-embedded / uisp ~ amd64
You can add flags to install examples and documentation:
echo dev-embedded / arduino doc examples >> /etc/portage/package.use
Installation:
# emerge arduino
We start arduino
We select your Arduino option in the Tools -> Board menu and Tools -> Serial Port - the port that appeared after the converter was connected, usually it is / dev / ttyUSB0. The simplest Blink sketch was already loaded on my board by the manufacturer, so to check how everything works, I modified it: now the LED blinks alternately with a short and long flash:
/*
Blink A Morse code
Turns on an LED on adruino 'Dot - Dash - Pause'
*/
// Pin 13 has an LED connected on most Arduino boards.
int led = 13;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
void loop() {
digitalWrite(led, HIGH);
delay(200);
digitalWrite(led, LOW);
delay(200);
digitalWrite(led, HIGH);
delay(500);
digitalWrite(led, LOW);
delay(500);
}
Click the “Check” checkbox and the “Download” arrow and you will be happy. In fact, it may not be, because it is necessary to eliminate some more problems, and more on that below.
Problems:
If the serial port selection item is deactivated, then again you need to return to the beginning of the article and
- check kernel converter support:
#zgrep FTDI /proc/config.gz CONFIG_USB_SERIAL_FTDI_SIO = m
- the presence of the module in memory:
# lsmod | grep ftdi
- You can try to restart it:
# modprobe -r ftdi_sio # modprobe ftdi_sio
- check rxtx version:
# qlist -ICv rxtx dev-java / rxtx-2.2_pre2
If everyone checked, try rebooting the system, in one case it helped me.
When compiling, an error is output:
/ usr / libexec / gcc / avr / ld: cannot open linker script file ldscripts / avr5.x: There is no such file or directory collect2: error: ld execution failed with return code 1
the reason is that the paths along which the toolchain is installed do not match the paths where the arduino is looking for it. First we find where the file is:
# find / usr / -name avr5.x /usr/lib64/binutils/avr/2.23.1/ldscripts/avr5.x
then create a symbolic link:
# ln -s /usr/lib64/binutils/avr/2.23.1/ldscripts / usr / avr / lib / ldscripts
When compiling, an error is output:
/ usr / libexec / gcc / avr / ld: cannot find crtm328p.o: There is no such file or directory collect2: error: ld execution failed with return code 1
For your board, the file name may be different, but the solution is the same; you need to create the corresponding symbolic link. We are looking for a file:
# find / usr / -name crtm328p.o /usr/avr/lib/avr5/crtm328p.o
create a link:
# ln -s /usr/avr/lib/avr5/crtm328p.o / usr / avr / lib /
UPDATE: 03/28/2013
There is a problem with binutils version higher than 2.19
The problem is that all of the above works, everything is compiled, assembled and loaded into the board without the slightest error. But the firmware does not work. In my case, the board simply blinks an LED, the second is on, it goes off for a second, that is, the classic Blink.
The solution is described here , the bug is registered on Gentoo's Bugzilla .
To solve the problem, reinstall the toolchain as follows:
crossdev -C avr
USE = "multilib -cxx" crossdev --b 2.19.1-r1 -S -s1 --target avr
USE = "multilib cxx" crossdev --b 2.19.1-r1 -S -s4 --target avr
Everything written above regarding incorrect paths remains valid.
UPDATE: 04/13/2013
For systems with a hardened core:
USE = "multilib-cxx nopie-nossp -hardened -pic -openmp" crossdev --b 2.19.1-r1 -S -s1 --target avr
USE = "multilib-cxx nopie -hardened -pic -openmp" crossdev --b 2.19.1-r1 -S -s4 --target avr
Instead of a conclusion
The board itself and how to use it interested me in the context of building the Smart Home system. Now I have a major overhaul of the apartment in full swing, and I can lay any cables, place any junction boxes, etc.
Content
- Arduino programming from Linux, gentoo-way, quick start
- Arduino programming from the console, gentoo-way, nothing more
Used sources
- playground.arduino.cc/linux/gentoo
- forums.gentoo.org/viewtopic-t-907860.html
- arduino.cc/en/Tutorial/blink
- forums.gentoo.org/viewtopic-t-834097.html
- bugs.gentoo.org/show_bug.cgi?id=147155
- lpig.wordpress.com/2011/09/28/arduino-and-gentoo
- en.gentoo-wiki.com/wiki/Crossdev
- bugs.gentoo.org/show_bug.cgi?id=378387