aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md40
-rw-r--r--arduino-mk/Arduino.mk171
-rwxr-xr-xbin/ard-parse-boards (renamed from arduino-mk/ard-parse-boards)0
-rwxr-xr-xbin/ard-reset-arduino115
-rw-r--r--examples/AnalogInOutSerial/Makefile4
-rw-r--r--examples/Blink/Makefile6
-rw-r--r--examples/BlinkWithoutDelay/Makefile4
-rw-r--r--examples/Fade/Makefile4
-rw-r--r--examples/HelloWorld/Makefile4
-rw-r--r--examples/WebServer/Makefile6
-rw-r--r--examples/master_reader/Makefile4
-rw-r--r--examples/toneMelody/Makefile4
12 files changed, 290 insertions, 72 deletions
diff --git a/README.md b/README.md
index e976748..f086c92 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,45 @@ still find [what
documentation](http://mjo.tc/atelier/2009/02/arduino-cli.html
"Documentation") exists.
-If you're using Debian or Ubuntu, you can find this in the arduino-core package.
+If you're using Debian or Ubuntu, you can find this in the
+arduino-core package.
+
+# Important Changes, 2012-04-29
+
+I've rejigged the path calculations so that:
+
+1. Few, if any paths, need to specified in the project specific Makefiles.
+
+1. The paths can be grabber from the environment e.g. set up in a user's .bashrc.
+
+1. It should be easier to move between e.g. Mac and Linux.
+
+I'm indebted to Christopher Peplin for making me think about this, and indeed for
+contributing code which did similar things in different ways.
+
+The upshot of all this is that you'll need to set up some variables if you want
+this to work:
+
+On the Mac you might want to set:
+
+ ARDUINO_DIR = /Applications/Arduino.app/Contents/Resources/Java
+ ARDMK_DIR = /usr/local
+
+On Linux, you might prefer:
+
+ ARDUINO_DIR = /usr/share/arduino
+ ARDMK_DIR = /usr/local
+ AVR_TOOLS_DIR = /usr
+
+The Makefile also delegates resetting the board to a short Perl program.
+You'll need to install Device::SerialPort to use it though. On Debian or
+Ubuntu do
+
+ apt-get install libdevice-serial-perl
+
+On other systems
+
+ cpanm Device::SerialPort
## User Libraries
diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk
index 26fd3bb..5261afa 100644
--- a/arduino-mk/Arduino.mk
+++ b/arduino-mk/Arduino.mk
@@ -72,7 +72,62 @@
# defined (ex Peplin)
# - Added a monitor target which talks to the
# Arduino serial port (Peplin's suggestion)
-#
+# - Rejigged PATH calculations for general
+# tidiness (ex Peplin)
+# - Moved the reset target to Perl for
+# clarity and better error handling (ex
+# Daniele Vergini)
+#
+########################################################################
+#
+# PATHS YOU NEED TO SET UP
+#
+# I've reworked the way paths to executables are constructed in this
+# version (0.9) of the Makefile.
+#
+# We need to worry about three different sorts of file:
+#
+# 1. Things which are included in this distribution e.g. ard-parse-boards
+# => ARDMK_DIR
+#
+# 2. Things which are always in the Arduino distribution e.g.
+# boards.txt, libraries, &c.
+# => ARDUINO_DIR
+#
+# 3. Things which might be bundled with the Arduino distribution, but
+# might come from the system. Most of the toolchain is like this:
+# on Linux it's supplied by the system.
+# => AVR_TOOLS_DIR
+#
+# Having set these three variables, we can work out the rest assuming
+# that things are canonically arranged beneath the directories defined
+# above.
+#
+# On the Mac you might want to set:
+#
+# ARDUINO_DIR = /Applications/Arduino.app/Contents/Resources/Java
+# ARDMK_DIR = /usr/local
+#
+# On Linux, you might prefer:
+#
+# ARDUINO_DIR = /usr/share/arduino
+# ARDMK_DIR = /usr/local
+# AVR_TOOLS_DIR = /usr
+#
+# You can either set these up in the Makefile, or put them in your
+# environment e.g. in your .bashrc
+#
+# If you don't install the ard-... binaries to /usr/local/bin, but
+# instead copy them to e.g. /home/mjo/arduino.mk/bin then set
+# ARDML_DIR = /home/mjo/arduino.mk
+#
+########################################################################
+#
+# DEPENDENCIES
+#
+# The Perl programs need a couple of libraries:
+# YAML
+# Device::SerialPort
#
########################################################################
#
@@ -83,11 +138,7 @@
#
# For example:
#
-# ARDUINO_DIR = /Applications/arduino-0013
-#
-# TARGET = CLItest
# ARDUINO_LIBS = Ethernet Ethernet/utility SPI
-#
# BOARD_TAG = uno
# ARDUINO_PORT = /dev/cu.usb*
#
@@ -95,12 +146,6 @@
#
# Hopefully these will be self-explanatory but in case they're not:
#
-# ARDUINO_DIR - Where the Arduino software has been unpacked
-#
-# TARGET - The basename used for the final files. Canonically
-# this would match the .pde file, but it's not needed
-# here: you could always set it to xx if you wanted!
-#
# ARDUINO_LIBS - A list of any libraries used by the sketch (we
# assume these are in
# $(ARDUINO_DIR)/hardware/libraries
@@ -111,11 +156,6 @@
# BOARD_TAG - The ard-parse-boards tag for the board e.g. uno or mega
# 'make show_boards' shows a list
#
-# You might also want to specify these, but normally they'll be read from the
-# boards.txt file i.e. implied by BOARD_TAG
-#
-# MCU,F_CPU - The target processor description
-#
# Once this file has been created the typical workflow is just
#
# $ make upload
@@ -157,13 +197,42 @@
#
########################################################################
#
-# ARDUINO WITH OTHER TOOLS
+# PATHS
+#
+# I've reworked the way paths to executables are constructed in this
+# version of Makefile.
+#
+# We need to worry about three different sorts of file:
+#
+# 1. Things which are included in this distribution e.g. ard-parse-boards
+# => ARDMK_DIR
+#
+# 2. Things which are always in the Arduino distribution e.g.
+# boards.txt, libraries, &c.
+# => ARDUINO_DIR
+#
+# 3. Things which might be bundled with the Arduino distribution, but
+# might come from the system. Most of the toolchain is like this:
+# on Linux it's supplied by the system.
+# => AVR_TOOLS_DIR
+#
+# Having set these three variables, we can work out the rest assuming
+# that things are canonically arranged beneath the directories defined
+# above.
+#
+# So, on the Mac you might want to set:
#
-# If the tools aren't in the Arduino distribution, then you need to
-# specify their location:
+# ARDUINO_DIR = /Applications/Arduino.app/Contents/Resources/Java
+# ARDMK_DIR = /usr/local
#
-# AVR_TOOLS_PATH = /usr/bin
-# AVRDUDE_CONF = /etc/avrdude/avrdude.conf
+# On Linux, you might prefer:
+#
+# ARDUINO_DIR = /usr/share/arduino
+# ARDMK_DIR = /usr/local
+# AVR_TOOLS_DIR = /usr
+#
+#
+#
#
########################################################################
#
@@ -209,28 +278,49 @@ ifndef ARDUINO_VERSION
ARDUINO_VERSION = 100
endif
+########################################################################
+# Arduino and system paths
#
-# Some paths
-#
+ifdef ARDUINO_DIR
-ifneq (ARDUINO_DIR,)
+ifndef AVR_TOOLS_DIR
+AVR_TOOLS_DIR = $(ARDUINO_DIR)/hardware/tools/avr
+# The avrdude bundled with Arduino can't find it's config
+AVRDUDE_CONF = $(AVR_TOOLS_DIR)/etc/avrdude.conf
+endif
ifndef AVR_TOOLS_PATH
-AVR_TOOLS_PATH = $(ARDUINO_DIR)/hardware/tools/avr/bin
+AVR_TOOLS_PATH = $(AVR_TOOLS_DIR)/bin
endif
-ifndef ARDUINO_ETC_PATH
-ARDUINO_ETC_PATH = $(ARDUINO_DIR)/hardware/tools/avr/etc
+ARDUINO_LIB_PATH = $(ARDUINO_DIR)/libraries
+ARDUINO_CORE_PATH = $(ARDUINO_DIR)/hardware/arduino/cores/arduino
+ARDUINO_VAR_PATH = $(ARDUINO_DIR)/hardware/arduino/variants
+
+else
+
+echo $(error "ARDUINO_DIR is not defined")
+
endif
-ifndef AVRDUDE_CONF
-AVRDUDE_CONF = $(ARDUINO_ETC_PATH)/avrdude.conf
+########################################################################
+# Makefile distribution path
+#
+ifdef ARDMK_DIR
+
+ifndef ARDMK_PATH
+ARDMK_PATH = $(ARDMK_DIR)/bin
endif
-ARDUINO_LIB_PATH = $(ARDUINO_DIR)/libraries
-ARDUINO_CORE_PATH = $(ARDUINO_DIR)/hardware/arduino/cores/arduino
-ARDUINO_VAR_PATH = $(ARDUINO_DIR)/hardware/arduino/variants
+else
+
+echo $(error "ARDMK_DIR is not defined")
+
+endif
+########################################################################
+# Miscellanea
+#
ifndef ARDUINO_SKETCHBOOK
ARDUINO_SKETCHBOOK = $(HOME)/sketchbook
endif
@@ -239,8 +329,6 @@ ifndef USER_LIB_PATH
USER_LIB_PATH = $(ARDUINO_SKETCHBOOK)/libraries
endif
-endif
-
########################################################################
# Serial monitor (just a screen wrapper)
#
@@ -257,6 +345,12 @@ MONITOR_CMD = screen
endif
########################################################################
+# Reset
+ifndef RESET_CMD
+RESET_CMD = $(ARDMK_PATH)/ard-reset-arduino $(ARD_RESET_OPTS)
+endif
+
+########################################################################
# boards.txt parsing
#
ifndef BOARD_TAG
@@ -268,7 +362,7 @@ BOARDS_TXT = $(ARDUINO_DIR)/hardware/arduino/boards.txt
endif
ifndef PARSE_BOARD
-PARSE_BOARD = ard-parse-boards
+PARSE_BOARD = $(ARDMK_PATH)/ard-parse-boards
endif
ifndef PARSE_BOARD_OPTS
@@ -554,10 +648,13 @@ raw_upload: $(TARGET_HEX)
$(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ARD_OPTS) \
-U flash:w:$(TARGET_HEX):i
+reset:
+ $(RESET_CMD) $(ARD_PORT)
+
# stty on MacOS likes -F, but on Debian it likes -f redirecting
# stdin/out appears to work but generates a spurious error on MacOS at
# least. Perhaps it would be better to just do it in perl ?
-reset:
+reset_stty:
for STTYF in 'stty -F' 'stty --file' 'stty -f' 'stty <' ; \
do $$STTYF /dev/tty >/dev/null 2>/dev/null && break ; \
done ;\
@@ -591,6 +688,6 @@ show_boards:
monitor:
$(MONITOR_CMD) $(ARD_PORT) $(MONITOR_BAUDRATE)
-.PHONY: all clean depends upload raw_upload reset size show_boards monitor
+.PHONY: all clean depends upload raw_upload reset reset_stty size show_boards monitor
include $(DEP_FILE)
diff --git a/arduino-mk/ard-parse-boards b/bin/ard-parse-boards
index e2de71b..e2de71b 100755
--- a/arduino-mk/ard-parse-boards
+++ b/bin/ard-parse-boards
diff --git a/bin/ard-reset-arduino b/bin/ard-reset-arduino
new file mode 100755
index 0000000..22c7109
--- /dev/null
+++ b/bin/ard-reset-arduino
@@ -0,0 +1,115 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+
+use Device::SerialPort;
+use Getopt::Long;
+use Pod::Usage;
+
+my %Opt =
+ (
+ period => 0.1,
+ );
+
+GetOptions(\%Opt,
+ "period=f", # width of reset pulse in seconds
+ "verbose!",
+ "help!",
+ "info!",
+ );
+
+if ($Opt{help} || $Opt{info})
+ {
+ usage();
+ }
+
+die "No Arduinos found!\n"
+ unless @ARGV;
+
+foreach my $dev (@ARGV)
+ {
+ my $p = Device::SerialPort->new($dev)
+ or die "Unable to open $dev: $!\n";
+
+ my $dt = $Opt{period};
+
+ print STDERR "Setting DTR high for ${dt}s on $dev\n"
+ if $Opt{verbose};
+
+ die "Invalid pulse width ($dt), "
+ unless $dt > 0.0;
+
+ $p->pulse_dtr_on($dt * 1000.0);
+ }
+
+## here endeth the main
+
+sub usage
+ {
+ pod2usage(-verbose => 2);
+ }
+
+__END__
+
+=head1 NAME
+
+ard-reset-arduino - Reset an Arduino
+
+=head1 USAGE
+
+ $ ard-reset-arduino /dev/cu.usb*
+
+ $ ard-reset-arduino --verbose --period=0.1 /dev/cu.usb*
+
+=head1 DESCRIPTION
+
+To reset (most) Arduinos, it's enough to just pulse the DTR line.
+
+You can do that from the shell with stty, but there's an interesting
+diversity of command flags. This little program gives a uniform interface
+at the cost of requiring C<Device::SerialPort>.
+
+=head1 OPTIONS
+
+=over
+
+=item --verbose
+
+Watch what's going on on STDERR.
+
+=item --period=0.25
+
+Specify the DTR pulse width in seconds.
+
+=back
+
+=head1 BUGS AND LIMITATIONS
+
+There are no known bugs in this application.
+
+Please report problems to the author.
+
+Patches are welcome.
+
+=head1 AUTHOR
+
+Martin Oldfield, ex-atelier@mjo.tc
+
+Thanks to Daniele Vergini who suggested this to me, and supplied
+a command line version.
+
+=head1 LICENCE AND COPYRIGHT
+
+Copyright (c) 2012, Martin Oldfield. All rights reserved.
+
+This file is free software; you can redistribute it and/or modify it
+under the terms of the GNU Lesser General Public License as published
+by the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+
diff --git a/examples/AnalogInOutSerial/Makefile b/examples/AnalogInOutSerial/Makefile
index 5c8c1dd..eac50fb 100644
--- a/examples/AnalogInOutSerial/Makefile
+++ b/examples/AnalogInOutSerial/Makefile
@@ -1,9 +1,5 @@
-ARDUINO_DIR = /Applications/Arduino.app/Contents/Resources/Java
-PARSE_BOARD = ../../arduino-mk/ard-parse-boards
-
BOARD_TAG = uno
ARDUINO_PORT = /dev/cu.usb*
-
ARDUINO_LIBS =
include ../../arduino-mk/Arduino.mk \ No newline at end of file
diff --git a/examples/Blink/Makefile b/examples/Blink/Makefile
index 12cd3e6..1c61004 100644
--- a/examples/Blink/Makefile
+++ b/examples/Blink/Makefile
@@ -1,10 +1,6 @@
-ARDUINO_DIR = /Applications/Arduino.app/Contents/Resources/Java
-PARSE_BOARD = ../../arduino-mk/ard-parse-boards
-
BOARD_TAG = uno
ARDUINO_PORT = /dev/cu.usb*
-
ARDUINO_LIBS =
-include ../../arduino-mk/Arduino.mk
+include $(ARDMK_DIR)/arduino-mk/Arduino.mk
diff --git a/examples/BlinkWithoutDelay/Makefile b/examples/BlinkWithoutDelay/Makefile
index 5c8c1dd..eac50fb 100644
--- a/examples/BlinkWithoutDelay/Makefile
+++ b/examples/BlinkWithoutDelay/Makefile
@@ -1,9 +1,5 @@
-ARDUINO_DIR = /Applications/Arduino.app/Contents/Resources/Java
-PARSE_BOARD = ../../arduino-mk/ard-parse-boards
-
BOARD_TAG = uno
ARDUINO_PORT = /dev/cu.usb*
-
ARDUINO_LIBS =
include ../../arduino-mk/Arduino.mk \ No newline at end of file
diff --git a/examples/Fade/Makefile b/examples/Fade/Makefile
index 5c8c1dd..eac50fb 100644
--- a/examples/Fade/Makefile
+++ b/examples/Fade/Makefile
@@ -1,9 +1,5 @@
-ARDUINO_DIR = /Applications/Arduino.app/Contents/Resources/Java
-PARSE_BOARD = ../../arduino-mk/ard-parse-boards
-
BOARD_TAG = uno
ARDUINO_PORT = /dev/cu.usb*
-
ARDUINO_LIBS =
include ../../arduino-mk/Arduino.mk \ No newline at end of file
diff --git a/examples/HelloWorld/Makefile b/examples/HelloWorld/Makefile
index 591d575..6c71d22 100644
--- a/examples/HelloWorld/Makefile
+++ b/examples/HelloWorld/Makefile
@@ -1,9 +1,5 @@
-ARDUINO_DIR = /Applications/Arduino.app/Contents/Resources/Java
-PARSE_BOARD = ../../arduino-mk/ard-parse-boards
-
BOARD_TAG = uno
ARDUINO_PORT = /dev/cu.usb*
-
ARDUINO_LIBS = LiquidCrystal
include ../../arduino-mk/Arduino.mk \ No newline at end of file
diff --git a/examples/WebServer/Makefile b/examples/WebServer/Makefile
index 56e422f..d361759 100644
--- a/examples/WebServer/Makefile
+++ b/examples/WebServer/Makefile
@@ -1,9 +1,5 @@
-ARDUINO_DIR = /Applications/Arduino.app/Contents/Resources/Java
-PARSE_BOARD = ../../arduino-mk/ard-parse-boards
-
BOARD_TAG = uno
ARDUINO_PORT = /dev/cu.usb*
-
ARDUINO_LIBS = Ethernet Ethernet/utility SPI
-include ../../arduino-mk/Arduino.mk \ No newline at end of file
+include ../../arduino-mk/Arduino.mk
diff --git a/examples/master_reader/Makefile b/examples/master_reader/Makefile
index 7e744c1..f242a44 100644
--- a/examples/master_reader/Makefile
+++ b/examples/master_reader/Makefile
@@ -1,9 +1,5 @@
-ARDUINO_DIR = /Applications/Arduino.app/Contents/Resources/Java
-PARSE_BOARD = ../../arduino-mk/ard-parse-boards
-
BOARD_TAG = uno
ARDUINO_PORT = /dev/cu.usb*
-
ARDUINO_LIBS = Wire Wire/utility
include ../../arduino-mk/Arduino.mk
diff --git a/examples/toneMelody/Makefile b/examples/toneMelody/Makefile
index 17d67e8..7ea0a9f 100644
--- a/examples/toneMelody/Makefile
+++ b/examples/toneMelody/Makefile
@@ -1,9 +1,5 @@
-ARDUINO_DIR = /Applications/Arduino.app/Contents/Resources/Java
-PARSE_BOARD = ../../arduino-mk/ard-parse-boards
-
BOARD_TAG = uno
ARDUINO_PORT = /dev/cu.usb*
-
ARDUINO_LIBS =
include ../../arduino-mk/Arduino.mk