Andrey Yakovlev
Published

Arduboy Uploader for Linux

Linux version Uploader for Erwin's Arduboy Collection

IntermediateWork in progress21
Arduboy Uploader for Linux

Story

Read more

Code

arduboy

SH
save it anywhere, better somewhere int $PATH, and do chmod +x on it
#!/bin/bash

if [ $(ps -opgrp= -p$$) != $(ps -otpgid= -p$$) ]; then
  xterm -e "
    echo -ne '\e]2;Arduboy Uploader\a'
    $0 '$@'
  "
  exit
fi



DEV_BOOT=/dev/arduboy-boot
DEV_RUN=/dev/arduboy

TMP=$(mktemp -d --suffix=-arduboy)

usage(){
  IAM=$(basename $0)
  cat <<END >&2

Usage:
  $IAM {URL|FILE}
  $IAM eeprom {read|write} [filename]
  $IAM eeprom backup

END
}

dude(){
  echo "waiting for $DEV_BOOT (press RESET)" 1>&2
  while [ ! -e "$DEV_BOOT" ]; do
    if [ -e "$DEV_RUN" ]; then
      echo -e "\n$DEV_RUN found. trying to reset." 1>&2
      stty -F "$DEV_RUN" ispeed 1200 ospeed 1200
      while [ -e "$DEV_RUN" ]; do sleep 0.1; done;
    fi
    echo -n . 1>&2
    sleep 0.1
  done

  avrdude -p atmega32u4 -cavr109 -P"$DEV_BOOT" -D "$1"
}

flash(){
  dude -Uflash:w:"$1"
}

zflash(){
  HEX="${2%.*}"
  "$1" -vdc "$2" >"$TMP/${HEX##*/}"
  flash "$TMP/${HEX##*/}"
}

download(){
  FILE="$TMP/${1##*/}"
  wget -O "$FILE" "$1"
  if [ $? -eq 127 ]; then
    echo 'wget not found. trying with curl' 1>&2
    curl "$1" >"$FILE"
    if [ $? -eq 127 ]; then
      echo 'no curl found also. trying libwww' 1>&2
      GET "$1" >"$FILE"
      if [ $? -eq 127 ]; then
        echo -e 'also not found :(\ninstall one of them' 1>&2
        exit 127
      fi
    fi
  fi
}


case "$1" in
  eeprom)
    case "$2" in
      read)
        dude -Ueeprom:r:"${3:--}":i
        ;;
      write)
        dude -Ueeprom:w:"${3:--}"
        ;;
      backup)
        dude -Ueeprom:r:$(date +'%F_%T.eep'):i
        ;;
      *)usage;;
    esac
    exit 0
    ;;
  arduboy:*)
    download "${1#*:}"
    ;;
  http://*|https://*|ftp://*)
    download "$1"
    ;;
  *)
    FILE="$1"
    ;;
esac

[ $? -eq 0 ] || exit 1

case "$FILE" in
  *.arduboy|*.zip)
    unzip -d "$TMP" "$FILE" \*.hex
    HEXs=( "$TMP"/*.hex )
    case "${#HEXs[@]}" in
      0) echo "no .hex files found." ;;
      1) flash "${HEXs[0]}" ;;
      *) echo -e "\nmany .hex files found\nchoose:"
         select ans in "${HEXs[@]##*/}"
         do
           flash "$TMP/$ans"
           break
         done
         ;;
    esac
    ;;
  *.hex)
    flash "$FILE"
    ;;
  *.hex.gz)
    zflash gzip "$FILE"
    ;;
  *.hex.bz2)
    zflash bzip2 "$FILE"
    ;;
  *.hex.xz|*.hex.lzma)
    zflash zx "$FILE"
    ;;
  *)
    usage
    ;;
esac

rm -rf "$TMP"

99-arduboy.rules

INI
drop in /etc/udev/rules.d

ofcause u must have permissions to /dev/ttyACM* - in my case (gentoo) working user just added to uucp group, another (ugly) way - set permissions 666 by udev

i use arduboy clone based on leonardo from ali and ur VID:PID pairs may be anothers
ACTION=="add", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="003[67]", SYMLINK+="arduboy-boot"
ACTION=="add", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="803[67]", SYMLINK+="arduboy"
ACTION=="add", ATTRS{idVendor}=="2A03", ATTRS{idProduct}=="003[67]", SYMLINK+="arduboy-boot"
ACTION=="add", ATTRS{idVendor}=="2A03", ATTRS{idProduct}=="803[67]", SYMLINK+="arduboy"

Credits

Andrey Yakovlev

Andrey Yakovlev

2 projects • 0 followers

Comments