Rick Waldron edited this page Aug 19, 2018 · 43 revisions

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.

See also:

Parameters

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

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

    Property Type Value/ Description Default Required
    pin Number, String Any PWM Pin. The address of the PWM pin the ESC is attached to yes
    controller String DEFAULT, PCA9685. Controller interface type. "DEFAULT" no
    pwmRange Array [ min, max ] The pulse width range in microseconds. [1000, 2000] no
    device String FORWARD, FORWARD_REVERSE. Device capability type. "FORWARD" no
    neutral Number Neutral point, usually the middle of the PWM range. Varies by device no
  • PCA9685 Options (controller: "PCA9685")

    Property Type Value/Description Default Required
    address Number I2C device address. 0x40 no

Shape

Property Name Description Read Only
id A user definable id value. Defaults to a generated uid No
pin The pin address that the ESC is attached to No
value The value of the last/current speed. Yes

Component Initialization

Basic

new five.ESC(9);

ESC

ESC PCA9685

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

ESC

Bidirectional

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

ESC

Usage

Standard ESC

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

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

  var esc = new five.ESC(11);
  
  board.loop(100, () => 
  esc.throttle();

});

API

  • speed(value) Deprecated. Use throttle(μs)

  • throttle(value) Throttle the speed of the ESC by setting a pulse in μs.

    var esc = new five.ESC(9);
    
    esc.throttle(1500); // 1500μs is half speed of a single direction or neutral of a bidirectional
  • brake() Brake the ESC

    var esc = new five.ESC(9);
    
    esc.brake();

Examples

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 1000
#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() {  

}
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.