ESC - lyzadanger/johnny-five GitHub Wiki
The ESC
class constructs objects that represent a single ESC 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.
- pin A Number or String address for the ESC pin (PWM).
var esc = new five.ESC(12);
Tinkerkit:
// Attached to "Output 0"
var esc = new five.ESC("O0");
- options An object of property parameters.
Property Name | Type | Value(s) | Description | Required |
---|---|---|---|---|
pin | Number, String | Any PWM Pin | The address of the pin the esc is attached to, ie. 12 or "O1" (if using TinkerKit) | yes |
range | Array | [ lower, upper ] | The range of speed in percent. Defaults to [0, 100] | no |
pwmRange | Array | [ lower, upper ] | The range of speed in μs. Defaults to [600, 2400]. Overrides `range` | no |
startAt | Number | Any integer between 0...100 | Initial speed percentage | no |
{
id: A user definable id value. Defaults to a generated uid
pin: The pin address that the ESC is attached to
range: The range of speed as percent. Defaults to [0, 100]
speed: The last/current speed. READONLY
}
Standard ESC
var five = require("johnny-five"),
board = new five.Board();
board.on("ready", function() {
var esc = new five.ESC(12);
// Set to top speed. (this can be physically dangerous, you've been warned.)
esc.max();
});
- speed(value) Set the speed of the ESC, any integer 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(12);
// Set the motor's speed to 50%
esc.to(50);
- min() Set ESC to minimum speed. Defaults to 0, respects explicit range.
var esc = new five.ESC(12);
esc.min();
Or
var esc = new five.ESC({
pin: 12,
pwmRange: [ 1000, 1900 ]
});
esc.min();
- max() Set ESC to maximum speed. Defaults to 1, respects explicit range.
var esc = new five.ESC(12);
esc.max();
Or
var esc = new five.ESC({
pin: 12,
range: [ 1000, 1900 ]
});
esc.max();
- stop() Stop a moving esc.
var esc = new five.ESC(12);
esc.stop();
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() {
}