5.h.4. Bash script

The following shell script sends Set Target commands to the Maestro’s virtual COM port. This script allows you to easily control a Maestro over USB from a computer running Linux or Mac OS X 10.7 (Lion) or later. To use it, you will need to first run the Maestro Control Center on a Linux or Windows computer and set the Maestro’s serial mode to “USB Dual Port”. Then, on the computer you want to control the Maestro from, you should copy the code below into a file named maestro-set-target.sh. You can run it using the example commands given below. You will need to change the DEVICE argument to be the name of the Maestro’s Command Port (see Section 5.a).

#!/bin/bash
# Sends a Set Target command to a Pololu Maestro servo controller
# via its virtual serial port.
# Usage: maestro-set-target.sh DEVICE CHANNEL TARGET
# Linux example: bash maestro-set-target.sh /dev/ttyACM0 0 6000
# Mac OS X example: bash maestro-set-target.sh /dev/cu.usbmodem00234567 0 6000
# Windows example: bash maestro-set-target.sh '\\.\COM6' 0 6000
# CHANNEL is the channel number
# TARGET is the target in units of quarter microseconds.
# The Maestro must be configured to be in USB Dual Port mode.
DEVICE=$1
CHANNEL=$2
TARGET=$3

byte() {
  printf "\\x$(printf "%x" $1)"
}

stty raw -F $DEVICE

{
  byte 0x84
  byte $CHANNEL
  byte $((TARGET & 0x7F))
  byte $((TARGET >> 7 & 0x7F))
} > $DEVICE

This script can also be run on Windows, but since Windows does not have bash installed by default it is easier to use UscCmd.

Related Products

Micro Maestro 6-Channel USB Servo Controller (Partial Kit)
Micro Maestro 6-Channel USB Servo Controller (Assembled)
Mini Maestro 12-Channel USB Servo Controller (Assembled)
Mini Maestro 12-Channel USB Servo Controller (Partial Kit)
Mini Maestro 18-Channel USB Servo Controller (Assembled)
Mini Maestro 18-Channel USB Servo Controller (Partial Kit)
Mini Maestro 24-Channel USB Servo Controller (Assembled)
Mini Maestro 24-Channel USB Servo Controller (Partial Kit)
Log In
Pololu Robotics & Electronics
Shopping cart
(702) 262-6648
Same-day shipping, worldwide
Menu
Shop Blog Forum Support
My account Comments or questions? About Pololu Contact Ordering information Distributors