Search

Intel Edison linux upload arduino via ethernet, wifi or network

Intel Edison linux upload arduino via ethernet, wifi or network

The Intel Edison uses /dev/ttyACM0 to upload to the built in Arduino which is quite slow and requires a wired connection.
I have written a script that tries to upload firstly by ssh and failing that by falling back to the standard serial port.

Note that 192.168.2.15 is the Intel Edison ethernet over USB default address and that 192.168.0.16 is the IP address I have given the wifi in a previous post.

Save the file to /arduino-1.5.3-Intel.1.0.4/hardware/arduino/edison/tools/izmir/clupload_linux.sh

file clupload_linux:

#!/bin/sh

set -e

HOSTS=(192.168.2.15 192.168.0.16) # CHANGE THIS TO YOUR DEVICE'S IP
HOST=$HOST

for i in $HOSTS; do
ping -c 1 -W 1 $i
a="$?"
if [ "$a" == "0" ]; then
HOST=$i # CHANGE THIS TO YOUR DEVICE'S IP
break;
fi
done

SKETCH=/sketch/sketch.elf
OLD_SKETCH=${SKETCH}.old
TMP_DIR=/home/root/tmp
TMP_SKETCH=$TMP_DIR/${SKETCH}
TMUX=/home/root/bin/tmux

if [ "$HOST" != "" ]; then
echo "Host $HOST is alive, uploading over network"
ssh [email protected]$HOST "mv -f $SKETCH $OLD_SKETCH"
ret=$?
if [ "$ret" != "0" ]; then
echo "ssh error $ret, aborting"
exit 1;
fi
scp $2 [email protected]$HOST:$SKETCH
ssh [email protected]$HOST "chmod +x $SKETCH; killall -q -USR1 launcher.sh || true; killall -q clloader || true; killall -q sketch.elf || true; $SKETCH /dev/pts/0 > /dev/null 2>&1 &"

echo "Success"

exit 0
fi

echo "No hosts are alive, reverting to standard ttyACM0 upload"

echo "starting download script"
echo "Args to shell:" $*
#
# ARG 1: Path to lsz executable.
# ARG 2: Elf File to download
# ARG 3: TTY port to use.
#
#path may contain \ need to change all to /
path_to_exe=$1
fixed_path=${path_to_exe//\\/\/}
#
tty_port_id=$3
echo "Serial Port PORT" $com_port_id
echo "Using tty Port" $tty_port_id
#
echo "Sending Command String to move to download if not already in download mode"
echo "~sketch download" > $tty_port_id
#Give the host time to stop the process and wait for download
sleep 1
#
#Move the existing sketch on target.
echo "Deleting existing sketch on target"
"$fixed_path/lsz" --escape -c "mv -f /sketch/sketch.elf /sketch/sketch.elf.old" < $tty_port_id > $tty_port_id
#
# Execute the target download command
#
#Download the file.
host_file_name=$2
"$fixed_path/lsz" --escape --binary --overwrite $host_file_name < $tty_port_id > $tty_port_id
#
#mv the downloaded file to /sketch/sketch.elf
target_download_name="${host_file_name##*/}"
echo "Moving downloaded file to /sketch/sketch.elf on target"
"$fixed_path/lsz" --escape -c "mv $target_download_name /sketch/sketch.elf; chmod +x /sketch/sketch.elf" < $tty_port_id > $tty_port_id
#
#

Related posts

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.