The ESC class constructs objects that represent a single ESC (Electronic Speed Control) component attached to the physical board. ESC objects are similar to Servo objects as they both use PWM pins to communicate with the physical ESC. Currently, this class assumes the ESC is pre-calibrated.

If you are interested in working with multiple ESCs, see the ESCs page.

Parameters

  • pin A Number or String address for the ESC pin (PWM).

    var esc = new five.ESC(9);
    
  • Options An object of property parameters.

    PropertyTypeValue/ DescriptionDefaultRequired
    pinNumber, StringAny PWM Pin. The address of the PWM pin the ESC is attached toyes
    rangeArray[ lower, upper ]. The range of speed in percent.[0, 100]no
    startAtNumberInitial speed, 0-100%0no
    controllerStringDEFAULT, PCA9685. Controller interface type."DEFAULT"no
    deviceStringFORWARD, FORWARD_REVERSE. Device capability type."FORWARD"no
    neutralNumberNeutral point, 0-100.0no

  • PCA9685 Options (controller: "PCA9685")

    PropertyTypeValue/DescriptionDefaultRequired
    addressNumberI2C device address.0x40no

Shape

Property NameDescriptionRead Only
idA user definable id value. Defaults to a generated uidNo
pinThe pin address that the ESC is attached toNo
rangeThe range of speed as an array of fractional percent values. Defaults to [0, 100]No
valueThe value of the last/current speed.Yes

Component Initialization

Basic

new five.ESC(9);

ESC

Limited Speed Range

// Limited speed range to 0-80%
new five.ESC({
  pin: 9, 
  range: [ 0, 80 ]
});

ESC

ESC PCA9685

new five.ESC({
  controller: "PCA9685",
  pin: 1
});

ESC

Bidirectional

new five.ESC({
  pin: 9, 
  device: "FORWARD_REVERSE", 
  neutral: 50
});

ESC

Usage

Standard ESC

var five = require("johnny-five");
var board = new five.Board();

board.on("ready", function() {

  var esc = new five.ESC(11);

  // Set to top speed. (this can be physically dangerous, you've been warned.)
  esc.max();

});

API

  • speed(value) Set the speed of the ESC, any fractional number value from 0...100 as a percentage value. If the specified speed is the same as the current speed, no commands are sent.

    var esc = new five.ESC(11);
    
    // Set the motor's speed to 50%
    esc.speed(50);
    
  • min() Set ESC to minimum speed. Defaults to 0%, respects explicit range.

    var esc = new five.ESC(11);
    
    esc.min();
    

    Or

    var esc = new five.ESC({
      pin: 11, 
      range: [ 10, 100 ]
    });
    
    // Minimum speed at 10%
    esc.min();
    
  • max() Set ESC to maximum speed. Defaults to 100%, respects specified range.

    var esc = new five.ESC(11);
    
    esc.max();
    

    Or

    var esc = new five.ESC({
      pin: 11, 
      range: [ 0, 80 ]
    });
    
    // Max at 80%
    esc.max();
    
  • stop() Stop a moving esc.

    var esc = new five.ESC(12);
    
    esc.stop();
    

Calibrating an ESC

This isn't a requirement, but if you experience issues with your ESCs, it might prove helpful

Load the following sketch onto your Arduino, via the Arduino IDE follow the instructions.

This requires that the ESC's power source is off or disconnected at the start of the calibration process. You will be prompted to turn on/reconnect the power during the process.

#include <Servo.h>

#define MAX_SIGNAL 2000
#define MIN_SIGNAL 700
#define MOTOR_PIN 12

Servo motor;

void setup() {
  Serial.begin(9600);
  Serial.println("Program begin...");
  Serial.println("This program will calibrate the ESC.");

  motor.attach(MOTOR_PIN);

  Serial.println("Calibrating Maximum Signal");
  Serial.println("Turn on power source, then wait 2 seconds and press any key + <enter>");
  motor.writeMicroseconds(MAX_SIGNAL);

  // Wait for input
  while (!Serial.available());
  Serial.read();

  // Send min output
  Serial.println("Calibrating Minimum Signal");
  motor.writeMicroseconds(MIN_SIGNAL);

}

void loop() {  

}

Examples

Hi! The Johnny-Five community is building new projects every day. We made this newsletter to tell you about what's new, what's good, and what's next for Open Source robotics. Join us in exploring what we can make together.

Fork me on GitHub