EmacsWiki: Arduino Support (original) (raw)
Arduino is “an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It’s intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments.”
The Arduino IDE is useful for beginners, but Emacs is better.
- arduino-mode.el - major mode for editing .ino and .pde files.
- CEDET (CollectionOfEmacsDevelopmentEnvironmentTools) supports Arduino sketch projects, enabling compilation and uploading sketches to your microcontroller.
To compile sketches outside of the Arduino IDE, you will need to use Arduino.mk which comes with the Arduino development environment. This enables command line compilation of your sketches, and is used by the CEDET support.
Alternately, to use the Arduino IDE for compilation, but edit in Emacs, open the preferences in the IDE, and choose “Use External Editor”.
Emacs + arduino.mk - Quickstart for Linux
- Add yourself to dialout group (whatever group allows access to serial port). You will probably need to kill off emacs and re-login to have this take effect.
- Run regular arduino IDE and set up preferences to point to correct board type/serial port (arduino.mk reads this for automagically populating fields below)
- Install arduino-mk from your repository/github
- Create simple Makefile in the same directory as your .ino file. Contents can be as simple as this (only the include is truly necessary, all other lines can be omitted for simple sketches):
BOARD_TAG = uno (see make show_boards) ARDUINO_LIBS = <space separated list of libs, arduino.mk will try to guess> MONITOR_PORT = /dev/ttyUSB0 (will be automatically guessed from IDE prefs) include /usr/share/arduino/Arduino.mk
- Call Makefile with M-x compile RET make -k upload
Arduino Support for OS X
This is what I did in order to get Arduino support for OS X:
Install CEDET
CEDET is a very complex and powerful package, but I will perform a simple installation from the bazaar repository:
~/.emacs.d/vendor $ git clone http://git.code.sf.net/p/cedet/git cedet ~/.emacs.d/vendor $ cd cedet ~/.emacs.d/vendor $ make EMACS=/Applications/Emacs.app/Contents/MacOS/Emacs
or, if you are using Aquamacs, instead of using make
open ~/.emacs.d/vendor/cedet/cedet-build.el
in Aquamacs then:
M-x eval-buffer M-x cedet-build-in-this-emacs
Then, following the INSTALL file, add this to your emacs config file:
(load-file "~/.emacs.d/vendor/cedet/cedet-devel-load.el")
(add-to-list 'semantic-default-submodes 'global-semantic-idle-summary-mode t) (add-to-list 'semantic-default-submodes 'global-semantic-idle-completions-mode t) (add-to-list 'semantic-default-submodes 'global-cedet-m3-minor-mode t)
(semantic-mode 1)
(global-ede-mode 1)
(setq ede-arduino-appdir "/Applications/Arduino.app/Contents/Resources/Java")
You must add the last line in order to tell CEDET the path where the Arduino libraries are.
Install Arduino mode
Go to your emacs config directory and get a git copy of the Arduino-mode:
~/.emacs.d/vendor $ git clone git://repo.or.cz/arduino-mode.git
Configure your emacs init file to use it:
(add-to-list 'load-path "~/.emacs.d/vendor/arduino-mode") (setq auto-mode-alist (cons '("\.\(pde\|ino\)$" . arduino-mode) auto-mode-alist)) (autoload 'arduino-mode "arduino-mode" "Arduino editing mode." t)
Install Arduino IDE
Download the IDE and move it to your Applications folder. Connect your Arduino to the USB port, compile the blink example, and upload it. Verify that everything works fine. After that, from a terminal shell, create a directory in your $HOME folder and add a link to it following this steps:
~/ $ mkdir .arduino ~/ $ cd .arduino ~/.arduino $ ln -s /Users/yourusername/Library/Arduino/preferences.txt .
Install Arduino-cli tools
We need this tools in order to create the Makefile file. I downloaded them in my /opt/local/share dir.
/opt/local/share $ sudo git clone git://github.com/sudar/Arduino-Makefile.git
Edit the Aduino.mk file inside the new Arduino-Makefile/arduino-mk directory. Modify and uncomment this lines according to your installation:
ARDUINO_DIR = /Applications/Arduino.app/Contents/Resources/Java ARDMK_DIR = /opt/local/share/Arduino-Makefile
Add a link in your ARDUINO_DIR to the Arduino.mk file:
/Applications/Arduino.app/Contents/Resources/Java $ ln -s /opt/local/share/Arduino-Makefile/arduino-mk/Arduino.mk ./Arduino.mk
Install required Perl modules
Do this as root:
sudo /usr/bin/perl -MCPAN -e shell
. . .
cpan[1]> install YAML
. . .
cpan[2]> install Device::SerialPort
Test the installation
Open a .ino file. C-c . c will create the makefile and compile the code. C-c . U will upload it to the arduino. If you get this error: Cannot invoke project-compile-target, try M-x global-ede-mode.