Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Node module for control of Pololu Maestro servo controllers
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
.gitignore refactored library to implement compact protocol and added unit testi…
.groc.json adds close method and disconnect event to address #6
main.js Added ready event and removed serialport version dependency
package.json updated version


Dependency Status devDependency Status

This module allows control of the Pololu Maestro range of servo controllers from Node.js allowing your project to interact with the world!

See the API documentation for more information.


This module requires node-serialport in order to communicate with the Maestro, this should be installed automatically.

It also uses Winston for logging.


Install this module with

npm install pololumaestro


Run unit tests with:

npm test

A coverage report should then be available in coverage/lcov-report/index.html

Please submit tests along with new functionality


Here's a minimal example of how to use the module

var PololuMaestro = require("pololu-maestro");

//create new instance, specifying control com port and optionally the baud rate
var maestro = new PololuMaestro("COM17", 115200);

maestro.on("disconnected", function() {
    // yikes, someone pulled the plug

//wait until connection is ready
maestro.on("ready", function() {
    // set target of servo on channel 1 to 1500μs
    maestro.setTarget(1, 1500);

    // set a servo on channel 1 via mini-SSC protocol
    maestro.set8BitTarget(1, 128);

    // set speed of servo on channel 1
    maestro.setSpeed(1, 140);

    // set acceleration of servo on channel 1
    maestro.setAcceleration(1, 128);

    // get the last target value sent to the servo on channel 1
    maestro.getPosition(1, function(position) {
        // position is a number

    // find out if a servo is moving on channel 1
    maestro.getMovingState(1, function(state) {
        // state is a boolean

    // reset all servos to home position

    // read an analog input on channel 1
    maestro.analogRead(1, function(value) {
        // value is a number

    // read a digital input on channel 12
    maestro.digitalRead(12, function(value) {
        // value is a boolean

    // write to a digital output on channel 1
    maestro.digitalWrite(1, true);

    // set PWM channel value
    maestro.setPWM(onTime, period);

    // stop the currently running script

    // run subroutine 1

    // run subroutine 1 and read the result
    maestro.restartScriptAtSubroutine(1, function(data) {
        // data is a Buffer -

    // pass an argument to a subroutine
    maestro.restartScriptAtSubroutineWithParameter(1, 5);

    // pass an argument to a subroute and read the result
    maestro.restartScriptAtSubroutineWithParameter(1, 5, function(data) {
        // data is a Buffer -

    // find out if any scripts are currently running
    maestro.getScriptStatus(function(status) {
        // status is a boolean

    // close any serial ports the maestro has open
    maestro.close(function() {
        // invoked when serial port(s) are closed

// alternatively, attempt to auto-detect:
PololuMaestro.find(PololuMaestro.SERIAL_MODES.USB_DUAL_PORT, function(error, maestro) {
    // ... do something

Version history


  • Breaking change - the callback for PololuMaestro#find now takes arguments error, maestro to be more inline with node conventions
  • Not finding a Maestro no longer causes the process to exit, instead test for the error argument to PololuMaestro#find


  • Small tweak for OS X Mavericks compatibility


Updates (contributed by achingbrain):

  • Adds a find method to attempt to auto-detect a connected board


Updates (contributed by achingbrain):

  • Adds support for USB Dual Port mode
  • Adds generated documentation


Updates (contributed by achingbrain):

  • Refactored to implement full compact protocol
  • Added unit testing suite


  • Removed serialport v1.06 dependency to be compatible with node v0.10.x (Thanks achingbrain!)
  • Added a "ready" event to prevent calls to setPWM being made before the serial port is open


N.b. v2.0.0 breaks compatibilty with v1.1.0. To fix up your code, change the setPWM method to setTarget.

So where you were previously setting the target of channel 0 like this:

maestro.setPWM(0, 1500);

You should now use:

maestro.setTarget(0, 1500);
Something went wrong with that request. Please try again.