Difference between revisions of "Arduino"

From ArchWiki
Jump to: navigation, search
(Installation)
(replaced external links (https://github.com/lahwaacz/wiki-scripts/blob/master/link-checker.py (interactive)))
 
(83 intermediate revisions by 48 users not shown)
Line 1: Line 1:
 
[[Category:Development]]
 
[[Category:Development]]
 
[[Category:Mathematics and science]]
 
[[Category:Mathematics and science]]
 +
[[ja: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. More information is available on the [http://www.arduino.cc/ Arduino HomePage].
 
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. More information is available on the [http://www.arduino.cc/ Arduino HomePage].
  
==Installation==
+
== Installation ==
  
* Install {{AUR|arduino}} from the [[Arch User Repository|AUR]].
+
* Install {{AUR|arduino}} from the [[AUR]].
* Add yourself to the {{ic|uucp}} [[Users and Groups|group]]. (More information in the next section: "Accessing serial")
+
* Add yourself to the {{ic|uucp}} and {{ic|lock}} [[groups]] (more information in the [[#Accessing serial]] section).
 +
* You may need to [[Kernel modules|load]] the {{ic|cdc_acm}} module.
  
===Arduino Due===
+
=== Arduino Due / Yun ===
You need the version 1.5beta of the arduino ide. You can download an archive with the compiled version at the [http://arduino.cc/en/Main/Software Arduino software download] page.
+
  
==Configuration==
+
The [http://arduino.cc/en/Main/arduinoBoardDue Arduino Due] and the [http://arduino.cc/en/Main/ArduinoBoardYun Arduino Yun] need the version 1.5 or newer of the Arduino IDE.
  
===Accessing serial===
+
=== Pinoccio Scout ===
  
The arduino board communicates with the PC 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 in /dev/tts/ owned by group uucp so adding the user to the uucp group gives the required read/write access.
+
[https://pinocc.io/ Pinoccio Scouts] can also be programmed using the Arduino IDE. Instructions can be found [https://pinocc.io/solo here].
 +
Alternative you can install {{AUR|arduino-pinoccio}} from the [[AUR]].
  
gpasswd -a <user> uucp
+
=== Intel Galileo ===
  
{{Note|You will have to logout and login again for this to take effect.}}
+
The version of the Arduino IDE that supports the [http://arduino.cc/en/ArduinoCertified/IntelGalileo Intel Galileo] board can be downloaded [https://communities.intel.com/community/makers/software/drivers here].
  
Briefly run the {{ic|arduino}} command and stop it, then modify {{ic|~/.arduino/preferences.txt}} .
+
=== On Arm7 devices ===
  
Change serial port from COM1 to your serial port. With your arduino board connected, you can find out what your serial port is with:
+
See [http://blog.tklee.org/2014/10/arduino-ide-158-on-banana-pi.html here] for a work around.
  
  ls /dev/ttyUSB* /dev/ttyACM*
+
== Configuration ==
  
If in doubt, unconnect the board and look which of these disappears, and/or monitor {{ic|/var/log/everything.log}}.
+
=== 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 in {{ic|/dev/tts/}} owned by group {{ic|uucp}} so adding the user to the {{ic|uucp}} group gives the required read/write access. If you are planing to use the default Java IDE, add your user to the lock group for {{ic|/var/lock/lockdev}} access.
 +
 
 +
# gpasswd -a $USER uucp
 +
# gpasswd -a $USER lock
 +
{{Note|You will have to logout and login again for this to take effect.}}
  
The line to change in {{ic|~/.arduino/preferences.txt}} should look something like this when you are done:
+
The arduino board appears as {{ic|/dev/ttyACMx}} so if the above does not work try adding the user to the group {{ic|tty}}:
  
  serial.port=/dev/ttyACM3
+
# gpasswd -a $USER tty
  
Rerun {{ic|arduino}}. If you get a message like "Arduino Uno on /dev/tty*" message in the GUI's lower right corner, connection has been established.
+
Before uploading to the Arduino, be sure to set the correct serial port, board, and processor from the Tools menu.
  
 
== 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 a 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
 
Reading what your Arduino has to tell you
  cat /dev/ttyACM0
+
  $ cat /dev/ttyACM0
  
==Working with Uno/Mega2560==
+
== Alternatives for IDE ==
  
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.
+
=== ArduIDE ===
 
+
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].
+
 
+
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.
+
 
+
== Running Arduino Uno ==
+
  
Once Arduino is running you must ensure you have selected the correct board from the Tools->Boards menu item:
+
ArduIDE is a Qt-based IDE for Arduino. {{AUR|arduide-git}} is available in the [[AUR]].
Arduino Uno
+
  
Secondly you must ensure you have selected the correct serial port from the Tools->Serial Port menu item as explained above.
+
=== gnoduino ===
  
Once these are done you should be able to write and upload sketches to your Arduino Uno without any issues.
+
{{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.
  
==Alternatives for IDE==
 
 
===ArduIDE===
 
 
ArduIDE is a Qt-based IDE for Arduino. {{aur|arduide-git}} is available in the [[AUR]].
 
  
 
If you prefer working from terminal, below there are some other options to choose from.
 
If you prefer working from terminal, below there are some other options to choose from.
  
===gnoduino===
+
=== Arduino-CMake ===
  
{{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.
+
Using [https://github.com/queezythegreat/arduino-cmake arduino-cmake] 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.
  
===Scons===
+
Requirements:
 +
* [https://www.archlinux.org/packages/?sort=&q=cmake CMake]
 +
* [https://aur.archlinux.org/packages/arduino/ Arduino SDK]
 +
* [https://www.archlinux.org/packages/?sort=&q=avr-gcc avr-gcc]
 +
* [https://www.archlinux.org/packages/?sort=&q=avr-binutils avr-binutils]
 +
* [https://www.archlinux.org/packages/?sort=&q=avr-libc avr-libc]
 +
* [https://www.archlinux.org/packages/?sort=&q=avrdude avrdude]
  
Using [http://www.scons.org/ scons] together with [http://code.google.com/p/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 everything with
+
=== Ino ===
  
# pacman -S python-pyserial scons
+
[https://github.com/amperka/ino Ino] is a command line toolkit for working with arduino hardware. {{AUR|ino}} is available in the [[AUR]].
  
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 .pde (eg. test.pde). Get the [http://arscons.googlecode.com/git/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
+
Note that {{ic|Ino}} looks for the file {{ic|avrdude.conf}} in {{ic|/etc/avrdude/avrdude.conf}}, while [[pacman]] appears to place this file (upon  installation of {{pkg|avrdude}}) in {{ic|/etc/avrdude.conf}}. If {{ic|Ino}} gives you troubles create the directory {{ic|/etc/avrdude}} and make the symlink:
 +
ln -s /etc/avrdude.conf /etc/avrdude/avrdude.conf
  
$ scons                # This will build the project
+
=== Makefile ===
$ scons upload        # This will upload the project to your Arduino
+
  
===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].}}
Update 2011-03-12. Arduino Is not shipping a Makefile with version (22). The Makefile from the [http://code.google.com/p/dogm128/source/browse/libraries/Dogm/examples/SpaceTrash/Makefile.uno_dogs102 dogm128] project works for me though.
+
  
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 /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 {{ic|/usr/share/arduino/hardware/cores/arduino/Makefile}}
  
You will have to modify this a little bit to reflect your settings. The makefile should be pretty self explainatory. 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.
  
 
  PORT = usually /dev/ttyUSBx, where x is the usb serial port your arduino is plugged into
 
  PORT = usually /dev/ttyUSBx, where x is the usb serial port your arduino is plugged into
Line 101: Line 103:
 
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.
 
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.
+
Now you should be able to {{ic|make && make upload}} to your board to execute your sketch.
  
===Arduino-CMake===
+
=== Arduino-mk ===
  
Using [https://github.com/queezythegreat/arduino-cmake arduino-cmake] 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.
+
{{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.
  
Requirements:
+
For Arduino 1.5, try the following local Makefile (because Arduino 1.5's library directory structure is slightly different):
* [https://www.archlinux.org/packages/?sort=&q=cmake CMake]
+
* [https://aur.archlinux.org/packages.php?ID=8388 Arduino SDK]
+
* [https://www.archlinux.org/packages/?sort=&q=gcc-avr gcc-avr]
+
* [https://www.archlinux.org/packages/?sort=&q=binutils-avr binutils-avr]
+
* [https://www.archlinux.org/packages/?sort=&q=avr-libc avr-libc]
+
* [https://www.archlinux.org/packages/?sort=&q=avrdude avrdude]
+
  
==Troubleshooting==
+
ARDUINO_DIR = /usr/share/arduino
 
+
ARDMK_DIR = /usr/share/arduino
===delay() function does not work===
+
AVR_TOOLS_DIR = /usr
{{Out of date|the current arduino-git package is reported in the talk page as not being affected by this issue.|section=Update troubleshooting?}}
+
ARDUINO_CORE_PATH = /usr/share/arduino/hardware/arduino/avr/cores/arduino
There are some cases where the delay() function does not work, causing programs such as the example [http://www.arduino.cc/en/Tutorial/Blink Blink] to malfunction.
+
  BOARDS_TXT = /usr/share/arduino/hardware/arduino/avr/boards.txt
It appears that the Arch compiler sometimes generates code that writes to addresses before the start of memory. RAM starts at address 0x200 on the mega, but the Blink code has the delay() timer variables located at 0x100-0x10b. This only seems to happen when the code contains no initialized global variables (.data segment in asm-speak) - the linker is told that the data segment starts at 0x200, but if there is nothing to go in it it generates an incorrect start address for the uninitialized global variables (.bss segment). Since the timer variables are uninitialized globals (or globals initialized to zero) they end up at an illegal address.
+
ARDUINO_VAR_PATH = /usr/share/arduino/hardware/arduino/avr/variants
 
+
BOOTLOADER_PARENT = /usr/share/arduino/hardware/arduino/avr/bootloaders
There are currently two ways to bypass this issue.
+
 
+
* Use '''Serial.begin(9600);''' in '''setup()''' function. [[http://forums.adafruit.com/viewtopic.php?f=25&t=21075 Source post]]
+
 
+
{{bc|
+
/*
+
  Blink
+
  Turns on an LED on for one second, then off for one second, repeatedly.
+
 
   
 
   
  This example code is in the public domain.
 
*/
 
 
void setup() {               
 
  // initialize the digital pin as an output.
 
  // Pin 13 has an LED connected on most Arduino boards:
 
  pinMode(13, OUTPUT);   
 
  Serial.begin(9600);
 
}
 
 
void loop() {
 
  digitalWrite(13, HIGH);  // set the LED on
 
  delay(1000);              // wait for a second
 
  digitalWrite(13, LOW);    // set the LED off
 
  delay(1000);              // wait for a second
 
}
 
}}
 
 
* Use an initialized global variable. [[http://arduino.cc/forum/index.php/topic,49900.msg363688.html#msg363688 Source post]]
 
 
{{bc|<nowiki>
 
char dummyvariablecuzmaintainerborkedthecompiler = 123; // force something into the .data segment with non-zero initializer
 
/*
 
  Blink
 
  Turns on an LED on for one second, then off for one second, repeatedly.
 
 
   
 
   
  This example code is in the public domain.
+
BOARD_TAG    = uno
  */
+
  ARDUINO_LIBS =
 +
 +
include /usr/share/arduino/Arduino.mk
  
void setup() {
+
In some cases you could need to install {{pkg|avr-libc}} and {{pkg|avrdude}}.
  dummyvariablecuzmaintainerborkedthecompiler++;  // stops the linker from removing the global variable
+
 
+
  // initialize the digital pin as an output.
+
  // Pin 13 has an LED connected on most Arduino boards:
+
  pinMode(13, OUTPUT);   
+
}
+
  
void loop() {
+
=== Scons ===
  digitalWrite(13, HIGH);  // set the LED on
+
  delay(1000);              // wait for a second
+
  digitalWrite(13, LOW);    // set the LED off
+
  delay(1000);              // wait for a second
+
}</nowiki>}}
+
  
Related pages:
+
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}}.
* http://arduino.cc/forum/index.php/topic,56841.0.html
+
* http://arduino.cc/forum/index.php/topic,49900.0.html
+
* http://arduino.cc/forum/index.php?topic=59409.0.html
+
  
Fedora has the same problem with binutils 2.21 ([https://bugzilla.redhat.com/show_bug.cgi?id=688645 bug report]).
+
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
Downgraded packages that work are binutils-avr 2.20.1-3 and gcc-avr 4.5.1-2.  
+
There is also an upstream bug report [http://sourceware.org/bugzilla/show_bug.cgi?id=12757 here] but no one has replied yet.
+
  
===Error when launching Arduino IDE or uploading sketch===
+
$ scons                # This will build the project
If you run the Arduino IDE as a normal user (you should do that of course), you may get this error message :
+
$ scons upload        # This will upload the project to your Arduino
'''check_group_uucp(): error testing lock file creation Error details:Permission denied'''
+
  
You may also find that your Tools > Serial Port menu is greyed out, and you get this error message when attempting to upload a sketch:
+
=== PlatformIO ===
'''Serial port '/dev/ttyACM0' not found. Did you select the right one from the Tools > Serial Port menu?'''
+
  
Either way, this is probably because you don't have write permissions on ''/run/lock directory''. Try this to see if this solves your problem :
+
[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.
{{bc|
+
sudo chmod 777 /run/lock
+
}}
+
  
/run/lock is created on boot by /usr/lib/tmpfiles.d/legacy.conf (both on systemd and initscripts). So if you want to keep the permissions you set, simply copy the file /usr/lib/tmpfiles.d/legacy.conf to /etc/tmpfiles.d/ and edit it there (set 0777 permissions).
+
==== Installation ====
You can look here
+
  
=== Error opening serial port ===
+
Its recommended to use a virtual environment because platformio uses python2 because its based on SCons which does not support python3.  
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.
+
  
=== Arduino Mega2560 and new gcc-avr ===
+
$ virtualenv --python=python2 venv
 +
$ source ./venv/bin/activate
 +
$ pip install platformio
  
If you are using gcc-avr >= 4.3.5 then there is a C++ bug in the gcc-avr toolchain which builds bad firmware for the Atmel2560 processors. gcc-avr must be rebuilt using a patch found at [http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45263]. You can read more about the problems at [http://andybrown.me.uk/ws/2010/10/24/the-major-global-constructor-bug-in-avr-gcc/]. This bug has been fixed in  4.7.0 and backported to 4.5.4 [http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45263].
+
another option is to use platformio as an [[Atom]] plugin, using [http://docs.platformio.org/en/latest/ide/atom.html#manual-installation Atom Package Manager].  
  
Here is the patch for gcc:
+
==== Usage ====
{{bc|
+
--- gcc-4.5.1.orig/gcc/config/avr/libgcc.S 2009-05-23 17:16:07 +1000
+
$ platformio platforms install atmelavr
+++ gcc-4.5.1/gcc/config/avr/libgcc.S 2010-08-12 09:38:05 +1000
+
  $ platformio init
@@ -802,7 +802,9 @@
+
  $ vim platformio.ini
mov_h r31, r29
+
mov_l r30, r28
+
out    __RAMPZ__, r20
+
+ push r20
+
XCALL __tablejump_elpm__
+
+ pop r20
+
  .L__do_global_ctors_start:
+
cpi r28, lo8(__ctors_start)
+
cpc r29, r17
+
@@ -843,7 +845,9 @@
+
mov_h r31, r29
+
mov_l r30, r28
+
out    __RAMPZ__, r20
+
+ push r20
+
XCALL __tablejump_elpm__
+
+ pop r20
+
  .L__do_global_dtors_start:
+
cpi r28, lo8(__dtors_end)
+
cpc r29, r17
+
}}
+
  
The easiest way to rebuild gcc-avr is using ABS and makepkg.
+
#
 +
# Atmel AVR based board + Arduino Wiring Framework
 +
#
 +
[env:ArduinoMega2560]
 +
platform = atmelavr
 +
framework = arduino
 +
board = megaatmega2560 
 +
upload_port = /dev/ttyACM0
 +
targets = upload
  
=== Arduino Mega2560 and deprecated items in avr-libc ===
+
$ platformio run
  
The following error is known to occur when compiling using avr-libc versions newer than 1.8.0 with the Arduino Mega 2560.
+
===Emacs===
  
{{bc|
+
It is possible to configure [[Emacs]] as IDE.
build/core/HardwareSerial.cpp:107:41: error: attempt to use poisoned "SIG_USART0_RECV"
+
#if !defined(USART_RX_vect) && !defined(SIG_USART0_RECV) && \
+
                                        ^
+
build/core/HardwareSerial.cpp:117:15: error: attempt to use poisoned "SIG_USART0_RECV"
+
#elif defined(SIG_USART0_RECV)
+
              ^
+
build/core/HardwareSerial.cpp:161:15: error: attempt to use poisoned "SIG_USART1_RECV"
+
#elif defined(SIG_USART1_RECV)
+
              ^
+
build/core/HardwareSerial.cpp:178:15: error: attempt to use poisoned "SIG_USART2_RECV"
+
#elif defined(SIG_USART2_RECV)
+
              ^
+
build/core/HardwareSerial.cpp:195:15: error: attempt to use poisoned "SIG_USART3_RECV"
+
#elif defined(SIG_USART3_RECV)
+
}}
+
  
This problem is discussed in further detail [http://arduino.cc/forum/index.php/topic,92364.0.html here]. To fix this, you need to enable deprecated avr-libc items in an Arduino header file.
+
Install the package {{aur|emacs-arduino-mode-git}} from the [[AUR]] in order to enable the {{ic|arduino-mode}} in emacs.
  
{{hc|/usr/share/arduino/hardware/arduino/cores/arduino/Arduino.h|
+
Add to the init script:
#ifndef Arduino_h
+
{{hc|~/.emacs|
#define Arduino_h
+
;; arduino-mode
 +
(require 'cl)
 +
(autoload 'arduino-mode "arduino-mode" "Arduino editing mode." t)
 +
(add-to-list 'auto-mode-alist '("\.ino$" . arduino-mode))}}
  
// start: fix the compatibility issue
+
You can compile and upload the sketches using {{ic|Arduino-mk}} (see above) with {{ic|M-x compile}} {{ic|make upload}}.
#define __AVR_LIBC_DEPRECATED_ENABLE__ 1
+
// end: fix the compatibility issue
+
  
#include <stdlib.h>
+
Main resource: [http://www.emacswiki.org/emacs/ArduinoSupport here].
...
+
}}
+
  
=== Missing twi.o ===
+
== Troubleshooting ==
  
If the file /usr/share/arduino/lib/targets/libraries/Wire/utility/twi.o does not exist arduino may try to create it. Normal users do not have permission to write there so this will fail. Run arduino as root so it can create the file, after the file has been created arduino can be run under a normal user.
+
=== Version 1.6 ===
  
=== Unable to upload sketch to your Arduino ===
+
As of Oct 5, 2014, most of the 3rd party tools only work for Arduino 1.0 ({{AUR|arduino10}}). Some of the tools may partially work for Arduino version 1.6 ({{AUR|arduino}}) and after. Check the version if the tools do not work.
  
Install the [https://aur.archlinux.org/packages.php?ID=8389 rxtx] package from the AUR. That package is the working Java library for Serial IO.
+
=== Consistent naming of Arduino devices ===
 
+
=== 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:
 
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:
Line 291: Line 205:
 
  udevadm trigger
 
  udevadm trigger
  
== Bugs ==
+
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.
 +
 
 +
=== 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.
 +
 
 +
=== Missing twi.o ===
 +
 
 +
If the file {{ic|/usr/share/arduino/lib/targets/libraries/Wire/utility/twi.o}} does not exist arduino may try to create it. Normal users do not have permission to write there so this will fail. Run arduino as root so it can create the file, after the file has been created arduino can be run under a normal user.
 +
 
 +
=== 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 [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].
 +
 
 +
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.
 +
 
 +
=== Error compiling ===
 +
If you get following message (in verbose mode)
 +
/usr/share/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../avr/bin/ld: cannot find -lm
 +
 
 +
see this fix [https://bbs.archlinux.org/viewtopic.php?pid=1343402#p1343402]
 +
* install package avr-gcc
 +
* Replace build-in avr-gcc compiler by same from package installed on previous step:
 +
# cd /usr/share/arduino/hardware/tools/avr/bin
 +
# mv ./avr-gcc ./avr-gcc-backup
 +
# ln -s /usr/bin/avr-gcc ./
 +
 
 +
To use the avr tools that are system installed, remove the avr directory as per the Arduino Linux install page:
 +
"If you want to use your system's compiler, delete the folder {{ic|./hardware/tools/avr}} in your arduino IDE installation"
 +
 
 +
An alternate approach to take is to download the corresponding Linux install from Arduino.cc and replace the {{ic|/usr/share/arduino/hardware/tools/avr}} directory with the avr directory that comes in the stock installation archive.
 +
 
 +
=== avrdude missing libtinfo.so.5 ===
 +
When uploading a sketch to the Arduino, the following message is thrown in the Arduino UI concole:
 +
  /usr/share/arduino/hardware/tools/avr/bin/avrdude: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
 +
 
 +
Solve the dependency problem by creating a symbolic link
 +
# ln -s /usr/lib/libncurses.so.5 /usr/lib/libtinfo.so.5
  
This section is targeted at the package maintainers.
+
For more info:
 +
https://bbs.archlinux.org/viewtopic.php?pid=1108717#p1108717
  
{| border="1"
+
=== Application not resizing with WM, menus immediately closing ===
! Symptom !! Cause / Upstream bug report !! Patches / Workarounds !! Patched Packages / End-User solutions
+
see [[Java#Applications not resizing with WM, menus immediately closing]]
|-
+
| delay() sleeps forever || ??? || [[Arduino#delay.28.29_function_doesn.27t_work|workaround]] || none
+
|-
+
| progmem error || [http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49764 bug in gcc-avr (fixed, but unreleased)] || [http://arduino.cc/forum/index.php/topic,66710.msg491529.html#msg491529 workaround] || [https://aur.archlinux.org/packages.php?ID=50146 aur/gcc-avr-svn] or [https://aur.archlinux.org/packages.php?ID=8388 aur/arduino]
+
|}
+
  
==See also==
+
== See also ==
  
 
* https://bbs.archlinux.org/viewtopic.php?pid=295312
 
* https://bbs.archlinux.org/viewtopic.php?pid=295312
* http://regomodoslinux.blogspot.com/2007/10/how-to-install-arduino-ide-in-archlinux.html
 
* http://gunnewiek.com/2011/open-pde-files-with-arduino-ide-in-linux/
 
 
* https://bbs.archlinux.org/viewtopic.php?pid=981348
 
* https://bbs.archlinux.org/viewtopic.php?pid=981348
 
* http://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/

Latest revision as of 11:12, 30 April 2016

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. More information is available on the Arduino HomePage.

Installation

Arduino Due / Yun

The Arduino Due and the Arduino Yun need the version 1.5 or newer of the Arduino IDE.

Pinoccio Scout

Pinoccio Scouts can also be programmed using the Arduino IDE. Instructions can be found here. Alternative you can install arduino-pinoccioAUR from the AUR.

Intel Galileo

The version of the Arduino IDE that supports the Intel Galileo board can be downloaded here.

On Arm7 devices

See here for a work around.

Configuration

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 in /dev/tts/ owned by group uucp so adding the user to the uucp group gives the required read/write access. If you are planing to use the default Java IDE, add your user to the lock group for /var/lock/lockdev access.

# gpasswd -a $USER uucp
# gpasswd -a $USER lock
Note: You will have to logout and login again for this to take effect.

The arduino board appears as /dev/ttyACMx so if the above does not work try adding the user to the group tty:

# gpasswd -a $USER tty

Before uploading to the Arduino, be sure to set the correct serial port, board, and processor from the Tools menu.

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 a 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

$ cat /dev/ttyACM0

Alternatives for IDE

ArduIDE

ArduIDE is a Qt-based IDE for Arduino. arduide-gitAUR is available in the AUR.

gnoduino

gnoduinoAUR 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

Using arduino-cmake 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:

Ino

Ino is a command line toolkit for working with arduino hardware. inoAUR is available in the AUR.

Note that Ino looks for the file avrdude.conf in /etc/avrdude/avrdude.conf, while pacman appears to place this file (upon installation of avrdude) in /etc/avrdude.conf. If Ino gives you troubles create the directory /etc/avrdude and make the symlink:

ln -s /etc/avrdude.conf /etc/avrdude/avrdude.conf

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 on GitHub.

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 /usr/share/arduino/hardware/cores/arduino/Makefile

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 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
ARDUINO_CORE_PATH = /usr/share/arduino/hardware/arduino/avr/cores/arduino
BOARDS_TXT = /usr/share/arduino/hardware/arduino/avr/boards.txt
ARDUINO_VAR_PATH = /usr/share/arduino/hardware/arduino/avr/variants
BOOTLOADER_PARENT = /usr/share/arduino/hardware/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

Its recommended to use a virtual environment because platformio uses python2 because its based on SCons which does not support python3.

$ virtualenv --python=python2 venv
$ source ./venv/bin/activate
$ pip install platformio

another option is to use platformio as an Atom plugin, using Atom Package Manager.

Usage

$ platformio platforms install atmelavr
$ platformio init
$ vim platformio.ini
#
# Atmel AVR based board + Arduino Wiring Framework
#
[env:ArduinoMega2560]
platform = atmelavr
framework = arduino
board = megaatmega2560   
upload_port = /dev/ttyACM0 
targets = upload
$ platformio run

Emacs

It is possible to configure Emacs as IDE.

Install the package emacs-arduino-mode-gitAUR from the AUR 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

Version 1.6

As of Oct 5, 2014, most of the 3rd party tools only work for Arduino 1.0 (arduino10AUR). Some of the tools may partially work for Arduino version 1.6 (arduinoAUR) and after. Check the version if the tools do not work.

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

Missing twi.o

If the file /usr/share/arduino/lib/targets/libraries/Wire/utility/twi.o does not exist arduino may try to create it. Normal users do not have permission to write there so this will fail. Run arduino as root so it can create the file, after the file has been created arduino can be run under a normal user.

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

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.

Error compiling

If you get following message (in verbose mode)

/usr/share/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../avr/bin/ld: cannot find -lm

see this fix [3]

  • install package avr-gcc
  • Replace build-in avr-gcc compiler by same from package installed on previous step:
  1. cd /usr/share/arduino/hardware/tools/avr/bin
  2. mv ./avr-gcc ./avr-gcc-backup
  3. ln -s /usr/bin/avr-gcc ./

To use the avr tools that are system installed, remove the avr directory as per the Arduino Linux install page: "If you want to use your system's compiler, delete the folder ./hardware/tools/avr in your arduino IDE installation"

An alternate approach to take is to download the corresponding Linux install from Arduino.cc and replace the /usr/share/arduino/hardware/tools/avr directory with the avr directory that comes in the stock installation archive.

avrdude missing libtinfo.so.5

When uploading a sketch to the Arduino, the following message is thrown in the Arduino UI concole:

 /usr/share/arduino/hardware/tools/avr/bin/avrdude: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory

Solve the dependency problem by creating a symbolic link

# ln -s /usr/lib/libncurses.so.5 /usr/lib/libtinfo.so.5

For more info: https://bbs.archlinux.org/viewtopic.php?pid=1108717#p1108717

Application not resizing with WM, menus immediately closing

see Java#Applications not resizing with WM, menus immediately closing

See also